aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-13 06:32:50 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-13 06:32:50 +0000
commitdfa786631bb8476c8cae555ad8de5e83811dfe9d (patch)
treef1e9a04a9966a91ac4a283e9453134cbb95755de /activerecord/test/cases/associations_test.rb
parent08a4c9979da44654f057494dc76498ed6a8506bc (diff)
downloadrails-dfa786631bb8476c8cae555ad8de5e83811dfe9d.tar.gz
rails-dfa786631bb8476c8cae555ad8de5e83811dfe9d.tar.bz2
rails-dfa786631bb8476c8cae555ad8de5e83811dfe9d.zip
Introduce the :readonly option to all associations. Records from the association cannot be saved. Closes #11084.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8864 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/cases/associations_test.rb')
-rwxr-xr-xactiverecord/test/cases/associations_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index cfc58ffa10..89b978ad06 100755
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -469,6 +469,11 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_cant_save_readonly_association
+ assert_raise(ActiveRecord::ReadOnlyRecord) { companies(:first_firm).readonly_account.save! }
+ assert companies(:first_firm).readonly_account.readonly?
+ end
+
end
@@ -544,6 +549,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length
end
+ def test_dynamic_find_all_should_respect_readonly_access
+ companies(:first_firm).readonly_clients.find(:all).each { |c| assert_raise(ActiveRecord::ReadOnlyRecord) { c.save! } }
+ companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? }
+ end
+
def test_triple_equality
assert !(Array === Firm.find(:first).clients)
assert Firm.find(:first).clients === Array
@@ -1581,6 +1591,11 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal post.author_id, author2.id
end
+ def test_cant_save_readonly_association
+ assert_raise(ActiveRecord::ReadOnlyRecord) { companies(:first_client).readonly_firm.save! }
+ assert companies(:first_client).readonly_firm.readonly?
+ end
+
end
@@ -1987,6 +2002,11 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 2, projects(:active_record).limited_developers.find_all_by_name('Jamis', :limit => 9_000).length
end
+ def test_dynamic_find_all_should_respect_readonly_access
+ projects(:active_record).readonly_developers.each { |d| assert_raise(ActiveRecord::ReadOnlyRecord) { d.save! } if d.valid?}
+ projects(:active_record).readonly_developers.each { |d| d.readonly? }
+ end
+
def test_new_with_values_in_collection
jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis')
david = DeveloperForProjectWithAfterCreateHook.find_by_name('David')