cieloz 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,28 @@ en:
5
5
  cieloz/requisicao_transacao:
6
6
  attributes:
7
7
  autorizar:
8
+ inclusion: should be in [0,1,2,3,4]
8
9
  authentication_not_supported: Authentication not supported
9
10
  direct_auth_available_for_credit_only: Direct auth available for credit only
10
- forma_pagamento:
11
+ capturar:
12
+ inclusion: should be true or false
13
+ cieloz/requisicao_transacao/dados_portador:
14
+ attributes:
15
+ numero:
16
+ invalid: should have 16 digits
17
+ validade:
18
+ invalid: should be in YYYYDD format
19
+ codigo_seguranca:
20
+ invalid: should have 3 or 4 digits
21
+ cieloz/requisicao_transacao/dados_pedido:
22
+ attributes:
23
+ idioma:
24
+ inclusion: should be PT (Portuguese), EN (English) or ES (Spanish)
25
+ valor:
11
26
  minimum_installment_not_satisfied: Installment should be greater than or equal to R$ 5,00
27
+ cieloz/requisicao_transacao/forma_pagamento:
28
+ attributes:
29
+ bandeira:
30
+ blank: choose credit card flag
31
+ inclusion: choose credit card flag
32
+
@@ -5,7 +5,28 @@ pt-BR:
5
5
  cieloz/requisicao_transacao:
6
6
  attributes:
7
7
  autorizar:
8
+ inclusion: deveria estar entre [0,1,2,3,4]
8
9
  authentication_not_supported: Bandeira não possui programa de autenticação
9
10
  direct_auth_available_for_credit_only: Autorização Direta disponível apenas em operações de crédito
10
- forma_pagamento:
11
+ capturar:
12
+ inclusion: deveria ser true ou false
13
+ cieloz/requisicao_transacao/dados_portador:
14
+ attributes:
15
+ numero:
16
+ invalid: deve ter 16 dígitos
17
+ validade:
18
+ invalid: deve estar no formato YYYYDD
19
+ codigo_seguranca:
20
+ invalid: deve ter 3 ou 4 dígitos
21
+ cieloz/requisicao_transacao/dados_pedido:
22
+ attributes:
23
+ idioma:
24
+ inclusion: deveria ser PT (Português), EN (Inglês) ou ES (Espanhol)
25
+ valor:
11
26
  minimum_installment_not_satisfied: O valor mínimo da parcela deve ser R$ 5,00
27
+ cieloz/requisicao_transacao/forma_pagamento:
28
+ attributes:
29
+ bandeira:
30
+ blank: escolha a bandeira
31
+ inclusion: escolha a bandeira
32
+
@@ -4,17 +4,17 @@ module Cieloz
4
4
  AMEX, DINERS, DISCOVER, ELO, MASTERCARD, VISA = ALL
5
5
 
6
6
  def self.operacao produto
7
- case produto.to_sym
8
- when :mastercard_securecode
7
+ produto = produto.to_s
8
+ case produto
9
+ when 'mastercard_securecode'
9
10
  [MASTERCARD, :autorizar_somente_autenticada]
10
- when :verified_by_visa
11
+ when 'verified_by_visa'
11
12
  [VISA, :autorizar_somente_autenticada]
12
13
  else
13
- produto = produto.to_s
14
14
  if ALL.include? produto
15
15
  [produto, :autorizacao_direta]
16
16
  else
17
- raise "product_not_supported"
17
+ [nil, nil]
18
18
  end
19
19
  end
20
20
  end
@@ -8,14 +8,14 @@ class Cieloz::RequisicaoTransacao
8
8
 
9
9
  validates :numero, :valor, :moeda, :data_hora, presence: true
10
10
 
11
- validates :numero, length: { in: 1..20 }
11
+ validates :numero, length: { maximum: 20 }
12
12
 
13
- validates :valor, length: { in: 1..12 }
14
- validates :valor, numericality: { only_integer: true }
13
+ validates :valor, length: { maximum: 12 }
14
+ validates :valor, numericality: { only_integer: true }, unless: "@valor.blank?"
15
15
 
16
- validates :descricao, length: { in: 0..1024 }
16
+ validates :descricao, length: { maximum: 1024 }
17
17
  validates :idioma, inclusion: { in: IDIOMAS }
18
- validates :soft_descriptor, length: { in: 0..13 }
18
+ validates :soft_descriptor, length: { maximum: 13 }
19
19
 
20
20
  def attributes
21
21
  {
@@ -10,19 +10,21 @@ class Cieloz::RequisicaoTransacao
10
10
  attr_accessor :numero, :nome_portador, :validade
11
11
  attr_reader :indicador, :codigo_seguranca
12
12
 
13
- validates :nome_portador, length: { in: 0..50 }
13
+ validates :nome_portador, length: { maximum: 50 }
14
14
 
15
- validates :numero, :validade, :indicador, presence: true
16
-
17
- validates :numero, length: { is: 16 }
18
- validates :numero, numericality: { only_integer: true }
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! ' ', ''
21
+ end
19
22
 
20
- validates :validade, length: { is: 6 }
21
- validates :validade, format: { with: /2\d{3}(0[1-9]|1[012])/ }
22
- validates :validade, numericality: { only_integer: true }
23
+ validates :numero, format: { with: /^\d{16}$/ }
24
+ validates :validade, format: { with: /^2\d{3}(0[1-9]|1[012])$/ }
25
+ validates :codigo_seguranca, format: { with: /^(\d{3}|\d{4})$/ }
23
26
 
24
- validates :codigo_seguranca, length: { in: 3..4 }
25
- validates :codigo_seguranca, numericality: { only_integer: true }
27
+ validates :indicador, presence: true
26
28
 
27
29
  def initialize attrs={}
28
30
  super
@@ -23,18 +23,18 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
23
23
  validate :parcela_minima?,
24
24
  if: "not @dados_pedido.nil? and not @forma_pagamento.nil?"
25
25
 
26
- validates :autorizar, presence: true, inclusion: {
26
+ validates :autorizar, inclusion: {
27
27
  in: [
28
28
  SOMENTE_AUTENTICAR, AUTORIZAR_SE_AUTENTICADA,
29
29
  AUTORIZAR_NAO_AUTENTICADA, AUTORIZACAO_DIRETA, RECORRENTE
30
30
  ]
31
31
  }
32
32
  # validates string values because false.blank? is true, failing presence validation
33
- validates :capturar, presence: true, inclusion: { in: ["true", "false"] }
33
+ validates :capturar, inclusion: { in: ["true", "false"] }
34
34
 
35
35
  with_options if: "@autorizar != AUTORIZACAO_DIRETA" do |txn|
36
36
  txn.validates :url_retorno, presence: true
37
- txn.validates :url_retorno, length: { in: 1..1024 }
37
+ txn.validates :url_retorno, length: { maximum: 1024 }
38
38
  end
39
39
 
40
40
  validates :campo_livre, length: { maximum: 128 }
@@ -52,10 +52,9 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
52
52
  end
53
53
 
54
54
  def parcela_minima?
55
- if @dados_pedido.valid? and @forma_pagamento.valid?
56
- if @dados_pedido.valor / @forma_pagamento.parcelas < 500
57
- errors.add :forma_pagamento, :minimum_installment_not_satisfied
58
- end
55
+ valor, parcelas = @dados_pedido.valor.to_i, @forma_pagamento.parcelas.to_i
56
+ if parcelas > 0 and valor / parcelas < 500
57
+ @dados_pedido.errors.add :valor, :minimum_installment_not_satisfied
59
58
  end
60
59
  end
61
60
 
@@ -1,3 +1,3 @@
1
1
  module Cieloz
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -19,7 +19,6 @@ describe "Bandeiras e Operacoes" do
19
19
  end
20
20
 
21
21
  it "disallows unsupported products" do
22
- error = lambda { _.operacao("anything else") }.must_raise RuntimeError
23
- error.message.must_match /product_not_supported/
22
+ assert_equal [nil, nil], _.operacao("anything else")
24
23
  end
25
24
  end
@@ -16,18 +16,21 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
16
16
 
17
17
  it { must ensure_length_of(:nome_portador).is_at_most(50) }
18
18
 
19
- it { must validate_presence_of :numero }
20
- it { must ensure_length_of(:numero).is_equal_to 16 }
21
- it { must validate_numericality_of(:numero).only_integer }
19
+ it { must allow_value(1234567890123456).for(:numero) }
20
+ it { wont allow_value(123456789012345).for(:numero) }
21
+ it { wont allow_value(12345678901234567).for(:numero) }
22
+ it { wont allow_value("ABC4567890123456").for(:numero) }
22
23
 
23
- it { must validate_presence_of :validade }
24
- it { must ensure_length_of(:validade).is_equal_to 6 }
25
- it { must validate_numericality_of(:validade).only_integer }
24
+ it {
25
+ (100..9999).step(123).each {|val|
26
+ must allow_value(val).for(:codigo_seguranca)
27
+ }
28
+ }
26
29
 
27
- it { must ensure_length_of(:codigo_seguranca)
28
- .is_at_least(3)
29
- .is_at_most(4) }
30
- it { must validate_numericality_of(:codigo_seguranca).only_integer }
30
+ it { wont allow_value(99).for(:codigo_seguranca) }
31
+ it { wont allow_value(10000).for(:codigo_seguranca) }
32
+ it { wont allow_value("ab1").for(:codigo_seguranca) }
33
+ it { wont allow_value("abc1").for(:codigo_seguranca) }
31
34
 
32
35
  def mm_values range
33
36
  yyyy = 2013
@@ -90,15 +93,21 @@ end
90
93
 
91
94
  describe Cieloz::RequisicaoTransacao::DadosPedido do
92
95
  it { must validate_presence_of :numero }
93
- it { must ensure_length_of(:numero)
94
- .is_at_least(1)
95
- .is_at_most(20) }
96
+ it { must ensure_length_of(:numero).is_at_most(20) }
96
97
 
97
98
  it { must validate_presence_of :valor }
99
+ it { must ensure_length_of(:valor).is_at_most(12) }
98
100
  it { must validate_numericality_of(:valor).only_integer }
99
- it { must ensure_length_of(:valor)
100
- .is_at_least(1)
101
- .is_at_most(12) }
101
+
102
+ it "dont validate valor if it's blank" do
103
+ subject.valor = ""
104
+ refute subject.valid?
105
+ assert_equal [I18n.t('errors.messages.blank')], subject.errors[:valor]
106
+
107
+ subject.valor = "abc"
108
+ refute subject.valid?
109
+ assert_equal [I18n.t('errors.messages.not_a_number')], subject.errors[:valor]
110
+ end
102
111
 
103
112
  it { must validate_presence_of :moeda }
104
113
  it { must validate_presence_of :data_hora }
@@ -238,14 +247,13 @@ describe Cieloz::RequisicaoTransacao do
238
247
  wont validate_presence_of :url_retorno
239
248
  end
240
249
 
241
- it { must ensure_length_of(:url_retorno).is_at_least(1).is_at_most(1024) }
250
+ it { must ensure_length_of(:url_retorno).is_at_most(1024) }
242
251
 
243
252
  it "doesnt validate url_retorno length for autorizacao direta" do
244
253
  subject.autorizacao_direta
245
254
  wont ensure_length_of(:url_retorno).is_at_least(1).is_at_most(1024)
246
255
  end
247
256
 
248
- it { must validate_presence_of :autorizar }
249
257
  it {
250
258
  must ensure_inclusion_of(:autorizar).in_array [
251
259
  _::SOMENTE_AUTENTICAR, _::AUTORIZAR_SE_AUTENTICADA,
@@ -309,7 +317,6 @@ describe Cieloz::RequisicaoTransacao do
309
317
  }
310
318
  end
311
319
 
312
- it { must validate_presence_of :capturar }
313
320
  it { must ensure_inclusion_of(:capturar).in_array(["true", "false"]) }
314
321
 
315
322
  it { must ensure_length_of(:campo_livre).is_at_most(128) }
@@ -349,6 +356,6 @@ describe Cieloz::RequisicaoTransacao do
349
356
 
350
357
  refute subject.valid?
351
358
  msg = "Installment should be greater than or equal to R$ 5,00"
352
- assert_equal msg, subject.errors[:forma_pagamento].first
359
+ assert_equal msg, subject.dados_pedido.errors[:valor].first
353
360
  end
354
361
  end
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.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-18 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -246,12 +246,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  - - ! '>='
247
247
  - !ruby/object:Gem::Version
248
248
  version: '0'
249
+ segments:
250
+ - 0
251
+ hash: 3193634196579590297
249
252
  required_rubygems_version: !ruby/object:Gem::Requirement
250
253
  none: false
251
254
  requirements:
252
255
  - - ! '>='
253
256
  - !ruby/object:Gem::Version
254
257
  version: '0'
258
+ segments:
259
+ - 0
260
+ hash: 3193634196579590297
255
261
  requirements: []
256
262
  rubyforge_project:
257
263
  rubygems_version: 1.8.23