1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Convert many ActiveRecord::Base class variable into instance variables

Followup: https://github.com/rails/rails/pull/42442
This commit is contained in:
Jean Boussier 2021-06-10 16:34:28 +02:00
parent e65042707e
commit bcd6c0f3d0
15 changed files with 101 additions and 95 deletions

View file

@ -204,6 +204,57 @@ module ActiveRecord
singleton_class.attr_accessor :action_on_strict_loading_violation singleton_class.attr_accessor :action_on_strict_loading_violation
self.action_on_strict_loading_violation = :raise self.action_on_strict_loading_violation = :raise
##
# :singleton-method:
# Specifies the format to use when dumping the database schema with Rails'
# Rakefile. If :sql, the schema is dumped as (potentially database-
# specific) SQL statements. If :ruby, the schema is dumped as an
# ActiveRecord::Schema file which can be loaded into any database that
# supports migrations. Use :ruby if you want to have different database
# adapters for, e.g., your development and test environments.
singleton_class.attr_accessor :schema_format
self.schema_format = :ruby
##
# :singleton-method:
# Specifies if an error should be raised if the query has an order being
# ignored when doing batch queries. Useful in applications where the
# scope being ignored is error-worthy, rather than a warning.
singleton_class.attr_accessor :error_on_ignored_order
self.error_on_ignored_order = false
##
# :singleton-method:
# Specify whether or not to use timestamps for migration versions
singleton_class.attr_accessor :timestamped_migrations
self.timestamped_migrations = true
##
# :singleton-method:
# Specify whether schema dump should happen at the end of the
# bin/rails db:migrate command. This is true by default, which is useful for the
# development environment. This should ideally be false in the production
# environment where dumping schema is rarely needed.
singleton_class.attr_accessor :dump_schema_after_migration
self.dump_schema_after_migration = true
##
# :singleton-method:
# Specifies which database schemas to dump when calling db:schema:dump.
# If the value is :schema_search_path (the default), any schemas listed in
# schema_search_path are dumped. Use :all to dump all schemas regardless
# of schema_search_path, or a string of comma separated schemas for a
# custom list.
singleton_class.attr_accessor :dump_schemas
self.dump_schemas = :schema_search_path
##
# :singleton-method:
# Show a warning when Rails couldn't parse your database.yml
# for multiple databases.
singleton_class.attr_accessor :suppress_multiple_database_warning
self.suppress_multiple_database_warning = false
def self.eager_load! def self.eager_load!
super super
ActiveRecord::Locking.eager_load! ActiveRecord::Locking.eager_load!

View file

@ -70,51 +70,6 @@ module ActiveRecord
@@configurations @@configurations
end end
##
# :singleton-method:
# Specifies the format to use when dumping the database schema with Rails'
# Rakefile. If :sql, the schema is dumped as (potentially database-
# specific) SQL statements. If :ruby, the schema is dumped as an
# ActiveRecord::Schema file which can be loaded into any database that
# supports migrations. Use :ruby if you want to have different database
# adapters for, e.g., your development and test environments.
mattr_accessor :schema_format, instance_writer: false, default: :ruby
##
# :singleton-method:
# Specifies if an error should be raised if the query has an order being
# ignored when doing batch queries. Useful in applications where the
# scope being ignored is error-worthy, rather than a warning.
mattr_accessor :error_on_ignored_order, instance_writer: false, default: false
##
# :singleton-method:
# Specify whether or not to use timestamps for migration versions
mattr_accessor :timestamped_migrations, instance_writer: false, default: true
##
# :singleton-method:
# Specify whether schema dump should happen at the end of the
# bin/rails db:migrate command. This is true by default, which is useful for the
# development environment. This should ideally be false in the production
# environment where dumping schema is rarely needed.
mattr_accessor :dump_schema_after_migration, instance_writer: false, default: true
##
# :singleton-method:
# Specifies which database schemas to dump when calling db:schema:dump.
# If the value is :schema_search_path (the default), any schemas listed in
# schema_search_path are dumped. Use :all to dump all schemas regardless
# of schema_search_path, or a string of comma separated schemas for a
# custom list.
mattr_accessor :dump_schemas, instance_writer: false, default: :schema_search_path
##
# :singleton-method:
# Show a warning when Rails couldn't parse your database.yml
# for multiple databases.
mattr_accessor :suppress_multiple_database_warning, instance_writer: false, default: false
## ##
# :singleton-method: # :singleton-method:
# Force enumeration of all columns in SELECT statements. # Force enumeration of all columns in SELECT statements.

View file

@ -136,7 +136,7 @@ module ActiveRecord
action "Run pending migrations" do action "Run pending migrations" do
ActiveRecord::Tasks::DatabaseTasks.migrate ActiveRecord::Tasks::DatabaseTasks.migrate
if ActiveRecord::Base.dump_schema_after_migration if ActiveRecord.dump_schema_after_migration
ActiveRecord::Tasks::DatabaseTasks.dump_schema( ActiveRecord::Tasks::DatabaseTasks.dump_schema(
ActiveRecord::Base.connection_db_config ActiveRecord::Base.connection_db_config
) )
@ -632,7 +632,7 @@ module ActiveRecord
all_configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env) all_configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
needs_update = !all_configs.all? do |db_config| needs_update = !all_configs.all? do |db_config|
Tasks::DatabaseTasks.schema_up_to_date?(db_config, ActiveRecord::Base.schema_format) Tasks::DatabaseTasks.schema_up_to_date?(db_config, ActiveRecord.schema_format)
end end
if needs_update if needs_update
@ -994,7 +994,7 @@ module ActiveRecord
# Determines the version number of the next migration. # Determines the version number of the next migration.
def next_migration_number(number) def next_migration_number(number)
if ActiveRecord::Base.timestamped_migrations if ActiveRecord.timestamped_migrations
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max
else else
SchemaMigration.normalize_migration_number(number) SchemaMigration.normalize_migration_number(number)

View file

@ -96,9 +96,9 @@ db_namespace = namespace :db do
ActiveRecord::Base.establish_connection(original_db_config) ActiveRecord::Base.establish_connection(original_db_config)
end end
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false # IMPORTANT: This task won't dump the schema if ActiveRecord.dump_schema_after_migration is set to false
task :_dump do task :_dump do
if ActiveRecord::Base.dump_schema_after_migration if ActiveRecord.dump_schema_after_migration
db_namespace["schema:dump"].invoke db_namespace["schema:dump"].invoke
end end
# Allow this task to be called as many times as required. An example is the # Allow this task to be called as many times as required. An example is the
@ -108,9 +108,9 @@ db_namespace = namespace :db do
namespace :_dump do namespace :_dump do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name| ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false # IMPORTANT: This task won't dump the schema if ActiveRecord.dump_schema_after_migration is set to false
task name do task name do
if ActiveRecord::Base.dump_schema_after_migration if ActiveRecord.dump_schema_after_migration
db_namespace["schema:dump:#{name}"].invoke db_namespace["schema:dump:#{name}"].invoke
end end
# Allow this task to be called as many times as required. An example is the # Allow this task to be called as many times as required. An example is the
@ -430,7 +430,7 @@ db_namespace = namespace :db do
desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the database" desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the database"
task load: [:load_config, :check_protected_environments] do task load: [:load_config, :check_protected_environments] do
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord::Base.schema_format, ENV["SCHEMA"]) ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord.schema_format, ENV["SCHEMA"])
end end
task load_if_ruby: ["db:create", :environment] do task load_if_ruby: ["db:create", :environment] do
@ -438,7 +438,7 @@ db_namespace = namespace :db do
Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0. Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0.
Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead. Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead.
MSG MSG
db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby db_namespace["schema:load"].invoke if ActiveRecord.schema_format == :ruby
end end
namespace :dump do namespace :dump do
@ -458,7 +458,7 @@ db_namespace = namespace :db do
desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the #{name} database" desc "Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the #{name} database"
task name => :load_config do task name => :load_config do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name) db_config = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, ENV["SCHEMA"]) ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord.schema_format, ENV["SCHEMA"])
end end
end end
end end
@ -520,7 +520,7 @@ db_namespace = namespace :db do
Using `bin/rails db:structure:load_if_sql` is deprecated and will be removed in Rails 7.0. Using `bin/rails db:structure:load_if_sql` is deprecated and will be removed in Rails 7.0.
Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead. Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead.
MSG MSG
db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :sql db_namespace["schema:load"].invoke if ActiveRecord.schema_format == :sql
end end
namespace :dump do namespace :dump do
@ -577,7 +577,7 @@ db_namespace = namespace :db do
ActiveRecord::Schema.verbose = false ActiveRecord::Schema.verbose = false
ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |db_config| ActiveRecord::Base.configurations.configs_for(env_name: "test").each do |db_config|
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(db_config.name) filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(db_config.name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, filename) ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord.schema_format, filename)
end end
ensure ensure
if should_reconnect if should_reconnect
@ -623,7 +623,7 @@ db_namespace = namespace :db do
ActiveRecord::Schema.verbose = false ActiveRecord::Schema.verbose = false
filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(name) filename = ActiveRecord::Tasks::DatabaseTasks.dump_filename(name)
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", name: name) db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", name: name)
ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord::Base.schema_format, filename) ActiveRecord::Tasks::DatabaseTasks.load_schema(db_config, ActiveRecord.schema_format, filename)
ensure ensure
if should_reconnect if should_reconnect
ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym) ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym)

View file

@ -284,7 +284,7 @@ module ActiveRecord
end end
def act_on_ignored_order(error_on_ignore) def act_on_ignored_order(error_on_ignore)
raise_error = (error_on_ignore.nil? ? klass.error_on_ignored_order : error_on_ignore) raise_error = (error_on_ignore.nil? ? ActiveRecord.error_on_ignored_order : error_on_ignore)
if raise_error if raise_error
raise ArgumentError.new(ORDER_IGNORE_MESSAGE) raise ArgumentError.new(ORDER_IGNORE_MESSAGE)

View file

@ -13,8 +13,8 @@ module ActiveRecord
## ##
# :singleton-method: # :singleton-method:
# A list of tables which should not be dumped to the schema. # A list of tables which should not be dumped to the schema.
# Acceptable values are strings as well as regexp if ActiveRecord::Base.schema_format == :ruby. # Acceptable values are strings as well as regexp if ActiveRecord.schema_format == :ruby.
# Only strings are accepted if ActiveRecord::Base.schema_format == :sql. # Only strings are accepted if ActiveRecord.schema_format == :sql.
cattr_accessor :ignore_tables, default: [] cattr_accessor :ignore_tables, default: []
## ##

View file

@ -161,7 +161,7 @@ module ActiveRecord
begin begin
Rails.application.config.load_database_yaml Rails.application.config.load_database_yaml
rescue rescue
unless ActiveRecord::Base.suppress_multiple_database_warning unless ActiveRecord.suppress_multiple_database_warning
$stderr.puts "Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB." $stderr.puts "Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB."
end end
@ -210,8 +210,8 @@ module ActiveRecord
# Skipped when no database # Skipped when no database
migrate migrate
if ActiveRecord::Base.dump_schema_after_migration if ActiveRecord.dump_schema_after_migration
dump_schema(db_config, ActiveRecord::Base.schema_format) dump_schema(db_config, ActiveRecord.schema_format)
end end
rescue ActiveRecord::NoDatabaseError rescue ActiveRecord::NoDatabaseError
config_name = db_config.name config_name = db_config.name
@ -220,7 +220,7 @@ module ActiveRecord
if File.exist?(dump_filename(config_name)) if File.exist?(dump_filename(config_name))
load_schema( load_schema(
db_config, db_config,
ActiveRecord::Base.schema_format, ActiveRecord.schema_format,
nil nil
) )
else else
@ -358,7 +358,7 @@ module ActiveRecord
database_adapter_for(db_config, *arguments).structure_load(filename, flags) database_adapter_for(db_config, *arguments).structure_load(filename, flags)
end end
def load_schema(db_config, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc: def load_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
file ||= dump_filename(db_config.name, format) file ||= dump_filename(db_config.name, format)
verbose_was, Migration.verbose = Migration.verbose, verbose? && ENV["VERBOSE"] verbose_was, Migration.verbose = Migration.verbose, verbose? && ENV["VERBOSE"]
@ -380,7 +380,7 @@ module ActiveRecord
Migration.verbose = verbose_was Migration.verbose = verbose_was
end end
def schema_up_to_date?(configuration, format = ActiveRecord::Base.schema_format, file = nil, environment = nil, name = nil) def schema_up_to_date?(configuration, format = ActiveRecord.schema_format, file = nil, environment = nil, name = nil)
db_config = resolve_configuration(configuration) db_config = resolve_configuration(configuration)
if environment || name if environment || name
@ -401,7 +401,7 @@ module ActiveRecord
ActiveRecord::InternalMetadata[:schema_sha1] == schema_sha1(file) ActiveRecord::InternalMetadata[:schema_sha1] == schema_sha1(file)
end end
def reconstruct_from_schema(db_config, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc: def reconstruct_from_schema(db_config, format = ActiveRecord.schema_format, file = nil) # :nodoc:
file ||= dump_filename(db_config.name, format) file ||= dump_filename(db_config.name, format)
check_schema_file(file) check_schema_file(file)
@ -419,7 +419,7 @@ module ActiveRecord
load_schema(db_config, format, file) load_schema(db_config, format, file)
end end
def dump_schema(db_config, format = ActiveRecord::Base.schema_format) # :nodoc: def dump_schema(db_config, format = ActiveRecord.schema_format) # :nodoc:
require "active_record/schema_dumper" require "active_record/schema_dumper"
filename = dump_filename(db_config.name, format) filename = dump_filename(db_config.name, format)
connection = ActiveRecord::Base.connection connection = ActiveRecord::Base.connection
@ -441,12 +441,12 @@ module ActiveRecord
end end
end end
def schema_file(format = ActiveRecord::Base.schema_format) def schema_file(format = ActiveRecord.schema_format)
File.join(db_dir, schema_file_type(format)) File.join(db_dir, schema_file_type(format))
end end
deprecate :schema_file deprecate :schema_file
def schema_file_type(format = ActiveRecord::Base.schema_format) def schema_file_type(format = ActiveRecord.schema_format)
case format case format
when :ruby when :ruby
"schema.rb" "schema.rb"
@ -455,7 +455,7 @@ module ActiveRecord
end end
end end
def dump_filename(db_config_name, format = ActiveRecord::Base.schema_format) def dump_filename(db_config_name, format = ActiveRecord.schema_format)
filename = if ActiveRecord::Base.configurations.primary?(db_config_name) filename = if ActiveRecord::Base.configurations.primary?(db_config_name)
schema_file_type(format) schema_file_type(format)
else else
@ -475,7 +475,7 @@ module ActiveRecord
schema_cache_path || ENV["SCHEMA_CACHE"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename) schema_cache_path || ENV["SCHEMA_CACHE"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
end end
def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env) def load_schema_current(format = ActiveRecord.schema_format, file = nil, environment = env)
each_current_configuration(environment) do |db_config| each_current_configuration(environment) do |db_config|
load_schema(db_config, format, file) load_schema(db_config, format, file)
end end

View file

@ -50,13 +50,13 @@ module ActiveRecord
set_psql_env set_psql_env
search_path = \ search_path = \
case ActiveRecord::Base.dump_schemas case ActiveRecord.dump_schemas
when :schema_search_path when :schema_search_path
configuration_hash[:schema_search_path] configuration_hash[:schema_search_path]
when :all when :all
nil nil
when String when String
ActiveRecord::Base.dump_schemas ActiveRecord.dump_schemas
end end
args = ["--schema-only", "--no-privileges", "--no-owner", "--file", filename] args = ["--schema-only", "--no-privileges", "--no-owner", "--file", filename]

View file

@ -14,7 +14,7 @@ module ActiveRecord
ActiveRecord::Base.configurations.configs_for(env_name: env_name).each do |db_config| ActiveRecord::Base.configurations.configs_for(env_name: env_name).each do |db_config|
db_config._database = "#{db_config.database}-#{i}" db_config._database = "#{db_config.database}-#{i}"
ActiveRecord::Tasks::DatabaseTasks.reconstruct_from_schema(db_config, ActiveRecord::Base.schema_format, nil) ActiveRecord::Tasks::DatabaseTasks.reconstruct_from_schema(db_config, ActiveRecord.schema_format, nil)
end end
ensure ensure
ActiveRecord::Base.establish_connection ActiveRecord::Base.establish_connection

View file

@ -207,26 +207,26 @@ class EachTest < ActiveRecord::TestCase
def test_find_in_batches_should_not_error_if_config_overridden def test_find_in_batches_should_not_error_if_config_overridden
# Set the config option which will be overridden # Set the config option which will be overridden
prev = ActiveRecord::Base.error_on_ignored_order prev = ActiveRecord.error_on_ignored_order
ActiveRecord::Base.error_on_ignored_order = true ActiveRecord.error_on_ignored_order = true
assert_nothing_raised do assert_nothing_raised do
PostWithDefaultScope.find_in_batches(error_on_ignore: false) { } PostWithDefaultScope.find_in_batches(error_on_ignore: false) { }
end end
ensure ensure
# Set back to default # Set back to default
ActiveRecord::Base.error_on_ignored_order = prev ActiveRecord.error_on_ignored_order = prev
end end
def test_find_in_batches_should_error_on_config_specified_to_error def test_find_in_batches_should_error_on_config_specified_to_error
# Set the config option # Set the config option
prev = ActiveRecord::Base.error_on_ignored_order prev = ActiveRecord.error_on_ignored_order
ActiveRecord::Base.error_on_ignored_order = true ActiveRecord.error_on_ignored_order = true
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
PostWithDefaultScope.find_in_batches() { } PostWithDefaultScope.find_in_batches() { }
end end
ensure ensure
# Set back to default # Set back to default
ActiveRecord::Base.error_on_ignored_order = prev ActiveRecord.error_on_ignored_order = prev
end end
def test_find_in_batches_should_not_error_by_default def test_find_in_batches_should_not_error_by_default

View file

@ -1396,13 +1396,13 @@ class CopyMigrationsTest < ActiveRecord::TestCase
end end
def clear def clear
ActiveRecord::Base.timestamped_migrations = true ActiveRecord.timestamped_migrations = true
to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations
File.delete(*to_delete) File.delete(*to_delete)
end end
def test_copying_migrations_without_timestamps def test_copying_migrations_without_timestamps
ActiveRecord::Base.timestamped_migrations = false ActiveRecord.timestamped_migrations = false
@migrations_path = MIGRATIONS_ROOT + "/valid" @migrations_path = MIGRATIONS_ROOT + "/valid"
@existing_migrations = Dir[@migrations_path + "/*.rb"] @existing_migrations = Dir[@migrations_path + "/*.rb"]
@ -1423,7 +1423,7 @@ class CopyMigrationsTest < ActiveRecord::TestCase
end end
def test_copying_migrations_without_timestamps_from_2_sources def test_copying_migrations_without_timestamps_from_2_sources
ActiveRecord::Base.timestamped_migrations = false ActiveRecord.timestamped_migrations = false
@migrations_path = MIGRATIONS_ROOT + "/valid" @migrations_path = MIGRATIONS_ROOT + "/valid"
@existing_migrations = Dir[@migrations_path + "/*.rb"] @existing_migrations = Dir[@migrations_path + "/*.rb"]
@ -1507,7 +1507,7 @@ class CopyMigrationsTest < ActiveRecord::TestCase
end end
def test_copying_migrations_preserving_magic_comments def test_copying_migrations_preserving_magic_comments
ActiveRecord::Base.timestamped_migrations = false ActiveRecord.timestamped_migrations = false
@migrations_path = MIGRATIONS_ROOT + "/valid" @migrations_path = MIGRATIONS_ROOT + "/valid"
@existing_migrations = Dir[@migrations_path + "/*.rb"] @existing_migrations = Dir[@migrations_path + "/*.rb"]

View file

@ -482,11 +482,11 @@ if current_adapter?(:PostgreSQLAdapter)
private private
def with_dump_schemas(value, &block) def with_dump_schemas(value, &block)
old_dump_schemas = ActiveRecord::Base.dump_schemas old_dump_schemas = ActiveRecord.dump_schemas
ActiveRecord::Base.dump_schemas = value ActiveRecord.dump_schemas = value
yield yield
ensure ensure
ActiveRecord::Base.dump_schemas = old_dump_schemas ActiveRecord.dump_schemas = old_dump_schemas
end end
def with_structure_dump_flags(flags) def with_structure_dump_flags(flags)

View file

@ -1660,13 +1660,13 @@ module ApplicationTests
app "production" app "production"
assert_not ActiveRecord::Base.dump_schema_after_migration assert_not ActiveRecord.dump_schema_after_migration
end end
test "config.active_record.dump_schema_after_migration is true by default in development" do test "config.active_record.dump_schema_after_migration is true by default in development" do
app "development" app "development"
assert ActiveRecord::Base.dump_schema_after_migration assert ActiveRecord.dump_schema_after_migration
end end
test "config.active_record.verbose_query_logs is false by default in development" do test "config.active_record.verbose_query_logs is false by default in development" do
@ -1677,7 +1677,7 @@ module ApplicationTests
test "config.active_record.suppress_multiple_database_warning is false by default in development" do test "config.active_record.suppress_multiple_database_warning is false by default in development" do
app "development" app "development"
assert_not ActiveRecord::Base.suppress_multiple_database_warning assert_not ActiveRecord.suppress_multiple_database_warning
end end
test "config.annotations wrapping SourceAnnotationExtractor::Annotation class" do test "config.annotations wrapping SourceAnnotationExtractor::Annotation class" do

View file

@ -274,14 +274,14 @@ class ModelGeneratorTest < Rails::Generators::TestCase
end end
def test_migration_without_timestamps def test_migration_without_timestamps
ActiveRecord::Base.timestamped_migrations = false ActiveRecord.timestamped_migrations = false
run_generator ["account"] run_generator ["account"]
assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/ assert_file "db/migrate/001_create_accounts.rb", /class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/
run_generator ["project"] run_generator ["project"]
assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/ assert_file "db/migrate/002_create_projects.rb", /class CreateProjects < ActiveRecord::Migration\[[0-9.]+\]/
ensure ensure
ActiveRecord::Base.timestamped_migrations = true ActiveRecord.timestamped_migrations = true
end end
def test_migration_with_configured_path def test_migration_with_configured_path

View file

@ -203,7 +203,7 @@ module RailtiesTest
load "rails/tasks/engine.rake" load "rails/tasks/engine.rake"
RUBY RUBY
add_to_config "ActiveRecord::Base.timestamped_migrations = false" add_to_config "ActiveRecord.timestamped_migrations = false"
boot_rails boot_rails