aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/base_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-09-30 07:09:44 +0000
committerRick Olson <technoweenie@gmail.com>2007-09-30 07:09:44 +0000
commit66d05f5e2c7ac6b18220956fbcf34efcd32638fc (patch)
tree6544dd694d02af7438489a4864daec9c2bdce0b5 /activerecord/test/base_test.rb
parent30a652ad41428b922b1ed637f491776f1f1dff13 (diff)
downloadrails-66d05f5e2c7ac6b18220956fbcf34efcd32638fc.tar.gz
rails-66d05f5e2c7ac6b18220956fbcf34efcd32638fc.tar.bz2
rails-66d05f5e2c7ac6b18220956fbcf34efcd32638fc.zip
Add attr_readonly to specify columns that are skipped during a normal ActiveRecord #save operation. Closes #6896 [dcmanges]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7693 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/base_test.rb')
-rwxr-xr-xactiverecord/test/base_test.rb42
1 files changed, 29 insertions, 13 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 1883f369c3..4418b8d9e6 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -47,6 +47,10 @@ class TightDescendant < TightPerson
attr_accessible :phone_number
end
+class ReadonlyTitlePost < Post
+ attr_readonly :title
+end
+
class Booleantest < ActiveRecord::Base; end
class Task < ActiveRecord::Base
@@ -840,6 +844,19 @@ class BasicsTest < Test::Unit::TestCase
assert_nil TightDescendant.protected_attributes
assert_equal [ :name, :address, :phone_number ], TightDescendant.accessible_attributes
end
+
+ def test_readonly_attributes
+ assert_equal [ :title ], ReadonlyTitlePost.readonly_attributes
+
+ post = ReadonlyTitlePost.create(:title => "cannot change this", :body => "changeable")
+ post.reload
+ assert_equal "cannot change this", post.title
+
+ post.update_attributes(:title => "try to change", :body => "changed")
+ post.reload
+ assert_equal "cannot change this", post.title
+ assert_equal "changed", post.body
+ end
def test_multiparameter_attributes_on_date
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
@@ -1222,12 +1239,12 @@ class BasicsTest < Test::Unit::TestCase
end
def test_increment_attribute
- assert_equal 1, topics(:first).replies_count
- topics(:first).increment! :replies_count
- assert_equal 2, topics(:first, :reload).replies_count
-
- topics(:first).increment(:replies_count).increment!(:replies_count)
- assert_equal 4, topics(:first, :reload).replies_count
+ assert_equal 50, accounts(:signals37).credit_limit
+ accounts(:signals37).increment! :credit_limit
+ assert_equal 51, accounts(:signals37, :reload).credit_limit
+
+ accounts(:signals37).increment(:credit_limit).increment!(:credit_limit)
+ assert_equal 53, accounts(:signals37, :reload).credit_limit
end
def test_increment_nil_attribute
@@ -1237,14 +1254,13 @@ class BasicsTest < Test::Unit::TestCase
end
def test_decrement_attribute
- topics(:first).increment(:replies_count).increment!(:replies_count)
- assert_equal 3, topics(:first).replies_count
-
- topics(:first).decrement!(:replies_count)
- assert_equal 2, topics(:first, :reload).replies_count
+ assert_equal 50, accounts(:signals37).credit_limit
- topics(:first).decrement(:replies_count).decrement!(:replies_count)
- assert_equal 0, topics(:first, :reload).replies_count
+ accounts(:signals37).decrement!(:credit_limit)
+ assert_equal 49, accounts(:signals37, :reload).credit_limit
+
+ accounts(:signals37).decrement(:credit_limit).decrement!(:credit_limit)
+ assert_equal 47, accounts(:signals37, :reload).credit_limit
end
def test_toggle_attribute