提交 473202df 编写于 作者: J Jeremy Kemper

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
上级 32602acd
*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]
......
......@@ -76,7 +76,7 @@ def update_with_lock #:nodoc:
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
......
......@@ -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 @@ def test_lock_with_custom_column_without_default_sets_version_to_zero
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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册