has_validated_attributes 0.0.12 → 0.0.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b2fe85522c7049c5ce61c9ee316c2563a21e08a
|
4
|
+
data.tar.gz: ecc3a994935a6bdc798ee1caabac4f2f8dd7cfd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae885cf12f7273a38d4da36f9f1a219bb8685e2d254d8b247abf97f9c07cacd48ab6c07e3d00cd31f67111dc61ee85ed2b2ac6cbf0321f846c73af0b46ed0667
|
7
|
+
data.tar.gz: 5cdd2cf521e758a4804f41c65a996cbb8ac2ce476c57f3fc913726a91c2d495c715b25a371d19d628cb26726ddb8d7ddabd2ef9b43b70349fef7407aa957c5d5
|
@@ -38,14 +38,14 @@ module HasValidatedAttributes
|
|
38
38
|
## http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
|
39
39
|
:email => {:length => {:maximum => 63}, :format => {:with => /\A(?!\.)("([^"\r\\]|\\["\r\\])*"|([-a-z0-9!#$%&'’*+\/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]\z/i, :message => "should look like an email address."}, :has_if? => true},
|
40
40
|
:phone_number => {:numericality => {:greater_than_or_equal_to => 1000000000, :less_than => 10000000000, :message => 'accepts only 10 numbers and (),.- characters and must not be all 0s'}, :has_if? => true},
|
41
|
-
:phone_extension => {:
|
41
|
+
:phone_extension => {:length => {:maximum => 7}, :format => {:with => /\A\d+([\dxX]*\d)?\z/, :message => 'accepts only numbers (0-9) and "x"'}, :has_if? => true},
|
42
42
|
:domain => {:length => {:maximum => 63}, :format => {:with => /\A(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|pro|mobi|name|aero|jobs|museum)\z/i, :message => "should look like a domain name."}, :has_if? => true},
|
43
43
|
:zipcode => {:format => {:with => /\A\d{5}(\d{4})?\z/, :message => "must contain 5 or 9 numbers"}, :has_if? => true},
|
44
44
|
:middle_initial => {:format => {:with => /\A[a-zA-Z]{0,1}\z/u, :message => "accepts only one letter"}},
|
45
45
|
:dollar => {:format => {:with => /\A-?[0-9]{0,12}(\.[0-9]{0,2})?\z/, :message => "accepts only numeric characters, period, and negative sign"}, :numericality => {:greater_than => -1000000000000, :less_than => 1000000000000}, :allow_nil => true},
|
46
46
|
:positive_dollar => {:format => {:with => /\A[0-9]{0,12}(\.[0-9]{0,2})?\z/, :message => "accepts only numeric characters, period"}, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1000000000000}, :allow_nil => true},
|
47
|
-
:percent => {:format => {:with => /\A-?[0-9]{0,
|
48
|
-
:positive_percent => {:format => {:with => /\A[0-9]{0,
|
47
|
+
:percent => {:format => {:with => /\A-?[0-9]{0,4}(\.[0-9]{0,4})?\z/, :message => "accepts only numeric characters, period, negative sign, and must be equal/less/greater than +/- 100"}, :numericality => {:greater_than_or_equal_to => -100, :less_than_or_equal_to => 100}, :has_if? => true},
|
48
|
+
:positive_percent => {:format => {:with => /\A[0-9]{0,4}(\.[0-9]{0,4})?\z/, :message => "accepts only numeric characters, period, and must be equal/less than 100"}, :numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 100}, :allow_nil => true},
|
49
49
|
:url => {:length => {:maximum => 255}, :format => {:with => /\A(http|https|ftp):\/\/[A-Z0-9]+([\.]{1}[a-z0-9-]{1,63})*\.[a-zA-Z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/ix, :message => "web address isnt valid"}, :has_if? => true},
|
50
50
|
:social_security_number => {:length => {:is => 9}, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1000000000, :message => "must be in the format 111-11-1111"}, :has_if? => true},
|
51
51
|
:taxid => {:length => {:is => 9}, :numericality => {:greater_than_or_equal_to => 9999999, :less_than => 1000000000, :message => "must be in the format 11-1111111"}, :has_if? => true},
|
@@ -126,12 +126,16 @@ RSpec.shared_examples_for "phone number attribute" do |attr, normalized: false|
|
|
126
126
|
end
|
127
127
|
|
128
128
|
RSpec.shared_examples_for "phone extension attribute" do |attr|
|
129
|
-
["123", "123456"].each do |ext|
|
130
|
-
it {
|
129
|
+
["123", "123456", "123x4", "1x2x3"].each do |ext|
|
130
|
+
it "should allow '#{ ext }' for #{ attr }" do
|
131
|
+
should allow_value(ext).for(attr)
|
132
|
+
end
|
131
133
|
end
|
132
134
|
|
133
|
-
["-1", "qwert"].each do |ext|
|
134
|
-
it {
|
135
|
+
["-1", "qwert", "x123", "123x", "X123", "123X"].each do |ext|
|
136
|
+
it "should not allow '#{ ext }' for #{ attr }" do
|
137
|
+
should_not allow_value(ext).for(attr).with_message(HasValidatedAttributes.phone_extension_format[:format][:message])
|
138
|
+
end
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
@@ -152,21 +156,21 @@ RSpec.shared_examples_for "url attribute" do |attr, allowed: nil, disallowed: ni
|
|
152
156
|
end
|
153
157
|
|
154
158
|
RSpec.shared_examples_for "positive percent attribute" do |attr|
|
155
|
-
["100", "99", "1", "44", "99.999", "0.001"].each do |percent|
|
159
|
+
["100", "99", "1", "44", "99.999", "99.9999", "0.001"].each do |percent|
|
156
160
|
it { should allow_value(percent).for(attr) }
|
157
161
|
end
|
158
162
|
|
159
|
-
["100.001", "0.
|
163
|
+
["100.001", "0.22222", "abc", "&", "-44", "-44.4", "-44.4444"].each do |percent|
|
160
164
|
it { should_not allow_value(percent).for(attr) }
|
161
165
|
end
|
162
166
|
end
|
163
167
|
|
164
168
|
RSpec.shared_examples_for "percent attribute" do |attr|
|
165
|
-
["100", "99", "1", "44", "99.999", "0.001", "-100", "-99", "-1", "-44", "-99.999", "-0.001"].each do |value|
|
169
|
+
["100", "99", "1", "44", "99.999", "99.9999", "0.001", "-100", "-99", "-1", "-44", "-99.999", "-0.001"].each do |value|
|
166
170
|
it { should allow_value(value).for(attr) }
|
167
171
|
end
|
168
172
|
|
169
|
-
["100.001", "0.
|
173
|
+
["100.001", "0.22222", "-100.001", "-0.2222", "abc", "&"].each do |value|
|
170
174
|
it { should_not allow_value(value).for(attr) }
|
171
175
|
end
|
172
176
|
end
|