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

Makes minor refactors on Internet.domain_name method #1847

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,19 @@ def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false, domain: nil)
end

with_locale(:en) do
domain_elements = []

if domain
domain.split('.').each do |domain_part|
domain_elements << Char.prepare(domain_part)
end
domain_elements << domain_suffix if domain_elements.length < 2
domain_elements.unshift(Char.prepare(domain_word)) if subdomain && domain_elements.length < 3
domain
.split('.')
.map { |domain_part| Char.prepare(domain_part) }
.tap do |domain_elements|
domain_elements << domain_suffix if domain_elements.length < 2
domain_elements.unshift(Char.prepare(domain_word)) if subdomain && domain_elements.length < 3
end.join('.')
else
domain_elements << domain_word
domain_elements << domain_suffix
domain_elements.unshift(Char.prepare(domain_word)) if subdomain
[domain_word, domain_suffix].tap do |domain_elements|
domain_elements.unshift(Char.prepare(domain_word)) if subdomain
end.join('.')
end

domain_elements.join('.')
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_domain_name_with_subdomain_and_with_domain_option_given
assert @tester.domain_name(subdomain: true, domain: 'customdomain').match(/customdomain\.\w+/)
end

def test_domain_name_with_subdomain_and_with_domain_option_given_with_domain_suffixc
def test_domain_name_with_subdomain_and_with_domain_option_given_with_domain_suffix
assert @tester.domain_name(subdomain: true, domain: 'customdomain.customdomainsuffix').match(/customdomain\.customdomainsuffix/)
end

Expand Down