cieloz 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bafeb0b8ee2b0cc29837ae97e0a5b1c4a423fe22
4
- data.tar.gz: 228cd850f742e759568869938329499f22e5213f
3
+ metadata.gz: 173e98b9c3a20307cb97a34b4ca9d03e24a84bb1
4
+ data.tar.gz: fcf0bb0d462575a7bb65d9f145f573f371383400
5
5
  SHA512:
6
- metadata.gz: 369d7b7699e9c31cc23c664f7eb985fc35ef9cfcf6465204e2e50357db8c5fc5d04410560c718c1e95b1b7e57b717ce4e8ca8508d067e137b12d96cf4b1861b2
7
- data.tar.gz: 5c9f92497d3396a7a81ea34302fb022d477dedd32ab92d47d380a32b70355b04907111130c0a17b40f0c6d224c56d5196ce0c992e6b6d264640afb1921307b21
6
+ metadata.gz: 1c9e0deccc3a292b3c18adc85abcb619aa86461962e42ea62021525c72c2e0809320b8a02eac626ee266422e0e7c3eb52b948182c0da61495c61dff67f4d0df6
7
+ data.tar.gz: 917a5c365e4bbb64b1e387e5fa7f40b258501edd2c9c3bd819032e0df74ac460ab1b42f5dd4c590ce80040ba1696df899d3bf21790c7db9b120e8d52bc2730a7
@@ -29,6 +29,18 @@ module Cieloz
29
29
  end
30
30
 
31
31
  module InstanceMethods
32
+ def add_error(attr, message)
33
+ error_message = errors.add(attr, message).first
34
+ if @source
35
+ source_attr = @opts[attr]
36
+ if source_attr.is_a?(Symbol) and @source.respond_to?(source_attr)
37
+ @source.errors.add source_attr, error_message
38
+ else
39
+ @source.errors.add :base, "#{attr}: #{error_message}"
40
+ end
41
+ end
42
+ end
43
+
32
44
  def valid?
33
45
  valid = _valid?
34
46
  unless @source.nil?
@@ -82,7 +82,7 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
82
82
  def parcela_minima?
83
83
  valor, parcelas = @dados_pedido.valor.to_i, @forma_pagamento.parcelas.to_i
84
84
  if parcelas > 0 and valor / parcelas < 500
85
- @dados_pedido.errors.add :valor, :minimum_installment_not_satisfied
85
+ @dados_pedido.add_error :valor, :minimum_installment_not_satisfied
86
86
  end
87
87
  end
88
88
 
@@ -157,11 +157,11 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
157
157
  numero = dados_portador.numero.to_s
158
158
  case bandeira.to_s
159
159
  when Cieloz::Bandeiras::DINERS
160
- dados_portador.errors.add :numero, :invalid_diners unless numero =~ /\A\d{14}\z/
160
+ dados_portador.add_error :numero, :invalid_diners unless numero =~ /\A\d{14}\z/
161
161
  when Cieloz::Bandeiras::AMEX
162
- dados_portador.errors.add :numero, :invalid_amex unless numero =~ /\A\d{15}\z/
162
+ dados_portador.add_error :numero, :invalid_amex unless numero =~ /\A\d{15}\z/
163
163
  else
164
- dados_portador.errors.add :numero, :invalid unless numero =~ /\A\d{16}\z/
164
+ dados_portador.add_error :numero, :invalid unless numero =~ /\A\d{16}\z/
165
165
  end
166
166
  end
167
167
  end
@@ -13,11 +13,9 @@ class Cieloz::RequisicaoTransacao
13
13
  validates :nome_portador, length: { maximum: 50 }
14
14
 
15
15
  set_callback :validate, :before do |portador|
16
- [:numero, :validade, :codigo_seguranca].each {|attr|
17
- val = portador.send attr
18
- portador.instance_variable_set "@#{attr}", val.to_s
19
- }
20
- portador.numero.gsub! ' ', ''
16
+ portador.numero = portador.numero.to_s.gsub ' ', ''
17
+ portador.codigo_seguranca = portador.codigo_seguranca.to_s
18
+ portador.validade = portador.validade.to_s
21
19
  end
22
20
 
23
21
  validates :codigo_seguranca, format: { with: /\A(\d{3}|\d{4})\z/ }
@@ -1,3 +1,3 @@
1
1
  module Cieloz
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -34,4 +34,59 @@ describe Cieloz::Helpers do
34
34
  }.flatten
35
35
  txn.errors.messages[:base].must_equal expected_errors
36
36
  end
37
+
38
+ describe "errors that parent object injects on dependent objects" do
39
+ let(:pr) { Cieloz.portador order, numero: numero }
40
+ let(:pd) { Cieloz.pedido order, valor: valor }
41
+ let(:pg) { Cieloz.parcelado order, bandeira: 'visa', parcelas: 2 }
42
+ let(:txn){
43
+ Cieloz.transacao order, dados_portador: pr,
44
+ dados_pedido: pd,
45
+ forma_pagamento: pg
46
+ }
47
+ let(:err) { "activemodel.errors.models.cieloz/requisicao_transacao" }
48
+ let(:min_parcel_msg) {
49
+ I18n.t "#{err}/dados_pedido.attributes.valor.minimum_installment_not_satisfied"
50
+ }
51
+ let(:invalid_number_msg) {
52
+ I18n.t "#{err}/dados_portador.attributes.numero.invalid"
53
+ }
54
+
55
+ before { Cieloz::Configuracao.store_mode! }
56
+ after { Cieloz::Configuracao.reset! }
57
+
58
+ describe "to base" do
59
+ let(:valor) { 9.00 }
60
+ let(:numero) { "1234" }
61
+
62
+ before { txn.valid? }
63
+
64
+ it "validates parcela minima" do
65
+ order.errors[:base].must_include "valor: #{min_parcel_msg}"
66
+ end
67
+
68
+ it "validates credit card number" do
69
+ order.errors[:base].must_include "numero: #{invalid_number_msg}"
70
+ end
71
+ end
72
+
73
+ describe "to attribute" do
74
+ let(:valor) { :value }
75
+ let(:numero) { :number }
76
+
77
+ before {
78
+ def order.value ; 9.00 end
79
+ def order.number ; "invalid" end
80
+ txn.valid?
81
+ }
82
+
83
+ it "validates parcela minima" do
84
+ order.errors[:value].must_include min_parcel_msg
85
+ end
86
+
87
+ it "validates credit card number" do
88
+ order.errors[:number].must_include invalid_number_msg
89
+ end
90
+ end
91
+ end
37
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cieloz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fábio Luiz Nery de Miranda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri