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 CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .rvmrc
@@ -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.end_of_month.future?
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
-
@@ -1,3 +1,3 @@
1
1
  module BankCard
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -8,31 +8,41 @@ class CreditCard
8
8
  end
9
9
 
10
10
  describe CreditCard do
11
- before do
12
- CreditCard.reset_callbacks(:validate)
13
- end
11
+ before { CreditCard.reset_callbacks(:validate) }
14
12
 
15
- it "should validate number with Luhn algorithm" do
16
- CreditCard.validates :number, :luhn => true
17
- card = CreditCard.new
13
+ describe "validation" do
14
+ subject { CreditCard.new }
18
15
 
19
- card.number = '123'
20
- card.should be_invalid
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
- card.number = '4200000000000000'
24
- card.should be_valid
25
- end
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
- it "should validate card expiration" do
28
- CreditCard.validates_expiration_of :date
29
- card = CreditCard.new
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
- card.date = Date.today
36
- card.should be_valid
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
@@ -1,3 +1,5 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
2
 
3
3
  require 'bank_card'
4
+ require 'shoulda-matchers'
5
+ require 'timecop'
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.2
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-16 00:00:00.000000000 +03:00
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: &2152518680 !ruby/object:Gem::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: *2152518680
25
+ version_requirements: *2157467540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: guard
28
- requirement: &2152518260 !ruby/object:Gem::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: *2152518260
36
+ version_requirements: *2157467120
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: guard-rspec
39
- requirement: &2152517840 !ruby/object:Gem::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: *2152517840
47
+ version_requirements: *2157466700
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: guard-bundler
50
- requirement: &2152517420 !ruby/object:Gem::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: *2152517420
58
+ version_requirements: *2157466280
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ruby-debug19
61
- requirement: &2152517000 !ruby/object:Gem::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: *2152517000
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: &2152516580 !ruby/object:Gem::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: *2152516580
102
+ version_requirements: *2157464600
81
103
  - !ruby/object:Gem::Dependency
82
104
  name: activesupport
83
- requirement: &2152516160 !ruby/object:Gem::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: *2152516160
113
+ version_requirements: *2157495140
92
114
  description: Gem includes validations, card brand detection method, etc.
93
115
  email:
94
116
  - alovak@gmail.com