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

Allow subdomains for Internet.domain_name #1520

Merged
merged 3 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/default/internet.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Faker::Internet.password(10, 20, true) #=> "3k5qS15aNmG"

Faker::Internet.password(10, 20, true, true) #=> "*%NkOnJsH4"

# Optional arguments: subdomain=true
Faker::Internet.domain_name #=> "effertz.info"

Faker::Internet.domain_word #=> "haleyziemann"
Expand Down
8 changes: 6 additions & 2 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ def password(min_length = 8, max_length = 16, mix_case = true, special_chars = f
temp
end

def domain_name
with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
def domain_name(subdomain = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation should be updated to include this new param

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SpyMaster356 No problem, have done that and updated the PR

with_locale(:en) do
domain_elements = [Char.prepare(domain_word), domain_suffix]
domain_elements.unshift(Char.prepare(domain_word)) if subdomain
domain_elements.join('.')
end
end

def fix_umlauts(string = '')
Expand Down
6 changes: 5 additions & 1 deletion test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ def test_password_without_special_chars
assert @tester.password(8, 12, true).match(/[^!@#\$%\^&\*]+/)
end

def test_domain_name
def test_domain_name_without_subdomain
assert @tester.domain_name.match(/\w+\.\w+/)
end

def test_domain_name_with_subdomain
assert @tester.domain_name(true).match(/\w+\.\w+\.\w+/)
end

def test_domain_word
assert @tester.domain_word.match(/^\w+$/)
end
Expand Down