diff options
| author | Leonel Galán <leonel@getstealz.com> | 2017-06-16 15:09:15 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-16 15:09:15 -0400 | 
| commit | 095036467e4e06e56452da94077500d428dd0eed (patch) | |
| tree | 3443e6779bf5a1d0f73f3c6ceb5f22cdee12e303 /railties/lib/rails/generators | |
| parent | 0804e58e1e6a52190a950f863622102b6b21ccb8 (diff) | |
| parent | b55cf266f9ccadf49276de230a8b0c2076f05202 (diff) | |
| download | rails-095036467e4e06e56452da94077500d428dd0eed.tar.gz rails-095036467e4e06e56452da94077500d428dd0eed.tar.bz2 rails-095036467e4e06e56452da94077500d428dd0eed.zip  | |
Merge branch 'master' into bug/filtered_parameters_class
Diffstat (limited to 'railties/lib/rails/generators')
26 files changed, 81 insertions, 88 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index c715e5ac9f..8429b6c7b8 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -13,7 +13,6 @@ module Rails        DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver )        JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )        DATABASES.concat(JDBC_DATABASES) -      WEBPACKS = %w( react vue angular )        attr_accessor :rails_template        add_shebang_option! @@ -31,9 +30,6 @@ module Rails          class_option :database,           type: :string, aliases: "-d", default: "sqlite3",                                            desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})" -        class_option :webpack,            type: :string, default: nil, -                                          desc: "Preconfigure for app-like JavaScript with Webpack (options: #{WEBPACKS.join('/')})" -          class_option :skip_yarn,          type: :boolean, default: false,                                            desc: "Don't use Yarn for managing JavaScript dependencies" @@ -353,7 +349,7 @@ module Rails          if defined?(JRUBY_VERSION)            GemfileEntry.version "therubyrhino", nil, comment          else -          GemfileEntry.new "therubyracer", nil, comment, { platforms: :ruby }, true +          GemfileEntry.new "mini_racer", nil, comment, { platforms: :ruby }, true          end        end diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index a650c52626..e7f51dba99 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -215,7 +215,7 @@ module Rails        # Returns the base root for a common set of generators. This is used to dynamically        # guess the default source root.        def self.base_root -        File.dirname(__FILE__) +        __dir__        end        # Cache source root and add lib/generators/base/generator/templates to diff --git a/railties/lib/rails/generators/css/assets/assets_generator.rb b/railties/lib/rails/generators/css/assets/assets_generator.rb index 20baf31a34..af7b5cf609 100644 --- a/railties/lib/rails/generators/css/assets/assets_generator.rb +++ b/railties/lib/rails/generators/css/assets/assets_generator.rb @@ -3,7 +3,7 @@ require "rails/generators/named_base"  module Css # :nodoc:    module Generators # :nodoc:      class AssetsGenerator < Rails::Generators::NamedBase # :nodoc: -      source_root File.expand_path("../templates", __FILE__) +      source_root File.expand_path("templates", __dir__)        def copy_stylesheet          copy_file "stylesheet.css", File.join("app/assets/stylesheets", class_path, "#{file_name}.css") diff --git a/railties/lib/rails/generators/js/assets/assets_generator.rb b/railties/lib/rails/generators/js/assets/assets_generator.rb index 64d706ec91..52a71b58cd 100644 --- a/railties/lib/rails/generators/js/assets/assets_generator.rb +++ b/railties/lib/rails/generators/js/assets/assets_generator.rb @@ -3,7 +3,7 @@ require "rails/generators/named_base"  module Js # :nodoc:    module Generators # :nodoc:      class AssetsGenerator < Rails::Generators::NamedBase # :nodoc: -      source_root File.expand_path("../templates", __FILE__) +      source_root File.expand_path("templates", __dir__)        def copy_javascript          copy_file "javascript.js", File.join("app/assets/javascripts", class_path, "#{file_name}.js") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 669514b37e..45b9e7bdff 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -121,7 +121,6 @@ module Rails        action_cable_config_exist = File.exist?("config/cable.yml")        rack_cors_config_exist = File.exist?("config/initializers/cors.rb")        assets_config_exist = File.exist?("config/initializers/assets.rb") -      new_framework_defaults_5_1_exist = File.exist?("config/initializers/new_framework_defaults_5_1.rb")        config @@ -145,12 +144,6 @@ module Rails          unless assets_config_exist            remove_file "config/initializers/assets.rb"          end - -        # Sprockets owns the only new default for 5.1: -        # In API-only Applications, we don't want the file. -        unless new_framework_defaults_5_1_exist -          remove_file "config/initializers/new_framework_defaults_5_1.rb" -        end        end      end @@ -208,10 +201,12 @@ module Rails    module Generators      # We need to store the RAILS_DEV_PATH in a constant, otherwise the path      # can change in Ruby 1.8.7 when we FileUtils.cd. -    RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__)) +    RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)      RESERVED_NAMES = %w[application destroy plugin runner test]      class AppGenerator < AppBase # :nodoc: +      WEBPACKS = %w( react vue angular elm ) +        add_shared_options_for "application"        # Add bin/rails options @@ -224,6 +219,9 @@ module Rails        class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,                                   desc: "Don't run bundle install" +      class_option :webpack, type: :string, default: nil, +                             desc: "Preconfigure for app-like JavaScript with Webpack (options: #{WEBPACKS.join('/')})" +        def initialize(*args)          super @@ -401,7 +399,7 @@ module Rails        def delete_new_framework_defaults          unless options[:update] -          remove_file "config/initializers/new_framework_defaults_5_1.rb" +          remove_file "config/initializers/new_framework_defaults_5_2.rb"          end        end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 1911fb7a7b..64e2062aea 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,9 +1,5 @@  source 'https://rubygems.org' - -git_source(:github) do |repo_name| -  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") -  "https://github.com/#{repo_name}.git" -end +git_source(:github) { |repo| "https://github.com/#{repo}.git" }  <% gemfile_entries.each do |gem| -%>  <% if gem.comment -%> @@ -41,7 +37,7 @@ end  group :development do  <%- unless options.api? -%> -  # Access an IRB console on exception pages or by using <%%= console %> anywhere in the code. +  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.    <%- if options.dev? || options.edge? -%>    gem 'web-console', github: 'rails/web-console'    <%- else -%> diff --git a/railties/lib/rails/generators/rails/app/templates/bin/bundle b/railties/lib/rails/generators/rails/app/templates/bin/bundle index 1123dcf501..a84f0afe47 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/bundle +++ b/railties/lib/rails/generators/rails/app/templates/bin/bundle @@ -1,2 +1,2 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)  load Gem.bin_path('bundler', 'bundle') diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt index 52b3de5ee5..ee9d077c30 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -1,9 +1,8 @@ -require 'pathname'  require 'fileutils'  include FileUtils  # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__)  def system!(*args)    system(*args) || abort("\n== Command #{args} failed ==") diff --git a/railties/lib/rails/generators/rails/app/templates/bin/update.tt b/railties/lib/rails/generators/rails/app/templates/bin/update.tt index d385b363c6..5b6e50883e 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -1,9 +1,8 @@ -require 'pathname'  require 'fileutils'  include FileUtils  # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__)  def system!(*args)    system(*args) || abort("\n== Command #{args} failed ==") diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml index a21555e573..049de65f22 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml @@ -1,4 +1,4 @@ -# SQL Server (2012 or higher recommended) +# SQL Server (2012 or higher required)  #  # Install the adapters and driver  #   gem install tiny_tds @@ -12,7 +12,7 @@ default: &default    adapter: sqlserver    encoding: utf8    username: sa -  password: <%= ENV['SA_PASSWORD'] %> +  password: <%%= ENV['SA_PASSWORD'] %>    host: localhost  development: diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 9c4a77fd1d..d44331a888 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -36,8 +36,8 @@ Rails.application.configure do    config.assets.compile = false    # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb -  <%- end -%> +  <%- end -%>    # Enable serving of images, stylesheets, and JavaScripts from an asset server.    # config.action_controller.asset_host = 'http://assets.example.com' @@ -50,8 +50,8 @@ Rails.application.configure do    # config.action_cable.mount_path = nil    # config.action_cable.url = 'wss://example.com/cable'    # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] -  <%- end -%> +  <%- end -%>    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.    # config.force_ssl = true @@ -68,14 +68,15 @@ Rails.application.configure do    # Use a real queuing backend for Active Job (and separate queues per environment)    # config.active_job.queue_adapter     = :resque    # config.active_job.queue_name_prefix = "<%= app_name %>_#{Rails.env}" +    <%- unless options.skip_action_mailer? -%>    config.action_mailer.perform_caching = false    # Ignore bad email addresses and do not raise email delivery errors.    # Set this to true and configure the email server for immediate delivery to raise delivery errors.    # config.action_mailer.raise_delivery_errors = false -  <%- end -%> +  <%- end -%>    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to    # the I18n.default_locale when a translation cannot be found).    config.i18n.fallbacks = true diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt deleted file mode 100644 index a0c7f44b60..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt +++ /dev/null @@ -1,16 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 5.1 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Make `form_with` generate non-remote forms. -Rails.application.config.action_view.form_with_generates_remote_forms = false -<%- unless options[:skip_sprockets] -%> - -# Unknown asset fallback will return the path passed in when the given -# asset is not present in the asset pipeline. -# Rails.application.config.assets.unknown_asset_fallback = false -<%- end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt new file mode 100644 index 0000000000..3809936f9f --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt @@ -0,0 +1,19 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES 256 GCM authenticated encryption for encrypted cookies. +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index 2f92168eef..6ad1f11781 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../config/environment', __FILE__) +require_relative '../config/environment'  require 'rails/test_help'  class ActiveSupport::TestCase diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb index 8b29213610..1da2fbc1a5 100644 --- a/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +++ b/railties/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb @@ -36,25 +36,29 @@ module Rails        end        def add_encrypted_secrets_file -        unless File.exist?("config/secrets.yml.enc") +        unless (defined?(@@skip_secrets_file) && @@skip_secrets_file) || File.exist?("config/secrets.yml.enc")            say "Adding config/secrets.yml.enc to store secrets that needs to be encrypted."            say "" +          say "For now the file contains this but it's been encrypted with the generated key:" +          say "" +          say Secrets.template, :on_green +          say "" -          template "config/secrets.yml.enc" do |prefill| -            say "" -            say "For now the file contains this but it's been encrypted with the generated key:" -            say "" -            say prefill, :on_green -            say "" - -            Secrets.encrypt(prefill) -          end +          Secrets.write(Secrets.template)            say "You can edit encrypted secrets with `bin/rails secrets:edit`." - -          say "Add this to your config/environments/production.rb:" -          say "config.read_encrypted_secrets = true" +          say ""          end + +        say "Add this to your config/environments/production.rb:" +        say "config.read_encrypted_secrets = true" +      end + +      def self.skip_secrets_file +        @@skip_secrets_file = true +        yield +      ensure +        @@skip_secrets_file = false        end        private diff --git a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc b/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc deleted file mode 100644 index 70426a66a5..0000000000 --- a/railties/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +++ /dev/null @@ -1,3 +0,0 @@ -# See `secrets.yml` for tips on generating suitable keys. -# production: -#  external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289… diff --git a/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt b/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt index d0575772bc..178d5c3f9f 100644 --- a/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +++ b/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt @@ -1,3 +1,3 @@  class <%= class_name %>Generator < Rails::Generators::NamedBase -  source_root File.expand_path('../templates', __FILE__) +  source_root File.expand_path('templates', __dir__)  end diff --git a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec index d84d1aabdb..9a8c4bf098 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec @@ -1,4 +1,4 @@ -$:.push File.expand_path("../lib", __FILE__) +$:.push File.expand_path("lib", __dir__)  # Maintain your gem's version:  require "<%= namespaced_name %>/version" diff --git a/railties/lib/rails/generators/rails/plugin/templates/Rakefile b/railties/lib/rails/generators/rails/plugin/templates/Rakefile index 383d2fb2d1..3581dd401a 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/Rakefile +++ b/railties/lib/rails/generators/rails/plugin/templates/Rakefile @@ -15,7 +15,7 @@ RDoc::Task.new(:rdoc) do |rdoc|  end  <% if engine? && !options[:skip_active_record] && with_dummy_app? -%> -APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path("<%= dummy_path -%>/Rakefile", __dir__)  load 'rails/tasks/engine.rake'  <% end %> diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt index c03d9953d4..ffa277e334 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt @@ -1,12 +1,12 @@  # This command will automatically be run when you run "rails" with Rails gems  # installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/<%= namespaced_name -%>/engine', __FILE__) -APP_PATH = File.expand_path('../../<%= dummy_path -%>/config/application', __FILE__) +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/<%= namespaced_name -%>/engine', __dir__) +APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__)  # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)  require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])  require 'rails/all' diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt index 8385e6a8a2..8e7d321626 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/test.tt @@ -1,4 +1,4 @@ -$: << File.expand_path(File.expand_path("../../test", __FILE__)) +$: << File.expand_path("../test", __dir__)  require "bundler/setup"  require "rails/plugin/test" diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb index e84e403018..c281fc42ca 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb @@ -1,8 +1,8 @@ -require File.expand_path("../../<%= options[:dummy_path] -%>/config/environment.rb", __FILE__) +require_relative "<%= File.join('..', options[:dummy_path], 'config/environment') -%>"  <% unless options[:skip_active_record] -%> -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../<%= options[:dummy_path] -%>/db/migrate", __FILE__)] +ActiveRecord::Migrator.migrations_paths = [File.expand_path("../<%= options[:dummy_path] -%>/db/migrate", __dir__)]  <% if options[:mountable] -%> -ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) +ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)  <% end -%>  <% end -%>  require "rails/test_help" @@ -17,7 +17,7 @@ Rails::TestUnitReporter.executable = 'bin/test'  # Load fixtures from the engine  if ActiveSupport::TestCase.respond_to?(:fixture_path=) -  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +  ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)    ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path    ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"    ActiveSupport::TestCase.fixtures :all diff --git a/railties/lib/rails/generators/rails/scaffold_controller/USAGE b/railties/lib/rails/generators/rails/scaffold_controller/USAGE index 8ba4c5ccbc..28f229510b 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/USAGE +++ b/railties/lib/rails/generators/rails/scaffold_controller/USAGE @@ -12,7 +12,7 @@ Description:  Example:      `rails generate scaffold_controller CreditCard` -    Credit card controller with URLs like /credit_card/debit. +    Credit card controller with URLs like /credit_cards.          Controller: app/controllers/credit_cards_controller.rb          Test:       test/controllers/credit_cards_controller_test.rb          Views:      app/views/credit_cards/index.html.erb [...] diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 3eec929aeb..575af80303 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -14,7 +14,7 @@ module Rails      #      #   class AppGeneratorTest < Rails::Generators::TestCase      #     tests AppGenerator -    #     destination File.expand_path("../tmp", File.dirname(__FILE__)) +    #     destination File.expand_path("../tmp", __dir__)      #   end      #      # If you want to ensure your destination root is clean before running each test, @@ -22,7 +22,7 @@ module Rails      #      #   class AppGeneratorTest < Rails::Generators::TestCase      #     tests AppGenerator -    #     destination File.expand_path("../tmp", File.dirname(__FILE__)) +    #     destination File.expand_path("../tmp", __dir__)      #     setup :prepare_destination      #   end      class TestCase < ActiveSupport::TestCase diff --git a/railties/lib/rails/generators/test_unit/system/system_generator.rb b/railties/lib/rails/generators/test_unit/system/system_generator.rb index aec415a4e5..0514957d9c 100644 --- a/railties/lib/rails/generators/test_unit/system/system_generator.rb +++ b/railties/lib/rails/generators/test_unit/system/system_generator.rb @@ -10,7 +10,7 @@ module TestUnit # :nodoc:            template "application_system_test_case.rb", File.join("test", "application_system_test_case.rb")          end -        template "system_test.rb", File.join("test/system", "#{file_name.pluralize}_test.rb") +        template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb")        end      end    end diff --git a/railties/lib/rails/generators/testing/behaviour.rb b/railties/lib/rails/generators/testing/behaviour.rb index 64d641d096..ce0e42e60d 100644 --- a/railties/lib/rails/generators/testing/behaviour.rb +++ b/railties/lib/rails/generators/testing/behaviour.rb @@ -14,12 +14,12 @@ module Rails          include ActiveSupport::Testing::Stream          included do -          class_attribute :destination_root, :current_path, :generator_class, :default_arguments -            # Generators frequently change the current path using +FileUtils.cd+.            # So we need to store the path at file load and revert back to it after each test. -          self.current_path = File.expand_path(Dir.pwd) -          self.default_arguments = [] +          class_attribute :current_path, default: File.expand_path(Dir.pwd) +          class_attribute :default_arguments, default: [] +          class_attribute :destination_root +          class_attribute :generator_class          end          module ClassMethods @@ -40,7 +40,7 @@ module Rails            # Sets the destination of generator files:            # -          #   destination File.expand_path("../tmp", File.dirname(__FILE__)) +          #   destination File.expand_path("../tmp", __dir__)            def destination(path)              self.destination_root = path            end @@ -51,7 +51,7 @@ module Rails          #          #   class AppGeneratorTest < Rails::Generators::TestCase          #     tests AppGenerator -        #     destination File.expand_path("../tmp", File.dirname(__FILE__)) +        #     destination File.expand_path("../tmp", __dir__)          #     setup :prepare_destination          #          #     test "database.yml is not created when skipping Active Record" do  | 
