mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
core/doc: make sure name is usable as slug.
This commit is contained in:
parent
c01782a02e
commit
b36f3f8095
2 changed files with 16 additions and 1 deletions
|
@ -48,7 +48,10 @@ module Docs
|
|||
end
|
||||
|
||||
def slug
|
||||
slug = @slug || name.try(:downcase)
|
||||
slug = @slug || (
|
||||
raise "Slug must be set explicitly when name (#{name}) consists of anything else than [\\w\\.%]" if /[^\w\.%]/ =~ name
|
||||
name.try(:downcase)
|
||||
)
|
||||
version? ? "#{slug}~#{version_slug}" : slug
|
||||
end
|
||||
|
||||
|
|
|
@ -55,6 +55,18 @@ class DocsDocTest < MiniTest::Spec
|
|||
doc.version = '42'
|
||||
assert_equal 'foo~42', doc.slug
|
||||
end
|
||||
|
||||
it "returns 'foobar' when #name has been set to 'FooBar'" do
|
||||
doc.name = 'FooBar'
|
||||
assert_equal 'foobar', doc.slug
|
||||
end
|
||||
|
||||
it "raises error when #name has unsluggable characters" do
|
||||
assert_raises do
|
||||
doc.name = 'Foo-Bar'
|
||||
doc.slug
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".slug=" do
|
||||
|
|
Loading…
Reference in a new issue