aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-11-16 20:31:24 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-11-16 20:31:24 +0000
commit473202df83690d1b6ab08e6166a483109f8c769f (patch)
treeccf313d4a4fc223cf63ca268ef14086d82c31113
parent32602acdb70c59a22aac94640bedddd566616c1d (diff)
downloadrails-473202df83690d1b6ab08e6166a483109f8c769f.tar.gz
rails-473202df83690d1b6ab08e6166a483109f8c769f.tar.bz2
rails-473202df83690d1b6ab08e6166a483109f8c769f.zip
attr_readonly behaves well with optimistic locking. Closes #10188.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8156 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb2
-rw-r--r--activerecord/test/locking_test.rb16
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e9c6884c7d..7a9b1e11af 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* attr_readonly behaves well with optimistic locking. #10188 [Nick Bugajski]
+
* Base#to_xml supports the nil="true" attribute like Hash#to_xml. #8268 [Catfish]
* Change plings to the more conventional quotes in the documentation. Closes #10104 [danger]
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index d8f9dee372..ecd6a2b258 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -76,7 +76,7 @@ module ActiveRecord
begin
affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
UPDATE #{self.class.table_name}
- SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))}
+ SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false))}
WHERE #{self.class.primary_key} = #{quote_value(id)}
AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
end_sql
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb
index 5b23aab515..b0d6f8417f 100644
--- a/activerecord/test/locking_test.rb
+++ b/activerecord/test/locking_test.rb
@@ -10,6 +10,10 @@ class LockWithCustomColumnWithoutDefault < ActiveRecord::Base
set_locking_column :custom_lock_version
end
+class ReadonlyFirstNamePerson < Person
+ attr_readonly :first_name
+end
+
class OptimisticLockingTest < Test::Unit::TestCase
fixtures :people, :legacy_things
@@ -94,6 +98,18 @@ class OptimisticLockingTest < Test::Unit::TestCase
assert_equal 0, t1.custom_lock_version
end
+ def test_readonly_attributes
+ assert_equal [ :first_name ], ReadonlyFirstNamePerson.readonly_attributes
+
+ p = ReadonlyFirstNamePerson.create(:first_name => "unchangeable name")
+ p.reload
+ assert_equal "unchangeable name", p.first_name
+
+ p.update_attributes(:first_name => "changed name")
+ p.reload
+ assert_equal "unchangeable name", p.first_name
+ end
+
{ :lock_version => Person, :custom_lock_version => LegacyThing }.each do |name, model|
define_method("test_increment_counter_updates_#{name}") do
counter_test model, 1 do |id|