phony_rails 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phony_rails (0.3.2)
4
+ phony_rails (0.4.1)
5
5
  activesupport (>= 3.0)
6
6
  countries (>= 0.8.2)
7
7
  phony (>= 1.7.7)
@@ -9,24 +9,24 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (3.2.13)
13
- activesupport (= 3.2.13)
12
+ activemodel (3.2.14)
13
+ activesupport (= 3.2.14)
14
14
  builder (~> 3.0.0)
15
- activerecord (3.2.13)
16
- activemodel (= 3.2.13)
17
- activesupport (= 3.2.13)
15
+ activerecord (3.2.14)
16
+ activemodel (= 3.2.14)
17
+ activesupport (= 3.2.14)
18
18
  arel (~> 3.0.2)
19
19
  tzinfo (~> 0.3.29)
20
- activesupport (3.2.13)
21
- i18n (= 0.6.1)
20
+ activesupport (3.2.14)
21
+ i18n (~> 0.6, >= 0.6.4)
22
22
  multi_json (~> 1.0)
23
23
  arel (3.0.2)
24
24
  builder (3.0.4)
25
- countries (0.8.4)
25
+ countries (0.9.2)
26
26
  currencies (>= 0.4.0)
27
- currencies (0.4.0)
27
+ currencies (0.4.2)
28
28
  diff-lcs (1.1.3)
29
- ffi (1.1.0)
29
+ ffi (1.9.0)
30
30
  growl (1.0.3)
31
31
  guard (1.2.3)
32
32
  listen (>= 0.4.2)
@@ -34,38 +34,38 @@ GEM
34
34
  guard-bundler (1.0.0)
35
35
  bundler (~> 1.0)
36
36
  guard (~> 1.1)
37
- guard-rspec (1.2.0)
37
+ guard-rspec (1.2.1)
38
38
  guard (>= 1.1)
39
- i18n (0.6.1)
40
- listen (0.4.7)
41
- rb-fchange (~> 0.0.5)
42
- rb-fsevent (~> 0.9.1)
43
- rb-inotify (~> 0.8.8)
39
+ i18n (0.6.5)
40
+ listen (1.3.0)
41
+ rb-fsevent (>= 0.9.3)
42
+ rb-inotify (>= 0.9)
43
+ rb-kqueue (>= 0.2)
44
44
  mongoid (3.1.4)
45
45
  activemodel (~> 3.2)
46
46
  moped (~> 1.4)
47
47
  origin (~> 1.0)
48
48
  tzinfo (~> 0.3.22)
49
- moped (1.5.0)
50
- multi_json (1.7.2)
49
+ moped (1.5.1)
50
+ multi_json (1.7.9)
51
51
  origin (1.1.0)
52
52
  phony (1.9.0)
53
- rake (10.0.3)
54
- rb-fchange (0.0.5)
55
- ffi
56
- rb-fsevent (0.9.1)
57
- rb-inotify (0.8.8)
53
+ rake (10.1.0)
54
+ rb-fsevent (0.9.3)
55
+ rb-inotify (0.9.1)
56
+ ffi (>= 0.5.0)
57
+ rb-kqueue (0.2.0)
58
58
  ffi (>= 0.5.0)
59
59
  rspec (2.11.0)
60
60
  rspec-core (~> 2.11.0)
61
61
  rspec-expectations (~> 2.11.0)
62
62
  rspec-mocks (~> 2.11.0)
63
63
  rspec-core (2.11.1)
64
- rspec-expectations (2.11.1)
64
+ rspec-expectations (2.11.3)
65
65
  diff-lcs (~> 1.1.3)
66
- rspec-mocks (2.11.1)
67
- sqlite3 (1.3.6)
68
- thor (0.15.4)
66
+ rspec-mocks (2.11.3)
67
+ sqlite3 (1.3.8)
68
+ thor (0.18.1)
69
69
  tzinfo (0.3.37)
70
70
 
71
71
  PLATFORMS
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  (In its early days :) called PhonyNumber)
4
4
 
5
- This Gem adds useful methods to your Rails app to validate, display and save phone numbers.
5
+ This small Gem adds useful methods to your Rails app to validate, display and save phone numbers.
6
6
  It uses the super awesome Phony gem (https://github.com/floere/phony).
7
7
 
8
8
  ## Installation
@@ -84,6 +84,10 @@ so we can use:
84
84
 
85
85
  the i18n key is `:improbable_phone`
86
86
 
87
+ You can also validate if a number has the correct country code:
88
+
89
+ validates_plausible_phone :phone_number, :country_code => '61'
90
+
87
91
  ### Display / Views
88
92
 
89
93
  In your views use:
@@ -94,12 +98,12 @@ In your views use:
94
98
 
95
99
  To first normalize the String to a certain country use:
96
100
 
97
- <%= "010-12341234".phony_formatted(normalize => :NL, :format => :international, :spaces => '-') %>
101
+ <%= "010-12341234".phony_formatted(:normalize => :NL, :format => :international, :spaces => '-') %>
98
102
 
99
103
  You can also use the bang method (phony_formatted!):
100
104
 
101
105
  number = "010-12341234"
102
- number.phony_formatted!(normalize => :NL, :format => :international)
106
+ number.phony_formatted!(:normalize => :NL, :format => :international)
103
107
  number # => "+31 10 12341234"
104
108
 
105
109
  ### Find by normalized number
@@ -110,15 +114,18 @@ Say you want to find a record by a phone number. Best is to normalize user input
110
114
 
111
115
  ## Changelog
112
116
 
117
+ 0.4.2
118
+ * Added @fareastside validation for country_code.
119
+
113
120
  0.4.0/0.4.1
114
- * Better Mongoid support by @johnnyshields
121
+ * Better Mongoid support by @johnnyshields.
115
122
 
116
123
  0.3.0
117
124
  * Now ability to force change a country_code.
118
125
  See: https://github.com/joost/phony_rails/pull/23#issuecomment-17480463
119
126
 
120
127
  0.2.1
121
- * Better error handling by @k4nar
128
+ * Better error handling by @k4nar.
122
129
 
123
130
  0.1.12
124
131
  * Further loosened gemspec dependencies.
@@ -175,4 +182,4 @@ Say you want to find a record by a phone number. Best is to normalize user input
175
182
  4. Push to the branch (`git push origin my-new-feature`)
176
183
  5. Create new Pull Request
177
184
 
178
- Thanks to all contributors: ddidier, brutuscat, henning-koch.
185
+ Don't forget to add tests and run rspec before creating a pull request :)
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -6,7 +6,7 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
6
6
  # Validates a String using Phony.plausible? method.
7
7
  def validate_each(record, attribute, value)
8
8
  return if value.blank?
9
- record.errors.add(attribute, options[:message] || :improbable_phone) if not Phony.plausible?(value)
9
+ record.errors.add(attribute, options[:message] || :improbable_phone) if not Phony.plausible?(value, cc: options[:country_code])
10
10
  end
11
11
 
12
12
  end
@@ -34,6 +34,10 @@ ActiveRecord::Schema.define do
34
34
  create_table :big_helpful_homes do |table|
35
35
  table.column :phone_number, :string
36
36
  end
37
+
38
+ create_table :australian_helpful_homes do |table|
39
+ table.column :phone_number, :string
40
+ end
37
41
  end
38
42
 
39
43
  #--------------------
@@ -72,10 +76,16 @@ class NotFormattedHelpfulHome < ActiveRecord::Base
72
76
  validates_plausible_phone :phone_number, :without => /^\+\d+/
73
77
  end
74
78
 
79
+ #--------------------
80
+ class AustralianHelpfulHome < ActiveRecord::Base
81
+ attr_accessor :phone_number
82
+ validates_plausible_phone :phone_number, :country_code => "61"
83
+ end
84
+
75
85
  #--------------------
76
86
  class BigHelpfulHome < ActiveRecord::Base
77
87
  attr_accessor :phone_number
78
- validates_plausible_phone :phone_number, :presence => true, :with => /^\+\d+/
88
+ validates_plausible_phone :phone_number, :presence => true, :with => /^\+\d+/, :country_code => "33"
79
89
  end
80
90
 
81
91
  #-----------------------------------------------------------------------------------------------------------------------
@@ -83,7 +93,11 @@ end
83
93
  #-----------------------------------------------------------------------------------------------------------------------
84
94
 
85
95
  I18n.locale = :en
86
- VALID_NUMBER = '123456789'
96
+ VALID_NUMBER = '1234567890'
97
+ AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '61390133997'
98
+ FORMATTED_AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '+61 390133997'
99
+ FRENCH_NUMBER_WITH_COUNTRY_CODE = '330627899541'
100
+ FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE = '+33 0627899541'
87
101
  INVALID_NUMBER = '123456789 123456789 123456789 123456789'
88
102
 
89
103
  #-----------------------------------------------------------------------------------------------------------------------
@@ -265,6 +279,71 @@ describe ActiveModel::Validations::HelperMethods do
265
279
 
266
280
  end
267
281
 
282
+ #--------------------
283
+ context 'when a number must include a specific country code' do
284
+
285
+ before(:each) do
286
+ @home = AustralianHelpfulHome.new
287
+ end
288
+
289
+ it "should validate an empty number" do
290
+ @home.should be_valid
291
+ end
292
+
293
+ it "should validate a valid number with the right country code" do
294
+ @home.phone_number = AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE
295
+ @home.should be_valid
296
+ end
297
+
298
+ it "should invalidate a valid number with the wrong country code" do
299
+ @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
300
+ @home.should_not be_valid
301
+ @home.errors.messages.should include(:phone_number => ["is an invalid number"])
302
+ end
303
+
304
+ it "should invalidate a valid number without a country code" do
305
+ @home.phone_number = VALID_NUMBER
306
+ @home.should_not be_valid
307
+ @home.errors.messages.should include(:phone_number => ["is an invalid number"])
308
+ end
309
+
310
+ end
311
+
312
+ context 'when lots of things are being validated simultaneously' do
313
+
314
+ before(:each) do
315
+ @home = BigHelpfulHome.new
316
+ end
317
+
318
+ it "should invalidate an empty number" do
319
+ @home.should_not be_valid
320
+ end
321
+
322
+ it "should invalidate an invalid number" do
323
+ @home.phone_number = INVALID_NUMBER
324
+ @home.should_not be_valid
325
+ @home.errors.messages[:phone_number].should include "is an invalid number"
326
+ end
327
+
328
+ it "should invalidate a badly formatted number with the right country code" do
329
+ @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
330
+ @home.should_not be_valid
331
+ @home.errors.messages[:phone_number].should include "is invalid"
332
+ end
333
+
334
+ it "should invalidate a properly formatted number with the wrong country code" do
335
+ @home.phone_number = FORMATTED_AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE
336
+ @home.should_not be_valid
337
+ @home.errors.messages[:phone_number].should include "is an invalid number"
338
+ end
339
+
340
+ it "should validate a properly formatted number with the right country code" do
341
+ @home.phone_number = FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE
342
+ @home.should be_valid
343
+ end
344
+
345
+ end
346
+
268
347
  end
269
348
 
270
349
  end
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.1
4
+ version: 0.4.2
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: 2013-08-05 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: phony