aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2014-02-28 17:00:38 -0500
committerArthur Neves <arthurnn@gmail.com>2014-02-28 17:00:38 -0500
commit774160b9ad6908435bf3485e7ac98633deff76c6 (patch)
tree37c2e322ff4eae74c8d314912293b07efb46218b /activerecord/test/cases/associations
parentbe6f51a487eb412ca29765aa7e84d2f13a688891 (diff)
downloadrails-774160b9ad6908435bf3485e7ac98633deff76c6.tar.gz
rails-774160b9ad6908435bf3485e7ac98633deff76c6.tar.bz2
rails-774160b9ad6908435bf3485e7ac98633deff76c6.zip
Remove unnecessary db call when replacing.
When replacing a has_many association with the same one, there is no need to do a round-trip to the db to create/and drop a new transaction. [fixes #14220]
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index a86fb15719..49d3301044 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1242,6 +1242,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal orig_accounts, firm.accounts
end
+ def test_replace_with_same_content
+ firm = Firm.first
+ firm.clients = []
+ firm.save
+
+ assert_queries(0, ignore_none: true) do
+ firm.clients = []
+ end
+ end
+
def test_transactions_when_replacing_on_persisted
good = Client.new(:name => "Good")
bad = Client.new(:name => "Bad", :raise_on_save => true)