diff options
Diffstat (limited to 'railties')
10 files changed, 117 insertions, 30 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index e3c0759f95..50685a4d7a 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -19,14 +19,14 @@ module Rails initializer :set_eager_load, group: :all do if config.eager_load.nil? - warn <<-INFO -config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly: + warn <<~INFO + config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly: - * development - set it to false - * test - set it to false (unless you use a tool that preloads your test environment) - * production - set it to true + * development - set it to false + * test - set it to false (unless you use a tool that preloads your test environment) + * production - set it to true -INFO + INFO config.eager_load = config.cache_classes end end diff --git a/railties/lib/rails/application/dummy_erb_compiler.rb b/railties/lib/rails/application/dummy_erb_compiler.rb index c4659123bb..086b9e76f4 100644 --- a/railties/lib/rails/application/dummy_erb_compiler.rb +++ b/railties/lib/rails/application/dummy_erb_compiler.rb @@ -13,7 +13,12 @@ class DummyCompiler < ERB::Compiler # :nodoc: def compile_content(stag, out) case stag when "<%=" - out.push "_erbout << 'dummy_compiler'" + content = out.instance_variable_get(:@compiler).instance_variable_get(:@content) + if content.include?("?") && content.include?(":") + out.push "_erbout << 'dummy_key: dummy_value'" + else + out.push "_erbout << 'dummy_value'" + end end end end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 7e3560d9d2..8782a85391 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -307,7 +307,7 @@ module Rails def assets_gemfile_entry return [] if options[:skip_sprockets] - GemfileEntry.version("sass-rails", "~> 5", "Use SCSS for stylesheets") + GemfileEntry.version("sass-rails", ">= 5", "Use SCSS for stylesheets") end def webpacker_gemfile_entry diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt index 371415e6a8..006b0a74c3 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt @@ -1,4 +1,4 @@ -# SQLite version 3.x +# SQLite. Versions 3.8.0 and up are supported. # gem 'activerecord-jdbcsqlite3-adapter' # # Configure Using Gemfile diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt index 9510568124..a7c2bf2eac 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt @@ -1,4 +1,4 @@ -# SQLite version 3.x +# SQLite. Versions 3.8.0 and up are supported. # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile diff --git a/railties/lib/rails/tasks/zeitwerk.rake b/railties/lib/rails/tasks/zeitwerk.rake index b7f5cd154b..e748a479a7 100644 --- a/railties/lib/rails/tasks/zeitwerk.rake +++ b/railties/lib/rails/tasks/zeitwerk.rake @@ -1,5 +1,7 @@ # frozen_string_literal: true +indent = " " * 2 + ensure_classic_mode = ->() do if Rails.autoloaders.zeitwerk_enabled? abort <<~EOS @@ -17,8 +19,7 @@ eager_load = ->() do Rails.configuration.eager_load_namespaces.each(&:eager_load!) end -mismatches = [] -check_directory = ->(directory, parent) do +check_directory = ->(directory, parent, mismatches) do # test/mailers/previews might not exist. return unless File.exist?(directory) @@ -33,7 +34,7 @@ check_directory = ->(directory, parent) do cname = File.basename(abspath, ".rb").camelize.to_sym if parent.const_defined?(cname, false) if File.directory?(abspath) - check_directory[abspath, parent.const_get(cname)] + check_directory[abspath, parent.const_get(cname), mismatches] end else mismatches << [abspath, parent, cname] @@ -42,22 +43,47 @@ check_directory = ->(directory, parent) do end end -report = ->() do +report_mismatches = ->(mismatches) do + puts + rails_root_prefix_re = %r{\A#{Regexp.escape(Rails.root.to_path)}/} + mismatches.each do |abspath, parent, cname| + relpath = abspath.sub(rails_root_prefix_re, "") + cpath = parent == Object ? cname : "#{parent.name}::#{cname}" + puts indent + "Mismatch: Expected #{relpath} to define #{cpath}" + end + puts + + puts <<~EOS + Please revise the reported mismatches. You can normally fix them by adding + acronyms to config/initializers/inflections.rb or renaming the constants. + EOS +end + +report_not_checked = ->(not_checked) do + puts + puts <<~EOS + WARNING: The files in these directories cannot be checked because they + are not eager loaded: + EOS + puts + + not_checked.each { |dir| puts indent + dir } puts - if mismatches.empty? + + puts <<~EOS + You may verify them manually, or add them to config.eager_load_paths + in config/application.rb and run zeitwerk:check again. + EOS +end + +report = ->(mismatches, not_checked) do + puts + if mismatches.empty? && not_checked.empty? puts "All is good!" puts "Please, remember to delete `config.autoloader = :classic` from config/application.rb." else - mismatches.each do |abspath, parent, cname| - relpath = abspath.sub(%r{\A#{Regexp.escape(Rails.root.to_path)}/}, "") - cpath = parent == Object ? cname : "#{parent.name}::#{cname}" - puts "expected #{relpath} to define #{cpath}" - end - puts - puts <<~EOS - Please revise the reported mismatches. You can normally fix them by adding - acronyms to config/initializers/inflections.rb or renaming the constants. - EOS + report_mismatches[mismatches] if mismatches.any? + report_not_checked[not_checked] if not_checked.any? end end @@ -67,12 +93,21 @@ namespace :zeitwerk do ensure_classic_mode[] eager_load[] + eager_load_paths = Rails.configuration.eager_load_namespaces.map do |eln| + eln.config.eager_load_paths if eln.respond_to?(:config) + end.compact.flatten + + mismatches = [] + $stdout.sync = true - ActiveSupport::Dependencies.autoload_paths.each do |autoload_path| - check_directory[autoload_path, Object] + eager_load_paths.each do |eager_load_path| + check_directory[eager_load_path, Object, mismatches] end - puts - report[] + not_checked = ActiveSupport::Dependencies.autoload_paths - eager_load_paths + not_checked.select! { |dir| Dir.exist?(dir) } + not_checked.reject! { |dir| Dir.empty?(dir) } + + report[mismatches, not_checked] end end diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index d38952bb30..7b294751fc 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -45,7 +45,7 @@ module Rails patterns = extract_filters(argv) tests = Rake::FileList[patterns.any? ? patterns : "test/**/*_test.rb"] - tests.exclude("test/system/**/*") if patterns.empty? + tests.exclude("test/system/**/*", "test/dummy/**/*") if patterns.empty? tests.to_a.each { |path| require File.expand_path(path) } end diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 17df78ed4e..5fae521937 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -136,5 +136,21 @@ module ApplicationTests assert_match(/boooom/, last_response.body) assert_match(/測試テスト시험/, last_response.body) end + + test "displays diagnostics message when malformed query parameters are provided" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + end + end + RUBY + + app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true + + get "/foo?x[y]=1&x[y][][w]=2" + assert_equal 400, last_response.status + assert_match "Invalid query parameters", last_response.body + end end end diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 258066a7e6..ca2d45b1c9 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -122,6 +122,22 @@ module ApplicationTests db_create_and_drop("db/development.sqlite3", environment_loaded: false) end + test "db:create and db:drop dont raise errors when loading YAML with FIXME ERB" do + app_file "config/database.yml", <<-YAML + development: + <%= Rails.application.config.database ? 'database: db/development.sqlite3' : 'database: db/development.sqlite3' %> + adapter: sqlite3 + YAML + + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.database = "db/development.sqlite3" + end + RUBY + + db_create_and_drop("db/development.sqlite3", environment_loaded: false) + end + def with_database_existing Dir.chdir(app_path) do set_database_url diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index e6b614a935..65cde91436 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -270,6 +270,21 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_create_table_migration_with_timestamps + run_generator ["create_books", "title:string", "content:text"] + assert_migration "db/migrate/create_books.rb", /t.timestamps/ + end + + def test_create_table_timestamps_are_skipped + run_generator ["create_books", "title:string", "content:text", "--no-timestamps"] + + assert_migration "db/migrate/create_books.rb" do |m| + assert_method :change, m do |change| + assert_no_match(/t.timestamps/, change) + end + end + end + def test_add_uuid_to_create_table_migration run_generator ["create_books", "--primary_key_type=uuid"] assert_migration "db/migrate/create_books.rb" do |content| |