cieloz 0.0.14 → 0.0.15

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: 1e1982472d4621f9f7283be9cd04767f7d72a7df
4
- data.tar.gz: a1c912e103164cde71684125669f9fd1c1ac8cb4
3
+ metadata.gz: 8fa10e8fb7d7ceb3ccf85ed8400c8cb6385a588a
4
+ data.tar.gz: f852b5fc5c6649645ab1103b56c8dab3e5e38e5a
5
5
  SHA512:
6
- metadata.gz: 893b0252c1fc78c9816c04dad698926fef565f5c86f627c2bb1018c40e3c31f4e2ab5d2aed76db5b6210938ed3d98a0ae5a27e1d01c8726114b5fe85b3c6ee01
7
- data.tar.gz: 4c23e5013b12ab5b749100545a5d4cb73a345a07d4140cc4c94f513e19de919505c6d9a7e653fb0864f19e404b9c407f41d1725c569f974bcfd458e78c01668c
6
+ metadata.gz: ef0d3965f96503fa4537d6c0d60fb665e00e873cf1ba296daf5bb405211689d3fa5b90176f3b89ec44cbf1c51def6323261b272ff1231d07b1aa912589938303
7
+ data.tar.gz: 8f7b69358249d027ca89498c08469dabc39353db12a13f503bcab9dc401fdd877b2d4f30061c0b5fc97fbc45c08fee970ef03e5e1fcd1abbb921302e31eb6735
@@ -14,9 +14,6 @@ en:
14
14
  attributes:
15
15
  numero:
16
16
  invalid: should have 16 digits
17
- validade:
18
- invalid_year: invalid year
19
- invalid_month: invalid month
20
17
  codigo_seguranca:
21
18
  invalid: should have 3 or 4 digits
22
19
  cieloz/requisicao_transacao/dados_pedido:
@@ -14,9 +14,6 @@ pt-BR:
14
14
  attributes:
15
15
  numero:
16
16
  invalid: deve ter 16 dígitos
17
- validade:
18
- invalid_year: ano inválido
19
- invalid_month: mês inválido
20
17
  codigo_seguranca:
21
18
  invalid: deve ter 3 ou 4 dígitos
22
19
  cieloz/requisicao_transacao/dados_pedido:
@@ -23,8 +23,7 @@ class Cieloz::RequisicaoTransacao
23
23
  validates :numero, format: { with: /\A\d{16}\z/ }
24
24
  validates :codigo_seguranca, format: { with: /\A(\d{3}|\d{4})\z/ }
25
25
 
26
- validate :valida_ano_validade, unless: ->{ validade.nil? }
27
- validate :valida_mes_validade, unless: ->{ validade.nil? }
26
+ validate :valida_validade
28
27
 
29
28
  validates :indicador, presence: true
30
29
 
@@ -89,16 +88,11 @@ class Cieloz::RequisicaoTransacao
89
88
  end
90
89
 
91
90
  private
92
- def valida_mes_validade
93
- if mes = validade[4..5]
94
- errors.add :validade, :invalid_month unless mes.length == 2 and mes.to_i.between? 1, 12
95
- end
96
- end
97
-
98
- def valida_ano_validade
99
- if ano = validade[0..3]
100
- errors.add :validade, :invalid_year if ano.to_i < Date.today.year
101
- end
91
+ def valida_validade
92
+ val = validade.to_i
93
+ min = Date.today.strftime("%Y%m").to_i
94
+ max = 10.years.from_now.strftime("%Y%m").to_i
95
+ errors.add :validade, :invalid unless val.between?(min, max) and val % 100 <= 12
102
96
  end
103
97
  end
104
98
  end
@@ -1,3 +1,3 @@
1
1
  module Cieloz
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -42,38 +42,31 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
42
42
  end
43
43
 
44
44
  it "validates mês validade" do
45
- year = Date.today.year
46
- (1..12).each {|mes|
47
- must_allow_value :validade, "#{year}#{"%02d" % mes}"
45
+ year, month = Date.today.year, Date.today.month
46
+ (month..12).each {|m|
47
+ must_allow_value :validade, "#{year}#{"%02d" % m}"
48
+ }
49
+ (0..9).each {|m|
50
+ subject.validade = "#{year}#{"%d" % m}"
51
+ subject.valid?
52
+ subject.errors[:validade].must_equal [ I18n.t(:invalid, scope: [:errors, :messages]) ]
48
53
  }
49
- ((0..9).to_a + (13..99).to_a).each {|mes|
50
- subject.validade = "#{year}#{"%d" % mes}"
54
+ (13..99).each {|m|
55
+ subject.validade = "#{year}#{"%d" % m}"
51
56
  subject.valid?
52
- assert_equal [
53
- I18n.t(:invalid_month, scope:
54
- [ :activemodel, :errors, :models,
55
- "cieloz/requisicao_transacao/dados_portador",
56
- :attributes, :validade]
57
- )
58
- ], subject.errors[:validade]
57
+ subject.errors[:validade].must_equal [ I18n.t(:invalid, scope: [:errors, :messages]) ]
59
58
  }
60
59
  end
61
60
 
62
61
  it "validates ano validade" do
63
62
  year = Date.today.year
64
- (year..year+10).each {|ano|
65
- must_allow_value :validade, "#{year}01"
63
+ (year+1..year+10).each {|y|
64
+ must_allow_value :validade, "#{y}01"
66
65
  }
67
- (year-10..year-1).each {|ano|
68
- subject.validade = "#{ano}01"
66
+ (year-10..year-1).each {|y|
67
+ subject.validade = "#{y}01"
69
68
  subject.valid?
70
- assert_equal [
71
- I18n.t(:invalid_year,
72
- scope: [ :activemodel, :errors, :models,
73
- "cieloz/requisicao_transacao/dados_portador",
74
- :attributes, :validade]
75
- )
76
- ], subject.errors[:validade]
69
+ subject.errors[:validade].must_equal [ I18n.t(:invalid, scope: [:errors, :messages]) ]
77
70
  }
78
71
  end
79
72
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cieloz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fábio Luiz Nery de Miranda