diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-13 13:37:40 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-13 13:37:40 -0800 |
commit | 3d2e8cb71cf50457e18991018d913828199628e0 (patch) | |
tree | a4af47370355583778753534c5117daf168b2f9b /activerecord/test/cases | |
parent | c994e1086270cdfe4e145ea206049f05ef5414d6 (diff) | |
parent | b32ba367f584a6298fb8b7eef97be15388b5bd87 (diff) | |
download | rails-3d2e8cb71cf50457e18991018d913828199628e0.tar.gz rails-3d2e8cb71cf50457e18991018d913828199628e0.tar.bz2 rails-3d2e8cb71cf50457e18991018d913828199628e0.zip |
Merge pull request #12772 from dmathieu/no_touching
Add No Touching
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index ff1b01556d..8c45f2a3f8 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -11,6 +11,7 @@ class TimestampTest < ActiveRecord::TestCase def setup @developer = Developer.first + @owner = Owner.first @developer.update_columns(updated_at: Time.now.prev_month) @previously_updated_at = @developer.updated_at end @@ -92,6 +93,53 @@ class TimestampTest < ActiveRecord::TestCase assert_nothing_raised { Car.first.touch } end + def test_touching_a_no_touching_object + Developer.no_touching do + assert @developer.no_touching? + assert !@owner.no_touching? + @developer.touch + end + + assert !@developer.no_touching? + assert !@owner.no_touching? + assert_equal @previously_updated_at, @developer.updated_at + end + + def test_touching_related_objects + @owner = Owner.first + @previously_updated_at = @owner.updated_at + + Owner.no_touching do + @owner.pets.first.touch + end + + assert_equal @previously_updated_at, @owner.updated_at + end + + def test_global_no_touching + ActiveRecord::Base.no_touching do + assert @developer.no_touching? + assert @owner.no_touching? + @developer.touch + end + + assert !@developer.no_touching? + assert !@owner.no_touching? + assert_equal @previously_updated_at, @developer.updated_at + end + + def test_no_touching_threadsafe + Thread.new do + Developer.no_touching do + assert @developer.no_touching? + + sleep(1) + end + end + + assert !@developer.no_touching? + 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 |