Permalink
Browse files

Merge pull request #14899 from eileencodes/fix-delete-all-with-nil-de…

…pendency-to-not-produce-in-statement

Fix delete all with nil (:nullify) dependency to not produce in statement
  • Loading branch information...
2 parents b7b319e + 748daa3 commit 7763cff2981757ab6a4d5796c1d17b98a2f57f0a @tenderlove tenderlove committed Apr 29, 2014
@@ -252,10 +252,10 @@ def delete(*records)
end
def delete_all_with_dependency(dependent)
- if dependent == :delete_all
- delete_records(:all, dependent)
- else
+ if dependent == :destroy
delete_or_destroy(load_target, dependent)
+ else
+ delete_records(:all, dependent)
end
end
@@ -150,7 +150,7 @@ def test_has_and_belongs_to_many_remove_callback
"after_removing#{jamis.id}"], activerecord.developers_log
end
- def test_has_and_belongs_to_many_remove_callback_on_clear
+ def test_has_and_belongs_to_many_does_not_fire_callbacks_on_clear
activerecord = projects(:active_record)
assert activerecord.developers_log.empty?
if activerecord.developers_with_callbacks.size == 0
@@ -161,7 +161,7 @@ def test_has_and_belongs_to_many_remove_callback_on_clear
end
log_array = activerecord.developers_with_callbacks.flat_map {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.sort
assert activerecord.developers_with_callbacks.clear
- assert_equal log_array, activerecord.developers_log.sort
+ assert_predicate activerecord.developers_log, :empty?
end
def test_has_many_and_belongs_to_many_callbacks_for_save_on_parent
@@ -131,6 +131,19 @@ def test_delete_all_on_association_is_the_same_as_not_loaded
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
@@ -698,9 +698,6 @@ def test_association_callback_ordering
[:added, :before, "Roger"],
[:added, :after, "Roger"]
], log.last(4)
-
- post.people_with_callbacks.clear
- assert_equal((%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort)
end
def test_dynamic_find_should_respect_association_include

0 comments on commit 7763cff

Please sign in to comment.