Skip to content

Commit b378293

Browse files
committed
Move load_schema from Object to AR::TestCase
as its instance and class mathod
1 parent 946bc94 commit b378293

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

activerecord/test/cases/helper.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@
2727
ActiveRecord.raise_on_assign_to_attr_readonly = true
2828
ActiveRecord.belongs_to_required_validates_foreign_key = false
2929

30-
def load_schema
31-
# silence verbose schema loading
32-
original_stdout = $stdout
33-
$stdout = StringIO.new
34-
35-
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
36-
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
37-
38-
load SCHEMA_ROOT + "/schema.rb"
39-
40-
if File.exist?(adapter_specific_schema_file)
41-
load adapter_specific_schema_file
42-
end
43-
44-
ActiveRecord::FixtureSet.reset_cache
45-
ensure
46-
$stdout = original_stdout
47-
end
48-
49-
load_schema
50-
5130
class SQLSubscriber
5231
attr_reader :logged
5332
attr_reader :payloads

activerecord/test/cases/test_case.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_relative "../support/config"
1212
require_relative "../support/connection"
1313
require_relative "../support/adapter_helper"
14+
require_relative "../support/load_schema_helper"
1415

1516
module ActiveRecord
1617
# = Active Record Test Case
@@ -23,6 +24,8 @@ class TestCase < ActiveSupport::TestCase # :nodoc:
2324
include ActiveRecord::ValidationsRepairHelper
2425
include AdapterHelper
2526
extend AdapterHelper
27+
include LoadSchemaHelper
28+
extend LoadSchemaHelper
2629

2730
self.fixture_path = FIXTURES_ROOT
2831
self.use_instantiated_fixtures = false
@@ -225,6 +228,8 @@ def clean_up_connection_handler
225228

226229
# Connect to the database
227230
ARTest.connect
231+
# Load database schema
232+
load_schema
228233
end
229234

230235
class PostgreSQLTestCase < TestCase
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module LoadSchemaHelper
4+
def load_schema
5+
# silence verbose schema loading
6+
original_stdout = $stdout
7+
$stdout = StringIO.new
8+
9+
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
10+
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
11+
12+
load SCHEMA_ROOT + "/schema.rb"
13+
14+
if File.exist?(adapter_specific_schema_file)
15+
load adapter_specific_schema_file
16+
end
17+
18+
ActiveRecord::FixtureSet.reset_cache
19+
ensure
20+
$stdout = original_stdout
21+
end
22+
end

0 commit comments

Comments
 (0)