From 473202df83690d1b6ab08e6166a483109f8c769f Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 16 Nov 2007 20:31:24 +0000 Subject: 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 --- activerecord/test/locking_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test') 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| -- cgit v1.2.3