Skip to content

Commit 8a91f72

Browse files
committed
Use in_memory_db? test helper
1 parent 2f5dcb7 commit 8a91f72

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

activerecord/test/cases/migration/foreign_key_test.rb

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -554,37 +554,33 @@ def test_schema_dumping_with_defferable_initially_immediate
554554
end
555555
end
556556

557-
def test_does_not_create_foreign_keys_when_bypassed_by_config
558-
if current_adapter?(:SQLite3Adapter) && !ActiveRecord::Base.connection.supports_concurrent_connections?
559-
skip("Can't reopen in-memory database")
560-
else
561-
begin
562-
connection = ActiveRecord::Base.establish_connection(
563-
{
564-
adapter: "sqlite3",
565-
database: "test/db/test.sqlite3",
566-
foreign_keys: false,
567-
}
568-
).connection
569-
570-
connection.create_table "rockets", force: true do |t|
571-
t.string :name
572-
end
573-
connection.create_table "astronauts", force: true do |t|
574-
t.string :name
575-
t.references :rocket
576-
end
557+
unless in_memory_db?
558+
def test_does_not_create_foreign_keys_when_bypassed_by_config
559+
connection = ActiveRecord::Base.establish_connection(
560+
{
561+
adapter: "sqlite3",
562+
database: "test/db/test.sqlite3",
563+
foreign_keys: false,
564+
}
565+
).connection
566+
567+
connection.create_table "rockets", force: true do |t|
568+
t.string :name
569+
end
570+
connection.create_table "astronauts", force: true do |t|
571+
t.string :name
572+
t.references :rocket
573+
end
577574

578-
connection.add_foreign_key :astronauts, :rockets
575+
connection.add_foreign_key :astronauts, :rockets
579576

580-
foreign_keys = connection.foreign_keys("astronauts")
581-
assert_equal 0, foreign_keys.size
582-
ensure
583-
connection.drop_table "astronauts", if_exists: true rescue nil
584-
connection.drop_table "rockets", if_exists: true rescue nil
577+
foreign_keys = connection.foreign_keys("astronauts")
578+
assert_equal 0, foreign_keys.size
579+
ensure
580+
connection.drop_table "astronauts", if_exists: true rescue nil
581+
connection.drop_table "rockets", if_exists: true rescue nil
585582

586-
ActiveRecord::Base.establish_connection(:arunit)
587-
end
583+
ActiveRecord::Base.establish_connection(:arunit)
588584
end
589585
end
590586

activerecord/test/cases/schema_dumper_test.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,8 @@ def test_do_not_dump_foreign_keys_for_ignored_tables
417417
assert_equal ["authors"], output.scan(/^\s*add_foreign_key "([^"]+)".+$/).flatten
418418
end
419419

420-
def test_do_not_dump_foreign_keys_when_bypassed_by_config
421-
if current_adapter?(:SQLite3Adapter) && !ActiveRecord::Base.connection.supports_concurrent_connections?
422-
skip("Can't reopen in-memory database")
423-
end
424-
425-
begin
420+
unless in_memory_db?
421+
def test_do_not_dump_foreign_keys_when_bypassed_by_config
426422
ActiveRecord::Base.establish_connection(
427423
{
428424
adapter: "sqlite3",

0 commit comments

Comments
 (0)