Skip to content

Commit

Permalink
added test for timezone issue, issue# 33 - celsodantas#33
Browse files Browse the repository at this point in the history
  • Loading branch information
manpreetnarang committed Aug 9, 2017
1 parent fe3b440 commit 2a3ccff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/protokoll/counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.build_attrs(object, options)
end

def self.outdated?(record, options)
Time.now.utc.strftime(update_event(options)).to_i > record.updated_at.utc.strftime(update_event(options)).to_i
Time.zone.now.strftime(update_event(options)).to_i > record.updated_at.strftime(update_event(options)).to_i
end

def self.update_event(options)
Expand Down
34 changes: 34 additions & 0 deletions test/protokoll_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,40 @@ class Protocol < ActiveRecord::Base
assert_equal "20110900002", protocol2.number
end

test "timezone should not be a problem" do
class Protocol < ActiveRecord::Base
protokoll :number, pattern: "%y%m%d##"
end

Time.zone = 'America/New_York'
time = Time.local(2011, 9, 25, 9, 0, 0)
Timecop.travel(time)
protocol1 = Protocol.create

time = Time.local(2011, 9, 25, 22, 0, 0)
Timecop.travel(time)
protocol2 = Protocol.create

assert_not_equal protocol1.number, protocol2.number
end

test "timezone should not be a problem when the time is next day" do
class Protocol < ActiveRecord::Base
protokoll :number, pattern: "%y%m%d##"
end

Time.zone = 'America/New_York'
time = Time.local(2011, 9, 25, 9, 0, 0)
Timecop.travel(time)
protocol1 = Protocol.create

time = Time.local(2011, 9, 26, 02, 0, 0)
Timecop.travel(time)
protocol2 = Protocol.create

assert_not_equal protocol1.number, protocol2.number
end

test "should get 201100002 for second save (format number %Y#####)" do
class Protocol < ActiveRecord::Base
protokoll :number, :pattern => "%Y#####"
Expand Down

0 comments on commit 2a3ccff

Please sign in to comment.