Skip to content

Commit

Permalink
Faker::Internet.user_name can't handle UTF-8 arguments (faker-ruby#1421)
Browse files Browse the repository at this point in the history
* test: covered bug

* fix: passed

* fix: typo

* Minor fix

* Fix test_username_with_utf_8_arg - Faker::Internet.user_name

* Add comment above test_username_with_utf_8_arg

* Update test_faker_internet.rb
  • Loading branch information
ivanoblomov authored and vbrazo committed Oct 19, 2018
1 parent 8dd9660 commit 977fa68
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -21,7 +21,7 @@ def safe_email(name = nil)

def username(specifier = nil, separators = %w[. _])
with_locale(:en) do
return shuffle(specifier.scan(/\w+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)

if specifier.is_a?(Integer)
# If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
Expand Down
9 changes: 9 additions & 0 deletions test/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def test_username_with_integer_arg
end
end

def test_username_with_utf_8_arg
# RUBY_VERSION < '2.4.0' is not able to downcase or upcase non-ascii strings
if RUBY_VERSION < '2.4.0'
assert @tester.username('Łucja').match('Łucja')
else
assert @tester.username('Łucja').match('łucja')
end
end

def test_username_with_very_large_integer_arg
exception = assert_raises(ArgumentError) { @tester.username(10_000_000) }
assert_equal('Given argument is too large', exception.message)
Expand Down

0 comments on commit 977fa68

Please sign in to comment.