Skip to content

Commit

Permalink
#4 - Ajustado problemas com o time_zone das datas e horas. Alterado o…
Browse files Browse the repository at this point in the history
… ENV['TZ'] para 'UTC' ao rodar os testes.
  • Loading branch information
Brunomm committed Dec 15, 2016
1 parent 32252b4 commit 97471c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/br_nfe/product/nota_fiscal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,8 @@ def default_values
natureza_operacao: 'Venda',
forma_pagamento: 0, # 0=À vista
modelo_nf: 55, #NF-e
data_hora_emissao: Time.current,
data_hora_expedicao: Time.current,
data_hora_emissao: Time.current.in_time_zone,
data_hora_expedicao: Time.current.in_time_zone,
tipo_operacao: 1, # 1=Saída
tipo_impressao: 1, # 1=DANFE normal, Retrato;
finalidade_emissao: 1, # 1=NF-e normal;
Expand Down
6 changes: 3 additions & 3 deletions test/br_nfe/product/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,14 @@ class OtherClassEmitente < BrNfe::ActiveModelBase
describe '#inicio_contingencia' do
it "deve fazer parse para Time se passar qualquer valor" do
subject.inicio_contingencia = '05/06/2018 03:35'
subject.inicio_contingencia.must_equal Time.parse('05/06/2018 03:35')
subject.inicio_contingencia.must_be_close_to Time.zone.parse('05/06/2018 03:35')

subject.inicio_contingencia = now = DateTime.current
subject.inicio_contingencia.must_equal now.to_time
subject.inicio_contingencia.must_be_close_to now.to_time.in_time_zone
end
it "se passar um valor Time deve retornar o mesmo valor" do
subject.inicio_contingencia = now = Time.current
subject.inicio_contingencia.must_equal now
subject.inicio_contingencia.to_s.must_equal now.in_time_zone.to_s
end
it "deve retornar nil se passar um valor inválido" do
subject.inicio_contingencia = '77777777777'
Expand Down
2 changes: 1 addition & 1 deletion test/br_nfe/product/evento/cancelamento_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe '#default values' do
it 'for #data_hora' do
subject.class.new.data_hora.must_be_close_to Time.current
subject.class.new.data_hora.to_s.must_equal Time.current.in_time_zone.to_s
end
it 'for #numero_sequencial' do
subject.class.new.numero_sequencial.must_equal 1
Expand Down
8 changes: 4 additions & 4 deletions test/br_nfe/product/nota_fiscal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
it { must_have_alias_attribute :natOp, :natureza_operacao }
it { must_have_alias_attribute :indPag, :forma_pagamento }
it { must_have_alias_attribute :mod, :modelo_nf }
it { must_have_alias_attribute :dhEmi, :data_hora_emissao, Time.current }
it { must_have_alias_attribute :dhSaiEnt, :data_hora_expedicao, Time.current }
it { must_have_alias_attribute :dhEmi, :data_hora_emissao, Time.current.in_time_zone }
it { must_have_alias_attribute :dhSaiEnt, :data_hora_expedicao, Time.current.in_time_zone }
it { must_have_alias_attribute :tpNF, :tipo_operacao }
it { must_have_alias_attribute :tpEmis, :tipo_impressao }
it { must_have_alias_attribute :finNFe, :finalidade_emissao }
Expand Down Expand Up @@ -87,10 +87,10 @@
subject.class.new.modelo_nf.must_equal 55
end
it '#data_hora_emissao deve ter o padrão Time.current' do
subject.class.new.data_hora_emissao.must_be_within_delta Time.current
subject.class.new.data_hora_emissao.to_s.must_equal Time.current.in_time_zone.to_s
end
it '#data_hora_expedicao deve ter o padrão Time.current' do
subject.class.new.data_hora_expedicao.must_be_within_delta Time.current
subject.class.new.data_hora_expedicao.to_s.must_equal Time.current.in_time_zone.to_s
end
it '#tipo_operacao deve ter o padrão 1' do
subject.class.new.tipo_operacao.must_be_within_delta 1
Expand Down
20 changes: 16 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

require "savon/mock/spec_helper"

ENV['TZ'] = 'UTC'
Time.zone = 'Brasilia'

Minitest::Reporters.use!

if ActiveSupport.version >= Gem::Version.new('4.2')
Expand Down Expand Up @@ -101,11 +104,20 @@ def must_be_message_error(column, message=nil, msg_params={}, exec_valid = true)
end

def must_have_alias_attribute(alias_name, attribute, test_value=1)
subject.send("#{attribute}=", test_value)
subject.send(alias_name).must_equal test_value
if test_value.is_a?(Time)
test_value = Time.zone.parse('10/05/2017 03:58:47.000')
subject.send("#{attribute}=", test_value)
subject.send(alias_name).must_be_close_to test_value

subject.send("#{alias_name}=", test_value)
subject.send(attribute).must_be_close_to test_value
else
subject.send("#{attribute}=", test_value)
subject.send(alias_name).must_equal test_value

subject.send("#{alias_name}=", test_value)
subject.send(attribute).must_equal test_value
subject.send("#{alias_name}=", test_value)
subject.send(attribute).must_equal test_value
end
end

def must_accept_only_numbers attribute, opts={}
Expand Down

0 comments on commit 97471c6

Please sign in to comment.