diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/locking_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
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| |