aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-12-15 01:45:30 +0000
committerRick Olson <technoweenie@gmail.com>2007-12-15 01:45:30 +0000
commitce102e3af9ccdb5015e20ab7155d2a13c7832a9a (patch)
treee40fb1bf975de3acb64a7d2ffd37a330f2250e7a /activerecord
parentabd7cf343c3f43516d25e3b787e96af38d12ebf4 (diff)
downloadrails-ce102e3af9ccdb5015e20ab7155d2a13c7832a9a.tar.gz
rails-ce102e3af9ccdb5015e20ab7155d2a13c7832a9a.tar.bz2
rails-ce102e3af9ccdb5015e20ab7155d2a13c7832a9a.zip
Ensure optimistic locking handles nil #lock_version values properly. Closes #10510 [rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8395 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb2
-rw-r--r--activerecord/test/locking_test.rb9
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index f0bf07e65b..90885b18c0 100644
--- a/activerecord/CHANGELOG
+++ b/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]
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index ecd6a2b258..799309c17b 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -70,7 +70,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb
index 97fbfaaeb1..9a3b76e810 100644
--- a/activerecord/test/locking_test.rb
+++ b/activerecord/test/locking_test.rb
@@ -64,6 +64,15 @@ class OptimisticLockingTest < Test::Unit::TestCase
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)