2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2007-09-10 23:25:59 -04:00
|
|
|
|
|
|
|
class Mixin < ActiveRecord::Base
|
|
|
|
end
|
2004-12-14 19:46:26 -05:00
|
|
|
|
2008-01-21 12:20:51 -05:00
|
|
|
class TouchTest < ActiveRecord::TestCase
|
2004-12-14 19:46:26 -05:00
|
|
|
fixtures :mixins
|
2008-01-18 02:30:42 -05:00
|
|
|
|
2014-01-29 19:41:30 -05:00
|
|
|
setup do
|
2013-11-20 08:36:58 -05:00
|
|
|
travel_to Time.now
|
2006-09-13 20:50:42 -04:00
|
|
|
end
|
2005-11-10 01:24:33 -05:00
|
|
|
|
2014-01-29 19:41:30 -05:00
|
|
|
teardown do
|
|
|
|
travel_back
|
|
|
|
end
|
|
|
|
|
2004-12-14 19:46:26 -05:00
|
|
|
def test_update
|
2005-11-10 01:24:33 -05:00
|
|
|
stamped = Mixin.new
|
|
|
|
|
2004-12-19 08:01:47 -05:00
|
|
|
assert_nil stamped.updated_at
|
|
|
|
assert_nil stamped.created_at
|
|
|
|
stamped.save
|
2006-09-13 20:50:42 -04:00
|
|
|
assert_equal Time.now, stamped.updated_at
|
|
|
|
assert_equal Time.now, stamped.created_at
|
2005-11-10 01:24:33 -05:00
|
|
|
end
|
2004-12-14 19:46:26 -05:00
|
|
|
|
|
|
|
def test_create
|
2006-09-13 20:50:42 -04:00
|
|
|
obj = Mixin.create
|
|
|
|
assert_equal Time.now, obj.updated_at
|
|
|
|
assert_equal Time.now, obj.created_at
|
2005-11-10 01:24:33 -05:00
|
|
|
end
|
2004-12-19 08:01:47 -05:00
|
|
|
|
|
|
|
def test_many_updates
|
2005-11-10 01:24:33 -05:00
|
|
|
stamped = Mixin.new
|
2004-12-19 08:01:47 -05:00
|
|
|
|
|
|
|
assert_nil stamped.updated_at
|
|
|
|
assert_nil stamped.created_at
|
|
|
|
stamped.save
|
2006-09-13 20:50:42 -04:00
|
|
|
assert_equal Time.now, stamped.created_at
|
|
|
|
assert_equal Time.now, stamped.updated_at
|
2005-11-10 01:24:33 -05:00
|
|
|
|
2004-12-19 08:01:47 -05:00
|
|
|
old_updated_at = stamped.updated_at
|
|
|
|
|
2013-11-20 08:36:58 -05:00
|
|
|
travel 5.minutes do
|
|
|
|
stamped.lft_will_change!
|
|
|
|
stamped.save
|
2004-12-19 08:01:47 -05:00
|
|
|
|
2013-11-20 08:36:58 -05:00
|
|
|
assert_equal Time.now, stamped.updated_at
|
|
|
|
assert_equal old_updated_at, stamped.created_at
|
|
|
|
end
|
2004-12-19 08:01:47 -05:00
|
|
|
end
|
|
|
|
|
2004-12-16 10:21:16 -05:00
|
|
|
def test_create_turned_off
|
|
|
|
Mixin.record_timestamps = false
|
|
|
|
|
2007-11-26 17:45:43 -05:00
|
|
|
mixin = Mixin.new
|
2004-12-16 10:21:16 -05:00
|
|
|
|
2007-11-26 17:45:43 -05:00
|
|
|
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
|
|
|
|
ensure
|
2004-12-16 10:21:16 -05:00
|
|
|
Mixin.record_timestamps = true
|
|
|
|
end
|
2005-09-09 04:32:47 -04:00
|
|
|
|
2007-09-11 02:47:27 -04:00
|
|
|
end
|