credit_card_validations 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjAyN2VjODkxNmY1OWVhM2M2YjlhYTk0ZTE4ZDQ4Y2NkNjhkZGI0Ng==
5
+ data.tar.gz: !binary |-
6
+ NTM3MTY2NzdmYzBiODZiNTk0ODAyMzYxZTEyMDkwM2IwNGI2NTc5NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzY2Y2QwNTA2ZTc2NTFlNmM0NmNhYzBjZTUwNmFkNDU4MTY0YjIzMjBiNmUw
10
+ MTA1M2Y5ZGY2OWVjZTQxOTJmNDg1NjAxYTdkYWViODYxNTM2OWIwNjQwMDEz
11
+ MTE3MzViOTdjNzQwNmJiYjA4YWRlNmQyMDk3NGFjMDY5NDAxOWQ=
12
+ data.tar.gz: !binary |-
13
+ YWQ0OGIyODBhMmU0ZmM1ZGVkYzBjODA0Y2U1MTA4NzBiMmY0YzFmOWZiMTU2
14
+ ZmMxZTM2YWE5OTk0M2I3Mzg1NTA0MjIzYjc2NTQ0N2E5NGNhZTRjYjY4N2Fj
15
+ MjcyNDhmNjhhNmQ1Yzg2ZWFmM2JjODhlOWRlYzQ1MzYzY2JjNjU=
data/.travis.yml CHANGED
@@ -2,5 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - jruby-19mode
5
- - rbx-19mode
6
5
  - 2.0.0
data/README.md CHANGED
@@ -96,3 +96,6 @@ for all known brands
96
96
  3. Commit your changes (`git commit -am 'Add some feature'`)
97
97
  4. Push to the branch (`git push origin my-new-feature`)
98
98
  5. Create new Pull Request
99
+
100
+
101
+
@@ -11,17 +11,19 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{A ruby gem for validating credit card numbers (a port of ZF2 Zend\Validator\CreditCard)}
12
12
  gem.summary = "gem for credit card numbers validation, card brands detections"
13
13
  gem.homepage = "https://github.com/Fivell/credit_card_validations"
14
-
14
+ gem.license = 'MIT'
15
+
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
19
  gem.require_paths = ["lib"]
19
20
 
20
- gem.add_dependency "activemodel", ">= 3.0", "< 4.1"
21
- gem.add_dependency "activesupport", ">= 3.0", "< 4.1"
22
21
 
23
- gem.add_development_dependency "test-unit"
24
- gem.add_development_dependency "mocha"
25
- gem.add_development_dependency 'rake'
22
+ gem.add_dependency "activemodel", ">= 3.0", "<= 4.2"
23
+ gem.add_dependency "activesupport", ">= 3.0", "<= 4.2"
24
+
25
+ gem.add_development_dependency "test-unit",'~> 2.5'
26
+ gem.add_development_dependency "mocha", '~> 0.12'
27
+ gem.add_development_dependency 'rake', '~> 10'
26
28
 
27
29
  end
@@ -1,62 +1,60 @@
1
1
  module CreditCardValidations
2
2
  module CardRules
3
3
  ######## most used brands #########
4
-
5
-
6
- VISA = [
7
- {length: [16], prefixes: ['4']}
8
- ]
9
- MASTERCARD = [
10
- {length: [16], prefixes: ['51', '52', '53', '54', '55']}
11
- ]
12
- ######## other brands ########
13
- AMEX = [
14
- {length: [15], prefixes: ['34', '37']}
15
- ]
16
-
17
- DINERS = [
18
- {length: [14], prefixes: ['300', '301', '302', '303', '304', '305', '36']},
19
- ]
20
-
21
- #There are Diners Club (North America) cards that begin with 5. These are a joint venture between Diners Club and MasterCard, and are processed like a MasterCard
22
- DINERS_US = [
23
- {length: [16], prefixes: ['54', '55']}
24
- ]
25
-
26
- DISCOVER = [
27
- {length: [16], prefixes: ['6011', '622126', '622127', '622128', '622129', '62213',
28
- '62214', '62215', '62216', '62217', '62218', '62219',
29
- '6222', '6223', '6224', '6225', '6226', '6227', '6228',
30
- '62290', '62291', '622920', '622921', '622922', '622923',
31
- '622924', '622925', '644', '645', '646', '647', '648',
32
- '649', '65']}
33
- ]
34
-
35
- JCB = [
36
- {length: [16], prefixes: ['3528', '3529', '353', '354', '355', '356', '357', '358']}
37
- ]
38
-
39
-
40
- LASER = [
41
- {length: [16, 17, 18, 19], prefixes: ['6304', '6706', '6771', '6709']}
42
- ]
43
-
44
- MAESTRO = [
45
- {length: [12, 13, 14, 15, 16, 17, 18, 19], prefixes: ['5018', '5020', '5038', '6304', '6759', '6761', '6762','6763', '6764', '6765', '6766']}
46
- ]
47
-
48
- SOLO = [
49
- {length: [16, 18, 19], prefixes: ['6334', '6767']}
50
- ]
51
-
52
- UNIONPAY = [
53
- {length: [16, 17, 18, 19], prefixes: ['620', '621', '623', '625', '626'], skip_validation: true}
54
- ]
55
-
56
- DANKROT = [
57
- {length: [16], prefixes: ['5019']}
58
- ]
59
-
60
-
4
+ mattr_accessor :rules
5
+
6
+ self.rules = {
7
+ visa: [
8
+ {length: [16], prefixes: ['4']}
9
+ ],
10
+ mastercard: [
11
+ {length: [16], prefixes: ['51', '52', '53', '54', '55']}
12
+ ],
13
+ ######## other brands ########
14
+ amex: [
15
+ {length: [15], prefixes: ['34', '37']}
16
+ ],
17
+
18
+ diners: [
19
+ {length: [14], prefixes: ['300', '301', '302', '303', '304', '305', '36']},
20
+ ],
21
+
22
+ #There are Diners Club (North America) cards that begin with 5. These are a joint venture between Diners Club and MasterCard, and are processed like a MasterCard
23
+ # will be removed in next major version
24
+
25
+ diners_us: [
26
+ {length: [16], prefixes: ['54', '55']}
27
+ ],
28
+
29
+ discover: [
30
+ {length: [16], prefixes: ['6011', '644', '645', '646', '647', '648',
31
+ '649', '65']}
32
+ ],
33
+
34
+ jcb: [
35
+ {length: [16], prefixes: ['3528', '3529', '353', '354', '355', '356', '357', '358']}
36
+ ],
37
+
38
+
39
+ laser: [
40
+ {length: [16, 17, 18, 19], prefixes: ['6304', '6706', '6771', '6709']}
41
+ ],
42
+
43
+ maestro: [
44
+ {length: [12, 13, 14, 15, 16, 17, 18, 19], prefixes: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']}
45
+ ],
46
+
47
+ solo: [
48
+ {length: [16, 18, 19], prefixes: ['6334', '6767']}
49
+ ],
50
+ # Luhn validation are skipped for union pay cards because they have unknown generation algoritm
51
+ unionpay: [
52
+ {length: [16, 17, 18, 19], prefixes: ['622', '624', '625', '626', '628'], skip_validation: true}
53
+ ],
54
+
55
+ dankrot: [
56
+ {length: [16], prefixes: ['5019']}
57
+ ],
58
+ }
61
59
  end
62
60
  end
@@ -62,9 +62,9 @@ module CreditCardValidations
62
62
  end
63
63
  end
64
64
 
65
- CardRules.constants.each do |const_name|
66
- CardRules.const_get(const_name).each do |const_value|
67
- self.add_rule(const_name.to_s.downcase.to_sym , const_value[:length], const_value[:prefixes], const_value[:skip_validation])
65
+ CardRules.rules.each do |name, rules|
66
+ rules.each do |rule_value|
67
+ self.add_rule(name, rule_value[:length], rule_value[:prefixes], rule_value[:skip_validation])
68
68
  end
69
69
 
70
70
  end
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -15,71 +15,71 @@ class CreditCardValidationsTest < Test::Unit::TestCase
15
15
  validates :number, credit_card_number: {brands: [:amex, :maestro]}
16
16
  end
17
17
 
18
-
19
-
20
- class CreditCardModelAny
18
+ class CreditCardModelAny
21
19
  attr_accessor :number
22
20
  include ActiveModel::Validations
23
21
  validates :number, presence: true, credit_card_number: true
24
- end
25
-
22
+ end
26
23
 
27
24
  def initialize name
28
25
  super name
29
26
  @test_numbers = {
30
- visa: '4012 8888 8888 1881',
31
- mastercard: '5274 5763 9425 9961',
32
- diners: '3020 4169 3226 43',
33
- amex: '3782 8224 6310 005',
34
- discover: '6011 1111 1111 1117',
35
- maestro: '6759 6498 2643 8453',
36
- jcb: '3575 7591 5225 4876',
37
- solo: '6767 6222 2222 2222 222',
38
- unionpay: '6264-1852-1292-2132-067',
39
- dankrot: '5019717010103742'
40
-
27
+ visa: ['4012 8888 8888 1881','4111111111111111'],
28
+ mastercard: ['5274 5763 9425 9961', '5555-5555-5555-4444'],
29
+ diners: ['3020 4169 3226 43', '30569309025904'],
30
+ amex: ['3782 8224 6310 005', '371449635398431'],
31
+ discover: ['6011 1111 1111 1117','6011000990139424'],
32
+ maestro: ['6759 6498 2643 8453'],
33
+ jcb: ['3575 7591 5225 4876', '3566002020360505' ],
34
+ solo: ['6767 6222 2222 2222 222'],
35
+ unionpay: ['6264-1852-1292-2132-067', '6288997715452584', '6269 9920 5813 4322'],
36
+ dankrot: ['5019717010103742']
41
37
  }
42
38
  end
43
-
39
+
44
40
  def test_card_brand_detection
45
41
  @test_numbers.each do |key, value|
46
- assert_equal key, detector(value).brand
47
- assert detector(value).send("#{key}?")
42
+ value.each do |card_number|
43
+ assert detector(card_number).send("#{key}?")
44
+ assert_equal key, detector(card_number).brand
45
+ end
48
46
  end
49
47
  end
50
-
48
+
51
49
  def test_card_brand_is_nil_if_credit_card_invalid
52
50
  assert_nil detector('1111111111111111').brand
53
51
  end
54
-
52
+
55
53
  def test_card_brand_detection_with_restriction
56
54
  @test_numbers.slice(:visa, :mastercard).each do |key, value|
57
- assert_equal key, detector(value).brand(:visa, :mastercard)
55
+ assert_equal key, detector(value.first).brand(:visa, :mastercard)
58
56
  end
59
-
57
+
60
58
  @test_numbers.except(:visa, :mastercard).each do |key, value|
61
- assert_nil detector(value).brand(:visa, :mastercard)
59
+ assert_nil detector(value.first).brand(:visa, :mastercard)
62
60
  end
63
61
  end
64
-
62
+
65
63
  def test_card_valid_method
66
64
  @test_numbers.each do |key, value|
67
- assert detector(value).valid?(key)
68
- assert detector(value).valid?
65
+ value.each do |card_number|
66
+ assert detector(card_number).valid?(key)
67
+ assert detector(card_number).valid?
68
+ end
69
69
  end
70
70
  assert !detector('1111111111111111').valid?
71
71
  end
72
72
 
73
73
 
74
74
  def test_card_particular_brand_valid
75
- assert !detector(@test_numbers[:visa]).valid?(:mastercard)
76
- assert !detector(@test_numbers[:mastercard]).valid?(:visa)
75
+ assert !detector(@test_numbers[:visa].first).valid?(:mastercard)
76
+ assert !detector(@test_numbers[:mastercard].first).valid?(:visa)
77
77
  end
78
78
 
79
79
 
80
80
  def test_card_particular_brands_valid
81
- assert detector(@test_numbers[:visa]).valid?(:mastercard, :visa)
82
- assert !detector(@test_numbers[:visa]).valid?(:mastercard, :amex)
81
+ assert detector(@test_numbers[:visa].first).valid?(:mastercard, :visa)
82
+ assert !detector(@test_numbers[:visa].first).valid?(:mastercard, :amex)
83
83
  end
84
84
 
85
85
  #add rules which were not present before
@@ -96,11 +96,11 @@ end
96
96
 
97
97
  def test_active_model_validator
98
98
  cc = CreditCardModel.new
99
- cc.number = @test_numbers[:maestro]
99
+ cc.number = @test_numbers[:maestro].first
100
100
  assert cc.valid?
101
101
 
102
102
  cc = CreditCardModel.new
103
- cc.number = @test_numbers[:mastercard]
103
+ cc.number = @test_numbers[:mastercard].first
104
104
  assert !cc.valid?
105
105
  assert cc.errors[:number].include?(cc.errors.generate_message(:number, :invalid))
106
106
 
@@ -108,33 +108,31 @@ end
108
108
  cc = CreditCardModelAny.new
109
109
  cc.number='1'
110
110
  assert !cc.valid?
111
- cc.number = @test_numbers[:mastercard]
111
+ cc.number = @test_numbers[:mastercard].first
112
112
  assert cc.valid?
113
113
 
114
114
  end
115
115
 
116
116
  def test_string_extension
117
117
  require 'credit_card_validations/string'
118
- assert_equal @test_numbers[:mastercard].credit_card_brand, :mastercard
119
- assert @test_numbers[:mastercard].valid_credit_card_brand?(:mastercard)
120
- assert !@test_numbers[:mastercard].valid_credit_card_brand?(:visa, :amex)
118
+ assert_equal @test_numbers[:mastercard].first.credit_card_brand, :mastercard
119
+ assert @test_numbers[:mastercard].first.valid_credit_card_brand?(:mastercard)
120
+ assert !@test_numbers[:mastercard].first.valid_credit_card_brand?(:visa, :amex)
121
121
  end
122
122
 
123
123
 
124
124
  def test_skip_validation
125
- d = detector(@test_numbers[:unionpay])
125
+ d = detector(@test_numbers[:unionpay].first)
126
+
126
127
  d.expects(:valid_luhn?).never
127
128
  assert d.valid?(:unionpay)
128
129
 
129
- d = detector(@test_numbers[:unionpay])
130
130
  d.expects(:valid_luhn?).once
131
131
  assert !d.valid?(:visa)
132
132
 
133
- d = detector(@test_numbers[:unionpay])
134
133
  d.expects(:valid_luhn?).never
135
134
  assert d.valid?(:unionpay, :visa)
136
135
 
137
- d = detector(@test_numbers[:unionpay])
138
136
  d.expects(:valid_luhn?).once
139
137
  assert d.valid?(:visa, :unionpay)
140
138
  end
metadata CHANGED
@@ -1,108 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
5
- prerelease:
4
+ version: 1.4.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Igor
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activemodel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
- - - <
20
+ - - <=
23
21
  - !ruby/object:Gem::Version
24
- version: '4.1'
22
+ version: '4.2'
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '3.0'
33
- - - <
30
+ - - <=
34
31
  - !ruby/object:Gem::Version
35
- version: '4.1'
32
+ version: '4.2'
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: activesupport
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
37
  - - ! '>='
42
38
  - !ruby/object:Gem::Version
43
39
  version: '3.0'
44
- - - <
40
+ - - <=
45
41
  - !ruby/object:Gem::Version
46
- version: '4.1'
42
+ version: '4.2'
47
43
  type: :runtime
48
44
  prerelease: false
49
45
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
46
  requirements:
52
47
  - - ! '>='
53
48
  - !ruby/object:Gem::Version
54
49
  version: '3.0'
55
- - - <
50
+ - - <=
56
51
  - !ruby/object:Gem::Version
57
- version: '4.1'
52
+ version: '4.2'
58
53
  - !ruby/object:Gem::Dependency
59
54
  name: test-unit
60
55
  requirement: !ruby/object:Gem::Requirement
61
- none: false
62
56
  requirements:
63
- - - ! '>='
57
+ - - ~>
64
58
  - !ruby/object:Gem::Version
65
- version: '0'
59
+ version: '2.5'
66
60
  type: :development
67
61
  prerelease: false
68
62
  version_requirements: !ruby/object:Gem::Requirement
69
- none: false
70
63
  requirements:
71
- - - ! '>='
64
+ - - ~>
72
65
  - !ruby/object:Gem::Version
73
- version: '0'
66
+ version: '2.5'
74
67
  - !ruby/object:Gem::Dependency
75
68
  name: mocha
76
69
  requirement: !ruby/object:Gem::Requirement
77
- none: false
78
70
  requirements:
79
- - - ! '>='
71
+ - - ~>
80
72
  - !ruby/object:Gem::Version
81
- version: '0'
73
+ version: '0.12'
82
74
  type: :development
83
75
  prerelease: false
84
76
  version_requirements: !ruby/object:Gem::Requirement
85
- none: false
86
77
  requirements:
87
- - - ! '>='
78
+ - - ~>
88
79
  - !ruby/object:Gem::Version
89
- version: '0'
80
+ version: '0.12'
90
81
  - !ruby/object:Gem::Dependency
91
82
  name: rake
92
83
  requirement: !ruby/object:Gem::Requirement
93
- none: false
94
84
  requirements:
95
- - - ! '>='
85
+ - - ~>
96
86
  - !ruby/object:Gem::Version
97
- version: '0'
87
+ version: '10'
98
88
  type: :development
99
89
  prerelease: false
100
90
  version_requirements: !ruby/object:Gem::Requirement
101
- none: false
102
91
  requirements:
103
- - - ! '>='
92
+ - - ~>
104
93
  - !ruby/object:Gem::Version
105
- version: '0'
94
+ version: '10'
106
95
  description: A ruby gem for validating credit card numbers (a port of ZF2 Zend\Validator\CreditCard)
107
96
  email:
108
97
  - fedoronchuk@gmail.com
@@ -126,28 +115,28 @@ files:
126
115
  - lib/credit_card_validations/version.rb
127
116
  - test/credit_card_validations_test.rb
128
117
  homepage: https://github.com/Fivell/credit_card_validations
129
- licenses: []
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
130
121
  post_install_message:
131
122
  rdoc_options: []
132
123
  require_paths:
133
124
  - lib
134
125
  required_ruby_version: !ruby/object:Gem::Requirement
135
- none: false
136
126
  requirements:
137
127
  - - ! '>='
138
128
  - !ruby/object:Gem::Version
139
129
  version: '0'
140
130
  required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
131
  requirements:
143
132
  - - ! '>='
144
133
  - !ruby/object:Gem::Version
145
134
  version: '0'
146
135
  requirements: []
147
136
  rubyforge_project:
148
- rubygems_version: 1.8.24
137
+ rubygems_version: 2.2.0
149
138
  signing_key:
150
- specification_version: 3
139
+ specification_version: 4
151
140
  summary: gem for credit card numbers validation, card brands detections
152
141
  test_files:
153
142
  - test/credit_card_validations_test.rb