aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/locking_test.rb
diff options
context:
space:
mode:
authorAlfred Wong <alfiewong@gmail.com>2012-06-17 11:43:31 -0400
committerBen Woosley <ben.woosley@gmail.com>2013-07-22 04:39:35 -0700
commit39b5bfe2394d0a4d479b41ee8d170e0f6c65fd59 (patch)
treec8118d50c862e25505698b00327acad09d922e2c /activerecord/test/cases/locking_test.rb
parentbf2161d1abf2d8aa09a7cc36b72cf0da7f6e167c (diff)
downloadrails-39b5bfe2394d0a4d479b41ee8d170e0f6c65fd59.tar.gz
rails-39b5bfe2394d0a4d479b41ee8d170e0f6c65fd59.tar.bz2
rails-39b5bfe2394d0a4d479b41ee8d170e0f6c65fd59.zip
Specified column type for quote_value
When calling quote_value the underlying connection sometimes requires more information about the column to properly return the correct quoted value. I ran into this issue when using optimistic locking in JRuby and the activerecord-jdbcmssql-adapter. In SQLSever 2000, we aren't allowed to insert a integer into a NVARCHAR column type so we need to format it as N'3' if we want to insert into the NVARCHAR type. Unfortuantely, without the column type being passed the connection adapter cannot properly return the correct quote value because it doesn't know to return N'3' or '3'. This patch is fairly straight forward where it just passes in the column type into the quote_value, as it already has the ability to take in the column, so it can properly handle at the connection level. 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.
Diffstat (limited to 'activerecord/test/cases/locking_test.rb')
-rw-r--r--activerecord/test/cases/locking_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index db7d3b80ab..4a72b69848 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -1,4 +1,5 @@
require 'thread'
+require 'mocha/setup'
require "cases/helper"
require 'models/person'
require 'models/job'
@@ -28,6 +29,18 @@ end
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")