From 006aea643f020250d02673ce49b572c8cfc2dc37 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 13 Jul 2017 04:31:42 +0900 Subject: Remove extra `.merge!(order: "id")` for `Relation#first` in tests Since 07e5301, `Relation#first` will order by primary key if no order is defined. --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index a727cc6e60..a7ac291f23 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -647,8 +647,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase def test_new_record_with_foreign_key_but_no_object client = Client.new("firm_id" => 1) - # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first - assert_equal Firm.all.merge!(order: "id").first, client.firm_with_basic_id + assert_equal Firm.first, client.firm_with_basic_id end def test_setting_foreign_key_after_nil_target_loaded -- cgit v1.2.3 From 6137a4e8f77f0bba78d304d962b89ddf3cf465aa Mon Sep 17 00:00:00 2001 From: Lisa Ugray Date: Wed, 12 Jul 2017 10:22:20 -0400 Subject: Add test for fixed `counter_cache` double increment When an `after_create` callback did `update_attributes` on a record with multiple `belongs_to` associations with counter caches, even numbered associations would have their counters double-incremented. Fixes to `ActiveModel::Dirty` in 020abad fixed this. This adds regression tests for this bug fixed incidentally in the other commit, which also removed the need for the workaround using @_after_create_counter_called. --- .../test/cases/associations/belongs_to_associations_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index a7ac291f23..7270060639 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1167,6 +1167,17 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase Column.create! record: record assert_equal 1, Column.count end + + def test_multiple_counter_cache_with_after_create_update + post = posts(:welcome) + parent = comments(:greetings) + + assert_difference "parent.reload.children_count", +1 do + assert_difference "post.reload.comments_count", +1 do + comment = CommentWithAfterCreateUpdate.create(body: "foo", post: post, parent: parent) + end + end + end end class BelongsToWithForeignKeyTest < ActiveRecord::TestCase -- cgit v1.2.3 From 831be98f9a6685da3410b0c9bf4143bd8dd647af Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sun, 9 Jul 2017 20:41:28 +0300 Subject: Use frozen-string-literal in ActiveRecord --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index a7ac291f23..8bf2ecf88d 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "cases/helper" require "models/developer" require "models/project" -- cgit v1.2.3 From 56de573131cce08079c30d7631395726104eea1b Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 16 Jul 2017 11:39:09 +0900 Subject: Reset column information after schema changed This fixes the following failures. https://travis-ci.org/rails/rails/jobs/253990014 --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 8bf2ecf88d..7e4ded9fc9 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -217,6 +217,8 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase remove_column :admin_users, :region_id if column_exists?(:admin_users, :region_id) drop_table :admin_regions, if_exists: true end + + Admin::User.reset_column_information end def test_natural_assignment -- cgit v1.2.3 From 36b7f3ae5bce6443a1928ec7194ff611eb2232b5 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 25 Jul 2017 03:25:23 +0900 Subject: Fix `warning: assigned but unused variable - comment` ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/associations/belongs_to_associations_test.rb -n test_multiple_counter_cache_with_after_create_update test/cases/associations/belongs_to_associations_test.rb:1181: warning: assigned but unused variable - comment Using sqlite3 Run options: -n test_multiple_counter_cache_with_after_create_update --seed 49644 . Finished in 0.114266s, 8.7515 runs/s, 17.5030 assertions/s. 1 runs, 2 assertions, 0 failures, 0 errors, 0 skips ``` --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 4f9d5ee3fa..0f7a249bf3 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1178,7 +1178,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_difference "parent.reload.children_count", +1 do assert_difference "post.reload.comments_count", +1 do - comment = CommentWithAfterCreateUpdate.create(body: "foo", post: post, parent: parent) + CommentWithAfterCreateUpdate.create(body: "foo", post: post, parent: parent) end end end -- cgit v1.2.3