flash_validators 1.1.0 → 3.0.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 +4 -4
- data/README.md +258 -35
- data/config/locales/en.yml +66 -42
- data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_base64_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_cusip_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +12 -2
- data/lib/flash_validators/matchers/ensure_valid_gtin_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_isbn_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_isin_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_sedol_format_of.rb +26 -0
- data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +10 -2
- data/lib/flash_validators/matchers/ensure_valid_uuid_format_of.rb +26 -0
- data/lib/flash_validators/validators/alpha_numeric_validator.rb +21 -7
- data/lib/flash_validators/validators/alpha_validator.rb +22 -10
- data/lib/flash_validators/validators/base64_validator.rb +9 -0
- data/lib/flash_validators/validators/credit_card_validator.rb +123 -15
- data/lib/flash_validators/validators/currency_validator.rb +13 -7
- data/lib/flash_validators/validators/cusip_validator.rb +33 -0
- data/lib/flash_validators/validators/email_validator.rb +7 -7
- data/lib/flash_validators/validators/equality_validator.rb +7 -7
- data/lib/flash_validators/validators/gtin_validator.rb +59 -0
- data/lib/flash_validators/validators/hex_validator.rb +1 -1
- data/lib/flash_validators/validators/imei_validator.rb +8 -8
- data/lib/flash_validators/validators/isbn_validator.rb +9 -16
- data/lib/flash_validators/validators/isin_validator.rb +38 -0
- data/lib/flash_validators/validators/mac_address_validator.rb +10 -10
- data/lib/flash_validators/validators/password_validator.rb +13 -7
- data/lib/flash_validators/validators/sedol_validator.rb +32 -0
- data/lib/flash_validators/validators/url_validator.rb +13 -13
- data/lib/flash_validators/validators/uuid_validator.rb +28 -0
- data/lib/flash_validators/version.rb +1 -1
- data/lib/flash_validators.rb +12 -0
- data/spec/lib/alpha_numeric_validator_spec.rb +31 -1
- data/spec/lib/alpha_validator_spec.rb +68 -6
- data/spec/lib/base64_validator_spec.rb +33 -0
- data/spec/lib/credit_card_validator_spec.rb +495 -125
- data/spec/lib/cusip_validator_spec.rb +27 -0
- data/spec/lib/gtin_validator_spec.rb +101 -0
- data/spec/lib/hex_validator_spec.rb +20 -0
- data/spec/lib/isin_validator_spec.rb +35 -0
- data/spec/lib/sedol_validator_spec.rb +31 -0
- data/spec/lib/uuid_validator_spec.rb +157 -0
- metadata +26 -2
@@ -13,21 +13,110 @@ describe CreditCardValidator do
|
|
13
13
|
|
14
14
|
subject { klass.new }
|
15
15
|
|
16
|
-
it { should allow_value("
|
17
|
-
it { should allow_value("
|
18
|
-
it { should allow_value("
|
19
|
-
it { should allow_value("
|
20
|
-
it { should allow_value("
|
21
|
-
it { should allow_value("
|
22
|
-
it { should allow_value("
|
23
|
-
it { should allow_value("
|
24
|
-
it { should allow_value("
|
25
|
-
it { should allow_value("
|
26
|
-
it { should allow_value("
|
27
|
-
it { should allow_value("
|
28
|
-
it { should allow_value("
|
29
|
-
it { should allow_value("
|
30
|
-
it { should allow_value("
|
16
|
+
it { should allow_value("340000000000000").for(:cc_number) }
|
17
|
+
it { should allow_value("370000000000000").for(:cc_number) }
|
18
|
+
it { should allow_value("3700 0000.0000-000").for(:cc_number) }
|
19
|
+
it { should allow_value("30000000000000").for(:cc_number) }
|
20
|
+
it { should allow_value("30100000000000").for(:cc_number) }
|
21
|
+
it { should allow_value("30200000000000").for(:cc_number) }
|
22
|
+
it { should allow_value("30300000000000").for(:cc_number) }
|
23
|
+
it { should allow_value("30400000000000").for(:cc_number) }
|
24
|
+
it { should allow_value("30500000000000").for(:cc_number) }
|
25
|
+
it { should allow_value("36000000000000").for(:cc_number) }
|
26
|
+
it { should allow_value("54000000000000").for(:cc_number) }
|
27
|
+
it { should allow_value("55000000000000").for(:cc_number) }
|
28
|
+
it { should allow_value("5500000000000000").for(:cc_number) }
|
29
|
+
it { should allow_value("5500 0000.0000-00").for(:cc_number) }
|
30
|
+
it { should allow_value("5500 0000.0000-0000").for(:cc_number) }
|
31
|
+
it { should allow_value("6011000000000000").for(:cc_number) }
|
32
|
+
it { should allow_value("6221260000000000").for(:cc_number) }
|
33
|
+
it { should allow_value("6221270000000000").for(:cc_number) }
|
34
|
+
it { should allow_value("6221280000000000").for(:cc_number) }
|
35
|
+
it { should allow_value("6221290000000000").for(:cc_number) }
|
36
|
+
it { should allow_value("6221300000000000").for(:cc_number) }
|
37
|
+
it { should allow_value("6221400000000000").for(:cc_number) }
|
38
|
+
it { should allow_value("6221500000000000").for(:cc_number) }
|
39
|
+
it { should allow_value("6221600000000000").for(:cc_number) }
|
40
|
+
it { should allow_value("6221700000000000").for(:cc_number) }
|
41
|
+
it { should allow_value("6221800000000000").for(:cc_number) }
|
42
|
+
it { should allow_value("6221900000000000").for(:cc_number) }
|
43
|
+
it { should allow_value("6222000000000000").for(:cc_number) }
|
44
|
+
it { should allow_value("6223000000000000").for(:cc_number) }
|
45
|
+
it { should allow_value("6224000000000000").for(:cc_number) }
|
46
|
+
it { should allow_value("6225000000000000").for(:cc_number) }
|
47
|
+
it { should allow_value("6226000000000000").for(:cc_number) }
|
48
|
+
it { should allow_value("6227000000000000").for(:cc_number) }
|
49
|
+
it { should allow_value("6228000000000000").for(:cc_number) }
|
50
|
+
it { should allow_value("6229000000000000").for(:cc_number) }
|
51
|
+
it { should allow_value("6229100000000000").for(:cc_number) }
|
52
|
+
it { should allow_value("6229200000000000").for(:cc_number) }
|
53
|
+
it { should allow_value("6229210000000000").for(:cc_number) }
|
54
|
+
it { should allow_value("6229220000000000").for(:cc_number) }
|
55
|
+
it { should allow_value("6229230000000000").for(:cc_number) }
|
56
|
+
it { should allow_value("6229240000000000").for(:cc_number) }
|
57
|
+
it { should allow_value("6229250000000000").for(:cc_number) }
|
58
|
+
it { should allow_value("6440000000000000").for(:cc_number) }
|
59
|
+
it { should allow_value("6450000000000000").for(:cc_number) }
|
60
|
+
it { should allow_value("6460000000000000").for(:cc_number) }
|
61
|
+
it { should allow_value("6470000000000000").for(:cc_number) }
|
62
|
+
it { should allow_value("6480000000000000").for(:cc_number) }
|
63
|
+
it { should allow_value("6490000000000000").for(:cc_number) }
|
64
|
+
it { should allow_value("6500000000000000").for(:cc_number) }
|
65
|
+
it { should allow_value("6500 0000.0000-0000").for(:cc_number) }
|
66
|
+
it { should allow_value("3528000000000000").for(:cc_number) }
|
67
|
+
it { should allow_value("3529000000000000").for(:cc_number) }
|
68
|
+
it { should allow_value("3530000000000000").for(:cc_number) }
|
69
|
+
it { should allow_value("3540000000000000").for(:cc_number) }
|
70
|
+
it { should allow_value("3550000000000000").for(:cc_number) }
|
71
|
+
it { should allow_value("3560000000000000").for(:cc_number) }
|
72
|
+
it { should allow_value("3570000000000000").for(:cc_number) }
|
73
|
+
it { should allow_value("3580000000000000").for(:cc_number) }
|
74
|
+
it { should allow_value("3580 0000.0000-0000").for(:cc_number) }
|
75
|
+
it { should allow_value("6304000000000000").for(:cc_number) }
|
76
|
+
it { should allow_value("6706000000000000").for(:cc_number) }
|
77
|
+
it { should allow_value("6771000000000000").for(:cc_number) }
|
78
|
+
it { should allow_value("6709000000000000").for(:cc_number) }
|
79
|
+
it { should allow_value("67090000000000000").for(:cc_number) }
|
80
|
+
it { should allow_value("670900000000000000").for(:cc_number) }
|
81
|
+
it { should allow_value("6709000000000000000").for(:cc_number) }
|
82
|
+
it { should allow_value("6709 0000.0000-0000").for(:cc_number) }
|
83
|
+
it { should allow_value("6709 0000.0000-00000").for(:cc_number) }
|
84
|
+
it { should allow_value("6709 0000.0000-000000").for(:cc_number) }
|
85
|
+
it { should allow_value("6709 0000.0000-0000000").for(:cc_number) }
|
86
|
+
it { should allow_value("6221260000000000").for(:cc_number) }
|
87
|
+
it { should allow_value("6221270000000000").for(:cc_number) }
|
88
|
+
it { should allow_value("6221280000000000").for(:cc_number) }
|
89
|
+
it { should allow_value("6221300000000000").for(:cc_number) }
|
90
|
+
it { should allow_value("6221400000000000").for(:cc_number) }
|
91
|
+
it { should allow_value("6221500000000000").for(:cc_number) }
|
92
|
+
it { should allow_value("6221600000000000").for(:cc_number) }
|
93
|
+
it { should allow_value("6221700000000000").for(:cc_number) }
|
94
|
+
it { should allow_value("6221800000000000").for(:cc_number) }
|
95
|
+
it { should allow_value("6221900000000000").for(:cc_number) }
|
96
|
+
it { should allow_value("6222000000000000").for(:cc_number) }
|
97
|
+
it { should allow_value("6223000000000000").for(:cc_number) }
|
98
|
+
it { should allow_value("6224000000000000").for(:cc_number) }
|
99
|
+
it { should allow_value("6225000000000000").for(:cc_number) }
|
100
|
+
it { should allow_value("6226000000000000").for(:cc_number) }
|
101
|
+
it { should allow_value("6227000000000000").for(:cc_number) }
|
102
|
+
it { should allow_value("6228000000000000").for(:cc_number) }
|
103
|
+
it { should allow_value("6229000000000000").for(:cc_number) }
|
104
|
+
it { should allow_value("6229100000000000").for(:cc_number) }
|
105
|
+
it { should allow_value("6229200000000000").for(:cc_number) }
|
106
|
+
it { should allow_value("6229210000000000").for(:cc_number) }
|
107
|
+
it { should allow_value("6229220000000000").for(:cc_number) }
|
108
|
+
it { should allow_value("6229230000000000").for(:cc_number) }
|
109
|
+
it { should allow_value("6229240000000000").for(:cc_number) }
|
110
|
+
it { should allow_value("6229250000000000").for(:cc_number) }
|
111
|
+
it { should allow_value("62292500000000000").for(:cc_number) }
|
112
|
+
it { should allow_value("622925000000000000").for(:cc_number) }
|
113
|
+
it { should allow_value("6229250000000000000").for(:cc_number) }
|
114
|
+
it { should allow_value("6229 2500.0000-0000").for(:cc_number) }
|
115
|
+
it { should allow_value("6229 2500.0000-00000").for(:cc_number) }
|
116
|
+
it { should allow_value("6229 2500.0000-000000").for(:cc_number) }
|
117
|
+
it { should allow_value("6229 2500.0000-0000000").for(:cc_number) }
|
118
|
+
it { should allow_value("4000000000000000").for(:cc_number) }
|
119
|
+
it { should allow_value("4000 0000.0000-0000").for(:cc_number) }
|
31
120
|
|
32
121
|
it { should_not allow_value('').for(:cc_number) }
|
33
122
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -35,8 +124,38 @@ describe CreditCardValidator do
|
|
35
124
|
it { should_not allow_value("#").for(:cc_number) }
|
36
125
|
it { should_not allow_value("9").for(:cc_number) }
|
37
126
|
it { should_not allow_value("a").for(:cc_number) }
|
38
|
-
it { should_not allow_value("
|
39
|
-
it { should_not allow_value("
|
127
|
+
it { should_not allow_value("270000000000000").for(:cc_number) }
|
128
|
+
it { should_not allow_value("37000000000000").for(:cc_number) }
|
129
|
+
it { should_not allow_value("3700000000000000").for(:cc_number) }
|
130
|
+
it { should_not allow_value("2700 0000.0000-000").for(:cc_number) }
|
131
|
+
it { should_not allow_value("3700 0000.0000-00").for(:cc_number) }
|
132
|
+
it { should_not allow_value("3700 0000.0000-0000").for(:cc_number) }
|
133
|
+
it { should_not allow_value("5500000000000").for(:cc_number) }
|
134
|
+
it { should_not allow_value("5500 0000.0000-0").for(:cc_number) }
|
135
|
+
it { should_not allow_value("650000000000000").for(:cc_number) }
|
136
|
+
it { should_not allow_value("65000000000000000").for(:cc_number) }
|
137
|
+
it { should_not allow_value("6500 0000.0000-000").for(:cc_number) }
|
138
|
+
it { should_not allow_value("6500 0000.0000-00000").for(:cc_number) }
|
139
|
+
it { should_not allow_value("2580000000000000").for(:cc_number) }
|
140
|
+
it { should_not allow_value("358000000000000").for(:cc_number) }
|
141
|
+
it { should_not allow_value("35800000000000000").for(:cc_number) }
|
142
|
+
it { should_not allow_value("2580 0000.0000-0000").for(:cc_number) }
|
143
|
+
it { should_not allow_value("3580 0000.0000-000").for(:cc_number) }
|
144
|
+
it { should_not allow_value("3580 0000.0000-00000").for(:cc_number) }
|
145
|
+
it { should_not allow_value("5709000000000000").for(:cc_number) }
|
146
|
+
it { should_not allow_value("670900000000000").for(:cc_number) }
|
147
|
+
it { should_not allow_value("67090000000000000000").for(:cc_number) }
|
148
|
+
it { should_not allow_value("5709 0000.0000-0000").for(:cc_number) }
|
149
|
+
it { should_not allow_value("6709 0000.0000-000").for(:cc_number) }
|
150
|
+
it { should_not allow_value("6709 0000.0000-00000000").for(:cc_number) }
|
151
|
+
it { should_not allow_value("622925000000000").for(:cc_number) }
|
152
|
+
it { should_not allow_value("62292500000000000000").for(:cc_number) }
|
153
|
+
it { should_not allow_value("6229 2500.0000-000").for(:cc_number) }
|
154
|
+
it { should_not allow_value("6229 2500.0000-00000000").for(:cc_number) }
|
155
|
+
it { should_not allow_value("400000000000000").for(:cc_number) }
|
156
|
+
it { should_not allow_value("40000000000000000").for(:cc_number) }
|
157
|
+
it { should_not allow_value("4000 0000.0000-000").for(:cc_number) }
|
158
|
+
it { should_not allow_value("4000 0000.0000-00000").for(:cc_number) }
|
40
159
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
41
160
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
42
161
|
|
@@ -44,19 +163,20 @@ describe CreditCardValidator do
|
|
44
163
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
45
164
|
end
|
46
165
|
|
47
|
-
context "with :american_express option has a valid value" do
|
166
|
+
context "with card: :american_express option has a valid value" do
|
48
167
|
let(:klass) do
|
49
168
|
Class.new do
|
50
169
|
include ActiveModel::Validations
|
51
170
|
attr_accessor :cc_number, :name
|
52
|
-
validates :cc_number, credit_card: {
|
171
|
+
validates :cc_number, credit_card: { card: :american_express }
|
53
172
|
end
|
54
173
|
end
|
55
174
|
|
56
175
|
subject { klass.new }
|
57
176
|
|
58
|
-
it { should allow_value("
|
59
|
-
it { should allow_value("
|
177
|
+
it { should allow_value("340000000000000").for(:cc_number) }
|
178
|
+
it { should allow_value("370000000000000").for(:cc_number) }
|
179
|
+
it { should allow_value("3700 0000.0000-000").for(:cc_number) }
|
60
180
|
|
61
181
|
it { should_not allow_value('').for(:cc_number) }
|
62
182
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -64,8 +184,12 @@ describe CreditCardValidator do
|
|
64
184
|
it { should_not allow_value("#").for(:cc_number) }
|
65
185
|
it { should_not allow_value("9").for(:cc_number) }
|
66
186
|
it { should_not allow_value("a").for(:cc_number) }
|
67
|
-
it { should_not allow_value("
|
68
|
-
it { should_not allow_value("
|
187
|
+
it { should_not allow_value("270000000000000").for(:cc_number) }
|
188
|
+
it { should_not allow_value("37000000000000").for(:cc_number) }
|
189
|
+
it { should_not allow_value("3700000000000000").for(:cc_number) }
|
190
|
+
it { should_not allow_value("2700 0000.0000-000").for(:cc_number) }
|
191
|
+
it { should_not allow_value("3700 0000.0000-00").for(:cc_number) }
|
192
|
+
it { should_not allow_value("3700 0000.0000-0000").for(:cc_number) }
|
69
193
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
70
194
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
71
195
|
|
@@ -73,19 +197,29 @@ describe CreditCardValidator do
|
|
73
197
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
74
198
|
end
|
75
199
|
|
76
|
-
context "with :
|
200
|
+
context "with card: :diners_club option has a valid value" do
|
77
201
|
let(:klass) do
|
78
202
|
Class.new do
|
79
203
|
include ActiveModel::Validations
|
80
204
|
attr_accessor :cc_number, :name
|
81
|
-
validates :cc_number, credit_card: {
|
205
|
+
validates :cc_number, credit_card: { card: :diners_club }
|
82
206
|
end
|
83
207
|
end
|
84
208
|
|
85
209
|
subject { klass.new }
|
86
210
|
|
87
|
-
it { should allow_value("
|
88
|
-
it { should allow_value("
|
211
|
+
it { should allow_value("30000000000000").for(:cc_number) }
|
212
|
+
it { should allow_value("30100000000000").for(:cc_number) }
|
213
|
+
it { should allow_value("30200000000000").for(:cc_number) }
|
214
|
+
it { should allow_value("30300000000000").for(:cc_number) }
|
215
|
+
it { should allow_value("30400000000000").for(:cc_number) }
|
216
|
+
it { should allow_value("30500000000000").for(:cc_number) }
|
217
|
+
it { should allow_value("36000000000000").for(:cc_number) }
|
218
|
+
it { should allow_value("54000000000000").for(:cc_number) }
|
219
|
+
it { should allow_value("55000000000000").for(:cc_number) }
|
220
|
+
it { should allow_value("5500000000000000").for(:cc_number) }
|
221
|
+
it { should allow_value("5500 0000.0000-00").for(:cc_number) }
|
222
|
+
it { should allow_value("5500 0000.0000-0000").for(:cc_number) }
|
89
223
|
|
90
224
|
it { should_not allow_value('').for(:cc_number) }
|
91
225
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -93,19 +227,12 @@ describe CreditCardValidator do
|
|
93
227
|
it { should_not allow_value("#").for(:cc_number) }
|
94
228
|
it { should_not allow_value("9").for(:cc_number) }
|
95
229
|
it { should_not allow_value("a").for(:cc_number) }
|
96
|
-
it { should_not allow_value("
|
97
|
-
it { should_not allow_value("
|
98
|
-
it { should_not allow_value("
|
99
|
-
it { should_not allow_value("
|
100
|
-
it { should_not allow_value("
|
101
|
-
it { should_not allow_value("
|
102
|
-
it { should_not allow_value("5555555555554444").for(:cc_number) }
|
103
|
-
it { should_not allow_value("5200828282828210").for(:cc_number) }
|
104
|
-
it { should_not allow_value("5105105105105100").for(:cc_number) }
|
105
|
-
it { should_not allow_value("4242424242424242").for(:cc_number) }
|
106
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
107
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
108
|
-
it { should_not allow_value("4000056655665556").for(:cc_number) }
|
230
|
+
it { should_not allow_value("4500000000000000").for(:cc_number) }
|
231
|
+
it { should_not allow_value("5500000000000").for(:cc_number) }
|
232
|
+
it { should_not allow_value("55000000000000000").for(:cc_number) }
|
233
|
+
it { should_not allow_value("4500 0000.0000-0000").for(:cc_number) }
|
234
|
+
it { should_not allow_value("5500 0000.0000-0").for(:cc_number) }
|
235
|
+
it { should_not allow_value("5500 0000.0000-00000").for(:cc_number) }
|
109
236
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
110
237
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
111
238
|
|
@@ -113,19 +240,52 @@ describe CreditCardValidator do
|
|
113
240
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
114
241
|
end
|
115
242
|
|
116
|
-
context "with :
|
243
|
+
context "with card: :discover option has a valid value" do
|
117
244
|
let(:klass) do
|
118
245
|
Class.new do
|
119
246
|
include ActiveModel::Validations
|
120
247
|
attr_accessor :cc_number, :name
|
121
|
-
validates :cc_number, credit_card: {
|
248
|
+
validates :cc_number, credit_card: { card: :discover }
|
122
249
|
end
|
123
250
|
end
|
124
251
|
|
125
252
|
subject { klass.new }
|
126
253
|
|
127
|
-
it { should allow_value("
|
128
|
-
it { should allow_value("
|
254
|
+
it { should allow_value("6011000000000000").for(:cc_number) }
|
255
|
+
it { should allow_value("6221260000000000").for(:cc_number) }
|
256
|
+
it { should allow_value("6221270000000000").for(:cc_number) }
|
257
|
+
it { should allow_value("6221280000000000").for(:cc_number) }
|
258
|
+
it { should allow_value("6221290000000000").for(:cc_number) }
|
259
|
+
it { should allow_value("6221300000000000").for(:cc_number) }
|
260
|
+
it { should allow_value("6221400000000000").for(:cc_number) }
|
261
|
+
it { should allow_value("6221500000000000").for(:cc_number) }
|
262
|
+
it { should allow_value("6221600000000000").for(:cc_number) }
|
263
|
+
it { should allow_value("6221700000000000").for(:cc_number) }
|
264
|
+
it { should allow_value("6221800000000000").for(:cc_number) }
|
265
|
+
it { should allow_value("6221900000000000").for(:cc_number) }
|
266
|
+
it { should allow_value("6222000000000000").for(:cc_number) }
|
267
|
+
it { should allow_value("6223000000000000").for(:cc_number) }
|
268
|
+
it { should allow_value("6224000000000000").for(:cc_number) }
|
269
|
+
it { should allow_value("6225000000000000").for(:cc_number) }
|
270
|
+
it { should allow_value("6226000000000000").for(:cc_number) }
|
271
|
+
it { should allow_value("6227000000000000").for(:cc_number) }
|
272
|
+
it { should allow_value("6228000000000000").for(:cc_number) }
|
273
|
+
it { should allow_value("6229000000000000").for(:cc_number) }
|
274
|
+
it { should allow_value("6229100000000000").for(:cc_number) }
|
275
|
+
it { should allow_value("6229200000000000").for(:cc_number) }
|
276
|
+
it { should allow_value("6229210000000000").for(:cc_number) }
|
277
|
+
it { should allow_value("6229220000000000").for(:cc_number) }
|
278
|
+
it { should allow_value("6229230000000000").for(:cc_number) }
|
279
|
+
it { should allow_value("6229240000000000").for(:cc_number) }
|
280
|
+
it { should allow_value("6229250000000000").for(:cc_number) }
|
281
|
+
it { should allow_value("6440000000000000").for(:cc_number) }
|
282
|
+
it { should allow_value("6450000000000000").for(:cc_number) }
|
283
|
+
it { should allow_value("6460000000000000").for(:cc_number) }
|
284
|
+
it { should allow_value("6470000000000000").for(:cc_number) }
|
285
|
+
it { should allow_value("6480000000000000").for(:cc_number) }
|
286
|
+
it { should allow_value("6490000000000000").for(:cc_number) }
|
287
|
+
it { should allow_value("6500000000000000").for(:cc_number) }
|
288
|
+
it { should allow_value("6500 0000.0000-0000").for(:cc_number) }
|
129
289
|
|
130
290
|
it { should_not allow_value('').for(:cc_number) }
|
131
291
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -133,19 +293,12 @@ describe CreditCardValidator do
|
|
133
293
|
it { should_not allow_value("#").for(:cc_number) }
|
134
294
|
it { should_not allow_value("9").for(:cc_number) }
|
135
295
|
it { should_not allow_value("a").for(:cc_number) }
|
136
|
-
it { should_not allow_value("
|
137
|
-
it { should_not allow_value("
|
138
|
-
it { should_not allow_value("
|
139
|
-
it { should_not allow_value("
|
140
|
-
it { should_not allow_value("
|
141
|
-
it { should_not allow_value("
|
142
|
-
it { should_not allow_value("5555555555554444").for(:cc_number) }
|
143
|
-
it { should_not allow_value("5200828282828210").for(:cc_number) }
|
144
|
-
it { should_not allow_value("5105105105105100").for(:cc_number) }
|
145
|
-
it { should_not allow_value("4242424242424242").for(:cc_number) }
|
146
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
147
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
148
|
-
it { should_not allow_value("4000056655665556").for(:cc_number) }
|
296
|
+
it { should_not allow_value("5500000000000000").for(:cc_number) }
|
297
|
+
it { should_not allow_value("650000000000000").for(:cc_number) }
|
298
|
+
it { should_not allow_value("65000000000000000").for(:cc_number) }
|
299
|
+
it { should_not allow_value("5500 0000.0000-0000").for(:cc_number) }
|
300
|
+
it { should_not allow_value("6500 0000.0000-000").for(:cc_number) }
|
301
|
+
it { should_not allow_value("6500 0000.0000-00000").for(:cc_number) }
|
149
302
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
150
303
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
151
304
|
|
@@ -153,19 +306,26 @@ describe CreditCardValidator do
|
|
153
306
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
154
307
|
end
|
155
308
|
|
156
|
-
context "with :
|
309
|
+
context "with card: :jcb option has a valid value" do
|
157
310
|
let(:klass) do
|
158
311
|
Class.new do
|
159
312
|
include ActiveModel::Validations
|
160
313
|
attr_accessor :cc_number, :name
|
161
|
-
validates :cc_number, credit_card: {
|
314
|
+
validates :cc_number, credit_card: { card: :jcb }
|
162
315
|
end
|
163
316
|
end
|
164
317
|
|
165
318
|
subject { klass.new }
|
166
319
|
|
167
|
-
it { should allow_value("
|
168
|
-
it { should allow_value("
|
320
|
+
it { should allow_value("3528000000000000").for(:cc_number) }
|
321
|
+
it { should allow_value("3529000000000000").for(:cc_number) }
|
322
|
+
it { should allow_value("3530000000000000").for(:cc_number) }
|
323
|
+
it { should allow_value("3540000000000000").for(:cc_number) }
|
324
|
+
it { should allow_value("3550000000000000").for(:cc_number) }
|
325
|
+
it { should allow_value("3560000000000000").for(:cc_number) }
|
326
|
+
it { should allow_value("3570000000000000").for(:cc_number) }
|
327
|
+
it { should allow_value("3580000000000000").for(:cc_number) }
|
328
|
+
it { should allow_value("3580 0000.0000-0000").for(:cc_number) }
|
169
329
|
|
170
330
|
it { should_not allow_value('').for(:cc_number) }
|
171
331
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -173,19 +333,12 @@ describe CreditCardValidator do
|
|
173
333
|
it { should_not allow_value("#").for(:cc_number) }
|
174
334
|
it { should_not allow_value("9").for(:cc_number) }
|
175
335
|
it { should_not allow_value("a").for(:cc_number) }
|
176
|
-
it { should_not allow_value("
|
177
|
-
it { should_not allow_value("
|
178
|
-
it { should_not allow_value("
|
179
|
-
it { should_not allow_value("
|
180
|
-
it { should_not allow_value("
|
181
|
-
it { should_not allow_value("
|
182
|
-
it { should_not allow_value("5555555555554444").for(:cc_number) }
|
183
|
-
it { should_not allow_value("5200828282828210").for(:cc_number) }
|
184
|
-
it { should_not allow_value("5105105105105100").for(:cc_number) }
|
185
|
-
it { should_not allow_value("4242424242424242").for(:cc_number) }
|
186
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
187
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
188
|
-
it { should_not allow_value("4000056655665556").for(:cc_number) }
|
336
|
+
it { should_not allow_value("2580000000000000").for(:cc_number) }
|
337
|
+
it { should_not allow_value("358000000000000").for(:cc_number) }
|
338
|
+
it { should_not allow_value("35800000000000000").for(:cc_number) }
|
339
|
+
it { should_not allow_value("2580 0000.0000-0000").for(:cc_number) }
|
340
|
+
it { should_not allow_value("3580 0000.0000-000").for(:cc_number) }
|
341
|
+
it { should_not allow_value("3580 0000.0000-00000").for(:cc_number) }
|
189
342
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
190
343
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
191
344
|
|
@@ -193,19 +346,28 @@ describe CreditCardValidator do
|
|
193
346
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
194
347
|
end
|
195
348
|
|
196
|
-
context "with :
|
349
|
+
context "with card: :laser option has a valid value" do
|
197
350
|
let(:klass) do
|
198
351
|
Class.new do
|
199
352
|
include ActiveModel::Validations
|
200
353
|
attr_accessor :cc_number, :name
|
201
|
-
validates :cc_number, credit_card: {
|
354
|
+
validates :cc_number, credit_card: { card: :laser }
|
202
355
|
end
|
203
356
|
end
|
204
357
|
|
205
358
|
subject { klass.new }
|
206
359
|
|
207
|
-
it { should allow_value("
|
208
|
-
it { should allow_value("
|
360
|
+
it { should allow_value("6304000000000000").for(:cc_number) }
|
361
|
+
it { should allow_value("6706000000000000").for(:cc_number) }
|
362
|
+
it { should allow_value("6771000000000000").for(:cc_number) }
|
363
|
+
it { should allow_value("6709000000000000").for(:cc_number) }
|
364
|
+
it { should allow_value("67090000000000000").for(:cc_number) }
|
365
|
+
it { should allow_value("670900000000000000").for(:cc_number) }
|
366
|
+
it { should allow_value("6709000000000000000").for(:cc_number) }
|
367
|
+
it { should allow_value("6709 0000.0000-0000").for(:cc_number) }
|
368
|
+
it { should allow_value("6709 0000.0000-00000").for(:cc_number) }
|
369
|
+
it { should allow_value("6709 0000.0000-000000").for(:cc_number) }
|
370
|
+
it { should allow_value("6709 0000.0000-0000000").for(:cc_number) }
|
209
371
|
|
210
372
|
it { should_not allow_value('').for(:cc_number) }
|
211
373
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -213,19 +375,12 @@ describe CreditCardValidator do
|
|
213
375
|
it { should_not allow_value("#").for(:cc_number) }
|
214
376
|
it { should_not allow_value("9").for(:cc_number) }
|
215
377
|
it { should_not allow_value("a").for(:cc_number) }
|
216
|
-
it { should_not allow_value("
|
217
|
-
it { should_not allow_value("
|
218
|
-
it { should_not allow_value("
|
219
|
-
it { should_not allow_value("
|
220
|
-
it { should_not allow_value("
|
221
|
-
it { should_not allow_value("
|
222
|
-
it { should_not allow_value("5555555555554444").for(:cc_number) }
|
223
|
-
it { should_not allow_value("5200828282828210").for(:cc_number) }
|
224
|
-
it { should_not allow_value("5105105105105100").for(:cc_number) }
|
225
|
-
it { should_not allow_value("4242424242424242").for(:cc_number) }
|
226
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
227
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
228
|
-
it { should_not allow_value("4000056655665556").for(:cc_number) }
|
378
|
+
it { should_not allow_value("5709000000000000").for(:cc_number) }
|
379
|
+
it { should_not allow_value("670900000000000").for(:cc_number) }
|
380
|
+
it { should_not allow_value("67090000000000000000").for(:cc_number) }
|
381
|
+
it { should_not allow_value("5709 0000.0000-0000").for(:cc_number) }
|
382
|
+
it { should_not allow_value("6709 0000.0000-000").for(:cc_number) }
|
383
|
+
it { should_not allow_value("6709 0000.0000-00000000").for(:cc_number) }
|
229
384
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
230
385
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
231
386
|
|
@@ -233,20 +388,43 @@ describe CreditCardValidator do
|
|
233
388
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
234
389
|
end
|
235
390
|
|
236
|
-
context "with :
|
391
|
+
context "with card: :maestro option has a valid value" do
|
237
392
|
let(:klass) do
|
238
393
|
Class.new do
|
239
394
|
include ActiveModel::Validations
|
240
395
|
attr_accessor :cc_number, :name
|
241
|
-
validates :cc_number, credit_card: {
|
396
|
+
validates :cc_number, credit_card: { card: :maestro }
|
242
397
|
end
|
243
398
|
end
|
244
399
|
|
245
400
|
subject { klass.new }
|
246
401
|
|
247
|
-
it { should allow_value("
|
248
|
-
it { should allow_value("
|
249
|
-
it { should allow_value("
|
402
|
+
it { should allow_value("501800000000").for(:cc_number) }
|
403
|
+
it { should allow_value("502000000000").for(:cc_number) }
|
404
|
+
it { should allow_value("503800000000").for(:cc_number) }
|
405
|
+
it { should allow_value("630400000000").for(:cc_number) }
|
406
|
+
it { should allow_value("675900000000").for(:cc_number) }
|
407
|
+
it { should allow_value("676100000000").for(:cc_number) }
|
408
|
+
it { should allow_value("676200000000").for(:cc_number) }
|
409
|
+
it { should allow_value("676300000000").for(:cc_number) }
|
410
|
+
it { should allow_value("676400000000").for(:cc_number) }
|
411
|
+
it { should allow_value("676500000000").for(:cc_number) }
|
412
|
+
it { should allow_value("676600000000").for(:cc_number) }
|
413
|
+
it { should allow_value("6766000000000").for(:cc_number) }
|
414
|
+
it { should allow_value("67660000000000").for(:cc_number) }
|
415
|
+
it { should allow_value("676600000000000").for(:cc_number) }
|
416
|
+
it { should allow_value("6766000000000000").for(:cc_number) }
|
417
|
+
it { should allow_value("67660000000000000").for(:cc_number) }
|
418
|
+
it { should allow_value("676600000000000000").for(:cc_number) }
|
419
|
+
it { should allow_value("6766000000000000000").for(:cc_number) }
|
420
|
+
it { should allow_value("6766 0000.0000").for(:cc_number) }
|
421
|
+
it { should allow_value("6766 0000.0000-0").for(:cc_number) }
|
422
|
+
it { should allow_value("6766 0000.0000-00").for(:cc_number) }
|
423
|
+
it { should allow_value("6766 0000.0000-000").for(:cc_number) }
|
424
|
+
it { should allow_value("6766 0000.0000-0000").for(:cc_number) }
|
425
|
+
it { should allow_value("6766 0000.0000-00000").for(:cc_number) }
|
426
|
+
it { should allow_value("6766 0000.0000-000000").for(:cc_number) }
|
427
|
+
it { should allow_value("6766 0000.0000-0000000").for(:cc_number) }
|
250
428
|
|
251
429
|
it { should_not allow_value('').for(:cc_number) }
|
252
430
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -254,18 +432,12 @@ describe CreditCardValidator do
|
|
254
432
|
it { should_not allow_value("#").for(:cc_number) }
|
255
433
|
it { should_not allow_value("9").for(:cc_number) }
|
256
434
|
it { should_not allow_value("a").for(:cc_number) }
|
257
|
-
it { should_not allow_value("
|
258
|
-
it { should_not allow_value("
|
259
|
-
it { should_not allow_value("
|
260
|
-
it { should_not allow_value("
|
261
|
-
it { should_not allow_value("
|
262
|
-
it { should_not allow_value("
|
263
|
-
it { should_not allow_value("3530111333300000").for(:cc_number) }
|
264
|
-
it { should_not allow_value("3566002020360505").for(:cc_number) }
|
265
|
-
it { should_not allow_value("4242424242424242").for(:cc_number) }
|
266
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
267
|
-
it { should_not allow_value("4012888888881881").for(:cc_number) }
|
268
|
-
it { should_not allow_value("4000056655665556").for(:cc_number) }
|
435
|
+
it { should_not allow_value("576600000000").for(:cc_number) }
|
436
|
+
it { should_not allow_value("67660000000").for(:cc_number) }
|
437
|
+
it { should_not allow_value("67660000000000000000").for(:cc_number) }
|
438
|
+
it { should_not allow_value("5766 0000.0000").for(:cc_number) }
|
439
|
+
it { should_not allow_value("6766 0000.000").for(:cc_number) }
|
440
|
+
it { should_not allow_value("6766 0000.0000-00000000").for(:cc_number) }
|
269
441
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
270
442
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
271
443
|
|
@@ -273,21 +445,23 @@ describe CreditCardValidator do
|
|
273
445
|
it { should_not ensure_valid_credit_card_format_of(:name) }
|
274
446
|
end
|
275
447
|
|
276
|
-
context "with :
|
448
|
+
context "with card: :mastercard option has a valid value" do
|
277
449
|
let(:klass) do
|
278
450
|
Class.new do
|
279
451
|
include ActiveModel::Validations
|
280
452
|
attr_accessor :cc_number, :name
|
281
|
-
validates :cc_number, credit_card: {
|
453
|
+
validates :cc_number, credit_card: { card: :mastercard }
|
282
454
|
end
|
283
455
|
end
|
284
456
|
|
285
457
|
subject { klass.new }
|
286
458
|
|
287
|
-
it { should allow_value("
|
288
|
-
it { should allow_value("
|
289
|
-
it { should allow_value("
|
290
|
-
it { should allow_value("
|
459
|
+
it { should allow_value("5100000000000000").for(:cc_number) }
|
460
|
+
it { should allow_value("5200000000000000").for(:cc_number) }
|
461
|
+
it { should allow_value("5300000000000000").for(:cc_number) }
|
462
|
+
it { should allow_value("5400000000000000").for(:cc_number) }
|
463
|
+
it { should allow_value("5500000000000000").for(:cc_number) }
|
464
|
+
it { should allow_value("5500 0000.0000-0000").for(:cc_number) }
|
291
465
|
|
292
466
|
it { should_not allow_value('').for(:cc_number) }
|
293
467
|
it { should_not allow_value(' ').for(:cc_number) }
|
@@ -295,17 +469,213 @@ describe CreditCardValidator do
|
|
295
469
|
it { should_not allow_value("#").for(:cc_number) }
|
296
470
|
it { should_not allow_value("9").for(:cc_number) }
|
297
471
|
it { should_not allow_value("a").for(:cc_number) }
|
298
|
-
it { should_not allow_value("
|
299
|
-
it { should_not allow_value("
|
300
|
-
it { should_not allow_value("
|
301
|
-
it { should_not allow_value("
|
302
|
-
it { should_not allow_value("
|
303
|
-
it { should_not allow_value("
|
304
|
-
it { should_not allow_value("
|
305
|
-
it { should_not allow_value("
|
306
|
-
|
307
|
-
it {
|
308
|
-
it { should_not
|
472
|
+
it { should_not allow_value("4500000000000000").for(:cc_number) }
|
473
|
+
it { should_not allow_value("550000000000000").for(:cc_number) }
|
474
|
+
it { should_not allow_value("55000000000000000").for(:cc_number) }
|
475
|
+
it { should_not allow_value("4500 0000.0000-0000").for(:cc_number) }
|
476
|
+
it { should_not allow_value("5500 0000.0000-00000").for(:cc_number) }
|
477
|
+
it { should_not allow_value("5500 0000.0000-000").for(:cc_number) }
|
478
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
479
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
480
|
+
|
481
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
482
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
483
|
+
end
|
484
|
+
|
485
|
+
context "with card: :solo option has a valid value" do
|
486
|
+
let(:klass) do
|
487
|
+
Class.new do
|
488
|
+
include ActiveModel::Validations
|
489
|
+
attr_accessor :cc_number, :name
|
490
|
+
validates :cc_number, credit_card: { card: :solo }
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
subject { klass.new }
|
495
|
+
|
496
|
+
it { should allow_value("6334000000000000").for(:cc_number) }
|
497
|
+
it { should allow_value("6767000000000000").for(:cc_number) }
|
498
|
+
it { should allow_value("676700000000000000").for(:cc_number) }
|
499
|
+
it { should allow_value("6767000000000000000").for(:cc_number) }
|
500
|
+
it { should allow_value("6767 0000.0000-0000").for(:cc_number) }
|
501
|
+
it { should allow_value("6767 0000.0000-000000").for(:cc_number) }
|
502
|
+
it { should allow_value("6767 0000.0000-0000000").for(:cc_number) }
|
503
|
+
|
504
|
+
it { should_not allow_value('').for(:cc_number) }
|
505
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
506
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
507
|
+
it { should_not allow_value("#").for(:cc_number) }
|
508
|
+
it { should_not allow_value("9").for(:cc_number) }
|
509
|
+
it { should_not allow_value("a").for(:cc_number) }
|
510
|
+
it { should_not allow_value("5767000000000000").for(:cc_number) }
|
511
|
+
it { should_not allow_value("676700000000000").for(:cc_number) }
|
512
|
+
it { should_not allow_value("67670000000000000").for(:cc_number) }
|
513
|
+
it { should_not allow_value("67670000000000000000").for(:cc_number) }
|
514
|
+
it { should_not allow_value("5767 0000.0000-0000").for(:cc_number) }
|
515
|
+
it { should_not allow_value("6767 0000.0000-000").for(:cc_number) }
|
516
|
+
it { should_not allow_value("6767 0000.0000-00000").for(:cc_number) }
|
517
|
+
it { should_not allow_value("6767 0000.0000-00000000").for(:cc_number) }
|
518
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
519
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
520
|
+
|
521
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
522
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
523
|
+
end
|
524
|
+
|
525
|
+
context "with card: :unionpay option has a valid value" do
|
526
|
+
let(:klass) do
|
527
|
+
Class.new do
|
528
|
+
include ActiveModel::Validations
|
529
|
+
attr_accessor :cc_number, :name
|
530
|
+
validates :cc_number, credit_card: { card: :unionpay }
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
subject { klass.new }
|
535
|
+
|
536
|
+
it { should allow_value("6221260000000000").for(:cc_number) }
|
537
|
+
it { should allow_value("6221270000000000").for(:cc_number) }
|
538
|
+
it { should allow_value("6221280000000000").for(:cc_number) }
|
539
|
+
it { should allow_value("6221300000000000").for(:cc_number) }
|
540
|
+
it { should allow_value("6221400000000000").for(:cc_number) }
|
541
|
+
it { should allow_value("6221500000000000").for(:cc_number) }
|
542
|
+
it { should allow_value("6221600000000000").for(:cc_number) }
|
543
|
+
it { should allow_value("6221700000000000").for(:cc_number) }
|
544
|
+
it { should allow_value("6221800000000000").for(:cc_number) }
|
545
|
+
it { should allow_value("6221900000000000").for(:cc_number) }
|
546
|
+
it { should allow_value("6222000000000000").for(:cc_number) }
|
547
|
+
it { should allow_value("6223000000000000").for(:cc_number) }
|
548
|
+
it { should allow_value("6224000000000000").for(:cc_number) }
|
549
|
+
it { should allow_value("6225000000000000").for(:cc_number) }
|
550
|
+
it { should allow_value("6226000000000000").for(:cc_number) }
|
551
|
+
it { should allow_value("6227000000000000").for(:cc_number) }
|
552
|
+
it { should allow_value("6228000000000000").for(:cc_number) }
|
553
|
+
it { should allow_value("6229000000000000").for(:cc_number) }
|
554
|
+
it { should allow_value("6229100000000000").for(:cc_number) }
|
555
|
+
it { should allow_value("6229200000000000").for(:cc_number) }
|
556
|
+
it { should allow_value("6229210000000000").for(:cc_number) }
|
557
|
+
it { should allow_value("6229220000000000").for(:cc_number) }
|
558
|
+
it { should allow_value("6229230000000000").for(:cc_number) }
|
559
|
+
it { should allow_value("6229240000000000").for(:cc_number) }
|
560
|
+
it { should allow_value("6229250000000000").for(:cc_number) }
|
561
|
+
it { should allow_value("62292500000000000").for(:cc_number) }
|
562
|
+
it { should allow_value("622925000000000000").for(:cc_number) }
|
563
|
+
it { should allow_value("6229250000000000000").for(:cc_number) }
|
564
|
+
it { should allow_value("6229 2500.0000-0000").for(:cc_number) }
|
565
|
+
it { should allow_value("6229 2500.0000-00000").for(:cc_number) }
|
566
|
+
it { should allow_value("6229 2500.0000-000000").for(:cc_number) }
|
567
|
+
it { should allow_value("6229 2500.0000-0000000").for(:cc_number) }
|
568
|
+
|
569
|
+
it { should_not allow_value('').for(:cc_number) }
|
570
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
571
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
572
|
+
it { should_not allow_value("#").for(:cc_number) }
|
573
|
+
it { should_not allow_value("9").for(:cc_number) }
|
574
|
+
it { should_not allow_value("a").for(:cc_number) }
|
575
|
+
it { should_not allow_value("5229250000000000").for(:cc_number) }
|
576
|
+
it { should_not allow_value("622925000000000").for(:cc_number) }
|
577
|
+
it { should_not allow_value("62292500000000000000").for(:cc_number) }
|
578
|
+
it { should_not allow_value("5229 2500.0000-0000").for(:cc_number) }
|
579
|
+
it { should_not allow_value("6229 2500.0000-000").for(:cc_number) }
|
580
|
+
it { should_not allow_value("6229 2500.0000-00000000").for(:cc_number) }
|
581
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
582
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
583
|
+
|
584
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
585
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
586
|
+
end
|
587
|
+
|
588
|
+
context "with card: :visa option has a valid value" do
|
589
|
+
let(:klass) do
|
590
|
+
Class.new do
|
591
|
+
include ActiveModel::Validations
|
592
|
+
attr_accessor :cc_number, :name
|
593
|
+
validates :cc_number, credit_card: { card: :visa }
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
subject { klass.new }
|
598
|
+
|
599
|
+
it { should allow_value("4000000000000000").for(:cc_number) }
|
600
|
+
it { should allow_value("4000 0000.0000-0000").for(:cc_number) }
|
601
|
+
|
602
|
+
it { should_not allow_value('').for(:cc_number) }
|
603
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
604
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
605
|
+
it { should_not allow_value("#").for(:cc_number) }
|
606
|
+
it { should_not allow_value("9").for(:cc_number) }
|
607
|
+
it { should_not allow_value("a").for(:cc_number) }
|
608
|
+
it { should_not allow_value("3000000000000000").for(:cc_number) }
|
609
|
+
it { should_not allow_value("400000000000000").for(:cc_number) }
|
610
|
+
it { should_not allow_value("40000000000000000").for(:cc_number) }
|
611
|
+
it { should_not allow_value("3000 0000.0000-0000").for(:cc_number) }
|
612
|
+
it { should_not allow_value("4000 0000.0000-000").for(:cc_number) }
|
613
|
+
it { should_not allow_value("4000 0000.0000-00000").for(:cc_number) }
|
614
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
615
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
616
|
+
|
617
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
618
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
619
|
+
end
|
620
|
+
|
621
|
+
context "with :strict option has a valid value" do
|
622
|
+
let(:klass) do
|
623
|
+
Class.new do
|
624
|
+
include ActiveModel::Validations
|
625
|
+
attr_accessor :cc_number, :name
|
626
|
+
validates :cc_number, credit_card: { strict: true }
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
subject { klass.new }
|
631
|
+
|
632
|
+
it { should allow_value("4000000000000000").for(:cc_number) }
|
633
|
+
|
634
|
+
it { should_not allow_value('').for(:cc_number) }
|
635
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
636
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
637
|
+
it { should_not allow_value("#").for(:cc_number) }
|
638
|
+
it { should_not allow_value("9").for(:cc_number) }
|
639
|
+
it { should_not allow_value("a").for(:cc_number) }
|
640
|
+
it { should_not allow_value("400000000000000").for(:cc_number) }
|
641
|
+
it { should_not allow_value("40000000000000000").for(:cc_number) }
|
642
|
+
it { should_not allow_value("3000 0000.0000-00").for(:cc_number) }
|
643
|
+
it { should_not allow_value("4000 0000.0000-000").for(:cc_number) }
|
644
|
+
it { should_not allow_value("4000 0000.0000-0000").for(:cc_number) }
|
645
|
+
it { should_not allow_value("4000 0000.0000-00000").for(:cc_number) }
|
646
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
647
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
648
|
+
|
649
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
650
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
651
|
+
end
|
652
|
+
|
653
|
+
context "with card: :visa and :strict options has a valid value" do
|
654
|
+
let(:klass) do
|
655
|
+
Class.new do
|
656
|
+
include ActiveModel::Validations
|
657
|
+
attr_accessor :cc_number, :name
|
658
|
+
validates :cc_number, credit_card: { card: :visa, strict: true }
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
subject { klass.new }
|
663
|
+
|
664
|
+
it { should allow_value("4000000000000000").for(:cc_number) }
|
665
|
+
|
666
|
+
it { should_not allow_value('').for(:cc_number) }
|
667
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
668
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
669
|
+
it { should_not allow_value("#").for(:cc_number) }
|
670
|
+
it { should_not allow_value("9").for(:cc_number) }
|
671
|
+
it { should_not allow_value("a").for(:cc_number) }
|
672
|
+
it { should_not allow_value("3000000000000000").for(:cc_number) }
|
673
|
+
it { should_not allow_value("400000000000000").for(:cc_number) }
|
674
|
+
it { should_not allow_value("40000000000000000").for(:cc_number) }
|
675
|
+
it { should_not allow_value("3000 0000.0000-0000").for(:cc_number) }
|
676
|
+
it { should_not allow_value("4000 0000.0000-000").for(:cc_number) }
|
677
|
+
it { should_not allow_value("4000 0000.0000-0000").for(:cc_number) }
|
678
|
+
it { should_not allow_value("4000 0000.0000-00000").for(:cc_number) }
|
309
679
|
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
310
680
|
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
311
681
|
|