Skip to content

Commit

Permalink
Fix Faker::Internet.ip_v4_address to include all IP ranges (faker-rub…
Browse files Browse the repository at this point in the history
…y#1494)

* Change ip_v4 generator to use 0..255 range for all octects

* Add test for minimum ip address range
  • Loading branch information
lucasqueiroz authored and vbrazo committed Dec 16, 2018
1 parent 73c0a66 commit a254ec6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def mac_address(prefix = '')
end

def ip_v4_address
ary = (2..254).to_a
[sample(ary), sample(ary), sample(ary), sample(ary)].join('.')
[rand_in_range(0, 255), rand_in_range(0, 255),
rand_in_range(0, 255), rand_in_range(0, 255)].join('.')
end

def private_ip_v4_address
Expand Down
1 change: 1 addition & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_ip_v4_address
assert_equal 3, @tester.ip_v4_address.count('.')

100.times do
assert @tester.ip_v4_address.split('.').map(&:to_i).min >= 0
assert @tester.ip_v4_address.split('.').map(&:to_i).max <= 255
end
end
Expand Down

0 comments on commit a254ec6

Please sign in to comment.