evelpidon_validators 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Evelpidon Validators changelog
2
2
 
3
+ ## 0.4.3 / 2012-01-16
4
+
5
+ * Fixed bug with validation raising an error if number is nil.
6
+ * Fixed Credit Card Validator type_attribute option is optional.
7
+
3
8
  ## 0.4.2 / 2012-01-16
4
9
 
5
10
  * Fixed type deprecation warning added in the wrong place
@@ -17,14 +17,19 @@ module ActiveModel
17
17
  end
18
18
 
19
19
  def self.valid_credit_card?(number, type)
20
+ return false if number.nil?
21
+
20
22
  if type
21
23
  ::CreditCardValidator::Validator.options[:allowed_card_types] = [type.underscore.to_sym]
24
+ else
25
+ ::CreditCardValidator::Validator.options[:allowed_card_types] = nil
22
26
  end
23
27
  ::CreditCardValidator::Validator.valid?(number)
24
28
  end
25
29
 
26
30
  def validate_each(record, attribute, value)
27
- unless self.class.valid_credit_card? value, record.send(options[:type_attribute])
31
+ type = record.send(options[:type_attribute]) if options[:type_attribute]
32
+ unless self.class.valid_credit_card? value, type
28
33
  record.errors.add(attribute, :credit_card, options)
29
34
  end
30
35
  end
@@ -1,3 +1,3 @@
1
1
  module EvelpidonValidators
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -14,6 +14,16 @@ class CreditCardValidatorTest < ActiveSupport::TestCase
14
14
  @payment = Payment.new
15
15
  end
16
16
 
17
+ test "nil number" do
18
+ assert_invalid_card_type_and_number 'Visa', nil
19
+ assert_invalid_card_type_and_number 'MasterCard', nil
20
+ assert_invalid_card_type_and_number 'DinersClub', nil
21
+ assert_invalid_card_type_and_number 'Amex', nil
22
+ assert_invalid_card_type_and_number 'Discover', nil
23
+ assert_invalid_card_type_and_number 'Maestro', nil
24
+ assert_invalid_card_type_and_number nil, nil
25
+ end
26
+
17
27
  test "visa cards" do
18
28
  assert_valid_card_type_and_number 'Visa', '4111111111111111'
19
29
  assert_valid_card_type_and_number 'visa', '4111111111111111'
@@ -86,6 +96,23 @@ class CreditCardValidatorTest < ActiveSupport::TestCase
86
96
  assert_invalid_card_type_and_number 'Discover', '6759671431256542'
87
97
  end
88
98
 
99
+ test "type attribute option is optional" do
100
+ class PaymentWithNoTypeValidation
101
+ include ActiveModel::Validations
102
+ attr_accessor :card_type, :card_number
103
+ validates :card_number, :credit_card => true
104
+ end
105
+
106
+ @payment = PaymentWithNoTypeValidation.new
107
+
108
+ assert_valid_card_type_and_number 'Visa', '4111111111111111'
109
+ assert_valid_card_type_and_number 'MasterCard', '4111111111111111'
110
+ assert_valid_card_type_and_number 'DinersClub', '4111111111111111'
111
+ assert_valid_card_type_and_number 'Amex', '4111111111111111'
112
+ assert_valid_card_type_and_number 'Discover', '4111111111111111'
113
+ assert_valid_card_type_and_number 'Maestro', '4111111111111111'
114
+ end
115
+
89
116
  #########
90
117
  protected
91
118
  #########
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evelpidon_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-16 00:00:00.000000000 Z
13
+ date: 2012-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &14644520 !ruby/object:Gem::Requirement
17
+ requirement: &7759920 !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: *14644520
25
+ version_requirements: *7759920
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &14644080 !ruby/object:Gem::Requirement
28
+ requirement: &7759480 !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: *14644080
36
+ version_requirements: *7759480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: evelpidon_test_helpers
39
- requirement: &14643640 !ruby/object:Gem::Requirement
39
+ requirement: &7759040 !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: *14643640
47
+ version_requirements: *7759040
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: test-unit
50
- requirement: &14643140 !ruby/object:Gem::Requirement
50
+ requirement: &7758620 !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: *14643140
58
+ version_requirements: *7758620
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: activemodel
61
- requirement: &14642660 !ruby/object:Gem::Requirement
61
+ requirement: &7758200 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *14642660
69
+ version_requirements: *7758200
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: credit_card_validator
72
- requirement: &14642200 !ruby/object:Gem::Requirement
72
+ requirement: &7757720 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *14642200
80
+ version_requirements: *7757720
81
81
  description: Useful ActiveModel validators with ClientSideValidations support.
82
82
  email:
83
83
  - n.dimitrakopoulos@pamediakopes.gr