phony_rails 0.14.0 → 0.14.1
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +10 -10
- data/lib/phony_rails.rb +1 -1
- data/lib/phony_rails/version.rb +1 -1
- data/lib/validators/phony_validator.rb +6 -6
- data/spec/lib/phony_rails_spec.rb +15 -0
- data/spec/lib/validators/phony_validator_spec.rb +54 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a94ea35203b1527927eaf9a83b224ae5e587edf9
|
4
|
+
data.tar.gz: 8bc0db14a7ad0ab389f6d709d73fd562f9473c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 029272fcd410ec0a990ca107d47db48bf910dc4cfc8260e818e6810c3826dd74a7df347a6cef50f258d746b26fe49cc353684c0c80bcbac7209042dd4cba7636
|
7
|
+
data.tar.gz: cc4a133e257531605b669ff9137e7fc35147fc86b488c8d475fb71d3e4cebb18be6d0af12ffa8fc98b2870a0d3b3e668836d67a04474afcf0bfdb323e42e44ad
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.14.1](https://github.com/joost/phony_rails/tree/v0.14.1) (2016-05-08)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.0...v0.14.1)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Pull request \#139 \(released in 0.14.0\) breaks message: :improbable\_phone option [\#140](https://github.com/joost/phony_rails/issues/140)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Fixed a bug that prevents a normalized attribute from being set to nil [\#142](https://github.com/joost/phony_rails/pull/142) ([kylerippey](https://github.com/kylerippey))
|
14
|
+
|
15
|
+
- Read message value directly from options [\#141](https://github.com/joost/phony_rails/pull/141) ([monfresh](https://github.com/monfresh))
|
16
|
+
|
3
17
|
## [v0.14.0](https://github.com/joost/phony_rails/tree/v0.14.0) (2016-04-21)
|
4
18
|
|
5
19
|
[Full Changelog](https://github.com/joost/phony_rails/compare/v0.13.0...v0.14.0)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phony_rails (0.14.
|
4
|
+
phony_rails (0.14.1)
|
5
5
|
activesupport (>= 3.0)
|
6
6
|
phony (~> 2.12)
|
7
7
|
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
tzinfo (~> 1.1)
|
24
24
|
arel (6.0.3)
|
25
25
|
ast (2.2.0)
|
26
|
-
bson (4.0
|
26
|
+
bson (4.1.0)
|
27
27
|
builder (3.2.2)
|
28
28
|
coderay (1.1.1)
|
29
29
|
coveralls (0.8.13)
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
guard (~> 2.2)
|
51
51
|
guard-compat (~> 1.1)
|
52
52
|
guard-compat (1.2.1)
|
53
|
-
guard-rspec (4.6.
|
53
|
+
guard-rspec (4.6.5)
|
54
54
|
guard (~> 2.1)
|
55
55
|
guard-compat (~> 1.1)
|
56
56
|
rspec (>= 2.99.0, < 4.0)
|
@@ -64,7 +64,7 @@ GEM
|
|
64
64
|
minitest (5.8.4)
|
65
65
|
mongo (2.2.4)
|
66
66
|
bson (~> 4.0)
|
67
|
-
mongoid (5.1.
|
67
|
+
mongoid (5.1.3)
|
68
68
|
activemodel (~> 4.0)
|
69
69
|
mongo (~> 2.1)
|
70
70
|
origin (~> 2.2)
|
@@ -74,16 +74,16 @@ GEM
|
|
74
74
|
nenv (~> 0.1)
|
75
75
|
shellany (~> 0.0)
|
76
76
|
origin (2.2.0)
|
77
|
-
parser (2.3.0.
|
77
|
+
parser (2.3.0.7)
|
78
78
|
ast (~> 2.2)
|
79
|
-
phony (2.15.
|
79
|
+
phony (2.15.21)
|
80
80
|
powerpack (0.1.1)
|
81
81
|
pry (0.10.3)
|
82
82
|
coderay (~> 1.1.0)
|
83
83
|
method_source (~> 0.8.1)
|
84
84
|
slop (~> 3.4)
|
85
85
|
rainbow (2.1.0)
|
86
|
-
rake (11.1.
|
86
|
+
rake (11.1.2)
|
87
87
|
rb-fsevent (0.9.7)
|
88
88
|
rb-inotify (0.9.7)
|
89
89
|
ffi (>= 0.5.0)
|
@@ -100,8 +100,8 @@ GEM
|
|
100
100
|
diff-lcs (>= 1.2.0, < 2.0)
|
101
101
|
rspec-support (~> 3.4.0)
|
102
102
|
rspec-support (3.4.1)
|
103
|
-
rubocop (0.
|
104
|
-
parser (>= 2.3.0.
|
103
|
+
rubocop (0.39.0)
|
104
|
+
parser (>= 2.3.0.7, < 3.0)
|
105
105
|
powerpack (~> 0.1)
|
106
106
|
rainbow (>= 1.99.1, < 3.0)
|
107
107
|
ruby-progressbar (~> 1.7)
|
@@ -122,7 +122,7 @@ GEM
|
|
122
122
|
tins (1.6.0)
|
123
123
|
tzinfo (1.2.2)
|
124
124
|
thread_safe (~> 0.1)
|
125
|
-
unicode-display_width (1.0.
|
125
|
+
unicode-display_width (1.0.3)
|
126
126
|
|
127
127
|
PLATFORMS
|
128
128
|
ruby
|
data/lib/phony_rails.rb
CHANGED
@@ -144,7 +144,7 @@ module PhonyRails
|
|
144
144
|
attribute_name = options[:as] || attribute
|
145
145
|
raise("No attribute #{attribute_name} found on #{self.class.name} (PhonyRails)") unless self.class.attribute_method?(attribute_name)
|
146
146
|
new_value = PhonyRails.normalize_number(send(attribute), options)
|
147
|
-
send("#{attribute_name}=", new_value) if new_value
|
147
|
+
send("#{attribute_name}=", new_value) if new_value || attribute_name != attribute
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
data/lib/phony_rails/version.rb
CHANGED
@@ -15,7 +15,7 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def error_message
|
18
|
-
|
18
|
+
options[:message] || :improbable_phone
|
19
19
|
end
|
20
20
|
|
21
21
|
def country_number
|
@@ -43,11 +43,11 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def options_value(option)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
option_value = options[option]
|
47
|
+
|
48
|
+
return option_value unless option_value.is_a?(Symbol)
|
49
|
+
|
50
|
+
@record.send(option_value)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -634,6 +634,13 @@ describe PhonyRails do
|
|
634
634
|
expect(model.phone_number).to eql('+31101234123')
|
635
635
|
end
|
636
636
|
|
637
|
+
it 'should nilify attribute when it is set to nil' do
|
638
|
+
model = model_klass.new(phone_number: '+31-(0)10-1234123')
|
639
|
+
model.phone_number = nil
|
640
|
+
expect(model).to be_valid
|
641
|
+
expect(model.phone_number).to eql(nil)
|
642
|
+
end
|
643
|
+
|
637
644
|
it 'should set a normalized version of an attribute using :as option' do
|
638
645
|
model_klass.phony_normalize :phone_number, as: :phone_number_as_normalized
|
639
646
|
model = model_klass.new(phone_number: '+31-(0)10-1234123')
|
@@ -641,6 +648,14 @@ describe PhonyRails do
|
|
641
648
|
expect(model.phone_number_as_normalized).to eql('+31101234123')
|
642
649
|
end
|
643
650
|
|
651
|
+
it 'should nilify normalized version of an attribute when it is set to nil using :as option ' do
|
652
|
+
model_klass.phony_normalize :phone_number, as: :phone_number_as_normalized
|
653
|
+
model = model_klass.new(phone_number: '+31-(0)10-1234123', phone_number_as_normalized: '+31101234123')
|
654
|
+
model.phone_number = nil
|
655
|
+
expect(model).to be_valid
|
656
|
+
expect(model.phone_number_as_normalized).to eq(nil)
|
657
|
+
end
|
658
|
+
|
644
659
|
it 'should not add a + using :add_plus option' do
|
645
660
|
model_klass.phony_normalize :phone_number, add_plus: false
|
646
661
|
model = model_klass.new(phone_number: '+31-(0)10-1234123')
|
@@ -143,6 +143,28 @@ class SymbolizableHelpfulHome < ActiveRecord::Base
|
|
143
143
|
attr_accessor :phone_number, :phone_number_country_code
|
144
144
|
validates_plausible_phone :phone_number, country_code: :phone_number_country_code
|
145
145
|
end
|
146
|
+
|
147
|
+
#--------------------
|
148
|
+
class NoModelMethod < HelpfulHome
|
149
|
+
attr_accessor :phone_number
|
150
|
+
validates_plausible_phone :phone_number, country_code: :nonexistent_method
|
151
|
+
end
|
152
|
+
|
153
|
+
#--------------------
|
154
|
+
class MessageOptionUndefinedInModel < HelpfulHome
|
155
|
+
attr_accessor :phone_number
|
156
|
+
validates_plausible_phone :phone_number, message: :email
|
157
|
+
end
|
158
|
+
|
159
|
+
#--------------------
|
160
|
+
class MessageOptionSameAsModelMethod < HelpfulHome
|
161
|
+
attr_accessor :phone_number
|
162
|
+
validates_plausible_phone :phone_number, message: :email
|
163
|
+
|
164
|
+
def email
|
165
|
+
'user@example.com'
|
166
|
+
end
|
167
|
+
end
|
146
168
|
#-----------------------------------------------------------------------------------------------------------------------
|
147
169
|
# Tests
|
148
170
|
#-----------------------------------------------------------------------------------------------------------------------
|
@@ -544,5 +566,37 @@ describe ActiveModel::Validations::HelperMethods do
|
|
544
566
|
expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
|
545
567
|
end
|
546
568
|
end
|
569
|
+
|
570
|
+
#--------------------
|
571
|
+
context 'when a nonexistent method is passed as a symbol to an option other than message' do
|
572
|
+
it 'raises NoMethodError' do
|
573
|
+
@home = NoModelMethod.new
|
574
|
+
@home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
|
575
|
+
|
576
|
+
expect { @home.save }.to raise_error(NoMethodError)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
#--------------------
|
581
|
+
context 'when a nonexistent method is passed as a symbol to the message option' do
|
582
|
+
it 'does not raise an error' do
|
583
|
+
@home = MessageOptionUndefinedInModel.new
|
584
|
+
@home.phone_number = INVALID_NUMBER
|
585
|
+
|
586
|
+
expect { @home.save }.to_not raise_error
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
#--------------------
|
591
|
+
context 'when an existing Model method is passed as a symbol to the message option' do
|
592
|
+
it 'does not use the Model method' do
|
593
|
+
@home = MessageOptionSameAsModelMethod.new
|
594
|
+
@home.phone_number = INVALID_NUMBER
|
595
|
+
|
596
|
+
expect(@home).to_not receive(:email)
|
597
|
+
|
598
|
+
@home.save
|
599
|
+
end
|
600
|
+
end
|
547
601
|
end
|
548
602
|
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.14.
|
4
|
+
version: 0.14.1
|
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-
|
11
|
+
date: 2016-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phony
|