Permalink
Browse files

Merge pull request #26497 from koppen/26496-touch_with_optimistic_loc…

…king

Clear attribute changes after handling locking
  • Loading branch information...
eileencodes committed Sep 17, 2016
2 parents b5ef59f + e835596 commit 2159a932335486d6e982bfb42ca297f42e0e42c0
@@ -1,3 +1,10 @@
+* Calling `touch` on a model using optimistic locking will now leave the model
+ in a non-dirty state with no attribute changes.
+
+ Fixes #26496.
+
+ *Jakob Skjerning*
+
* Using a mysql2 connection after it fails to reconnect will now have an error message
saying the connection is closed rather than an undefined method error message.
@@ -498,7 +498,6 @@ def touch(*names, time: nil)
changes[column] = write_attribute(column, time)
end
- clear_attribute_changes(changes.keys)
primary_key = self.class.primary_key
scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key))
@@ -508,6 +507,7 @@ def touch(*names, time: nil)
changes[locking_column] = increment_lock
end
+ clear_attribute_changes(changes.keys)
result = scope.update_all(changes) == 1
if !result && locking_enabled?
@@ -181,6 +181,7 @@ def test_touch_existing_lock
p1.touch
assert_equal 1, p1.lock_version
+ assert_not p1.changed?, "Changes should have been cleared"
end
def test_touch_stale_object

0 comments on commit 2159a93

Please sign in to comment.