From 687ad53e046fb9e39bfd8546092b710f57ec9557 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Fri, 8 Nov 2013 16:58:37 +0000 Subject: [PATCH 1/2] Test to confirm user_name with range and separators --- test/test_faker_internet.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_faker_internet.rb b/test/test_faker_internet.rb index 88553a0d71..2708945cd8 100644 --- a/test/test_faker_internet.rb +++ b/test/test_faker_internet.rb @@ -52,6 +52,15 @@ def test_user_name_with_open_range_arg end end + def test_user_name_with_range_and_separators + (1..32).each do |min_length| + (min_length+1..33).each do |max_length| + u = @tester.user_name((min_length...max_length), %w(=)) + assert u.length.between? min_length, max_length-1 + assert u.match(/\A[a-z]+((=)?[a-z]*)*\z/) + end + end + end def test_password assert @tester.password.match(/\w{3}/) From ef28febbfe2b86d4638a1e8686396e7f6e07bd8a Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Fri, 8 Nov 2013 16:59:01 +0000 Subject: [PATCH 2/2] Support user_name with range and separators --- lib/faker/internet.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/faker/internet.rb b/lib/faker/internet.rb index ba368e050c..920806a768 100644 --- a/lib/faker/internet.rb +++ b/lib/faker/internet.rb @@ -20,7 +20,7 @@ def user_name(specifier = nil, separators = %w(. _)) elsif specifier.kind_of? Integer tries = 0 # Don't try forever in case we get something like 1_000_000. begin - result = user_name + result = user_name nil, separators tries += 1 end while result.length < specifier and tries < 7 until result.length >= specifier @@ -30,7 +30,7 @@ def user_name(specifier = nil, separators = %w(. _)) elsif specifier.kind_of? Range tries = 0 begin - result = user_name specifier.min + result = user_name specifier.min, separators tries += 1 end while not specifier.include? result.length and tries < 7 return result[0...specifier.max]