phony_rails 0.12.13 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97008ef55c4d1d7748babd4150f0cd8ff7cabaeb
4
- data.tar.gz: 37045f7383c7811809ba99f151dd133448c4967c
3
+ metadata.gz: b0995738663fcaf74c4d16fcd132e826cf36f463
4
+ data.tar.gz: afe9c6ae8831a0bd1fe3c9f3cceab16f3d9cdea3
5
5
  SHA512:
6
- metadata.gz: 39dc96431aca90966b4d79f6441213cbe6e1fbd920a86e50b1fe10f49606fbe020bb4ae557b0edec411b4a8e15814d3f15e8e102c595b63c6eabf2790596a130
7
- data.tar.gz: 73b3c1c05704b4dd21e442888eedd2550688d5d6bb2dbe68475f29671bdff61228f2d0522c919ce8744781ff46060e79eb47c6d5b06bfb523f9d01de9757368c
6
+ metadata.gz: 7a07bee573a1fc7a166b77346012eec5d5e75d68e339bd59dabbee25e311896fcd05c5431b8b47daea45a00fd7e3ca8c2946160665ace3fd1b590bfaa9e7a34e
7
+ data.tar.gz: 1744da3879089e47af553e672859a88ccca9f4b85a91a21beeb7074eff1e972bf721a6b2e90b6887b9ac72401c196d5c594af979fbcf3ddebced839a6f2b6644
@@ -1,5 +1,31 @@
1
1
  # Change Log
2
2
 
3
+ ## [Unreleased](https://github.com/joost/phony_rails/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/joost/phony_rails/compare/v0.12.11...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Adding country code twice for Luxemburg numbers [\#128](https://github.com/joost/phony_rails/issues/128)
10
+
11
+ - Unexpected result when calling normalize\_number multiple times with country\_code option [\#126](https://github.com/joost/phony_rails/issues/126)
12
+
13
+ - No method find\_by\_normalized\_phone\_number [\#125](https://github.com/joost/phony_rails/issues/125)
14
+
15
+ - Invalid number is valid? [\#124](https://github.com/joost/phony_rails/issues/124)
16
+
17
+ - Can it validate mobile phone? [\#122](https://github.com/joost/phony_rails/issues/122)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Do not raise NoMethodError when an illegal country code is set [\#133](https://github.com/joost/phony_rails/pull/133) ([klaustopher](https://github.com/klaustopher))
22
+
23
+ - only assigned normalize values if there is one [\#132](https://github.com/joost/phony_rails/pull/132) ([Smcchoi](https://github.com/Smcchoi))
24
+
25
+ - Adding Kosovo phone code [\#131](https://github.com/joost/phony_rails/pull/131) ([Xanders](https://github.com/Xanders))
26
+
27
+ - Add Dutch translation for invalid number [\#129](https://github.com/joost/phony_rails/pull/129) ([bdewater](https://github.com/bdewater))
28
+
3
29
  ## [v0.12.11](https://github.com/joost/phony_rails/tree/v0.12.11) (2015-11-12)
4
30
 
5
31
  [Full Changelog](https://github.com/joost/phony_rails/compare/v0.12.9...v0.12.11)
@@ -1,41 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phony_rails (0.12.12)
4
+ phony_rails (0.13.0)
5
5
  activesupport (>= 3.0)
6
6
  phony (~> 2.12)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (4.2.5.1)
12
- activesupport (= 4.2.5.1)
11
+ activemodel (4.2.6)
12
+ activesupport (= 4.2.6)
13
13
  builder (~> 3.1)
14
- activerecord (4.2.5.1)
15
- activemodel (= 4.2.5.1)
16
- activesupport (= 4.2.5.1)
14
+ activerecord (4.2.6)
15
+ activemodel (= 4.2.6)
16
+ activesupport (= 4.2.6)
17
17
  arel (~> 6.0)
18
- activesupport (4.2.5.1)
18
+ activesupport (4.2.6)
19
19
  i18n (~> 0.7)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
22
22
  thread_safe (~> 0.3, >= 0.3.4)
23
23
  tzinfo (~> 1.1)
24
24
  arel (6.0.3)
25
- bson (4.0.1)
25
+ bson (4.0.4)
26
26
  builder (3.2.2)
27
- coderay (1.1.0)
28
- coveralls (0.8.10)
27
+ coderay (1.1.1)
28
+ coveralls (0.8.13)
29
29
  json (~> 1.8)
30
- rest-client (>= 1.6.8, < 2)
31
30
  simplecov (~> 0.11.0)
32
31
  term-ansicolor (~> 1.3)
33
32
  thor (~> 0.19.1)
34
33
  tins (~> 1.6.0)
35
34
  diff-lcs (1.2.5)
36
35
  docile (1.1.5)
37
- domain_name (0.5.20160128)
38
- unf (>= 0.0.5, < 1.0.0)
39
36
  ffi (1.9.10)
40
37
  formatador (0.2.5)
41
38
  guard (2.13.0)
@@ -56,8 +53,6 @@ GEM
56
53
  guard (~> 2.1)
57
54
  guard-compat (~> 1.1)
58
55
  rspec (>= 2.99.0, < 4.0)
59
- http-cookie (1.0.2)
60
- domain_name (~> 0.5)
61
56
  i18n (0.7.0)
62
57
  json (1.8.3)
63
58
  listen (3.0.6)
@@ -65,39 +60,33 @@ GEM
65
60
  rb-inotify (>= 0.9.7)
66
61
  lumberjack (1.0.10)
67
62
  method_source (0.8.2)
68
- mime-types (2.99)
69
63
  minitest (5.8.4)
70
- mongo (2.2.2)
64
+ mongo (2.2.4)
71
65
  bson (~> 4.0)
72
- mongoid (5.1.0)
66
+ mongoid (5.1.1)
73
67
  activemodel (~> 4.0)
74
68
  mongo (~> 2.1)
75
69
  origin (~> 2.2)
76
70
  tzinfo (>= 0.3.37)
77
71
  nenv (0.3.0)
78
- netrc (0.11.0)
79
72
  notiffany (0.0.8)
80
73
  nenv (~> 0.1)
81
74
  shellany (~> 0.0)
82
75
  origin (2.2.0)
83
- phony (2.15.15)
76
+ phony (2.15.17)
84
77
  pry (0.10.3)
85
78
  coderay (~> 1.1.0)
86
79
  method_source (~> 0.8.1)
87
80
  slop (~> 3.4)
88
- rake (10.5.0)
81
+ rake (11.1.0)
89
82
  rb-fsevent (0.9.7)
90
83
  rb-inotify (0.9.7)
91
84
  ffi (>= 0.5.0)
92
- rest-client (1.8.0)
93
- http-cookie (>= 1.0.2, < 2.0)
94
- mime-types (>= 1.16, < 3.0)
95
- netrc (~> 0.7)
96
85
  rspec (3.4.0)
97
86
  rspec-core (~> 3.4.0)
98
87
  rspec-expectations (~> 3.4.0)
99
88
  rspec-mocks (~> 3.4.0)
100
- rspec-core (3.4.2)
89
+ rspec-core (3.4.4)
101
90
  rspec-support (~> 3.4.0)
102
91
  rspec-expectations (3.4.0)
103
92
  diff-lcs (>= 1.2.0, < 2.0)
@@ -121,9 +110,6 @@ GEM
121
110
  tins (1.6.0)
122
111
  tzinfo (1.2.2)
123
112
  thread_safe (~> 0.1)
124
- unf (0.1.4)
125
- unf_ext
126
- unf_ext (0.0.7.2)
127
113
 
128
114
  PLATFORMS
129
115
  ruby
@@ -8,7 +8,7 @@ module PhonyRails
8
8
  def self.country_number_for(country_code)
9
9
  return if country_code.nil?
10
10
 
11
- country_codes_hash[country_code.to_s.upcase]['country_code']
11
+ country_codes_hash.fetch(country_code.to_s.upcase, {})['country_code']
12
12
  end
13
13
 
14
14
  def self.country_codes_hash
@@ -94,7 +94,8 @@ module PhonyRails
94
94
  attributes.each do |attribute|
95
95
  attribute_name = options[:as] || attribute
96
96
  fail(RuntimeError, "No attribute #{attribute_name} found on #{self.class.name} (PhonyRails)") unless self.class.attribute_method?(attribute_name)
97
- send("#{attribute_name}=", PhonyRails.normalize_number(send(attribute), options))
97
+ new_value= PhonyRails.normalize_number(send(attribute), options)
98
+ send("#{attribute_name}=", new_value) if new_value
98
99
  end
99
100
  end
100
101
  end
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = '0.12.13'
2
+ VERSION = '0.13.0'
3
3
  end
@@ -174,6 +174,26 @@ describe PhonyRails do
174
174
  phone = PhonyRails.normalize_number(phone, default_country_code: 'FR')
175
175
  expect(phone).to eq('+336123456789')
176
176
  end
177
+
178
+ it 'should pass Github issue #92 (invalid number with normalization)' do
179
+ ActiveRecord::Schema.define do
180
+ create_table :normal_homes do |table|
181
+ table.column :phone_number, :string
182
+ end
183
+ end
184
+
185
+ class NormalHome < ActiveRecord::Base
186
+ attr_accessor :phone_number
187
+ phony_normalize :phone_number, default_country_code: 'US'
188
+ validates :phone_number, phony_plausible: true
189
+ end
190
+
191
+ normal = NormalHome.new
192
+ normal.phone_number = 'HAHA'
193
+ expect(normal).to_not be_valid
194
+ expect(normal.phone_number).to eq('HAHA')
195
+ expect(normal.errors.messages).to include(phone_number: ["is an invalid number"])
196
+ end
177
197
  end
178
198
 
179
199
  it 'should not change original String' do
@@ -50,6 +50,10 @@ ActiveRecord::Schema.define do
50
50
  create_table :mismatched_helpful_homes do |table|
51
51
  table.column :phone_number, :string
52
52
  end
53
+
54
+ create_table :invalid_country_code_helpful_homes do |table|
55
+ table.column :phone_number, :string
56
+ end
53
57
  end
54
58
 
55
59
  #--------------------
@@ -117,6 +121,17 @@ class MismatchedHelpfulHome < ActiveRecord::Base
117
121
  attr_accessor :phone_number, :country_code
118
122
  validates :phone_number, phony_plausible: {ignore_record_country_code: true}
119
123
  end
124
+
125
+ #--------------------
126
+
127
+ class InvalidCountryCodeHelpfulHome < ActiveRecord::Base
128
+ attr_accessor :phone_number
129
+ validates_plausible_phone :phone_number
130
+
131
+ def country_code
132
+ "--"
133
+ end
134
+ end
120
135
  #-----------------------------------------------------------------------------------------------------------------------
121
136
  # Tests
122
137
  #-----------------------------------------------------------------------------------------------------------------------
@@ -130,6 +145,7 @@ FORMATTED_AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '+61 390133997'
130
145
  FRENCH_NUMBER_WITH_COUNTRY_CODE = '33627899541'
131
146
  FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE = '+33 627899541'
132
147
  INVALID_NUMBER = '123456789 123456789 123456789 123456789'
148
+ NOT_A_NUMBER = 'HAHA'
133
149
  JAPAN_COUNTRY = 'jp'
134
150
 
135
151
  #-----------------------------------------------------------------------------------------------------------------------
@@ -157,6 +173,12 @@ describe PhonyPlausibleValidator do
157
173
  expect(@home.errors.messages).to include(phone_number: ["is an invalid number"])
158
174
  end
159
175
 
176
+ it "should invalidate not a number" do
177
+ @home.phone_number = NOT_A_NUMBER
178
+ expect(@home).to_not be_valid
179
+ expect(@home.errors.messages).to include(phone_number: ["is an invalid number"])
180
+ end
181
+
160
182
  it "should translate the error message in Dutch" do
161
183
  I18n.with_locale(:nl) do
162
184
  @home.phone_number = INVALID_NUMBER
@@ -480,6 +502,29 @@ describe ActiveModel::Validations::HelperMethods do
480
502
  end
481
503
  end
482
504
 
505
+ #--------------------
506
+ context 'when a country code is set to something invalid' do
507
+ before(:each) do
508
+ @home = InvalidCountryCodeHelpfulHome.new
509
+ end
510
+
511
+ it "should allow any valid number" do
512
+ @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
513
+ expect(@home).to be_valid
514
+ end
515
+
516
+ it "should not allow any invalid number" do
517
+ @home.phone_number = INVALID_NUMBER
518
+ expect(@home).to_not be_valid
519
+ end
520
+
521
+ it "should not raise a NoMethodError when looking up a country fails (Regression)" do
522
+ expect {
523
+ @home.valid?
524
+ }.to_not raise_error
525
+ end
526
+ end
527
+
483
528
  end
484
529
 
485
530
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.13
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joost Hietbrink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phony