Skip to content

Commit bcb56a7

Browse files
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`.
1 parent 45d2e7a commit bcb56a7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

activerecord/test/cases/primary_keys_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,24 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase
287287
def setup
288288
@connection = ActiveRecord::Base.connection
289289
@connection.schema_cache.clear!
290-
@connection.create_table(:barcodes, primary_key: ["region", "code"], force: true) do |t|
290+
@connection.create_table(:uber_barcodes, primary_key: ["region", "code"], force: true) do |t|
291291
t.string :region
292292
t.integer :code
293293
end
294294
end
295295

296296
def teardown
297-
@connection.drop_table(:barcodes, if_exists: true)
297+
@connection.drop_table(:uber_barcodes, if_exists: true)
298298
end
299299

300300
def test_composite_primary_key
301-
assert_equal ["region", "code"], @connection.primary_keys("barcodes")
301+
assert_equal ["region", "code"], @connection.primary_keys("uber_barcodes")
302302
end
303303

304304
def test_primary_key_issues_warning
305305
model = Class.new(ActiveRecord::Base) do
306306
def self.table_name
307-
"barcodes"
307+
"uber_barcodes"
308308
end
309309
end
310310
warning = capture(:stderr) do
@@ -314,8 +314,8 @@ def self.table_name
314314
end
315315

316316
def test_collectly_dump_composite_primary_key
317-
schema = dump_table_schema "barcodes"
318-
assert_match %r{create_table "barcodes", primary_key: \["region", "code"\]}, schema
317+
schema = dump_table_schema "uber_barcodes"
318+
assert_match %r{create_table "uber_barcodes", primary_key: \["region", "code"\]}, schema
319319
end
320320
end
321321

0 commit comments

Comments
 (0)