1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00

Merge pull request #15 from jinn999/fix-issue-10-internet-user-name

Fix issue 10 internet user name
This commit is contained in:
Aşkın Gedik 2021-03-18 00:13:35 +03:00 committed by GitHub
commit 77ec8b25f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 24 deletions

View File

@ -169,32 +169,32 @@ describe Faker::Internet do
it "should return deterministic results when seeded" do it "should return deterministic results when seeded" do
Faker.seed 123456 Faker.seed 123456
Faker::Internet.email.should eq "faker_internet@deckowboyer.biz" Faker::Internet.email.should eq "danyka.gleichner@fay.net"
Faker::Internet.email("Nancy").should eq "nancy@batz.org" Faker::Internet.email("Nancy").should eq "nancy@barrows.name"
Faker::Internet.free_email.should eq "internet.faker@hotmail.com" Faker::Internet.free_email.should eq "dayne_brown@hotmail.com"
Faker::Internet.free_email("Nancy").should eq "nancy@yahoo.com" Faker::Internet.free_email("Nancy").should eq "nancy@yahoo.com"
Faker::Internet.safe_email.should eq "internet_faker@example.org" Faker::Internet.safe_email.should eq "cassie@example.net"
Faker::Internet.safe_email("Nancy").should eq "nancy@example.com" Faker::Internet.safe_email("Nancy").should eq "nancy@example.org"
Faker::Internet.user_name.should eq "internet.faker" Faker::Internet.user_name.should eq "eve_batz"
Faker::Internet.user_name("Nancy").should eq "nancy" Faker::Internet.user_name("Nancy").should eq "nancy"
Faker::Internet.user_name("Nancy Johnson", [".", "_", "-"] of ::String).should eq "nancy-johnson" Faker::Internet.user_name("Nancy Johnson", [".", "_", "-"] of ::String).should eq "nancy-johnson"
Faker::Internet.password.should eq "NuSjR9XpA" Faker::Internet.password.should eq "P2AtB7Vm"
Faker::Internet.password(8).should eq "Tb7vMjXzD" Faker::Internet.password(8).should eq "XzKdXc0qG"
Faker::Internet.password(10, 20).should eq "Xc0qFgOxMo" Faker::Internet.password(10, 20).should eq "Vj9gVt6lDlQ"
Faker::Internet.password(10, 20, true).should eq "J9GvT6LdLd7" Faker::Internet.password(10, 20, true).should eq "7c2s0zXmQlT"
Faker::Internet.password(10, 20, true, true).should eq "#*^!#&@%^iG" Faker::Internet.password(10, 20, true, true).should eq "@6IpGuR8PvG"
Faker::Internet.domain_name.should eq "hackett.net" Faker::Internet.domain_name.should eq "beatty.io"
Faker::Internet.domain_word.should eq "murphy" Faker::Internet.domain_word.should eq "veum"
Faker::Internet.domain_suffix.should eq "co" Faker::Internet.domain_suffix.should eq "io"
Faker::Internet.ip_v4_address.should eq "38.54.91.207" Faker::Internet.ip_v4_address.should eq "230.101.43.38"
Faker::Internet.ip_v6_address.should eq "f682:cc5a:cb38:94d3:7911:ff68:94df:f377" Faker::Internet.ip_v6_address.should eq "a970:ba8b:26b8:f682:cc5a:cb38:94d3:7911"
Faker::Internet.mac_address.should eq "00:d0:57:d9:d8:d5" Faker::Internet.mac_address.should eq "00:68:df:77:d0:57"
Faker::Internet.mac_address("55:44:33").should eq "55:44:33:bc:fd:c8" Faker::Internet.mac_address("55:44:33").should eq "55:44:33:d9:d8:d5"
Faker::Internet.url.should eq "http://vonruedenlind.name/faker_internet" Faker::Internet.url.should eq "http://raugottlieb.com/mia_hills"
Faker::Internet.url("example.com").should eq "http://example.com/internet_faker" Faker::Internet.url("example.com").should eq "http://example.com/daron_nolan"
Faker::Internet.url("example.com", "/foobar.html").should eq "http://example.com/foobar.html" Faker::Internet.url("example.com", "/foobar.html").should eq "http://example.com/foobar.html"
Faker::Internet.slug.should eq "mollitia.nostrum" Faker::Internet.slug.should eq "doloribus_quidem"
Faker::Internet.slug("foo bar").should eq "foo.bar" Faker::Internet.slug("foo bar").should eq "foo_bar"
Faker::Internet.slug("foo bar", "-").should eq "foo-bar" Faker::Internet.slug("foo bar", "-").should eq "foo-bar"
end end
end end

View File

@ -46,7 +46,6 @@ module Faker
return result[0...specifier.max] return result[0...specifier.max]
end end
return name.scan(/\w+/).shuffle(Faker.rng).map(&.[0]).join(separators.sample(Faker.rng)).downcase if name
[ [
->{ Name.first_name.gsub(/\W/, "").downcase }, ->{ Name.first_name.gsub(/\W/, "").downcase },
->{ ->{
@ -132,7 +131,8 @@ module Faker
if special_chars if special_chars
chars = %w(! @ # $ % ^ & *) chars = %w(! @ # $ % ^ & *)
Faker.rng.rand(min_length).times do |i| number_of_substitutions = Faker.rng.rand(min_length - 1) + 1 # substitute at least one character
number_of_substitutions.times do |i|
temp = temp.sub({temp[i] => chars[Faker.rng.rand(chars.size)]}) temp = temp.sub({temp[i] => chars[Faker.rng.rand(chars.size)]})
end end
end end