Skip to content

Commit

Permalink
Modify Faker::Internet.slug (#1136)
Browse files Browse the repository at this point in the history
* Modify Modify Faker::Internet.slug

Before: slug('Something Co., Ltd.','-')
 => "something-co.,-ltd."

After: slug('Something Co., Ltd.','-')
 => "something-co-ltd"

* Add test for unwanted slug content i.e. extraneous commas and full stops.
  • Loading branch information
philduffen authored and vbrazo committed May 15, 2018
1 parent 448cc4f commit 4482309
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faker/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def url(host = domain_name, path = "/#{user_name}", scheme = 'http')

def slug(words = nil, glue = nil)
glue ||= sample(%w[- _ .])
(words || Faker::Lorem.words(2).join(' ')).gsub(' ', glue).downcase
(words || Faker::Lorem::words(2).join(' ')).delete(',.').gsub(' ', glue).downcase
end

def device_token
Expand Down
4 changes: 4 additions & 0 deletions test/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def test_slug_with_content_arg
assert @tester.slug('Foo bAr baZ').match(/^foo(_|\.|\-)bar(_|\.|\-)baz$/)
end

def test_slug_with_unwanted_content_arg
assert @tester.slug('Foo.. bAr., baZ,,').match(/^foo(_|\.|\-)bar(_|\.|\-)baz$/)
end

def test_slug_with_glue_arg
assert @tester.slug(nil, '+').match(/^[a-z]+\+[a-z]+$/)
end
Expand Down

0 comments on commit 4482309

Please sign in to comment.