aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/locking_test.rb
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 /activerecord/test/locking_test.rb
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
Diffstat (limited to 'activerecord/test/locking_test.rb')
-rw-r--r--activerecord/test/locking_test.rb16
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|