bank_card 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bank_card.gemspec +3 -1
- data/lib/bank_card/validations/expiration_validator.rb +1 -2
- data/lib/bank_card/version.rb +1 -1
- data/spec/lib/validations_spec.rb +31 -21
- data/spec/spec_helper.rb +2 -0
- metadata +38 -16
data/.gitignore
CHANGED
data/bank_card.gemspec
CHANGED
@@ -23,7 +23,9 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency "guard-rspec"
|
24
24
|
s.add_development_dependency "guard-bundler"
|
25
25
|
s.add_development_dependency "ruby-debug19"
|
26
|
-
|
26
|
+
s.add_development_dependency "shoulda-matchers"
|
27
|
+
s.add_development_dependency "timecop"
|
28
|
+
|
27
29
|
s.add_runtime_dependency "activemodel"
|
28
30
|
s.add_runtime_dependency "activesupport"
|
29
31
|
end
|
@@ -2,7 +2,7 @@ module BankCard
|
|
2
2
|
module Validations
|
3
3
|
class ExpirationValidator < ActiveModel::EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
-
record.errors.add(attribute, :is_expired, options) unless value && value.
|
5
|
+
record.errors.add(attribute, :is_expired, options) unless value && value >= Date.today
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -13,4 +13,3 @@ module BankCard
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
data/lib/bank_card/version.rb
CHANGED
@@ -8,31 +8,41 @@ class CreditCard
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe CreditCard do
|
11
|
-
before
|
12
|
-
CreditCard.reset_callbacks(:validate)
|
13
|
-
end
|
11
|
+
before { CreditCard.reset_callbacks(:validate) }
|
14
12
|
|
15
|
-
|
16
|
-
CreditCard.
|
17
|
-
card = CreditCard.new
|
13
|
+
describe "validation" do
|
14
|
+
subject { CreditCard.new }
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
card.errors[:number].should include("is invalid")
|
16
|
+
describe "number with Luhn algorithm" do
|
17
|
+
before { CreditCard.validates :number, :luhn => true }
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
it { should_not allow_value('123').for(:number) }
|
20
|
+
it { should allow_value('4200000000000000').for(:number) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "card expiration" do
|
24
|
+
before { CreditCard.validates_expiration_of :date }
|
25
|
+
|
26
|
+
it { should_not allow_value(Date.today.prev_month).for(:date) }
|
27
|
+
it { should allow_value(Date.today.next_month).for(:date) }
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
card.date = Date.today.prev_month
|
32
|
-
card.should be_invalid
|
33
|
-
card.errors[:date].should include("is expired")
|
29
|
+
context "when the validity period expires in this month" do
|
30
|
+
context "when now is first day of month" do
|
31
|
+
before { Timecop.freeze(Date.today.beginning_of_month) }
|
32
|
+
after { Timecop.return }
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
it { should allow_value(Date.today).for(:date) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when now is last day of month" do
|
38
|
+
before { Timecop.freeze(Date.today.end_of_month) }
|
39
|
+
after { Timecop.return }
|
40
|
+
|
41
|
+
it { should allow_value(Date.today).for(:date) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
37
46
|
end
|
47
|
+
|
38
48
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank_card
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-30 00:00:00.000000000 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157467540 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157467540
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: guard
|
28
|
-
requirement: &
|
28
|
+
requirement: &2157467120 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2157467120
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: guard-rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2157466700 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2157466700
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: guard-bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &2157466280 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2157466280
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ruby-debug19
|
61
|
-
requirement: &
|
61
|
+
requirement: &2157465860 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,32 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2157465860
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: shoulda-matchers
|
72
|
+
requirement: &2157465440 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2157465440
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: timecop
|
83
|
+
requirement: &2157465020 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *2157465020
|
70
92
|
- !ruby/object:Gem::Dependency
|
71
93
|
name: activemodel
|
72
|
-
requirement: &
|
94
|
+
requirement: &2157464600 !ruby/object:Gem::Requirement
|
73
95
|
none: false
|
74
96
|
requirements:
|
75
97
|
- - ! '>='
|
@@ -77,10 +99,10 @@ dependencies:
|
|
77
99
|
version: '0'
|
78
100
|
type: :runtime
|
79
101
|
prerelease: false
|
80
|
-
version_requirements: *
|
102
|
+
version_requirements: *2157464600
|
81
103
|
- !ruby/object:Gem::Dependency
|
82
104
|
name: activesupport
|
83
|
-
requirement: &
|
105
|
+
requirement: &2157495140 !ruby/object:Gem::Requirement
|
84
106
|
none: false
|
85
107
|
requirements:
|
86
108
|
- - ! '>='
|
@@ -88,7 +110,7 @@ dependencies:
|
|
88
110
|
version: '0'
|
89
111
|
type: :runtime
|
90
112
|
prerelease: false
|
91
|
-
version_requirements: *
|
113
|
+
version_requirements: *2157495140
|
92
114
|
description: Gem includes validations, card brand detection method, etc.
|
93
115
|
email:
|
94
116
|
- alovak@gmail.com
|