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/cases/primary_keys_test.rb') 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