Move load_schema from Object to AR::TestCase

as its instance and class mathod
This commit is contained in:
Akira Matsuda 2023-01-01 18:01:50 +09:00
parent 946bc94e82
commit b378293c0d
No known key found for this signature in database
3 changed files with 27 additions and 21 deletions

View File

@ -27,27 +27,6 @@ QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name("type")
ActiveRecord.raise_on_assign_to_attr_readonly = true
ActiveRecord.belongs_to_required_validates_foreign_key = false
def load_schema
# silence verbose schema loading
original_stdout = $stdout
$stdout = StringIO.new
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
load SCHEMA_ROOT + "/schema.rb"
if File.exist?(adapter_specific_schema_file)
load adapter_specific_schema_file
end
ActiveRecord::FixtureSet.reset_cache
ensure
$stdout = original_stdout
end
load_schema
class SQLSubscriber
attr_reader :logged
attr_reader :payloads

View File

@ -11,6 +11,7 @@ require "cases/validations_repair_helper"
require_relative "../support/config"
require_relative "../support/connection"
require_relative "../support/adapter_helper"
require_relative "../support/load_schema_helper"
module ActiveRecord
# = Active Record Test Case
@ -23,6 +24,8 @@ module ActiveRecord
include ActiveRecord::ValidationsRepairHelper
include AdapterHelper
extend AdapterHelper
include LoadSchemaHelper
extend LoadSchemaHelper
self.fixture_path = FIXTURES_ROOT
self.use_instantiated_fixtures = false
@ -225,6 +228,8 @@ module ActiveRecord
# Connect to the database
ARTest.connect
# Load database schema
load_schema
end
class PostgreSQLTestCase < TestCase

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
module LoadSchemaHelper
def load_schema
# silence verbose schema loading
original_stdout = $stdout
$stdout = StringIO.new
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
load SCHEMA_ROOT + "/schema.rb"
if File.exist?(adapter_specific_schema_file)
load adapter_specific_schema_file
end
ActiveRecord::FixtureSet.reset_cache
ensure
$stdout = original_stdout
end
end