aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/timestamp_test.rb
diff options
context:
space:
mode:
authorNathaniel Bibler <git@nathanielbibler.com>2010-01-24 13:06:29 -0500
committerwycats <wycats@gmail.com>2010-03-27 00:35:39 -0700
commit3a875e618487a06a56f6cf912cf5440f294921cc (patch)
treefe26b4bcf5c6f6f9a8425da4cc0aba2faad434ad /activerecord/test/cases/timestamp_test.rb
parent167017f65558a4461aaf8dc26a6f329a283366c2 (diff)
downloadrails-3a875e618487a06a56f6cf912cf5440f294921cc.tar.gz
rails-3a875e618487a06a56f6cf912cf5440f294921cc.tar.bz2
rails-3a875e618487a06a56f6cf912cf5440f294921cc.zip
Changed behavior of touch and added touch! Originally implemented by Obie Fernandez, updated touch! to act as a thin wrapper to touch. [#2520 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/test/cases/timestamp_test.rb')
-rw-r--r--activerecord/test/cases/timestamp_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb
index 24b237a72b..6c3596347d 100644
--- a/activerecord/test/cases/timestamp_test.rb
+++ b/activerecord/test/cases/timestamp_test.rb
@@ -30,6 +30,24 @@ class TimestampTest < ActiveRecord::TestCase
assert @previously_updated_at != @developer.updated_at
end
+ def test_touching_a_record_updates_its_timestamp_even_if_object_instance_is_invalid
+ @developer.name = nil
+ @developer.touch
+
+ assert @previously_updated_at != @developer.updated_at
+ end
+
+ def test_touch_bang_a_record_updates_its_timestamp
+ @developer.touch!
+
+ assert @previously_updated_at != @developer.updated_at
+ end
+
+ def test_touch_banging_a_record_fails_if_object_instance_is_invalid
+ @developer.name = nil
+ assert_raise(ActiveRecord::RecordInvalid) { @developer.touch! }
+ end
+
def test_touching_a_different_attribute
previously_created_at = @developer.created_at
@developer.touch(:created_at)
@@ -37,6 +55,13 @@ class TimestampTest < ActiveRecord::TestCase
assert previously_created_at != @developer.created_at
end
+ def test_touch_banging_a_different_attribute
+ previously_created_at = @developer.created_at
+ @developer.touch!(:created_at)
+
+ assert previously_created_at != @developer.created_at
+ end
+
def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
pet = Pet.first
owner = pet.owner