aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-04-30 15:04:08 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-04-30 15:04:08 -0500
commitc353794dff580c8aa63b357b2857c1fadff3104b (patch)
treeb57794919c8eabd9d928b44a15342784f4b4215b /activerecord
parent5cef8bcc549bf714c1c73e658fd96d5fea0fab84 (diff)
downloadrails-c353794dff580c8aa63b357b2857c1fadff3104b.tar.gz
rails-c353794dff580c8aa63b357b2857c1fadff3104b.tar.bz2
rails-c353794dff580c8aa63b357b2857c1fadff3104b.zip
Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67 state:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb2
-rw-r--r--activerecord/test/cases/locking_test.rb9
-rw-r--r--activerecord/test/schema/schema.rb1
4 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e96c5096e5..154b282130 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67]
+
* Fixed that change_column should be able to use :null => true on a field that formerly had false [Nate Wiger] [#26]
* Added that the MySQL adapter should map integer to either smallint, int, or bigint depending on the :limit just like PostgreSQL [DHH]
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index f2c2c5f070..65f88cfdc7 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -78,7 +78,7 @@ module ActiveRecord
begin
affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
- UPDATE #{self.class.table_name}
+ UPDATE #{self.class.quoted_table_name}
SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false, attribute_names))}
WHERE #{self.class.primary_key} = #{quote_value(id)}
AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index e80f902d0d..7db6c570b5 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -2,6 +2,7 @@ require "cases/helper"
require 'models/person'
require 'models/reader'
require 'models/legacy_thing'
+require 'models/reference'
class LockWithoutDefault < ActiveRecord::Base; end
@@ -15,7 +16,7 @@ class ReadonlyFirstNamePerson < Person
end
class OptimisticLockingTest < ActiveRecord::TestCase
- fixtures :people, :legacy_things
+ fixtures :people, :legacy_things, :references
# need to disable transactional fixtures, because otherwise the sqlite3
# adapter (at least) chokes when we try and change the schema in the middle
@@ -138,6 +139,12 @@ class OptimisticLockingTest < ActiveRecord::TestCase
end
end
end
+
+ def test_quote_table_name
+ ref = references(:michael_magician)
+ ref.favourite = !ref.favourite
+ assert ref.save
+ end
private
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index a9b2073b37..e22b78749c 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -206,6 +206,7 @@ ActiveRecord::Schema.define do
t.integer :person_id
t.integer :job_id
t.boolean :favourite
+ t.integer :lock_version, :default => 0
end
create_table :minimalistics, :force => true do |t|