aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-03-31 19:09:32 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-03-31 19:09:32 -0700
commite9f53f7a7a5c57838654aad9ee1d8b0086b685d7 (patch)
tree5e30ea8ac35821a8fd0fc087b17742bc820dbc95 /activerecord/test
parent165d93b22ff5f8798296bd5d7642d0ddb8996c74 (diff)
parente247f3257927e008ed89944249ac38a8838f719f (diff)
downloadrails-e9f53f7a7a5c57838654aad9ee1d8b0086b685d7.tar.gz
rails-e9f53f7a7a5c57838654aad9ee1d8b0086b685d7.tar.bz2
rails-e9f53f7a7a5c57838654aad9ee1d8b0086b685d7.zip
Merge pull request #14546 from eileencodes/fix_delete_all_to_not_use_IN_statement
Fix delete all to not produce sql in statement
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb17
-rw-r--r--activerecord/test/cases/test_case.rb6
2 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 49d3301044..3dfb0a27ba 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -22,6 +22,8 @@ require 'models/engine'
require 'models/categorization'
require 'models/minivan'
require 'models/speedometer'
+require 'models/reference'
+require 'models/job'
class HasManyAssociationsTestForReorderWithJoinDependency < ActiveRecord::TestCase
fixtures :authors, :posts, :comments
@@ -39,7 +41,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :categories, :companies, :developers, :projects,
:developers_projects, :topics, :authors, :comments,
:people, :posts, :readers, :taggings, :cars, :essays,
- :categorizations
+ :categorizations, :jobs
def setup
Client.destroyed_client_ids.clear
@@ -107,6 +109,19 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 0, Bulb.count, "bulbs should have been deleted using :delete_all strategy"
end
+ def test_delete_all_on_association_is_the_same_as_not_loaded
+ author = authors :david
+ author.thinking_posts.create!(:body => "test")
+ author.reload
+ expected_sql = capture_sql { author.thinking_posts.delete_all }
+
+ author.thinking_posts.create!(:body => "test")
+ author.reload
+ author.thinking_posts.inspect
+ loaded_sql = capture_sql { author.thinking_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
diff --git a/activerecord/test/cases/test_case.rb b/activerecord/test/cases/test_case.rb
index 4476ce3410..cbf6ea36bf 100644
--- a/activerecord/test/cases/test_case.rb
+++ b/activerecord/test/cases/test_case.rb
@@ -19,6 +19,12 @@ module ActiveRecord
end
end
+ def capture_sql
+ SQLCounter.clear_log
+ yield
+ SQLCounter.log_all.dup
+ end
+
def assert_sql(*patterns_to_match)
SQLCounter.clear_log
yield