active_validation 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -6
- data/.rspec +3 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/LICENSE.txt +17 -18
- data/README.md +100 -145
- data/active_validation.gemspec +4 -3
- data/bin/console +14 -0
- data/bin/rake +16 -0
- data/bin/setup +7 -0
- data/config/locales/en.yml +7 -8
- data/lib/active_validation.rb +4 -4
- data/lib/active_validation/matchers/{ensure_valid_latitude_format_of.rb → ensure_valid_coordinate_format_of.rb} +5 -5
- data/lib/active_validation/validators/coordinate_validator.rb +38 -0
- data/lib/active_validation/version.rb +1 -1
- metadata +11 -63
- data/lib/active_validation/matchers/ensure_valid_longitude_format_of.rb +0 -26
- data/lib/active_validation/validators/latitude_validator.rb +0 -9
- data/lib/active_validation/validators/longitude_validator.rb +0 -9
- data/spec/lib/alpha_numeric_validator_spec.rb +0 -91
- data/spec/lib/alpha_validator_spec.rb +0 -182
- data/spec/lib/base64_validator_spec.rb +0 -33
- data/spec/lib/boolean_validator_spec.rb +0 -35
- data/spec/lib/credit_card_validator_spec.rb +0 -686
- data/spec/lib/currency_validator_spec.rb +0 -63
- data/spec/lib/cusip_validator_spec.rb +0 -27
- data/spec/lib/email_validator_spec.rb +0 -109
- data/spec/lib/equality_validator_spec.rb +0 -334
- data/spec/lib/hex_validator_spec.rb +0 -73
- data/spec/lib/imei_validator_spec.rb +0 -41
- data/spec/lib/ip_validator_spec.rb +0 -33
- data/spec/lib/isbn_validator_spec.rb +0 -41
- data/spec/lib/isin_validator_spec.rb +0 -35
- data/spec/lib/latitude_validator_spec.rb +0 -31
- data/spec/lib/longitude_validator_spec.rb +0 -31
- data/spec/lib/mac_address_validator_spec.rb +0 -54
- data/spec/lib/name_validator_spec.rb +0 -39
- data/spec/lib/password_validator_spec.rb +0 -85
- data/spec/lib/phone_validator_spec.rb +0 -42
- data/spec/lib/sedol_validator_spec.rb +0 -31
- data/spec/lib/slug_validator_spec.rb +0 -41
- data/spec/lib/ssn_validator_spec.rb +0 -36
- data/spec/lib/url_validator_spec.rb +0 -106
- data/spec/lib/username_validator_spec.rb +0 -37
- data/spec/lib/uuid_validator_spec.rb +0 -157
- data/spec/spec_helper.rb +0 -12
@@ -1,182 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AlphaValidator do
|
4
|
-
|
5
|
-
context "has a valid value" do
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
include ActiveModel::Validations
|
9
|
-
attr_accessor :title, :name
|
10
|
-
validates :title, alpha: true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { klass.new }
|
15
|
-
|
16
|
-
it { should allow_value("Example").for(:title) }
|
17
|
-
it { should allow_value("Example Title").for(:title) }
|
18
|
-
|
19
|
-
it { should_not allow_value('').for(:title) }
|
20
|
-
it { should_not allow_value(' ').for(:title) }
|
21
|
-
it { should_not allow_value(nil).for(:title) }
|
22
|
-
it { should_not allow_value("Example1").for(:title) }
|
23
|
-
it { should_not allow_value("Example 1").for(:title) }
|
24
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
25
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
26
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
27
|
-
|
28
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
29
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with :strict option has a valid value" do
|
33
|
-
let(:klass) do
|
34
|
-
Class.new do
|
35
|
-
include ActiveModel::Validations
|
36
|
-
attr_accessor :title, :name
|
37
|
-
validates :title, alpha: { strict: true }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
subject { klass.new }
|
42
|
-
|
43
|
-
it { should allow_value("Example").for(:title) }
|
44
|
-
|
45
|
-
it { should_not allow_value('').for(:title) }
|
46
|
-
it { should_not allow_value(' ').for(:title) }
|
47
|
-
it { should_not allow_value(nil).for(:title) }
|
48
|
-
it { should_not allow_value("Example Title").for(:title) }
|
49
|
-
it { should_not allow_value("Example 1").for(:title) }
|
50
|
-
it { should_not allow_value("Example1").for(:title) }
|
51
|
-
it { should_not allow_value("Ex-ample").for(:title) }
|
52
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
53
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
54
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
55
|
-
|
56
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
57
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
58
|
-
end
|
59
|
-
|
60
|
-
context "with case: :lower option has a valid value" do
|
61
|
-
let(:klass) do
|
62
|
-
Class.new do
|
63
|
-
include ActiveModel::Validations
|
64
|
-
attr_accessor :title, :name
|
65
|
-
validates :title, alpha: { case: :lower }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
subject { klass.new }
|
70
|
-
|
71
|
-
it { should allow_value("example").for(:title) }
|
72
|
-
it { should allow_value("example title").for(:title) }
|
73
|
-
|
74
|
-
it { should_not allow_value('').for(:title) }
|
75
|
-
it { should_not allow_value(' ').for(:title) }
|
76
|
-
it { should_not allow_value(nil).for(:title) }
|
77
|
-
it { should_not allow_value("Example").for(:title) }
|
78
|
-
it { should_not allow_value("Example Title").for(:title) }
|
79
|
-
it { should_not allow_value("Example 1").for(:title) }
|
80
|
-
it { should_not allow_value("Example1").for(:title) }
|
81
|
-
it { should_not allow_value("Ex-ample").for(:title) }
|
82
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
83
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
84
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
85
|
-
|
86
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
87
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
88
|
-
end
|
89
|
-
|
90
|
-
context "with case: :upper option has a valid value" do
|
91
|
-
let(:klass) do
|
92
|
-
Class.new do
|
93
|
-
include ActiveModel::Validations
|
94
|
-
attr_accessor :title, :name
|
95
|
-
validates :title, alpha: { case: :upper }
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
subject { klass.new }
|
100
|
-
|
101
|
-
it { should allow_value("EXAMPLE").for(:title) }
|
102
|
-
it { should allow_value("EXAMPLE TITLE").for(:title) }
|
103
|
-
|
104
|
-
it { should_not allow_value('').for(:title) }
|
105
|
-
it { should_not allow_value(' ').for(:title) }
|
106
|
-
it { should_not allow_value(nil).for(:title) }
|
107
|
-
it { should_not allow_value("example").for(:title) }
|
108
|
-
it { should_not allow_value("Example").for(:title) }
|
109
|
-
it { should_not allow_value("Example Title").for(:title) }
|
110
|
-
it { should_not allow_value("Example 1").for(:title) }
|
111
|
-
it { should_not allow_value("Example1").for(:title) }
|
112
|
-
it { should_not allow_value("Ex-ample").for(:title) }
|
113
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
114
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
115
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
116
|
-
|
117
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
118
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
119
|
-
end
|
120
|
-
|
121
|
-
context "with case: :lower and :strict option has a valid value" do
|
122
|
-
let(:klass) do
|
123
|
-
Class.new do
|
124
|
-
include ActiveModel::Validations
|
125
|
-
attr_accessor :title, :name
|
126
|
-
validates :title, alpha: { case: :lower, strict: true }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
subject { klass.new }
|
131
|
-
|
132
|
-
it { should allow_value("example").for(:title) }
|
133
|
-
|
134
|
-
it { should_not allow_value('').for(:title) }
|
135
|
-
it { should_not allow_value(' ').for(:title) }
|
136
|
-
it { should_not allow_value(nil).for(:title) }
|
137
|
-
it { should_not allow_value("Example").for(:title) }
|
138
|
-
it { should_not allow_value("Example Title").for(:title) }
|
139
|
-
it { should_not allow_value("Example 1").for(:title) }
|
140
|
-
it { should_not allow_value("Example1").for(:title) }
|
141
|
-
it { should_not allow_value("Ex-ample").for(:title) }
|
142
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
143
|
-
it { should_not allow_value("example title").for(:title) }
|
144
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
145
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
146
|
-
|
147
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
148
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
149
|
-
end
|
150
|
-
|
151
|
-
context "with case: :upper and :strict option has a valid value" do
|
152
|
-
let(:klass) do
|
153
|
-
Class.new do
|
154
|
-
include ActiveModel::Validations
|
155
|
-
attr_accessor :title, :name
|
156
|
-
validates :title, alpha: { case: :upper, strict: true }
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
subject { klass.new }
|
161
|
-
|
162
|
-
it { should allow_value("EXAMPLE").for(:title) }
|
163
|
-
|
164
|
-
it { should_not allow_value('').for(:title) }
|
165
|
-
it { should_not allow_value(' ').for(:title) }
|
166
|
-
it { should_not allow_value(nil).for(:title) }
|
167
|
-
it { should_not allow_value("example").for(:title) }
|
168
|
-
it { should_not allow_value("Example").for(:title) }
|
169
|
-
it { should_not allow_value("Example Title").for(:title) }
|
170
|
-
it { should_not allow_value("Example 1").for(:title) }
|
171
|
-
it { should_not allow_value("Example1").for(:title) }
|
172
|
-
it { should_not allow_value("Ex-ample").for(:title) }
|
173
|
-
it { should_not allow_value("Ex-ample1").for(:title) }
|
174
|
-
it { should_not allow_value("EXAMPLE TITLE").for(:title) }
|
175
|
-
it { should_not allow_value("! \#$%\`|").for(:title) }
|
176
|
-
it { should_not allow_value("<>@[]\`|").for(:title) }
|
177
|
-
|
178
|
-
it { should ensure_valid_alpha_format_of(:title) }
|
179
|
-
it { should_not ensure_valid_alpha_format_of(:name) }
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Base64Validator do
|
4
|
-
|
5
|
-
context "has a valid value" do
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
include ActiveModel::Validations
|
9
|
-
attr_accessor :code, :name
|
10
|
-
validates :code, base64: true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { klass.new }
|
15
|
-
|
16
|
-
it { should allow_value("YW55IGNhcm5hbCBwbGVhcw==").for(:code) }
|
17
|
-
it { should allow_value("YW55IGNhcm5hbCBwbGVhc3U=").for(:code) }
|
18
|
-
it { should allow_value("YW55IGNhcm5hbCBwbGVhc3Vy").for(:code) }
|
19
|
-
it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZQ==").for(:code) }
|
20
|
-
it { should allow_value("YW55IGNhcm5hbCBwbGVhc3VyZS4=").for(:code) }
|
21
|
-
|
22
|
-
it { should_not allow_value('').for(:code) }
|
23
|
-
it { should_not allow_value(' ').for(:code) }
|
24
|
-
it { should_not allow_value(nil).for(:code) }
|
25
|
-
it { should_not allow_value("1a.b2").for(:code) }
|
26
|
-
it { should_not allow_value("1a b2").for(:code) }
|
27
|
-
it { should_not allow_value("1a.b2==").for(:code) }
|
28
|
-
|
29
|
-
it { should ensure_valid_base64_format_of(:code) }
|
30
|
-
it { should_not ensure_valid_base64_format_of(:name) }
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe BooleanValidator do
|
4
|
-
|
5
|
-
context "has a valid value" do
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
include ActiveModel::Validations
|
9
|
-
attr_accessor :active, :name
|
10
|
-
validates :active, boolean: true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { klass.new }
|
15
|
-
|
16
|
-
it { should allow_value(true).for(:active) }
|
17
|
-
it { should allow_value(false).for(:active) }
|
18
|
-
it { should allow_value(1).for(:active) }
|
19
|
-
it { should allow_value(0).for(:active) }
|
20
|
-
|
21
|
-
it { should_not allow_value('').for(:active) }
|
22
|
-
it { should_not allow_value(' ').for(:active) }
|
23
|
-
it { should_not allow_value(nil).for(:active) }
|
24
|
-
it { should_not allow_value("true").for(:active) }
|
25
|
-
it { should_not allow_value("false").for(:active) }
|
26
|
-
it { should_not allow_value("1").for(:active) }
|
27
|
-
it { should_not allow_value("0").for(:active) }
|
28
|
-
it { should_not allow_value("! \#$%\`|").for(:active) }
|
29
|
-
it { should_not allow_value("<>@[]\`|").for(:active) }
|
30
|
-
|
31
|
-
it { should ensure_valid_boolean_format_of(:active) }
|
32
|
-
it { should_not ensure_valid_boolean_format_of(:name) }
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,686 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CreditCardValidator do
|
4
|
-
|
5
|
-
context "has a valid value" do
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
include ActiveModel::Validations
|
9
|
-
attr_accessor :cc_number, :name
|
10
|
-
validates :cc_number, credit_card: true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { klass.new }
|
15
|
-
|
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) }
|
120
|
-
|
121
|
-
it { should_not allow_value('').for(:cc_number) }
|
122
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
123
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
124
|
-
it { should_not allow_value("#").for(:cc_number) }
|
125
|
-
it { should_not allow_value("9").for(:cc_number) }
|
126
|
-
it { should_not allow_value("a").for(:cc_number) }
|
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) }
|
159
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
160
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
161
|
-
|
162
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
163
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
164
|
-
end
|
165
|
-
|
166
|
-
context "with card: :american_express option has a valid value" do
|
167
|
-
let(:klass) do
|
168
|
-
Class.new do
|
169
|
-
include ActiveModel::Validations
|
170
|
-
attr_accessor :cc_number, :name
|
171
|
-
validates :cc_number, credit_card: { card: :american_express }
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
subject { klass.new }
|
176
|
-
|
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) }
|
180
|
-
|
181
|
-
it { should_not allow_value('').for(:cc_number) }
|
182
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
183
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
184
|
-
it { should_not allow_value("#").for(:cc_number) }
|
185
|
-
it { should_not allow_value("9").for(:cc_number) }
|
186
|
-
it { should_not allow_value("a").for(:cc_number) }
|
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) }
|
193
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
194
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
195
|
-
|
196
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
197
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
198
|
-
end
|
199
|
-
|
200
|
-
context "with card: :diners_club option has a valid value" do
|
201
|
-
let(:klass) do
|
202
|
-
Class.new do
|
203
|
-
include ActiveModel::Validations
|
204
|
-
attr_accessor :cc_number, :name
|
205
|
-
validates :cc_number, credit_card: { card: :diners_club }
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
subject { klass.new }
|
210
|
-
|
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) }
|
223
|
-
|
224
|
-
it { should_not allow_value('').for(:cc_number) }
|
225
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
226
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
227
|
-
it { should_not allow_value("#").for(:cc_number) }
|
228
|
-
it { should_not allow_value("9").for(:cc_number) }
|
229
|
-
it { should_not allow_value("a").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) }
|
236
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
237
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
238
|
-
|
239
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
240
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
241
|
-
end
|
242
|
-
|
243
|
-
context "with card: :discover option has a valid value" do
|
244
|
-
let(:klass) do
|
245
|
-
Class.new do
|
246
|
-
include ActiveModel::Validations
|
247
|
-
attr_accessor :cc_number, :name
|
248
|
-
validates :cc_number, credit_card: { card: :discover }
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
subject { klass.new }
|
253
|
-
|
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) }
|
289
|
-
|
290
|
-
it { should_not allow_value('').for(:cc_number) }
|
291
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
292
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
293
|
-
it { should_not allow_value("#").for(:cc_number) }
|
294
|
-
it { should_not allow_value("9").for(:cc_number) }
|
295
|
-
it { should_not allow_value("a").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) }
|
302
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
303
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
304
|
-
|
305
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
306
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
307
|
-
end
|
308
|
-
|
309
|
-
context "with card: :jcb option has a valid value" do
|
310
|
-
let(:klass) do
|
311
|
-
Class.new do
|
312
|
-
include ActiveModel::Validations
|
313
|
-
attr_accessor :cc_number, :name
|
314
|
-
validates :cc_number, credit_card: { card: :jcb }
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
subject { klass.new }
|
319
|
-
|
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) }
|
329
|
-
|
330
|
-
it { should_not allow_value('').for(:cc_number) }
|
331
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
332
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
333
|
-
it { should_not allow_value("#").for(:cc_number) }
|
334
|
-
it { should_not allow_value("9").for(:cc_number) }
|
335
|
-
it { should_not allow_value("a").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) }
|
342
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
343
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
344
|
-
|
345
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
346
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
347
|
-
end
|
348
|
-
|
349
|
-
context "with card: :laser option has a valid value" do
|
350
|
-
let(:klass) do
|
351
|
-
Class.new do
|
352
|
-
include ActiveModel::Validations
|
353
|
-
attr_accessor :cc_number, :name
|
354
|
-
validates :cc_number, credit_card: { card: :laser }
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
subject { klass.new }
|
359
|
-
|
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) }
|
371
|
-
|
372
|
-
it { should_not allow_value('').for(:cc_number) }
|
373
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
374
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
375
|
-
it { should_not allow_value("#").for(:cc_number) }
|
376
|
-
it { should_not allow_value("9").for(:cc_number) }
|
377
|
-
it { should_not allow_value("a").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) }
|
384
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
385
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
386
|
-
|
387
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
388
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
389
|
-
end
|
390
|
-
|
391
|
-
context "with card: :maestro option has a valid value" do
|
392
|
-
let(:klass) do
|
393
|
-
Class.new do
|
394
|
-
include ActiveModel::Validations
|
395
|
-
attr_accessor :cc_number, :name
|
396
|
-
validates :cc_number, credit_card: { card: :maestro }
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
subject { klass.new }
|
401
|
-
|
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) }
|
428
|
-
|
429
|
-
it { should_not allow_value('').for(:cc_number) }
|
430
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
431
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
432
|
-
it { should_not allow_value("#").for(:cc_number) }
|
433
|
-
it { should_not allow_value("9").for(:cc_number) }
|
434
|
-
it { should_not allow_value("a").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) }
|
441
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
442
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
443
|
-
|
444
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
445
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
446
|
-
end
|
447
|
-
|
448
|
-
context "with card: :mastercard option has a valid value" do
|
449
|
-
let(:klass) do
|
450
|
-
Class.new do
|
451
|
-
include ActiveModel::Validations
|
452
|
-
attr_accessor :cc_number, :name
|
453
|
-
validates :cc_number, credit_card: { card: :mastercard }
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
subject { klass.new }
|
458
|
-
|
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) }
|
465
|
-
|
466
|
-
it { should_not allow_value('').for(:cc_number) }
|
467
|
-
it { should_not allow_value(' ').for(:cc_number) }
|
468
|
-
it { should_not allow_value(nil).for(:cc_number) }
|
469
|
-
it { should_not allow_value("#").for(:cc_number) }
|
470
|
-
it { should_not allow_value("9").for(:cc_number) }
|
471
|
-
it { should_not allow_value("a").for(:cc_number) }
|
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) }
|
679
|
-
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
680
|
-
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
681
|
-
|
682
|
-
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
683
|
-
it { should_not ensure_valid_credit_card_format_of(:name) }
|
684
|
-
end
|
685
|
-
|
686
|
-
end
|