Skip to content

Commit

Permalink
Ensure optimistic locking handles nil #lock_version values properly. C…
Browse files Browse the repository at this point in the history
…loses rails#10510 [rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8395 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
technoweenie committed Dec 15, 2007
1 parent abd7cf3 commit ce102e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Ensure optimistic locking handles nil #lock_version values properly. Closes #10510 [rick]

* Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]

* Fix that validates_acceptance_of still works for non-existent tables (useful for bootstrapping new databases). Closes #10474 [hasmanyjosh]
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/locking/optimistic.rb
Expand Up @@ -70,7 +70,7 @@ def update_with_lock #:nodoc:
return update_without_lock unless locking_enabled?

lock_col = self.class.locking_column
previous_value = send(lock_col)
previous_value = send(lock_col).to_i
send(lock_col + '=', previous_value + 1)

begin
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/locking_test.rb
Expand Up @@ -64,6 +64,15 @@ def test_lock_new

assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
end

def test_lock_new_with_nil
p1 = Person.new(:first_name => 'anika')
p1.save!
p1.lock_version = nil # simulate bad fixture or column with no default
p1.save!
assert_equal 1, p1.lock_version
end


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

0 comments on commit ce102e3

Please sign in to comment.