diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 3 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 7 | ||||
-rw-r--r-- | railties/test/application/loading_test.rb | 6 | ||||
-rw-r--r-- | railties/test/application/rake/multi_dbs_test.rb | 20 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 42 |
7 files changed, 75 insertions, 27 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 50685a4d7a..1fdc7b2d71 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -34,20 +34,12 @@ module Rails # Initialize the logger early in the stack in case we need to log some deprecation. initializer :initialize_logger, group: :all do Rails.logger ||= config.logger || begin - path = config.paths["log"].first - unless File.exist? File.dirname path - FileUtils.mkdir_p File.dirname path - end - - f = File.open path, "a" - f.binmode - f.sync = config.autoflush_log # if true make sure every write flushes - - logger = ActiveSupport::Logger.new f + logger = ActiveSupport::Logger.new(config.default_log_file) logger.formatter = config.log_formatter logger = ActiveSupport::TaggedLogging.new(logger) logger rescue StandardError + path = config.paths["log"].first logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR)) logger.level = ActiveSupport::Logger::WARN logger.warn( diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 0b758dd3dd..da1c433e52 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -311,6 +311,18 @@ module Rails end end + def default_log_file + path = paths["log"].first + unless File.exist? File.dirname path + FileUtils.mkdir_p File.dirname path + end + + f = File.open path, "a" + f.binmode + f.sync = autoflush_log # if true make sure every write flushes + f + end + class Custom #:nodoc: def initialize @configurations = Hash.new diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 7336e235f6..578881d1ac 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -244,7 +244,6 @@ module Rails RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__) class AppGenerator < AppBase - # :stopdoc: WEBPACKS = %w( react vue angular elm stimulus ) @@ -495,7 +494,7 @@ module Rails "rails new #{arguments.map(&:usage).join(' ')} [options]" end - # :startdoc: + # :startdoc: private diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7c613585e0..6f9711cb37 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1607,6 +1607,13 @@ module ApplicationTests assert_not_nil Rails::SourceAnnotationExtractor::Annotation.extensions[/\.(coffee)$/] end + test "config.default_log_file returns a File instance" do + app "development" + + assert_instance_of File, app.config.default_log_file + assert_equal Rails.application.config.paths["log"].first, app.config.default_log_file.path + end + test "rake_tasks block works at instance level" do app_file "config/environments/development.rb", <<-RUBY Rails.application.configure do diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 9c98489590..322a6e1ca0 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -116,7 +116,7 @@ class LoadingTest < ActiveSupport::TestCase RUBY app_file "app/models/post.rb", <<-MODEL - class Post < ActiveRecord::Base + class Post < ApplicationRecord end MODEL @@ -133,9 +133,9 @@ class LoadingTest < ActiveSupport::TestCase require "#{rails_root}/config/environment" setup_ar! - assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort + assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort get "/load" - assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort + assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord, Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort get "/unload" assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort end diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb index 31ea2246a9..8c41b252da 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -303,6 +303,26 @@ module ApplicationTests require "#{app_path}/config/environment" db_prepare end + + test "db:prepare setups missing database without clearing existing one" do + require "#{app_path}/config/environment" + Dir.chdir(app_path) do + # Bug not visible on SQLite3. Can be simplified when https://github.com/rails/rails/issues/36383 resolved + use_postgresql(multi_db: true) + generate_models_for_animals + + rails "db:create:animals", "db:migrate:animals", "db:create:primary", "db:migrate:primary", "db:schema:dump" + rails "db:drop:primary" + Dog.create! + output = rails("db:prepare") + + assert_match(/Created database/, output) + assert_equal 1, Dog.count + ensure + Dog.connection.disconnect! + rails "db:drop" rescue nil + end + end end end end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index fab704944b..0fe62df8ba 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -448,18 +448,36 @@ module TestHelpers $:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' } end - def use_postgresql - File.open("#{app_path}/config/database.yml", "w") do |f| - f.puts <<-YAML - default: &default - adapter: postgresql - pool: 5 - database: railties_test - development: - <<: *default - test: - <<: *default - YAML + def use_postgresql(multi_db: false) + if multi_db + File.open("#{app_path}/config/database.yml", "w") do |f| + f.puts <<-YAML + default: &default + adapter: postgresql + pool: 5 + development: + primary: + <<: *default + database: railties_test + animals: + <<: *default + database: railties_animals_test + migrations_paths: db/animals_migrate + YAML + end + else + File.open("#{app_path}/config/database.yml", "w") do |f| + f.puts <<-YAML + default: &default + adapter: postgresql + pool: 5 + database: railties_test + development: + <<: *default + test: + <<: *default + YAML + end end end end |