credit_card_validations 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 134d3a1d35bcf4fab62fdf63c0b206651ec78a85
4
- data.tar.gz: 963f9f2965141892b7f42a767a652b79bea36c75
3
+ metadata.gz: 92ed6636ff7207c035a389f7554065a1cbb4a4fb
4
+ data.tar.gz: 4067f0e3be5ba8f16f417cb4a316d623b47c6b6c
5
5
  SHA512:
6
- metadata.gz: 8ffcd7329fb527258b52da513080fb46d82b89c47eac1b983f761e8a40abd15db3d860559f15bae659293b9890edbb0d52e613fef0087476d592bb4383b2c20d
7
- data.tar.gz: c6b3ce00d5af28b5477eba6843af878d4f50265579072a0a99a3a1a96bfcd69c4789308002654c2121eb5d319f0ca015d0f09836060c0f2b6ad69e27a49da7fd
6
+ metadata.gz: 5eacac666f287dd20318ba8bf38c0127f1afd50b49331204fb4cacafb13f1f2a3423b031b447d6f45664028e88d8ee933f6939f4b9e06b64bfa43470af5d1479
7
+ data.tar.gz: 6647c64262ec8997a352d4a3e99fed91b29d26d42e2cb6dc38ea8475cae3fe9a6099d7b512027eacf14acb2e779a9fd7778623404915ab08fc7dfb07ac1380b1
data/Changelog.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 2.0.2
2
+ * fix using ActiveModel Validator's message option
3
+
1
4
  # 2.0.1
2
5
  * fix typo dankrot -> dankort
3
6
 
@@ -43,7 +43,7 @@ module ActiveModel
43
43
  class CreditCardNumberValidator < EachValidator
44
44
 
45
45
  def validate_each(record, attribute, value)
46
- record.errors.add(attribute) unless credit_card_valid?(value, extract_brands(record, options))
46
+ record.errors.add(attribute, options[:message] || :invalid) unless credit_card_valid?(value, extract_brands(record, options))
47
47
  end
48
48
 
49
49
  def credit_card_valid?(number, brands = [])
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -12,58 +12,59 @@ describe "ActiveModel Validator" do
12
12
  card.valid?.must_equal false
13
13
  card.number6 = CreditCardValidations::Factory.random(:mastercard)
14
14
  card.valid?.must_equal true
15
-
16
15
  end
17
-
18
16
  end
19
17
 
20
18
  describe "Any Brand" do
21
19
  it "should be valid for all prepared valid numbers" do
22
20
  VALID_NUMBERS.each do |_, numbers|
23
-
24
21
  numbers.each do |number|
25
22
  card = model
26
23
  card.number4 = number
27
24
  card.number5 = number
28
25
  card.valid?.must_equal true
29
-
30
26
  end
31
27
  end
32
28
  end
33
29
  end
34
30
 
35
-
36
31
  describe "Except Amex and Maestro brand" do
37
32
  it "should reject all other valid numbers" do
38
- VALID_NUMBERS.except(:amex, :maestro) do |_, numbers|
33
+ VALID_NUMBERS.except(:amex, :maestro).each do |_, numbers|
39
34
  card = model
40
35
  card.number = numbers.first
41
36
  card.valid?.must_equal false
37
+ card.errors[:number].include?(card.errors.generate_message(:number, :invalid)).must_equal true
42
38
  end
43
39
  end
44
40
 
45
41
  it "should accept using except options" do
46
- VALID_NUMBERS.except(:amex, :maestro) do |_, numbers|
42
+ VALID_NUMBERS.except(:amex, :maestro).each do |_, numbers|
47
43
  card = model
48
44
  card.number3 = numbers.first
49
45
  card.valid?.must_equal true
50
46
  end
51
47
  end
52
-
53
48
  end
54
49
 
55
50
  describe "Only Amex and Mestro brands" do
56
-
57
-
58
51
  it "should accept amex and maestro brand if valid" do
59
- VALID_NUMBERS.slice(:amex, :maestro) do |_, numbers|
52
+ VALID_NUMBERS.slice(:amex, :maestro).each do |_, numbers|
60
53
  card = model
61
54
  card.number = numbers.first
62
55
  card.number2 = numbers.first
63
56
  card.valid?.must_equal true
64
57
  end
65
58
  end
59
+ end
66
60
 
67
-
61
+ describe "Custom error message" do
62
+ it "should allow custom message" do
63
+ card = model
64
+ card.number7 = 'wrong'
65
+ card.valid?.must_equal false
66
+ card.errors[:number7].must_equal ["Custom message"]
67
+ end
68
68
  end
69
+
69
70
  end
@@ -1,5 +1,5 @@
1
1
  class CreditCard
2
- attr_accessor :number, :number2, :number3, :number4, :number5, :number6, :card_type
2
+ attr_accessor :number, :number2, :number3, :number4, :number5, :number6, :number7, :card_type
3
3
  include ActiveModel::Validations
4
4
  validates :number, credit_card_number: {brands: [:amex, :maestro]} , allow_blank: true
5
5
  validates :number2, credit_card_number: {only: [:amex, :maestro]}, allow_blank: true
@@ -7,7 +7,7 @@ class CreditCard
7
7
  validates :number4, credit_card_number: {brands: :any} , allow_blank: true
8
8
  validates :number5, credit_card_number: true , allow_blank: true
9
9
  validates :number6, credit_card_number: { brands: ->(record){ record.supported_brand } } , allow_blank: true
10
-
10
+ validates :number7, credit_card_number: { message: "Custom message" } , allow_blank: true
11
11
 
12
12
  def supported_brand
13
13
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel