Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Username splits names by space and doesn't regex match them #2950

Merged
merged 9 commits into from
May 28, 2024
7 changes: 6 additions & 1 deletion lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def email(name: nil, separators: nil, domain: nil)
# Faker::Internet.username(specifier: 20, separators: ['_']) #=> "nikki_sawaynnikki_saway"
def username(specifier: nil, separators: %w[. _])
with_locale(:en) do
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
if specifier.respond_to?(:scan)
keshavbiswa marked this conversation as resolved.
Show resolved Hide resolved
keshavbiswa marked this conversation as resolved.
Show resolved Hide resolved
names = specifier&.split
shuffled_names = shuffle(names)

return shuffled_names.join(sample(separators)).downcase
end

case specifier
when Integer
Expand Down
4 changes: 4 additions & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def test_username
assert_match(/[a-z]+((_|\.)[a-z]+)?/, @tester.username)
end

def test_username_with_apostrophes
assert_match(/\A[a-z']+([_.][a-z']+)*\z/, @tester.username(specifier: "Alexis O'Connell"))
keshavbiswa marked this conversation as resolved.
Show resolved Hide resolved
end

def test_user_name_alias
assert_equal @tester.method(:username), @tester.method(:user_name)
end
Expand Down
2 changes: 1 addition & 1 deletion test/faker/default/test_faker_omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def test_omniauth_linkedin
end

def test_omniauth_linkedin_with_name
keshavbiswa marked this conversation as resolved.
Show resolved Hide resolved
custom_name = 'Happy Gilmore'
custom_name = "Alexis O'Connell"
first_name, last_name = custom_name.split
auth = @tester.linkedin(name: custom_name)
info = auth[:info]
Expand Down
Loading