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 ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ - ruby-head
8
+ - jruby-head
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
- This is a port of Zend Framework `Zend\Validator\CreditCard` .
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, presence: true, credit_card_number: {brands: [:amex, :maestro]}
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('activemodel', '~> 3.0')
21
- gem.add_dependency('activesupport', '~> 3.0')
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[attribute] << (options[:message] || "is not valid") unless credit_card_valid?(value, Array.wrap(brands))
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 = [])
@@ -6,7 +6,7 @@ module CreditCardValidations
6
6
  attr_reader :number
7
7
 
8
8
  def initialize(number)
9
- @number = number.to_s.delete(' ')
9
+ @number = number.to_s.tr('- ','')
10
10
  end
11
11
 
12
12
  # credit card number
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -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, presence: true, credit_card_number: {brands: [:amex, :maestro]}
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: '3400 0000 0000 009',
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: '6264185212922132067',
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 = @test_numbers[:amex]
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.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-04-23 00:00:00.000000000 Z
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: &70129509894700 !ruby/object:Gem::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: *70129509894700
27
+ version_requirements: *70126777364960
25
28
  - !ruby/object:Gem::Dependency
26
29
  name: activesupport
27
- requirement: &70129509900380 !ruby/object:Gem::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: *70129509900380
41
+ version_requirements: *70126777364180
36
42
  - !ruby/object:Gem::Dependency
37
43
  name: test-unit
38
- requirement: &70129509896480 !ruby/object:Gem::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: *70129509896480
52
+ version_requirements: *70126777363520
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: rake
49
- requirement: &70129509904920 !ruby/object:Gem::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: *70129509904920
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