core/doc: make sure name is usable as slug.

This commit is contained in:
Andreas Stenius 2017-01-18 11:43:52 +01:00 committed by Thibaut Courouble
parent c01782a02e
commit b36f3f8095
2 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -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