Skip to content

Commit

Permalink
Revert "Merge pull request #19783 from vngrs/raise_error_on_touch_if_…
Browse files Browse the repository at this point in the history
…object_is_stale"

This reverts commit 3036490.

Reason: It brokes some tests with has_one association what can cause an
regression
  • Loading branch information
rafaelfranca committed Apr 19, 2015
1 parent 57565f3 commit 16df732
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
18 changes: 3 additions & 15 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -466,23 +466,11 @@ def touch(*names)
changes[column] = write_attribute(column, current_time)
end

changes[self.class.locking_column] = increment_lock if locking_enabled?

clear_attribute_changes(changes.keys)
primary_key = self.class.primary_key
scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key))

if locking_enabled?
locking_column = self.class.locking_column
scope = scope.where(locking_column => _read_attribute(locking_column))
changes[locking_column] = increment_lock
end

result = scope.update_all(changes) == 1

if !result && locking_enabled?
raise ActiveRecord::StaleObjectError.new(self, "touch")
end

result
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
else
true
end
Expand Down
10 changes: 0 additions & 10 deletions activerecord/test/cases/locking_test.rb
Expand Up @@ -177,16 +177,6 @@ def test_touch_existing_lock
assert_equal 1, p1.lock_version
end

def test_touch_stale_object
person = Person.create!(first_name: 'Mehmet Emin')
stale_person = Person.find(person.id)
person.update_attribute(:gender, 'M')

assert_raises(ActiveRecord::StaleObjectError) do
stale_person.touch
end
end

def test_lock_column_name_existing
t1 = LegacyThing.find(1)
t2 = LegacyThing.find(1)
Expand Down

0 comments on commit 16df732

Please sign in to comment.