Skip to content

Commit

Permalink
Allow subdomains for Internet.domain_name (faker-ruby#1520)
Browse files Browse the repository at this point in the history
* Allow subdomains for Internet.domain_name

* Update CHANGELOG.md
  • Loading branch information
cianooooo authored and vbrazo committed Feb 14, 2019
1 parent fa69de5 commit 7199e66
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@
### Feature Request

- [PR #1537](https://github.com/stympy/faker/pull/1537) Adds the Faker::Sports::Basketball generator [@ecbrodie](https://github.com/ecbrodie)
- [PR #1520](https://github.com/stympy/faker/pull/1520) Allow subdomains for Internet.domain_name [@cianooooo](https://github.com/cianooooo)

### Suggestion

Expand Down
1 change: 1 addition & 0 deletions doc/default/internet.md
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
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.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
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 7199e66

Please sign in to comment.