Skip to content

Commit

Permalink
Allow subdomains for Internet.domain_name
Browse files Browse the repository at this point in the history
  • Loading branch information
ciano committed Jan 30, 2019
1 parent fcbfaa2 commit 5db4de0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/faker/default/internet.rb
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)
with_locale(:en) do
domain_elements = [Char.prepare(domain_word), domain_suffix]
domain_elements.prepend(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
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

0 comments on commit 5db4de0

Please sign in to comment.