Skip to content
Browse files

Do not use default_scope in ActiveRecord::Persistence#touch.

  • Loading branch information...
1 parent 96711aa commit 54f5fb5dc3f79b28f0150573e7b912ac0f747818 @dmitriy-kiriyenko dmitriy-kiriyenko committed with jonleighton Jun 6, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/persistence.rb
  2. +9 −0 activerecord/test/cases/timestamp_test.rb
View
2 activerecord/lib/active_record/persistence.rb
@@ -277,7 +277,7 @@ def touch(name = nil)
@changed_attributes.except!(*changes.keys)
primary_key = self.class.primary_key
- self.class.update_all(changes, { primary_key => self[primary_key] }) == 1
+ self.class.unscoped.update_all(changes, { primary_key => self[primary_key] }) == 1
end
end
View
9 activerecord/test/cases/timestamp_test.rb
@@ -67,6 +67,15 @@ def test_touching_a_record_updates_its_timestamp
assert_equal previous_salary, @developer.salary
end
+ def test_touching_a_record_with_default_scope_that_exludes_it_updates_its_timestamp
+ developer = @developer.becomes(DeveloperCalledJamis)
+
+ developer.touch
+ assert_not_equal @previously_updated_at, developer.updated_at
+ developer.reload
+ assert_not_equal @previously_updated_at, developer.updated_at
+ end
+
def test_saving_when_record_timestamps_is_false_doesnt_update_its_timestamp
Developer.record_timestamps = false
@developer.name = "John Smith"

0 comments on commit 54f5fb5

Please sign in to comment.
Something went wrong with that request. Please try again.