Don't reuse the same connection to drop the tables

The test can disconnect the connection so we can't reuse.
This commit is contained in:
Rafael Mendonça França 2021-06-17 01:00:59 +00:00
parent 115d4a3994
commit a34eb120f1
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
4 changed files with 20 additions and 20 deletions

@ -15,10 +15,10 @@ class Sample < ActiveRecord::Base
@abort, Thread.abort_on_exception = Thread.abort_on_exception, false @abort, Thread.abort_on_exception = Thread.abort_on_exception, false
Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception
@connection = ActiveRecord::Base.connection connection = ActiveRecord::Base.connection
@connection.clear_cache! connection.clear_cache!
@connection.create_table("samples", force: true) do |t| connection.create_table("samples", force: true) do |t|
t.integer "value" t.integer "value"
end end
@ -27,7 +27,7 @@ class Sample < ActiveRecord::Base
teardown do teardown do
ActiveRecord::Base.clear_active_connections! ActiveRecord::Base.clear_active_connections!
@connection.drop_table "samples", if_exists: true ActiveRecord::Base.connection.drop_table "samples", if_exists: true
Thread.abort_on_exception = @abort Thread.abort_on_exception = @abort
Thread.report_on_exception = @original_report_on_exception Thread.report_on_exception = @original_report_on_exception

@ -15,12 +15,12 @@ class Sample < ActiveRecord::Base
@abort, Thread.abort_on_exception = Thread.abort_on_exception, false @abort, Thread.abort_on_exception = Thread.abort_on_exception, false
Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception
@connection = ActiveRecord::Base.connection connection = ActiveRecord::Base.connection
@connection.clear_cache! connection.clear_cache!
@connection.transaction do connection.transaction do
@connection.drop_table "samples", if_exists: true connection.drop_table "samples", if_exists: true
@connection.create_table("samples") do |t| connection.create_table("samples") do |t|
t.integer "value" t.integer "value"
end end
end end
@ -29,7 +29,7 @@ class Sample < ActiveRecord::Base
end end
teardown do teardown do
@connection.drop_table "samples", if_exists: true ActiveRecord::Base.connection.drop_table "samples", if_exists: true
Thread.abort_on_exception = @abort Thread.abort_on_exception = @abort
Thread.report_on_exception = @original_report_on_exception Thread.report_on_exception = @original_report_on_exception

@ -16,11 +16,11 @@ class Sample < ActiveRecord::Base
@abort, Thread.abort_on_exception = Thread.abort_on_exception, false @abort, Thread.abort_on_exception = Thread.abort_on_exception, false
Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception
@connection = ActiveRecord::Base.connection connection = ActiveRecord::Base.connection
@connection.transaction do connection.transaction do
@connection.drop_table "samples", if_exists: true connection.drop_table "samples", if_exists: true
@connection.create_table("samples") do |t| connection.create_table("samples") do |t|
t.integer "value" t.integer "value"
end end
end end
@ -29,7 +29,7 @@ class Sample < ActiveRecord::Base
end end
teardown do teardown do
@connection.drop_table "samples", if_exists: true ActiveRecord::Base.connection.drop_table "samples", if_exists: true
Thread.abort_on_exception = @abort Thread.abort_on_exception = @abort
Thread.report_on_exception = @original_report_on_exception Thread.report_on_exception = @original_report_on_exception

@ -16,11 +16,11 @@ class Sample < ActiveRecord::Base
@abort, Thread.abort_on_exception = Thread.abort_on_exception, false @abort, Thread.abort_on_exception = Thread.abort_on_exception, false
Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception
@connection = ActiveRecord::Base.connection connection = ActiveRecord::Base.connection
@connection.transaction do connection.transaction do
@connection.drop_table "samples", if_exists: true connection.drop_table "samples", if_exists: true
@connection.create_table("samples") do |t| connection.create_table("samples") do |t|
t.integer "value" t.integer "value"
end end
end end
@ -29,7 +29,7 @@ class Sample < ActiveRecord::Base
end end
teardown do teardown do
@connection.drop_table "samples", if_exists: true ActiveRecord::Base.connection.drop_table "samples", if_exists: true
Thread.abort_on_exception = @abort Thread.abort_on_exception = @abort
Thread.report_on_exception = @original_report_on_exception Thread.report_on_exception = @original_report_on_exception