diff options
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-x | activerecord/test/cases/associations_test.rb | 20 | ||||
-rw-r--r-- | activerecord/test/cases/reflection_test.rb | 6 |
2 files changed, 23 insertions, 3 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') diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index c2dedec3ef..c8ee40ea09 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -159,9 +159,9 @@ class ReflectionTest < ActiveRecord::TestCase end def test_reflection_of_all_associations - assert_equal 17, Firm.reflect_on_all_associations.size - assert_equal 15, Firm.reflect_on_all_associations(:has_many).size - assert_equal 2, Firm.reflect_on_all_associations(:has_one).size + assert_equal 19, Firm.reflect_on_all_associations.size + assert_equal 16, Firm.reflect_on_all_associations(:has_many).size + assert_equal 3, Firm.reflect_on_all_associations(:has_one).size assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size end |