phony_rails 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/phony_rails.rb +12 -0
- data/lib/phony_rails/locales/km.yml +4 -0
- data/lib/phony_rails/version.rb +1 -1
- data/phony_rails.gemspec +1 -1
- data/spec/lib/phony_rails_spec.rb +41 -0
- data/spec/lib/validators/phony_validator_spec.rb +8 -0
- metadata +5 -4
data/Gemfile.lock
CHANGED
@@ -4,7 +4,7 @@ PATH
|
|
4
4
|
phony_rails (0.8.2)
|
5
5
|
activesupport (>= 3.0)
|
6
6
|
countries (>= 0.8.2)
|
7
|
-
phony (~> 2.
|
7
|
+
phony (~> 2.10.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -71,7 +71,7 @@ GEM
|
|
71
71
|
nenv (0.1.1)
|
72
72
|
optionable (0.2.0)
|
73
73
|
origin (2.1.1)
|
74
|
-
phony (2.
|
74
|
+
phony (2.10.1)
|
75
75
|
pry (0.10.1)
|
76
76
|
coderay (~> 1.1.0)
|
77
77
|
method_source (~> 0.8.1)
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ so we can use:
|
|
87
87
|
validates_plausible_phone :phone_number, :without => /^\+\d+/
|
88
88
|
validates_plausible_phone :phone_number, :presence => true, :with => /^\+\d+/
|
89
89
|
|
90
|
-
the i18n key is `:improbable_phone
|
90
|
+
the i18n key is `:improbable_phone`. Languages supported by default: de, en, fr, it, ja, kh and tr.
|
91
91
|
|
92
92
|
You can also validate if a number has the correct country number:
|
93
93
|
|
data/lib/phony_rails.rb
CHANGED
@@ -35,6 +35,18 @@ module PhonyRails
|
|
35
35
|
number # If all goes wrong .. we still return the original input.
|
36
36
|
end
|
37
37
|
|
38
|
+
# Wrapper for Phony.plausible?. Takes the same options as #normalize_number.
|
39
|
+
# NB: This method calls #normalize_number and passes _options_ directly to that method.
|
40
|
+
def self.plausible_number?(number, options = {})
|
41
|
+
return false if number.nil? || number.blank?
|
42
|
+
number = normalize_number(number, options)
|
43
|
+
country_number = options[:country_number] || country_number_for(options[:country_code]) ||
|
44
|
+
default_country_number = options[:default_country_number] || country_number_for(options[:default_country_code])
|
45
|
+
Phony.plausible? number, cc: country_number
|
46
|
+
rescue
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
38
50
|
module Extension
|
39
51
|
extend ActiveSupport::Concern
|
40
52
|
|
data/lib/phony_rails/version.rb
CHANGED
data/phony_rails.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = PhonyRails::VERSION
|
18
18
|
|
19
|
-
gem.add_dependency "phony", "~> 2.
|
19
|
+
gem.add_dependency "phony", "~> 2.10.1"
|
20
20
|
gem.add_dependency "countries", ">= 0.8.2"
|
21
21
|
gem.add_dependency "activesupport", ">= 3.0"
|
22
22
|
gem.add_development_dependency "activerecord", ">= 3.0"
|
@@ -184,6 +184,47 @@ describe PhonyRails do
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
+
describe 'PhonyRails#plausible_number?' do
|
188
|
+
let(:valid_number) { '1 555 555 5555' }
|
189
|
+
let(:invalid_number) { '123456789 123456789 123456789 123456789' }
|
190
|
+
let(:normalizable_number) { '555 555 5555' }
|
191
|
+
let(:formatted_french_number_with_country_code) { '+33 627899541' }
|
192
|
+
let(:empty_number) { '' }
|
193
|
+
let(:nil_number) { nil }
|
194
|
+
|
195
|
+
it "should return true for a valid number" do
|
196
|
+
PhonyRails.plausible_number?(valid_number, country_code: 'US').should be_true
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should return false for an invalid number" do
|
200
|
+
PhonyRails.plausible_number?(invalid_number, country_code: 'US').should be_false
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return true for a normalizable number" do
|
204
|
+
PhonyRails.plausible_number?(normalizable_number, country_code: 'US').should be_true
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return false for a valid number with the wrong country code" do
|
208
|
+
PhonyRails.plausible_number?(valid_number, country_code: 'FR').should be_false
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should return true for a well formatted valid number" do
|
212
|
+
PhonyRails.plausible_number?(formatted_french_number_with_country_code, country_code: 'FR').should be_true
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should return false for an empty number" do
|
216
|
+
PhonyRails.plausible_number?(empty_number, country_code: 'US').should be_false
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should return false for a nil number" do
|
220
|
+
PhonyRails.plausible_number?(nil_number, country_code: 'US').should be_false
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should return false when no country code is supplied" do
|
224
|
+
PhonyRails.plausible_number?(normalizable_number).should be_false
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
187
228
|
shared_examples_for 'model with PhonyRails' do
|
188
229
|
describe 'defining model#phony_normalized_method' do
|
189
230
|
it "should add a normalized_phone_attribute method" do
|
@@ -170,6 +170,14 @@ describe PhonyPlausibleValidator do
|
|
170
170
|
@home.errors.messages.should include(:phone_number => ["は正し電話番号ではありません"])
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
it "should translate the error message in Khmer" do
|
175
|
+
I18n.with_locale(:km) do
|
176
|
+
@home.phone_number = INVALID_NUMBER
|
177
|
+
@home.valid?
|
178
|
+
@home.errors.messages.should include(:phone_number => ["គឺជាលេខមិនត្រឹមត្រូវ"])
|
179
|
+
end
|
180
|
+
end
|
173
181
|
end
|
174
182
|
end
|
175
183
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: phony
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
21
|
+
version: 2.10.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 2.10.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: countries
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/phony_rails/locales/fr.yml
|
114
114
|
- lib/phony_rails/locales/it.yml
|
115
115
|
- lib/phony_rails/locales/ja.yml
|
116
|
+
- lib/phony_rails/locales/km.yml
|
116
117
|
- lib/phony_rails/locales/tr.yml
|
117
118
|
- lib/phony_rails/string_extensions.rb
|
118
119
|
- lib/phony_rails/version.rb
|