diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-07-06 17:33:26 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-07-06 17:33:26 -0300 |
commit | 7948d7890548a3e70d04dfed26497b391920b058 (patch) | |
tree | 2056056a8a2e1a8efcb7e88f69e40f83e949427b /activerecord/test/cases | |
parent | 8d8d4b7782145aedc0604d9179931ec9b9b5225a (diff) | |
parent | 1ecc3e83b6f62e2f6858c458231e3a49ef0bd916 (diff) | |
download | rails-7948d7890548a3e70d04dfed26497b391920b058.tar.gz rails-7948d7890548a3e70d04dfed26497b391920b058.tar.bz2 rails-7948d7890548a3e70d04dfed26497b391920b058.zip |
Merge pull request #11306 from jetthoughts/11288_remove_extra_queries_for_belongs_to_with_touch
#11288: Removed duplicated touching
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index cc72ab7b2a..0267cdf6e0 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require 'cases/helper' require 'models/developer' require 'models/project' require 'models/company' @@ -14,6 +14,8 @@ require 'models/sponsor' require 'models/member' require 'models/essay' require 'models/toy' +require 'models/invoice' +require 'models/line_item' class BelongsToAssociationsTest < ActiveRecord::TestCase fixtures :accounts, :companies, :developers, :projects, :topics, @@ -324,6 +326,45 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal 1, Topic.find(topic.id)[:replies_count] end + def test_belongs_to_with_touch_option_on_touch + line_item = LineItem.create! + Invoice.create!(line_items: [line_item]) + + assert_queries(1) { line_item.touch } + end + + def test_belongs_to_with_touch_option_on_touch_and_removed_parent + line_item = LineItem.create! + Invoice.create!(line_items: [line_item]) + + line_item.invoice = nil + + assert_queries(2) { line_item.touch } + end + + def test_belongs_to_with_touch_option_on_update + line_item = LineItem.create! + Invoice.create!(line_items: [line_item]) + + assert_queries(2) { line_item.update amount: 10 } + end + + def test_belongs_to_with_touch_option_on_destroy + line_item = LineItem.create! + Invoice.create!(line_items: [line_item]) + + assert_queries(2) { line_item.destroy } + end + + def test_belongs_to_with_touch_option_on_touch_and_reassigned_parent + line_item = LineItem.create! + Invoice.create!(line_items: [line_item]) + + line_item.invoice = Invoice.create! + + assert_queries(3) { line_item.touch } + end + def test_belongs_to_counter_after_update topic = Topic.create!(title: "37s") topic.replies.create!(title: "re: 37s", content: "rails") |