Skip to content
Browse files

Added tests for optimistic lock update method

I've added the tests required to make sure that the quote_value method
is being passed the column type so that the underlying connection can
determine how to quote the value.
  • Loading branch information...
1 parent 7510cd6 commit dd51a399cf00ed179df702ba42498bbc9acec633 @alfredw committed Dec 16, 2012
Showing with 20 additions and 0 deletions.
  1. +7 −0 activerecord/CHANGELOG.md
  2. +13 −0 activerecord/test/cases/locking_test.rb
View
7 activerecord/CHANGELOG.md
@@ -1,5 +1,12 @@
## Rails 4.0.0 (unreleased) ##
+* When using optimisitc locking, `update` whas not passing the column type to `quote_value`
+ to allow the connection adapter to properly determine how to quote the value. This was
+ affecting certain databases that use specific colmn types.
+ Fix #6763
+
+ *Alfred Wong*
+
* Do not log the binding values for binary columns.
*Matthew M. Boedicker*
View
13 activerecord/test/cases/locking_test.rb
@@ -1,4 +1,5 @@
require 'thread'
+require 'mocha/setup'
require "cases/helper"
require 'models/person'
require 'models/job'
@@ -26,6 +27,18 @@ class ReadonlyNameShip < Ship
class OptimisticLockingTest < ActiveRecord::TestCase
fixtures :people, :legacy_things, :references, :string_key_objects, :peoples_treasures
+ def test_quote_value_passed_lock_col
+ p1 = Person.find(1)
+ assert_equal 0, p1.lock_version
+
+ Person.expects(:quote_value).with(0, Person.columns_hash[Person.locking_column]).returns('0').once
+
+ p1.first_name = 'anika2'
+ p1.save!
+
+ assert_equal 1, p1.lock_version
+ end
+
def test_non_integer_lock_existing
s1 = StringKeyObject.find("record1")
s2 = StringKeyObject.find("record1")

0 comments on commit dd51a39

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