credit_card_validations 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/README.md +2 -2
- data/credit_card_validations.gemspec +2 -2
- data/lib/active_model/credit_card_number_validator.rb +1 -1
- data/lib/credit_card_validations/detector.rb +1 -1
- data/lib/credit_card_validations/version.rb +1 -1
- data/test/credit_card_validations_test.rb +8 -5
- metadata +19 -12
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# CreditCardValidations
|
2
2
|
|
3
3
|
Gem adds validator to check whether or not a given number actually falls within the ranges of possible numbers prior to performing such verification, and, as such, CreditCardValidations simply verifies that the credit card number provided is well-formed.
|
4
|
-
|
4
|
+
|
5
5
|
|
6
6
|
## Build status
|
7
7
|
[![Build Status](https://travis-ci.org/Fivell/credit_card_validations.png)](https://travis-ci.org/Fivell/credit_card_validations)
|
@@ -74,7 +74,7 @@ only for certain brads
|
|
74
74
|
class CreditCardModel
|
75
75
|
attr_accessor :number
|
76
76
|
include ActiveModel::Validations
|
77
|
-
validates :number,
|
77
|
+
validates :number, credit_card_number: {brands: [:amex, :maestro]}
|
78
78
|
end
|
79
79
|
|
80
80
|
for all known brands
|
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_dependency
|
20
|
+
gem.add_dependency "activemodel", ">= 3.0", "< 4.1"
|
21
|
+
gem.add_dependency "activesupport", ">= 3.0", "< 4.1"
|
22
22
|
|
23
23
|
gem.add_development_dependency "test-unit"
|
24
24
|
gem.add_development_dependency 'rake'
|
@@ -4,7 +4,7 @@ module ActiveModel
|
|
4
4
|
|
5
5
|
def validate_each(record, attribute, value)
|
6
6
|
brands = options.fetch(:brands)
|
7
|
-
record.errors
|
7
|
+
record.errors.add(attribute) unless credit_card_valid?(value, brands == :any ? [] : Array.wrap(brands) )
|
8
8
|
end
|
9
9
|
|
10
10
|
def credit_card_valid?(number, brands = [])
|
@@ -11,7 +11,7 @@ class CreditCardValidationsTest < Test::Unit::TestCase
|
|
11
11
|
class CreditCardModel
|
12
12
|
attr_accessor :number
|
13
13
|
include ActiveModel::Validations
|
14
|
-
validates :number,
|
14
|
+
validates :number, credit_card_number: {brands: [:amex, :maestro]}
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize name
|
@@ -20,12 +20,12 @@ class CreditCardValidationsTest < Test::Unit::TestCase
|
|
20
20
|
visa: '4012 8888 8888 1881',
|
21
21
|
mastercard: '5274 5763 9425 9961',
|
22
22
|
diners: '3020 4169 3226 43',
|
23
|
-
amex: '
|
23
|
+
amex: '3782 8224 6310 005',
|
24
24
|
discover: '6011 1111 1111 1117',
|
25
25
|
maestro: '6759 6498 2643 8453',
|
26
26
|
jcb: '3575 7591 5225 4876',
|
27
27
|
solo: '6767 6222 2222 2222 222',
|
28
|
-
unionpay: '
|
28
|
+
unionpay: '6264-1852-1292-2132-067',
|
29
29
|
|
30
30
|
}
|
31
31
|
end
|
@@ -74,11 +74,14 @@ class CreditCardValidationsTest < Test::Unit::TestCase
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_active_model_validator
|
77
|
+
cc = CreditCardModel.new
|
78
|
+
cc.number = @test_numbers[:maestro]
|
79
|
+
assert cc.valid?
|
80
|
+
|
77
81
|
cc = CreditCardModel.new
|
78
82
|
cc.number = @test_numbers[:mastercard]
|
79
83
|
assert !cc.valid?
|
80
|
-
cc.number
|
81
|
-
assert cc.valid?
|
84
|
+
assert cc.errors[:number].include?(cc.errors.generate_message(:number, :invalid))
|
82
85
|
end
|
83
86
|
|
84
87
|
def test_string_extension
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credit_card_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,39 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70126777364960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.0'
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '4.1'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
|
-
version_requirements: *
|
27
|
+
version_requirements: *70126777364960
|
25
28
|
- !ruby/object:Gem::Dependency
|
26
29
|
name: activesupport
|
27
|
-
requirement: &
|
30
|
+
requirement: &70126777364180 !ruby/object:Gem::Requirement
|
28
31
|
none: false
|
29
32
|
requirements:
|
30
|
-
- -
|
33
|
+
- - ! '>='
|
31
34
|
- !ruby/object:Gem::Version
|
32
35
|
version: '3.0'
|
36
|
+
- - <
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '4.1'
|
33
39
|
type: :runtime
|
34
40
|
prerelease: false
|
35
|
-
version_requirements: *
|
41
|
+
version_requirements: *70126777364180
|
36
42
|
- !ruby/object:Gem::Dependency
|
37
43
|
name: test-unit
|
38
|
-
requirement: &
|
44
|
+
requirement: &70126777363520 !ruby/object:Gem::Requirement
|
39
45
|
none: false
|
40
46
|
requirements:
|
41
47
|
- - ! '>='
|
@@ -43,10 +49,10 @@ dependencies:
|
|
43
49
|
version: '0'
|
44
50
|
type: :development
|
45
51
|
prerelease: false
|
46
|
-
version_requirements: *
|
52
|
+
version_requirements: *70126777363520
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
name: rake
|
49
|
-
requirement: &
|
55
|
+
requirement: &70126777363040 !ruby/object:Gem::Requirement
|
50
56
|
none: false
|
51
57
|
requirements:
|
52
58
|
- - ! '>='
|
@@ -54,7 +60,7 @@ dependencies:
|
|
54
60
|
version: '0'
|
55
61
|
type: :development
|
56
62
|
prerelease: false
|
57
|
-
version_requirements: *
|
63
|
+
version_requirements: *70126777363040
|
58
64
|
description: A ruby gem for validating credit card numbers (a port of ZF2 Zend\Validator\CreditCard)
|
59
65
|
email:
|
60
66
|
- fedoronchuk@gmail.com
|
@@ -62,6 +68,7 @@ executables: []
|
|
62
68
|
extensions: []
|
63
69
|
extra_rdoc_files: []
|
64
70
|
files:
|
71
|
+
- .travis.yml
|
65
72
|
- Gemfile
|
66
73
|
- LICENSE.txt
|
67
74
|
- README.md
|