Skip to content

Commit 90e9179

Browse files
committed
refactor(test): ensure tables are always unlogged
1 parent 2394a2f commit 90e9179

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

test/cases/create_unlogged_tables_test.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
module ActiveRecord
1212
module CockroachDB
1313
class UnloggedTablesTest < ActiveRecord::PostgreSQLTestCase
14-
include SchemaDumpingHelper
1514

1615
TABLE_NAME = "things"
1716
LOGGED_FIELD = "relpersistence"
@@ -24,24 +23,18 @@ class Thing < ActiveRecord::Base
2423
self.table_name = TABLE_NAME
2524
end
2625

27-
def setup
28-
@connection = ActiveRecord::Base.lease_connection
29-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = false
30-
end
31-
32-
teardown do
33-
@connection.drop_table TABLE_NAME, if_exists: true
34-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = false
35-
end
36-
3726
# Cockroachdb ignores the UNLOGGED specifier.
3827
# https://github.com/cockroachdb/cockroach/issues/56827
3928
def test_unlogged_in_test_environment_when_unlogged_setting_enabled
29+
@original_create_unlogged_tables = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables
4030
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
31+
connection = ActiveRecord::Base.lease_connection
4132

42-
@connection.create_table(TABLE_NAME) do |t|
33+
connection.create_table(TABLE_NAME) do |t|
4334
end
44-
assert_equal @connection.execute(LOGGED_QUERY).first[LOGGED_FIELD], LOGGED
35+
assert_equal connection.execute(LOGGED_QUERY).first[LOGGED_FIELD], LOGGED
36+
ensure
37+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = @original_create_unlogged_tables
4538
end
4639
end
4740
end

0 commit comments

Comments
 (0)