1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't quote ID's as Arel will quote them -- follow same conventions as the delete method.

This commit is contained in:
Christopher Meiklejohn 2011-03-14 22:19:47 -04:00 committed by Jon Leighton
parent a45f300e5f
commit 4fbd8adf48
5 changed files with 52 additions and 2 deletions

View file

@ -94,7 +94,7 @@ module ActiveRecord
relation = self.class.unscoped
stmt = relation.where(
relation.table[self.class.primary_key].eq(quoted_id).and(
relation.table[self.class.primary_key].eq(id).and(
relation.table[lock_col].eq(quote_value(previous_lock_value))
)
).arel.compile_update(arel_attributes_values(false, false, attribute_names))

View file

@ -5,6 +5,7 @@ require 'models/job'
require 'models/reader'
require 'models/legacy_thing'
require 'models/reference'
require 'models/string_key_object'
class LockWithoutDefault < ActiveRecord::Base; end
@ -18,7 +19,40 @@ class ReadonlyFirstNamePerson < Person
end
class OptimisticLockingTest < ActiveRecord::TestCase
fixtures :people, :legacy_things, :references
fixtures :people, :legacy_things, :references, :string_key_objects
def test_non_integer_lock_existing
s1 = StringKeyObject.find("record1")
s2 = StringKeyObject.find("record1")
assert_equal 0, s1.lock_version
assert_equal 0, s2.lock_version
s1.name = 'updated record'
s1.save!
assert_equal 1, s1.lock_version
assert_equal 0, s2.lock_version
s2.name = 'doubly updated record'
assert_raise(ActiveRecord::StaleObjectError) { s2.save! }
end
def test_non_integer_lock_destroy
s1 = StringKeyObject.find("record1")
s2 = StringKeyObject.find("record1")
assert_equal 0, s1.lock_version
assert_equal 0, s2.lock_version
s1.name = 'updated record'
s1.save!
assert_equal 1, s1.lock_version
assert_equal 0, s2.lock_version
assert_raise(ActiveRecord::StaleObjectError) { s2.destroy }
assert s1.destroy
assert s1.frozen?
assert s1.destroyed?
assert_raises(ActiveRecord::RecordNotFound) { StringKeyObject.find("record1") }
end
def test_lock_existing
p1 = Person.find(1)

View file

@ -0,0 +1,7 @@
first:
id: record1
name: first record
second:
id: record2
name: second record

View file

@ -0,0 +1,3 @@
class StringKeyObject < ActiveRecord::Base
set_primary_key :id
end

View file

@ -543,6 +543,12 @@ ActiveRecord::Schema.define do
t.string :sponsorable_type
end
create_table :string_key_objects, :id => false, :primary_key => :id, :force => true do |t|
t.string :id
t.string :name
t.integer :lock_version, :null => false, :default => 0
end
create_table :students, :force => true do |t|
t.string :name
end