diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-08-16 12:57:55 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-16 12:57:55 -0300 |
commit | 149c144409cc9cbc4e960dbd70c9c77d86b06d8d (patch) | |
tree | 3cfa2862262417908cea333ca17a12a488810d69 /activerecord | |
parent | 82ec6b36065e91fe0ec5a87f9419840618ce2c5d (diff) | |
parent | ed34b6760793ebc8477f3cd6398ac3ef829b57d1 (diff) | |
download | rails-149c144409cc9cbc4e960dbd70c9c77d86b06d8d.tar.gz rails-149c144409cc9cbc4e960dbd70c9c77d86b06d8d.tar.bz2 rails-149c144409cc9cbc4e960dbd70c9c77d86b06d8d.zip |
Merge pull request #26183 from Shopify/fix-no-touching-touch-later
Makes touch_later respects no_touching policy
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/base.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/no_touching.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/touch_later_test.rb | 9 |
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 01d7886406..1e7e939097 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -312,8 +312,8 @@ module ActiveRecord #:nodoc: include NestedAttributes include Aggregations include Transactions - include NoTouching include TouchLater + include NoTouching include Reflection include Serialization include Store diff --git a/activerecord/lib/active_record/no_touching.rb b/activerecord/lib/active_record/no_touching.rb index edb5066fa0..4059020e25 100644 --- a/activerecord/lib/active_record/no_touching.rb +++ b/activerecord/lib/active_record/no_touching.rb @@ -45,6 +45,10 @@ module ActiveRecord NoTouching.applied_to?(self.class) end + def touch_later(*) # :nodoc: + super unless no_touching? + end + def touch(*) # :nodoc: super unless no_touching? end diff --git a/activerecord/test/cases/touch_later_test.rb b/activerecord/test/cases/touch_later_test.rb index 697447a4f3..d1e8c649d9 100644 --- a/activerecord/test/cases/touch_later_test.rb +++ b/activerecord/test/cases/touch_later_test.rb @@ -24,6 +24,15 @@ class TouchLaterTest < ActiveRecord::TestCase assert_not invoice.changed? end + def test_touch_later_respects_no_touching_policy + time = Time.now.utc - 25.days + topic = Topic.create!(updated_at: time, created_at: time) + Topic.no_touching do + topic.touch_later + end + assert_equal time.to_i, topic.updated_at.to_i + end + def test_touch_later_update_the_attributes time = Time.now.utc - 25.days topic = Topic.create!(updated_at: time, created_at: time) |