diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-05 11:27:54 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-05 11:34:52 +0100 |
commit | 155f86675ce6f2995a61eee9e3d814c974d2bec8 (patch) | |
tree | a104bb9efc87c3168cad4ee43f78670412965d4b | |
parent | dce398d579e484ff64a0260cea4591ad952dc99c (diff) | |
download | rails-155f86675ce6f2995a61eee9e3d814c974d2bec8.tar.gz rails-155f86675ce6f2995a61eee9e3d814c974d2bec8.tar.bz2 rails-155f86675ce6f2995a61eee9e3d814c974d2bec8.zip |
Improve `belongs_to touch: true` timestamp test
Round off time to a whole second value to compensate for databases
that don't support fractional timestamps. Also add a assertion to
check that the old record is touched when the association is cleared.
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index f42ecbb340..9d84f64c96 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -187,17 +187,11 @@ class TimestampTest < ActiveRecord::TestCase toy2 = klass.find(2) new_pet = toy2.pet - time = 3.days.ago + time = 3.days.ago.at_beginning_of_hour old_pet.update_columns(updated_at: time) new_pet.update_columns(updated_at: time) - old_pet.reload - new_pet.reload - - assert_equal time, new_pet.updated_at - assert_equal time, old_pet.updated_at - toy1.pet = new_pet toy1.save! @@ -208,6 +202,26 @@ class TimestampTest < ActiveRecord::TestCase assert_not_equal time, old_pet.updated_at end + def test_clearing_association_touches_the_old_record + klass = Class.new(ActiveRecord::Base) do + def self.name; 'Toy'; end + belongs_to :pet, touch: true + end + + toy = klass.find(1) + pet = toy.pet + time = 3.days.ago.at_beginning_of_hour + + pet.update_columns(updated_at: time) + + toy.pet = nil + toy.save! + + pet.reload + + assert_not_equal time, pet.updated_at + end + def test_timestamp_attributes_for_create toy = Toy.first assert_equal toy.send(:timestamp_attributes_for_create), [:created_at, :created_on] |