Skip to content

Commit

Permalink
refactor(test): ensure tables are always unlogged
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Jan 10, 2025
1 parent 2394a2f commit 90e9179
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions test/cases/create_unlogged_tables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
module ActiveRecord
module CockroachDB
class UnloggedTablesTest < ActiveRecord::PostgreSQLTestCase
include SchemaDumpingHelper

TABLE_NAME = "things"
LOGGED_FIELD = "relpersistence"
Expand All @@ -24,24 +23,18 @@ class Thing < ActiveRecord::Base
self.table_name = TABLE_NAME
end

def setup
@connection = ActiveRecord::Base.lease_connection
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = false
end

teardown do
@connection.drop_table TABLE_NAME, if_exists: true
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = false
end

# Cockroachdb ignores the UNLOGGED specifier.
# https://github.com/cockroachdb/cockroach/issues/56827
def test_unlogged_in_test_environment_when_unlogged_setting_enabled
@original_create_unlogged_tables = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
connection = ActiveRecord::Base.lease_connection

@connection.create_table(TABLE_NAME) do |t|
connection.create_table(TABLE_NAME) do |t|
end
assert_equal @connection.execute(LOGGED_QUERY).first[LOGGED_FIELD], LOGGED
assert_equal connection.execute(LOGGED_QUERY).first[LOGGED_FIELD], LOGGED
ensure
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = @original_create_unlogged_tables
end
end
end
Expand Down

0 comments on commit 90e9179

Please sign in to comment.