1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/mixin_test.rb
Rafael Mendonça França 7abb6e00c0 Remove automatic removal of Date/Time stubs after each test case
This behavior is only work out-of-box with minitest and also add a
downside to run after each test case, even if we don't used the travel
or travel_to methods
2014-01-30 10:17:48 -02:00

70 lines
1.4 KiB
Ruby

require "cases/helper"
class Mixin < ActiveRecord::Base
end
class TouchTest < ActiveRecord::TestCase
fixtures :mixins
setup do
travel_to Time.now
end
teardown do
travel_back
end
def test_update
stamped = Mixin.new
assert_nil stamped.updated_at
assert_nil stamped.created_at
stamped.save
assert_equal Time.now, stamped.updated_at
assert_equal Time.now, stamped.created_at
end
def test_create
obj = Mixin.create
assert_equal Time.now, obj.updated_at
assert_equal Time.now, obj.created_at
end
def test_many_updates
stamped = Mixin.new
assert_nil stamped.updated_at
assert_nil stamped.created_at
stamped.save
assert_equal Time.now, stamped.created_at
assert_equal Time.now, stamped.updated_at
old_updated_at = stamped.updated_at
travel 5.minutes do
stamped.lft_will_change!
stamped.save
assert_equal Time.now, stamped.updated_at
assert_equal old_updated_at, stamped.created_at
end
end
def test_create_turned_off
Mixin.record_timestamps = false
mixin = Mixin.new
assert_nil mixin.updated_at
mixin.save
assert_nil mixin.updated_at
# Make sure Mixin.record_timestamps gets reset, even if this test fails,
# so that other tests do not fail because Mixin.record_timestamps == false
rescue Exception => e
raise e
ensure
Mixin.record_timestamps = true
end
end