From 16ef8482699f3c23eb7c01123779484bdbfa2fa0 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 12 Jul 2016 22:45:58 +0530 Subject: Don't add specific id's to the readers fixtures - This causes failures in the `test_create_resets_cached_counters` from the has_many_associations tests because sometimes a Post record gets created with id as 1 so the readers records get associated with it and `person.readers` returns these 2 records instead of empty array. - Better to just remove the ids. --- activerecord/test/fixtures/readers.yml | 2 -- 1 file changed, 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/fixtures/readers.yml b/activerecord/test/fixtures/readers.yml index 14b883f041..d8df05f7fc 100644 --- a/activerecord/test/fixtures/readers.yml +++ b/activerecord/test/fixtures/readers.yml @@ -1,11 +1,9 @@ michael_welcome: - id: 1 post_id: 1 person_id: 1 first_post_id: 2 michael_authorless: - id: 2 post_id: 3 person_id: 1 first_post_id: 3 -- cgit v1.2.3 From e59d1354e8c2983aba64dbf3dd83f03d3845ceb9 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 12 Jul 2016 23:21:50 +0530 Subject: Fix random test failure of test_create_resets_cached_counters - In earlier commit, I removed setting id manually for readers fixtures but that did not fix the randomly failing test_create_resets_cached_counters from has_many_associations tests. - Because the problem was with the `person_id` of the readers. As it is set to 1 in fixtures, if a post gets created with id 1 then that post automatically has 2 readers. - Fixed by removing the person_id. --- activerecord/test/fixtures/readers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/fixtures/readers.yml b/activerecord/test/fixtures/readers.yml index d8df05f7fc..af5f888e4b 100644 --- a/activerecord/test/fixtures/readers.yml +++ b/activerecord/test/fixtures/readers.yml @@ -1,9 +1,9 @@ michael_welcome: post_id: 1 - person_id: 1 + person: michael first_post_id: 2 michael_authorless: post_id: 3 - person_id: 1 + person: michael first_post_id: 3 -- cgit v1.2.3 From 8d791b0370a0285fe6ef5346c12e5fd9444b02dc Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 16 Jul 2016 11:32:05 +0530 Subject: Fix the random failure of `test_create_resets_cached_counters` - Tried specifying `id` for the `readers` records but it is interconnected with so many tests that many random tests started failing. - So switched to the approach of deleting all readers in the `create_resets_cached_counters` test. --- activerecord/test/cases/associations/has_many_associations_test.rb | 3 +++ activerecord/test/fixtures/readers.yml | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 1eb10c1dbe..6ba738ed6c 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -456,7 +456,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_create_resets_cached_counters + Reader.delete_all + person = Person.create!(first_name: "tenderlove") + post = Post.first assert_equal [], person.readers diff --git a/activerecord/test/fixtures/readers.yml b/activerecord/test/fixtures/readers.yml index af5f888e4b..14b883f041 100644 --- a/activerecord/test/fixtures/readers.yml +++ b/activerecord/test/fixtures/readers.yml @@ -1,9 +1,11 @@ michael_welcome: + id: 1 post_id: 1 - person: michael + person_id: 1 first_post_id: 2 michael_authorless: + id: 2 post_id: 3 - person: michael + person_id: 1 first_post_id: 3 -- cgit v1.2.3 From f67ddb0ffebb6e3e2bb88536c27975a4cc92de55 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 17 Jul 2016 15:46:59 +0530 Subject: Fix one more test randomly failing due to array ordering issue on PG adapter Reproduction command - ARCONN=postgresql be ruby -w -Itest test/cases/autosave_association_test.rb --seed 34101 --- activerecord/test/cases/autosave_association_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 2203aa1788..f72a9520e0 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -1370,7 +1370,7 @@ module AutosaveAssociationOnACollectionAssociationTests @pirate.send(@association_name).each_with_index { |child, i| child.name = new_names[i] } @pirate.save - assert_equal new_names, @pirate.reload.send(@association_name).map(&:name) + assert_equal new_names.sort, @pirate.reload.send(@association_name).map(&:name).sort end def test_should_automatically_save_bang_the_associated_models @@ -1378,7 +1378,7 @@ module AutosaveAssociationOnACollectionAssociationTests @pirate.send(@association_name).each_with_index { |child, i| child.name = new_names[i] } @pirate.save! - assert_equal new_names, @pirate.reload.send(@association_name).map(&:name) + assert_equal new_names.sort, @pirate.reload.send(@association_name).map(&:name).sort end def test_should_update_children_when_autosave_is_true_and_parent_is_new_but_child_is_not -- cgit v1.2.3 From ebeae19917bfed29f0ce7efa013ae950d22953f3 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 21 Aug 2016 19:55:32 +0530 Subject: Don't use same table between primary_keys tests and composite_primary_keys tests - The test `PrimaryKeyAnyTypeTest#test_any_type_primary_key` was failing if ran after running all tests from `CompositePrimaryKeyTest`. - This was happening because `CompositePrimaryKeyTest` was changing the primary key of the barcodes table which was cached in schema cache. - As we were always going to drop the `barcodes` table at the end of tests in both `PrimaryKeyTest` and `CompositePrimaryKeyTest`, solved this issue by using different table name for tests in `CompositePrimaryKeyTest`. --- activerecord/test/cases/primary_keys_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 5ded619716..80cbfdba06 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -311,7 +311,7 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase def setup @connection = ActiveRecord::Base.connection @connection.schema_cache.clear! - @connection.create_table(:barcodes, primary_key: ["region", "code"], force: true) do |t| + @connection.create_table(:uber_barcodes, primary_key: ["region", "code"], force: true) do |t| t.string :region t.integer :code end @@ -322,11 +322,11 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase end def teardown - @connection.drop_table(:barcodes, if_exists: true) + @connection.drop_table(:uber_barcodes, if_exists: true) end def test_composite_primary_key - assert_equal ["region", "code"], @connection.primary_keys("barcodes") + assert_equal ["region", "code"], @connection.primary_keys("uber_barcodes") end def test_composite_primary_key_out_of_order @@ -337,7 +337,7 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase def test_primary_key_issues_warning model = Class.new(ActiveRecord::Base) do def self.table_name - "barcodes" + "uber_barcodes" end end warning = capture(:stderr) do @@ -346,9 +346,9 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase assert_match(/WARNING: Active Record does not support composite primary key\./, warning) end - def test_dumping_composite_primary_key - schema = dump_table_schema "barcodes" - assert_match %r{create_table "barcodes", primary_key: \["region", "code"\]}, schema + def test_collectly_dump_composite_primary_key + schema = dump_table_schema "uber_barcodes" + assert_match %r{create_table "uber_barcodes", primary_key: \["region", "code"\]}, schema end def test_dumping_composite_primary_key_out_of_order -- cgit v1.2.3 From b4b3b14bd086051fc036af2e9aa4755e4c2931c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 26 Apr 2017 23:58:48 -0700 Subject: Only clean the connection of the current connection pool This will avoid us to close the connection of the saved connection pool. --- activerecord/test/cases/query_cache_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 494663eb04..17b5304cc4 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -130,7 +130,7 @@ class QueryCacheTest < ActiveRecord::TestCase assert_cache :off, conn end ensure - ActiveRecord::Base.clear_all_connections! + ActiveRecord::Base.connection_pool.disconnect! end end end -- cgit v1.2.3 From ee9e08679ab1dc60852236741f73ff82b6d96302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 27 Apr 2017 01:10:04 -0700 Subject: Run ReloadModelTest in a different proccess This will make sure it doesn't change the state of the current proccess when removing the owners constant. --- activerecord/test/cases/reload_models_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/reload_models_test.rb b/activerecord/test/cases/reload_models_test.rb index 5dc9d6d8b7..dffb55ba81 100644 --- a/activerecord/test/cases/reload_models_test.rb +++ b/activerecord/test/cases/reload_models_test.rb @@ -3,6 +3,8 @@ require "models/owner" require "models/pet" class ReloadModelsTest < ActiveRecord::TestCase + include ActiveSupport::Testing::Isolation + fixtures :pets, :owners def test_has_one_with_reload @@ -19,4 +21,4 @@ class ReloadModelsTest < ActiveRecord::TestCase pet.owner = Owner.find_by_name("ashley") assert_equal pet.owner, Owner.find_by_name("ashley") end -end +end unless in_memory_db? -- cgit v1.2.3 From 21e0b675c3cef207c8c4c79a8b580c2d6c138cfa Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 13 May 2017 15:59:06 +0900 Subject: Explicitly create necessary data for test `DefaultScopingWithThreadTest` expects that there are two or more of `developers` data, but have not created data in the test. Therefore, tests may fail depending on execution order. --- activerecord/test/cases/scoping/default_scoping_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 89fb434b27..6f1010d701 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -486,6 +486,8 @@ class DefaultScopingWithThreadTest < ActiveRecord::TestCase end def test_default_scope_is_threadsafe + 2.times { ThreadsafeDeveloper.unscoped.create! } + threads = [] assert_not_equal 1, ThreadsafeDeveloper.unscoped.count @@ -504,5 +506,7 @@ class DefaultScopingWithThreadTest < ActiveRecord::TestCase ThreadsafeDeveloper.connection.close end threads.each(&:join) + ensure + ThreadsafeDeveloper.unscoped.destroy_all end end unless in_memory_db? -- cgit v1.2.3 From e5913a1aa3cc909d1044f212ae61a0344060de76 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 31 May 2017 09:06:46 +0900 Subject: Make sure to disable extension after test If keep the extension, can not test properly to make sure that extension can be enabled. --- activerecord/test/cases/adapters/postgresql/hstore_test.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb index f9cce10fb8..4d650bd431 100644 --- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb +++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb @@ -19,12 +19,7 @@ if ActiveRecord::Base.connection.supports_extensions? def setup @connection = ActiveRecord::Base.connection - unless @connection.extension_enabled?("hstore") - @connection.enable_extension "hstore" - @connection.commit_db_transaction - end - - @connection.reconnect! + enable_extension!("hstore", @connection) @connection.transaction do @connection.create_table("hstores") do |t| @@ -40,6 +35,7 @@ if ActiveRecord::Base.connection.supports_extensions? teardown do @connection.drop_table "hstores", if_exists: true + disable_extension!("hstore", @connection) end def test_hstore_included_in_extensions -- cgit v1.2.3 From dcd3b940e9e163ff87cf3dfa7748a5f18220b58d Mon Sep 17 00:00:00 2001 From: Alex Kitchens Date: Tue, 30 May 2017 09:04:36 -0500 Subject: Reset primary key sequence in FixturesResetPkSequenceTests The primary key sequence for each test in FixturesResetPkSequenceTest is reset. The state in some of the FixturesResetPkSequenceTest tests are leaking, causing failurse in others. Using a seed of `48104`, the `FixturesResetPkSequenceTest#test_resets_to_min_pk_with_specified_pk_and_sequence` runs before the `DatabaseStatementsTest` tests, and the tests fail with duplicate primary key errors: ``` Run options: --seed 48104 -n "/^(?:FixturesResetPkSequenceTest#(?:test_resets_to_min_pk_with_specified_pk_and_sequence)|DatabaseStatementsTest#(?:test_create_should_return_the_inserted_id|test_exec_insert|test_insert_should_return_the_inserted_id))$/" .EEE 1) Error: DatabaseStatementsTest#test_exec_insert: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "accounts_pkey" DETAIL: Key (id)=(2) already exists. 2) Error: DatabaseStatementsTest#test_create_should_return_the_inserted_id: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "accounts_pkey" DETAIL: Key (id)=(3) already exists. 3) Error: DatabaseStatementsTest#test_insert_should_return_the_inserted_id: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "accounts_pkey" DETAIL: Key (id)=(4) already exists. ``` --- activerecord/test/cases/fixtures_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index a0a6d3c7ef..718bbfdb74 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -365,6 +365,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!) class FixturesResetPkSequenceTest < ActiveRecord::TestCase fixtures :accounts fixtures :companies + self.use_transactional_tests = false def setup @instances = [Account.new(credit_limit: 50), Company.new(name: "RoR Consulting"), Course.new(name: "Test")] -- cgit v1.2.3 From 23cd1a1b0ca1596dbe61cd81c85dd2bbfefb4c28 Mon Sep 17 00:00:00 2001 From: Alex Kitchens Date: Wed, 31 May 2017 11:12:58 -0500 Subject: Ensure fixtures are loaded for FoxyFixturesTest Ensure that the fixtures are properly loaded for FoxyFixturesTest When tests are randomized, FoxyFixturesTest often fails due to unloaded fixtures. --- activerecord/test/cases/fixtures_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index a0a6d3c7ef..c79a56f5ee 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -809,6 +809,8 @@ class FasterFixturesTest < ActiveRecord::TestCase end class FoxyFixturesTest < ActiveRecord::TestCase + # Set to false to blow away fixtures cache and ensure our fixtures are loaded + self.use_transactional_tests = false fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books -- cgit v1.2.3 From 550eadf436749c20fff2e7a2f9e82d703db7760e Mon Sep 17 00:00:00 2001 From: Alex Kitchens Date: Thu, 1 Jun 2017 17:03:59 -0500 Subject: Use existing class in PersistenceTest::SaveTest Creating a new class for widgets was causing failing tests because it clashed with other widget classes. This test does not need to create its own class, so I changed it to an existing class. ``` ARCONN=mysql2 bin/test --seed 25364 test/cases/*test.rb -n \ "/^(?:PrimaryKeyIntegerTest#(?:test_primary_key_with_serial_integer_are_automatically_numbered)|PersistenceTest::SaveTest#(?:test_save_touch_false))$/" ``` --- activerecord/test/cases/persistence_test.rb | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 5895c51714..e9df570176 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -993,33 +993,19 @@ class PersistenceTest < ActiveRecord::TestCase end class SaveTest < ActiveRecord::TestCase - self.use_transactional_tests = false - def test_save_touch_false - widget = Class.new(ActiveRecord::Base) do - connection.create_table :widgets, force: true do |t| - t.string :name - t.timestamps null: false - end - - self.table_name = :widgets - end - - instance = widget.create!( + pet = Pet.create!( name: "Bob", created_at: 1.day.ago, updated_at: 1.day.ago) - created_at = instance.created_at - updated_at = instance.updated_at + created_at = pet.created_at + updated_at = pet.updated_at - instance.name = "Barb" - instance.save!(touch: false) - assert_equal instance.created_at, created_at - assert_equal instance.updated_at, updated_at - ensure - ActiveRecord::Base.connection.drop_table widget.table_name - widget.reset_column_information + pet.name = "Barb" + pet.save!(touch: false) + assert_equal pet.created_at, created_at + assert_equal pet.updated_at, updated_at end end -- cgit v1.2.3 From db507c3fc06963b3a9c005b9057ef79ed8dd2d6f Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Fri, 2 Jun 2017 15:02:05 +0000 Subject: Clean up `type_map` at the end of test_respond_to_for_non_selected_element `test_only_reload_type_map_once_for_every_unknown_type` expects no one already registers unknown OID to `type_map`. However, `test_respond_to_for_non_selected_element` registers it and does not clean up it. Addresses #29331 at unlock-minitest branch --- activerecord/test/cases/relation_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 5fb32270b7..17198247a9 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -3,9 +3,12 @@ require "models/post" require "models/comment" require "models/author" require "models/rating" +require "support/connection_helper" module ActiveRecord class RelationTest < ActiveRecord::TestCase + include ConnectionHelper + fixtures :posts, :comments, :authors, :author_addresses FakeKlass = Struct.new(:table_name, :name) do @@ -250,6 +253,8 @@ module ActiveRecord silence_warnings { post = Post.select("'title' as post_title").first } assert_equal false, post.respond_to?(:title), "post should not respond_to?(:body) since invoking it raises exception" + ensure + reset_connection end def test_select_quotes_when_using_from_clause -- cgit v1.2.3 From 50c4bd9ff60cb135b30a8bba2ba9b80f158bb0ef Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sat, 3 Jun 2017 16:28:54 +0930 Subject: Reset the fixture cache after (re)loading the schema --- activerecord/test/cases/helper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 5a3b8e3fb5..8506a44d6a 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -141,6 +141,8 @@ def load_schema if File.exist?(adapter_specific_schema_file) load adapter_specific_schema_file end + + ActiveRecord::FixtureSet.reset_cache ensure $stdout = original_stdout end -- cgit v1.2.3 From cd64345812567cf67fc7cca740ffc211b272e9f1 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 3 Jun 2017 14:00:25 +0900 Subject: Explicitly clear type map before run `test_only_reload_type_map_once_for_every_unknown_type` Currently, the following test fails. ``` bin/test -a sqlite3_mem --seed 37473 test/cases/relation_test.rb ``` This is due to reset connection in `test_respond_to_for_non_selected_element` postprocessing. This reset is added with #29332 for `test_only_reload_type_map_once_for_every_unknown_type`. Since the above test expects the type map to be empty at the time of test run, I think that it is better to empty the type map before test run. --- .../adapters/postgresql/postgresql_adapter_test.rb | 18 ++++++++++++------ activerecord/test/cases/relation_test.rb | 4 ---- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index bfc763e1ef..b55b766d20 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -325,15 +325,18 @@ module ActiveRecord end def test_only_reload_type_map_once_for_every_unknown_type + reset_connection + connection = ActiveRecord::Base.connection + silence_warnings do assert_queries 2, ignore_none: true do - @connection.select_all "SELECT NULL::anyelement" + connection.select_all "SELECT NULL::anyelement" end assert_queries 1, ignore_none: true do - @connection.select_all "SELECT NULL::anyelement" + connection.select_all "SELECT NULL::anyelement" end assert_queries 2, ignore_none: true do - @connection.select_all "SELECT NULL::anyarray" + connection.select_all "SELECT NULL::anyarray" end end ensure @@ -341,10 +344,13 @@ module ActiveRecord end def test_only_warn_on_first_encounter_of_unknown_oid + reset_connection + connection = ActiveRecord::Base.connection + warning = capture(:stderr) { - @connection.select_all "SELECT NULL::anyelement" - @connection.select_all "SELECT NULL::anyelement" - @connection.select_all "SELECT NULL::anyelement" + connection.select_all "SELECT NULL::anyelement" + connection.select_all "SELECT NULL::anyelement" + connection.select_all "SELECT NULL::anyelement" } assert_match(/\Aunknown OID \d+: failed to recognize type of 'anyelement'\. It will be treated as String\.\n\z/, warning) ensure diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 17198247a9..e31e21e765 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -3,11 +3,9 @@ require "models/post" require "models/comment" require "models/author" require "models/rating" -require "support/connection_helper" module ActiveRecord class RelationTest < ActiveRecord::TestCase - include ConnectionHelper fixtures :posts, :comments, :authors, :author_addresses @@ -253,8 +251,6 @@ module ActiveRecord silence_warnings { post = Post.select("'title' as post_title").first } assert_equal false, post.respond_to?(:title), "post should not respond_to?(:body) since invoking it raises exception" - ensure - reset_connection end def test_select_quotes_when_using_from_clause -- cgit v1.2.3 From c40502f9f063baf7fb07ea4203b0b277fddd95a1 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 6 Jun 2017 07:24:22 +0900 Subject: Load schema before assertion Without this, test fails because the load schema when pluck is executed. Steps to reproduce: ``` bin/test -a postgresql -w --seed 61689 test/cases/*test.rb -n "/^(?:InheritanceComputeTypeTest#(?:test_inheritance_new_with_subclass_as_default)|CalculationsTest#(?:test_pluck_loaded_relation))$/" # Running: .F Failure: CalculationsTest#test_pluck_loaded_relation [/home/yaginuma/program/rails/master_y_yagi/rails/activerecord/test/cases/calculations_test.rb:722]: 1 instead of 0 queries were executed. Queries: SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relname = 'companies' AND c.relkind IN ('r','v','m'). Expected: 0 Actual: 1 bin/test test/cases/calculations_test.rb:7 ``` --- activerecord/test/cases/calculations_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 21c5c0efee..adfca08289 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -718,21 +718,27 @@ class CalculationsTest < ActiveRecord::TestCase end def test_pluck_loaded_relation + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:id).limit(3).load + assert_no_queries do assert_equal ["37signals", "Summit", "Microsoft"], companies.pluck(:name) end end def test_pluck_loaded_relation_multiple_columns + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:id).limit(3).load + assert_no_queries do assert_equal [[1, "37signals"], [2, "Summit"], [3, "Microsoft"]], companies.pluck(:id, :name) end end def test_pluck_loaded_relation_sql_fragment + Company.attribute_names # Load schema information so we don't query below companies = Company.order(:name).limit(3).load + assert_queries 1 do assert_equal ["37signals", "Apex", "Ex Nihilo"], companies.pluck("DISTINCT name") end -- cgit v1.2.3 From 5cd85941dcf02f8458d343ffdaaef83bd9bf654f Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Wed, 7 Jun 2017 12:21:55 +0000 Subject: Add teardown to reset_connection at MysqlTypeLookupTest to address `Mysql2BooleanTest#test_column_type_without_emulated_booleans` failure --- .../test/cases/connection_adapters/mysql_type_lookup_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb index 3657b8340d..736eb3e3a0 100644 --- a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb +++ b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb @@ -1,13 +1,20 @@ require "cases/helper" +require "support/connection_helper" if current_adapter?(:Mysql2Adapter) module ActiveRecord module ConnectionAdapters class MysqlTypeLookupTest < ActiveRecord::TestCase + include ConnectionHelper + setup do @connection = ActiveRecord::Base.connection end + def teardown + reset_connection + end + def test_boolean_types emulate_booleans(true) do assert_lookup_type :boolean, "tinyint(1)" -- cgit v1.2.3 From cac0c7924db46474b0554f8da5b196d4fd9d9ed6 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 7 Jun 2017 10:56:14 +0900 Subject: Insert environment value to `InternalMetadata` after recreating the table Sometimes `ActiveRecord::DatabaseTasksUtilsTask#test_raises_an_error_when_called_with_protected_environment` test fails. https://travis-ci.org/rails/rails/jobs/238861562 https://travis-ci.org/rails/rails/jobs/239950092 There seems to be an error because `environment` value is not exist. This is because did not set the environment after recreating the table in `SchemaMigrationsTest#test_initializes_internal_metadata_for_encoding_utf8mb4`. Therefore, we create value after the test to maintain the original state. --- activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb b/activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb index 251a50e41e..e7459546e4 100644 --- a/activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb +++ b/activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb @@ -1,6 +1,8 @@ require "cases/helper" class SchemaMigrationsTest < ActiveRecord::Mysql2TestCase + self.use_transactional_tests = false + def test_renaming_index_on_foreign_key connection.add_index "engines", "car_id" connection.add_foreign_key :engines, :cars, name: "fk_engines_cars" @@ -31,6 +33,8 @@ class SchemaMigrationsTest < ActiveRecord::Mysql2TestCase assert connection.column_exists?(table_name, :key, :string) end + ensure + ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment end private -- cgit v1.2.3 From ca63f6d1cc8854d3e113ffb94c1fcebeeb7f472e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sat, 15 Jul 2017 21:20:01 +0200 Subject: Stupid empty line added after merge. --- activerecord/test/cases/relation_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index e4f68eef1b..a403824f1a 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -6,7 +6,6 @@ require "models/rating" module ActiveRecord class RelationTest < ActiveRecord::TestCase - fixtures :posts, :comments, :authors, :author_addresses, :ratings FakeKlass = Struct.new(:table_name, :name) do -- cgit v1.2.3 From ad22c38d77ad3ea62aee04f822e8a5e571c5d4e3 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') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index a727cc6e60..61389e29cf 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -215,6 +215,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 1701709e7f87520a07eed87dec1570be13584f72 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 17 Jul 2017 15:06:38 +0900 Subject: Move `reset_pk_sequence!` test to `AdapterTestWithoutTransaction` If execute PostgreSQL test with specifying 53853 for seed, the following error will occur. ``` 1) Error: TransactionTest#test_restore_custom_primary_key_after_rollback: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "movies_pkey" DETAIL: Key (movieid)=(2) already exists. : INSERT INTO "movies" ("name") VALUES ($1) RETURNING "movieid" ``` travis is here https://travis-ci.org/rails/rails/jobs/254095918 As with #29287, it seems like a problem that the value of primary key obtained from connection gets different. Therefore, fixed to execute that test within transaction. --- activerecord/test/cases/adapter_test.rb | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 827bcba121..eccd250d19 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -156,26 +156,6 @@ module ActiveRecord end end - # test resetting sequences in odd tables in PostgreSQL - if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) - require "models/movie" - require "models/subscriber" - - def test_reset_empty_table_with_custom_pk - Movie.delete_all - Movie.connection.reset_pk_sequence! "movies" - assert_equal 1, Movie.create(name: "fight club").id - end - - def test_reset_table_with_non_integer_pk - Subscriber.delete_all - Subscriber.connection.reset_pk_sequence! "subscribers" - sub = Subscriber.new(name: "robert drake") - sub.id = "bob drake" - assert_nothing_raised { sub.save! } - end - end - def test_uniqueness_violations_are_translated_to_specific_exception @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" error = assert_raises(ActiveRecord::RecordNotUnique) do @@ -368,5 +348,25 @@ module ActiveRecord assert !@connection.transaction_open? end end + + # test resetting sequences in odd tables in PostgreSQL + if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) + require "models/movie" + require "models/subscriber" + + def test_reset_empty_table_with_custom_pk + Movie.delete_all + Movie.connection.reset_pk_sequence! "movies" + assert_equal 1, Movie.create(name: "fight club").id + end + + def test_reset_table_with_non_integer_pk + Subscriber.delete_all + Subscriber.connection.reset_pk_sequence! "subscribers" + sub = Subscriber.new(name: "robert drake") + sub.id = "bob drake" + assert_nothing_raised { sub.save! } + end + end end end -- cgit v1.2.3