flash_validators 0.0.1 → 1.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/.travis.yml +2 -3
- data/README.md +483 -232
- data/config/locales/en.yml +12 -0
- data/lib/flash_validators.rb +6 -0
- data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +18 -0
- data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +18 -0
- data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +18 -0
- data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +2 -4
- data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +2 -4
- data/lib/flash_validators/validators/alpha_numeric_validator.rb +17 -0
- data/lib/flash_validators/validators/alpha_validator.rb +19 -0
- data/lib/flash_validators/validators/credit_card_validator.rb +25 -0
- data/lib/flash_validators/validators/password_validator.rb +9 -1
- data/lib/flash_validators/version.rb +2 -2
- data/spec/lib/alpha_numeric_validator_spec.rb +61 -0
- data/spec/lib/alpha_validator_spec.rb +120 -0
- data/spec/lib/credit_card_validator_spec.rb +316 -0
- data/spec/lib/currency_validator_spec.rb +1 -1
- data/spec/lib/password_validator_spec.rb +42 -0
- metadata +15 -3
@@ -1,7 +1,15 @@
|
|
1
1
|
class PasswordValidator < ActiveModel::EachValidator
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
|
-
|
4
|
+
strict_mode = options[:strict] || false
|
5
|
+
|
6
|
+
if strict_mode
|
7
|
+
format = /^(?=^.{6,18}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/ # Strict: requires length between 6 and 18, one number, lowercase, upcase letter
|
8
|
+
else
|
9
|
+
format = /^[a-z0-9!@#$%^&*_-]{6,18}$/
|
10
|
+
end
|
11
|
+
|
12
|
+
unless value =~ format
|
5
13
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.password'))
|
6
14
|
end
|
7
15
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module FlashValidators
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AlphaNumericValidator do
|
4
|
+
|
5
|
+
context "Alpha-numeric 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_numeric: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value(' ').for(:title) }
|
17
|
+
it { should allow_value("Example").for(:title) }
|
18
|
+
it { should allow_value("Example Title").for(:title) }
|
19
|
+
it { should allow_value("Example1").for(:title) }
|
20
|
+
it { should allow_value("Example 1").for(:title) }
|
21
|
+
|
22
|
+
it { should_not allow_value('').for(:title) }
|
23
|
+
it { should_not allow_value(nil).for(:title) }
|
24
|
+
it { should_not allow_value("Ex-ample").for(:title) }
|
25
|
+
it { should_not allow_value("Ex-ample1").for(:title) }
|
26
|
+
it { should_not allow_value("! \#$%\`|").for(:title) }
|
27
|
+
it { should_not allow_value("<>@[]\`|").for(:title) }
|
28
|
+
|
29
|
+
it { should ensure_valid_alpha_numeric_format_of(:title) }
|
30
|
+
it { should_not ensure_valid_alpha_numeric_format_of(:name) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "Alpha-numeric with :strict option has a valid value" do
|
34
|
+
let(:klass) do
|
35
|
+
Class.new do
|
36
|
+
include ActiveModel::Validations
|
37
|
+
attr_accessor :title, :name
|
38
|
+
validates :title, alpha_numeric: { strict: true }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { klass.new }
|
43
|
+
|
44
|
+
it { should allow_value("Example").for(:title) }
|
45
|
+
it { should allow_value("Example1").for(:title) }
|
46
|
+
|
47
|
+
it { should_not allow_value('').for(:title) }
|
48
|
+
it { should_not allow_value(' ').for(:title) }
|
49
|
+
it { should_not allow_value(nil).for(:title) }
|
50
|
+
it { should_not allow_value("Example Title").for(:title) }
|
51
|
+
it { should_not allow_value("Example 1").for(:title) }
|
52
|
+
it { should_not allow_value("Ex-ample").for(:title) }
|
53
|
+
it { should_not allow_value("Ex-ample1").for(:title) }
|
54
|
+
it { should_not allow_value("! \#$%\`|").for(:title) }
|
55
|
+
it { should_not allow_value("<>@[]\`|").for(:title) }
|
56
|
+
|
57
|
+
it { should ensure_valid_alpha_numeric_format_of(:title) }
|
58
|
+
it { should_not ensure_valid_alpha_numeric_format_of(:name) }
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AlphaValidator do
|
4
|
+
|
5
|
+
context "Alpha 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(' ').for(:title) }
|
17
|
+
it { should allow_value("Example").for(:title) }
|
18
|
+
it { should allow_value("Example Title").for(:title) }
|
19
|
+
|
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-ample").for(:title) }
|
25
|
+
it { should_not allow_value("Ex-ample1").for(:title) }
|
26
|
+
it { should_not allow_value("! \#$%\`|").for(:title) }
|
27
|
+
it { should_not allow_value("<>@[]\`|").for(:title) }
|
28
|
+
|
29
|
+
it { should ensure_valid_alpha_format_of(:title) }
|
30
|
+
it { should_not ensure_valid_alpha_format_of(:name) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "Alpha with :strict option has a valid value" do
|
34
|
+
let(:klass) do
|
35
|
+
Class.new do
|
36
|
+
include ActiveModel::Validations
|
37
|
+
attr_accessor :title, :name
|
38
|
+
validates :title, alpha: { strict: true }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { klass.new }
|
43
|
+
|
44
|
+
it { should allow_value("Example").for(:title) }
|
45
|
+
|
46
|
+
it { should_not allow_value('').for(:title) }
|
47
|
+
it { should_not allow_value(' ').for(:title) }
|
48
|
+
it { should_not allow_value(nil).for(:title) }
|
49
|
+
it { should_not allow_value("Example Title").for(:title) }
|
50
|
+
it { should_not allow_value("Example 1").for(:title) }
|
51
|
+
it { should_not allow_value("Example1").for(:title) }
|
52
|
+
it { should_not allow_value("Ex-ample").for(:title) }
|
53
|
+
it { should_not allow_value("Ex-ample1").for(:title) }
|
54
|
+
it { should_not allow_value("! \#$%\`|").for(:title) }
|
55
|
+
it { should_not allow_value("<>@[]\`|").for(:title) }
|
56
|
+
|
57
|
+
it { should ensure_valid_alpha_format_of(:title) }
|
58
|
+
it { should_not ensure_valid_alpha_format_of(:name) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "Alpha with :lowercase option has a valid value" do
|
62
|
+
let(:klass) do
|
63
|
+
Class.new do
|
64
|
+
include ActiveModel::Validations
|
65
|
+
attr_accessor :title, :name
|
66
|
+
validates :title, alpha: { lowercase: true }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
subject { klass.new }
|
71
|
+
|
72
|
+
it { should allow_value("example").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 "Alpha with :uppercase 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: { uppercase: true }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
subject { klass.new }
|
100
|
+
|
101
|
+
it { should allow_value("EXAMPLE").for(:title) }
|
102
|
+
|
103
|
+
it { should_not allow_value('').for(:title) }
|
104
|
+
it { should_not allow_value(' ').for(:title) }
|
105
|
+
it { should_not allow_value(nil).for(:title) }
|
106
|
+
it { should_not allow_value("example").for(:title) }
|
107
|
+
it { should_not allow_value("Example").for(:title) }
|
108
|
+
it { should_not allow_value("Example Title").for(:title) }
|
109
|
+
it { should_not allow_value("Example 1").for(:title) }
|
110
|
+
it { should_not allow_value("Example1").for(:title) }
|
111
|
+
it { should_not allow_value("Ex-ample").for(:title) }
|
112
|
+
it { should_not allow_value("Ex-ample1").for(:title) }
|
113
|
+
it { should_not allow_value("! \#$%\`|").for(:title) }
|
114
|
+
it { should_not allow_value("<>@[]\`|").for(:title) }
|
115
|
+
|
116
|
+
it { should ensure_valid_alpha_format_of(:title) }
|
117
|
+
it { should_not ensure_valid_alpha_format_of(:name) }
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,316 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CreditCardValidator do
|
4
|
+
|
5
|
+
context "Credit card 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("378282246310005").for(:cc_number) } # American Express
|
17
|
+
it { should allow_value("371449635398431").for(:cc_number) } # American Express
|
18
|
+
it { should allow_value("30569309025904").for(:cc_number) } # Diners Club
|
19
|
+
it { should allow_value("38520000023237").for(:cc_number) } # Diners Club
|
20
|
+
it { should allow_value("6011111111111117").for(:cc_number) } # Discover
|
21
|
+
it { should allow_value("6011000990139424").for(:cc_number) } # Discover
|
22
|
+
it { should allow_value("3530111333300000").for(:cc_number) } # JCB
|
23
|
+
it { should allow_value("3566002020360505").for(:cc_number) } # JCB
|
24
|
+
it { should allow_value("5555555555554444").for(:cc_number) } # Master Card
|
25
|
+
it { should allow_value("5200828282828210").for(:cc_number) } # Master Card Debit
|
26
|
+
it { should allow_value("5105105105105100").for(:cc_number) } # Master Card Prepaid
|
27
|
+
it { should allow_value("4242424242424242").for(:cc_number) } # Visa
|
28
|
+
it { should allow_value("4012888888881881").for(:cc_number) } # Visa
|
29
|
+
it { should allow_value("4012888888881881").for(:cc_number) } # Visa Debit
|
30
|
+
it { should allow_value("4000056655665556").for(:cc_number) } # Visa Debit
|
31
|
+
|
32
|
+
it { should_not allow_value('').for(:cc_number) }
|
33
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
34
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
35
|
+
it { should_not allow_value("#").for(:cc_number) }
|
36
|
+
it { should_not allow_value("9").for(:cc_number) }
|
37
|
+
it { should_not allow_value("a").for(:cc_number) }
|
38
|
+
it { should_not allow_value("400005665566").for(:cc_number) }
|
39
|
+
it { should_not allow_value("40000566556655566").for(:cc_number) }
|
40
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
41
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
42
|
+
|
43
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
44
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "Credit card with :american_express option has a valid value" do
|
48
|
+
let(:klass) do
|
49
|
+
Class.new do
|
50
|
+
include ActiveModel::Validations
|
51
|
+
attr_accessor :cc_number, :name
|
52
|
+
validates :cc_number, credit_card: { american_express: true }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
subject { klass.new }
|
57
|
+
|
58
|
+
it { should allow_value("378282246310005").for(:cc_number) }
|
59
|
+
it { should allow_value("371449635398431").for(:cc_number) }
|
60
|
+
|
61
|
+
it { should_not allow_value('').for(:cc_number) }
|
62
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
63
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
64
|
+
it { should_not allow_value("#").for(:cc_number) }
|
65
|
+
it { should_not allow_value("9").for(:cc_number) }
|
66
|
+
it { should_not allow_value("a").for(:cc_number) }
|
67
|
+
it { should_not allow_value("37828224631000").for(:cc_number) }
|
68
|
+
it { should_not allow_value("3714496353984315").for(:cc_number) }
|
69
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
70
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
71
|
+
|
72
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
73
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "Credit card with :american_express option has a valid value" do
|
77
|
+
let(:klass) do
|
78
|
+
Class.new do
|
79
|
+
include ActiveModel::Validations
|
80
|
+
attr_accessor :cc_number, :name
|
81
|
+
validates :cc_number, credit_card: { american_express: true }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
subject { klass.new }
|
86
|
+
|
87
|
+
it { should allow_value("378282246310005").for(:cc_number) }
|
88
|
+
it { should allow_value("371449635398431").for(:cc_number) }
|
89
|
+
|
90
|
+
it { should_not allow_value('').for(:cc_number) }
|
91
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
92
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
93
|
+
it { should_not allow_value("#").for(:cc_number) }
|
94
|
+
it { should_not allow_value("9").for(:cc_number) }
|
95
|
+
it { should_not allow_value("a").for(:cc_number) }
|
96
|
+
it { should_not allow_value("30569309025904").for(:cc_number) }
|
97
|
+
it { should_not allow_value("38520000023237").for(:cc_number) }
|
98
|
+
it { should_not allow_value("6011111111111117").for(:cc_number) }
|
99
|
+
it { should_not allow_value("6011000990139424").for(:cc_number) }
|
100
|
+
it { should_not allow_value("3530111333300000").for(:cc_number) }
|
101
|
+
it { should_not allow_value("3566002020360505").for(:cc_number) }
|
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) }
|
109
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
110
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
111
|
+
|
112
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
113
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "Credit card with :diners_club option has a valid value" do
|
117
|
+
let(:klass) do
|
118
|
+
Class.new do
|
119
|
+
include ActiveModel::Validations
|
120
|
+
attr_accessor :cc_number, :name
|
121
|
+
validates :cc_number, credit_card: { diners_club: true }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
subject { klass.new }
|
126
|
+
|
127
|
+
it { should allow_value("30569309025904").for(:cc_number) }
|
128
|
+
it { should allow_value("38520000023237").for(:cc_number) }
|
129
|
+
|
130
|
+
it { should_not allow_value('').for(:cc_number) }
|
131
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
132
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
133
|
+
it { should_not allow_value("#").for(:cc_number) }
|
134
|
+
it { should_not allow_value("9").for(:cc_number) }
|
135
|
+
it { should_not allow_value("a").for(:cc_number) }
|
136
|
+
it { should_not allow_value("378282246310005").for(:cc_number) }
|
137
|
+
it { should_not allow_value("371449635398431").for(:cc_number) }
|
138
|
+
it { should_not allow_value("6011111111111117").for(:cc_number) }
|
139
|
+
it { should_not allow_value("6011000990139424").for(:cc_number) }
|
140
|
+
it { should_not allow_value("3530111333300000").for(:cc_number) }
|
141
|
+
it { should_not allow_value("3566002020360505").for(:cc_number) }
|
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) }
|
149
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
150
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
151
|
+
|
152
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
153
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
154
|
+
end
|
155
|
+
|
156
|
+
context "Credit card with :discover option has a valid value" do
|
157
|
+
let(:klass) do
|
158
|
+
Class.new do
|
159
|
+
include ActiveModel::Validations
|
160
|
+
attr_accessor :cc_number, :name
|
161
|
+
validates :cc_number, credit_card: { discover: true }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
subject { klass.new }
|
166
|
+
|
167
|
+
it { should allow_value("6011111111111117").for(:cc_number) }
|
168
|
+
it { should allow_value("6011000990139424").for(:cc_number) }
|
169
|
+
|
170
|
+
it { should_not allow_value('').for(:cc_number) }
|
171
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
172
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
173
|
+
it { should_not allow_value("#").for(:cc_number) }
|
174
|
+
it { should_not allow_value("9").for(:cc_number) }
|
175
|
+
it { should_not allow_value("a").for(:cc_number) }
|
176
|
+
it { should_not allow_value("378282246310005").for(:cc_number) }
|
177
|
+
it { should_not allow_value("371449635398431").for(:cc_number) }
|
178
|
+
it { should_not allow_value("30569309025904").for(:cc_number) }
|
179
|
+
it { should_not allow_value("38520000023237").for(:cc_number) }
|
180
|
+
it { should_not allow_value("3530111333300000").for(:cc_number) }
|
181
|
+
it { should_not allow_value("3566002020360505").for(:cc_number) }
|
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) }
|
189
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
190
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
191
|
+
|
192
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
193
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
194
|
+
end
|
195
|
+
|
196
|
+
context "Credit card with :jbc option has a valid value" do
|
197
|
+
let(:klass) do
|
198
|
+
Class.new do
|
199
|
+
include ActiveModel::Validations
|
200
|
+
attr_accessor :cc_number, :name
|
201
|
+
validates :cc_number, credit_card: { jbc: true }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
subject { klass.new }
|
206
|
+
|
207
|
+
it { should allow_value("3530111333300000").for(:cc_number) }
|
208
|
+
it { should allow_value("3566002020360505").for(:cc_number) }
|
209
|
+
|
210
|
+
it { should_not allow_value('').for(:cc_number) }
|
211
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
212
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
213
|
+
it { should_not allow_value("#").for(:cc_number) }
|
214
|
+
it { should_not allow_value("9").for(:cc_number) }
|
215
|
+
it { should_not allow_value("a").for(:cc_number) }
|
216
|
+
it { should_not allow_value("378282246310005").for(:cc_number) }
|
217
|
+
it { should_not allow_value("371449635398431").for(:cc_number) }
|
218
|
+
it { should_not allow_value("30569309025904").for(:cc_number) }
|
219
|
+
it { should_not allow_value("38520000023237").for(:cc_number) }
|
220
|
+
it { should_not allow_value("6011111111111117").for(:cc_number) }
|
221
|
+
it { should_not allow_value("6011000990139424").for(:cc_number) }
|
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) }
|
229
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
230
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
231
|
+
|
232
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
233
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
234
|
+
end
|
235
|
+
|
236
|
+
context "Credit card with :master_card option has a valid value" do
|
237
|
+
let(:klass) do
|
238
|
+
Class.new do
|
239
|
+
include ActiveModel::Validations
|
240
|
+
attr_accessor :cc_number, :name
|
241
|
+
validates :cc_number, credit_card: { master_card: true }
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
subject { klass.new }
|
246
|
+
|
247
|
+
it { should allow_value("5555555555554444").for(:cc_number) }
|
248
|
+
it { should allow_value("5200828282828210").for(:cc_number) }
|
249
|
+
it { should allow_value("5105105105105100").for(:cc_number) }
|
250
|
+
|
251
|
+
it { should_not allow_value('').for(:cc_number) }
|
252
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
253
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
254
|
+
it { should_not allow_value("#").for(:cc_number) }
|
255
|
+
it { should_not allow_value("9").for(:cc_number) }
|
256
|
+
it { should_not allow_value("a").for(:cc_number) }
|
257
|
+
it { should_not allow_value("378282246310005").for(:cc_number) }
|
258
|
+
it { should_not allow_value("371449635398431").for(:cc_number) }
|
259
|
+
it { should_not allow_value("30569309025904").for(:cc_number) }
|
260
|
+
it { should_not allow_value("38520000023237").for(:cc_number) }
|
261
|
+
it { should_not allow_value("6011111111111117").for(:cc_number) }
|
262
|
+
it { should_not allow_value("6011000990139424").for(:cc_number) }
|
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) }
|
269
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
270
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
271
|
+
|
272
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
273
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
274
|
+
end
|
275
|
+
|
276
|
+
context "Credit card with :visa option has a valid value" do
|
277
|
+
let(:klass) do
|
278
|
+
Class.new do
|
279
|
+
include ActiveModel::Validations
|
280
|
+
attr_accessor :cc_number, :name
|
281
|
+
validates :cc_number, credit_card: { visa: true }
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
subject { klass.new }
|
286
|
+
|
287
|
+
it { should allow_value("4242424242424242").for(:cc_number) }
|
288
|
+
it { should allow_value("4012888888881881").for(:cc_number) }
|
289
|
+
it { should allow_value("4012888888881881").for(:cc_number) }
|
290
|
+
it { should allow_value("4000056655665556").for(:cc_number) }
|
291
|
+
|
292
|
+
it { should_not allow_value('').for(:cc_number) }
|
293
|
+
it { should_not allow_value(' ').for(:cc_number) }
|
294
|
+
it { should_not allow_value(nil).for(:cc_number) }
|
295
|
+
it { should_not allow_value("#").for(:cc_number) }
|
296
|
+
it { should_not allow_value("9").for(:cc_number) }
|
297
|
+
it { should_not allow_value("a").for(:cc_number) }
|
298
|
+
it { should_not allow_value("378282246310005").for(:cc_number) }
|
299
|
+
it { should_not allow_value("371449635398431").for(:cc_number) }
|
300
|
+
it { should_not allow_value("30569309025904").for(:cc_number) }
|
301
|
+
it { should_not allow_value("38520000023237").for(:cc_number) }
|
302
|
+
it { should_not allow_value("6011111111111117").for(:cc_number) }
|
303
|
+
it { should_not allow_value("6011000990139424").for(:cc_number) }
|
304
|
+
it { should_not allow_value("3530111333300000").for(:cc_number) }
|
305
|
+
it { should_not allow_value("3566002020360505").for(:cc_number) }
|
306
|
+
it { should_not allow_value("5555555555554444").for(:cc_number) }
|
307
|
+
it { should_not allow_value("5200828282828210").for(:cc_number) }
|
308
|
+
it { should_not allow_value("5105105105105100").for(:cc_number) }
|
309
|
+
it { should_not allow_value("! \#$%\`|").for(:cc_number) }
|
310
|
+
it { should_not allow_value("<>@[]\`|").for(:cc_number) }
|
311
|
+
|
312
|
+
it { should ensure_valid_credit_card_format_of(:cc_number) }
|
313
|
+
it { should_not ensure_valid_credit_card_format_of(:name) }
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|