faker 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/lib/faker.rb +12 -1
- data/lib/faker/internet.rb +4 -0
- data/lib/faker/version.rb +1 -1
- data/test/test_faker_internet.rb +4 -0
- data/test/test_faker_street.rb +6 -0
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
== 1.0.
|
1
|
+
== 1.0.1 2011-09-27
|
2
|
+
* 1 minor enhancement
|
3
|
+
* Added safe_email method to get someaddress@example.com [Kazimierz Kiełkowicz]
|
4
|
+
* 1 bug fix:
|
5
|
+
* Use the locale fallback properly when parsing string formats
|
6
|
+
|
7
|
+
== 1.0.0 2011-09-08
|
2
8
|
* 2 major enhancements
|
3
9
|
* Moved all formats to locale files
|
4
10
|
* Stopped interfering with I18n's global settings for fallbacks
|
data/lib/faker.rb
CHANGED
@@ -47,7 +47,18 @@ module Faker
|
|
47
47
|
# into method calls that can be used to generate a
|
48
48
|
# formatted translation: e.g., "#{first_name} #{last_name}".
|
49
49
|
def parse(key)
|
50
|
-
fetch(key).scan(/#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|kls, meth, etc|
|
50
|
+
fetch(key).scan(/#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|kls, meth, etc|
|
51
|
+
# If the token had a class Prefix (e.g., Name.first_name)
|
52
|
+
# grab the constant, otherwise use self
|
53
|
+
cls = kls ? Faker.const_get(kls.chop) : self
|
54
|
+
|
55
|
+
# If the class has the method, call it, otherwise
|
56
|
+
# fetch the transation (i.e., faker.name.first_name)
|
57
|
+
text = cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}")
|
58
|
+
|
59
|
+
# And tack on spaces, commas, etc. left over in the string
|
60
|
+
text += etc.to_s
|
61
|
+
}.join
|
51
62
|
end
|
52
63
|
|
53
64
|
# Call I18n.translate with our configured locale if no
|
data/lib/faker/internet.rb
CHANGED
@@ -10,6 +10,10 @@ module Faker
|
|
10
10
|
[ user_name(name), fetch('internet.free_email') ].join('@')
|
11
11
|
end
|
12
12
|
|
13
|
+
def safe_email(name = nil)
|
14
|
+
[user_name(name), 'example.'+ %w[org com net].shuffle.first].join('@')
|
15
|
+
end
|
16
|
+
|
13
17
|
def user_name(name = nil)
|
14
18
|
return name.scan(/\w+/).shuffle.join(%w(. _).sample).downcase if name
|
15
19
|
|
data/lib/faker/version.rb
CHANGED
data/test/test_faker_internet.rb
CHANGED
@@ -14,6 +14,10 @@ class TestFakerInternet < Test::Unit::TestCase
|
|
14
14
|
assert @tester.free_email.match(/.+@(gmail|hotmail|yahoo)\.com/)
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_safe_email
|
18
|
+
assert @tester.safe_email.match(/.+@example.(com|net|org)/)
|
19
|
+
end
|
20
|
+
|
17
21
|
def test_user_name
|
18
22
|
assert @tester.user_name.match(/[a-z]+((_|\.)[a-z]+)?/)
|
19
23
|
end
|
data/test/test_faker_street.rb
CHANGED
@@ -35,4 +35,10 @@ class TestFakerStreet < Test::Unit::TestCase
|
|
35
35
|
assert_match(/Wide Cheerful Path \d \(Green Door\)/, Faker::Address.street_address(:include_secondary))
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
def test_street_address_with_locale_fallback
|
40
|
+
I18n.with_locale('en-gb') do
|
41
|
+
assert_match(/^\d+ \w+ \w+/, Faker::Address.street_address)
|
42
|
+
end
|
43
|
+
end
|
38
44
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Curtis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-27 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|