From 748daa39610585829cdd52810870adf8e8711bfc Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 28 Apr 2014 20:58:17 -0400 Subject: add test to check that loaded and non laoded are the same Test checks that SQL is the same for a loaded vs not loaded association (category.categorizations, category.categorization.delete_all vs category.cartegroization.delete_al). This was fixed for delete_all dependency but was not fixed for no (:nullify, or nil) dependency). --- .../test/cases/associations/has_many_associations_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activerecord') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index c79c0c87c5..2f5c9d6e1b 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -131,6 +131,19 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal(expected_sql, loaded_sql) end + def test_delete_all_on_association_with_nil_dependency_is_the_same_as_not_loaded + author = authors :david + author.posts.create!(:title => "test", :body => "body") + author.reload + expected_sql = capture_sql { author.posts.delete_all } + + author.posts.create!(:title => "test", :body => "body") + author.reload + author.posts.to_a + loaded_sql = capture_sql { author.posts.delete_all } + assert_equal(expected_sql, loaded_sql) + end + def test_building_the_associated_object_with_implicit_sti_base_class firm = DependentFirm.new company = firm.companies.build -- cgit v1.2.3