From 215857e0c185530d526dc91cbc3bbaff9c353746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Tue, 16 Feb 2016 00:31:39 +0200 Subject: Dynamically show available sql types [ci skip] Dynamically list available sql data types based on current database adapter. --- railties/lib/rails/generators/rails/model/USAGE | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index 025bcf4774..c95e523fb5 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -35,17 +35,7 @@ Available field types: type. If no type is specified the string type will be used by default. You can use the following types: - integer - primary_key - decimal - float - boolean - binary - string - text - date - time - datetime + <%= ActiveRecord::Base.connection.native_database_types.keys.join("\n\t") %> You can also consider `references` as a kind of type. For instance, if you run: -- cgit v1.2.3 From ea2bf991a90a1c04ce867cfbbe7ac52b8456359f Mon Sep 17 00:00:00 2001 From: seunghwan oh Date: Wed, 1 Jun 2016 18:15:44 +0900 Subject: Add --skip-coffee generating option Usage `rails new awesome-project --skip-coffee` --- railties/lib/rails/generators/app_base.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index f0a3289563..27229956a6 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -67,6 +67,9 @@ module Rails class_option :skip_listen, type: :boolean, default: false, desc: "Don't generate configuration that depends on the listen gem" + class_option :skip_coffee, type: :boolean, default: false, + desc: "Don't use CoffeeScript" + class_option :skip_javascript, type: :boolean, aliases: '-J', default: false, desc: 'Skip JavaScript files' @@ -319,7 +322,9 @@ module Rails if options[:skip_javascript] || options[:skip_sprockets] [] else - gems = [coffee_gemfile_entry, javascript_runtime_gemfile_entry] + gems = [javascript_runtime_gemfile_entry] + gems << coffee_gemfile_entry unless options[:skip_coffee] + gems << GemfileEntry.version("#{options[:javascript]}-rails", nil, "Use #{options[:javascript]} as the JavaScript library") -- cgit v1.2.3 From 2495a0ba33832d20e3eadc163999dd40123e10c1 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 12 May 2016 14:21:07 -0500 Subject: Extract notes from files in binary Prevents: ArgumentError: invalid byte sequence in UTF-8 railties/lib/rails/source_annotation_extractor.rb:115:in `=~' railties/lib/rails/source_annotation_extractor.rb:115:in `block in extract_annotations_from' And there's no reason we need to interpret the files as UTF-8 when scanning for annotations. Applies to Rails 4.2 as well. --- railties/lib/rails/source_annotation_extractor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index f0df76d3f3..c60e59cb88 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -116,7 +116,7 @@ class SourceAnnotationExtractor # Otherwise it returns an empty hash. def extract_annotations_from(file, pattern) lineno = 0 - result = File.readlines(file).inject([]) do |list, line| + result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line| lineno += 1 next list unless line =~ pattern list << Annotation.new(lineno, $1, $2) -- cgit v1.2.3 From 1b7263143a91f87faabde3a5d10c74308876f640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gomes=20J=C3=BAnior?= Date: Fri, 21 Oct 2016 10:32:49 -0200 Subject: don't create db directory when skip active_record --- railties/lib/rails/generators/rails/app/app_generator.rb | 1 + railties/test/generators/app_generator_test.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 9f9c50ca10..03573b274d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -241,6 +241,7 @@ module Rails end def create_db_files + return if options[:skip_active_record] build(:db) end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8f7fa1155f..830e49a1b5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -356,6 +356,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] + assert_no_directory "db/" assert_no_file "config/database.yml" assert_no_file "app/models/application_record.rb" assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ -- cgit v1.2.3 From 797f1dd63c68eb44c1af358d377cfef271e685c5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Oct 2016 11:27:26 -0700 Subject: Prevent the test framework from being loaded in production mode The test framework should not be autoloaded in production mode. Before this commit, the testing railtie would extend AS::TestCase. This caused AS::TestCase to be preloaded regardless of the environment in which we were running. This commit just moves the code that adds line filtering support in to the test command where we actually execute the test runner. That allows us to maintain the line runner feature but only load the minimal amount of code we need. --- railties/lib/rails/commands/test/test_command.rb | 5 +++++ railties/lib/rails/test_unit/railtie.rb | 6 ------ railties/test/application/runner_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 1b2e3af9cc..e97b9cbbba 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,5 +1,6 @@ require "rails/command" require "rails/test_unit/minitest_plugin" +require "rails/test_unit/line_filtering" module Rails module Command @@ -11,6 +12,10 @@ module Rails def perform(*) $LOAD_PATH << Rails::Command.root.join("test") + # Add test line filtering support for running test by line number + # via the command line. + ActiveSupport::TestCase.extend Rails::LineFiltering + Minitest.run_via[:rails] = true require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index d0fc795515..ec91673e40 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,5 +1,3 @@ -require "rails/test_unit/line_filtering" - if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV["RAILS_ENV"] ||= "test" end @@ -13,10 +11,6 @@ module Rails c.integration_tool :test_unit end - initializer "test_unit.line_filtering" do - ActiveSupport::TestCase.extend Rails::LineFiltering - end - rake_tasks do load "rails/test_unit/testing.rake" end diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 77e7a2cca5..8769703f66 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -43,6 +43,15 @@ module ApplicationTests assert_match "42", Dir.chdir(app_path) { `bin/rails runner "bin/count_users.rb"` } end + def test_no_minitest_loaded_in_production_mode + app_file "bin/print_features.rb", <<-SCRIPT + p $LOADED_FEATURES.grep(/minitest/) + SCRIPT + assert_match "[]", Dir.chdir(app_path) { + `RAILS_ENV=production bin/rails runner "bin/print_features.rb"` + } + end + def test_should_set_dollar_0_to_file app_file "bin/dollar0.rb", <<-SCRIPT puts $0 -- cgit v1.2.3 From b6f935bbf9b8470b370ea613dc61218849aabf89 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Oct 2016 14:44:17 -0700 Subject: Use `on_load` to trigger commandline processing code We need to use on_load so that plugins will get the same functionality --- railties/lib/rails/commands/test/test_command.rb | 5 ----- railties/lib/rails/test_unit/railtie.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index e97b9cbbba..1b2e3af9cc 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,6 +1,5 @@ require "rails/command" require "rails/test_unit/minitest_plugin" -require "rails/test_unit/line_filtering" module Rails module Command @@ -12,10 +11,6 @@ module Rails def perform(*) $LOAD_PATH << Rails::Command.root.join("test") - # Add test line filtering support for running test by line number - # via the command line. - ActiveSupport::TestCase.extend Rails::LineFiltering - Minitest.run_via[:rails] = true require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index ec91673e40..746120e6a1 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,3 +1,5 @@ +require "rails/test_unit/line_filtering" + if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV["RAILS_ENV"] ||= "test" end @@ -11,6 +13,12 @@ module Rails c.integration_tool :test_unit end + initializer "test_unit.line_filtering" do + ActiveSupport.on_load(:active_support_test_case) { + ActiveSupport::TestCase.extend Rails::LineFiltering + } + end + rake_tasks do load "rails/test_unit/testing.rake" end -- cgit v1.2.3 From 5b54a904101c48aac9467df1f060b83c67bee832 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 25 Oct 2016 07:58:05 +0900 Subject: remove assets config from `new_framework_defaults` if `--skip-sprockets` is true If `sprockets` is not loaded, `Rails.application.config.assets` is not defined. --- .../app/templates/config/initializers/new_framework_defaults.rb.tt | 2 ++ railties/test/generators/app_generator_test.rb | 3 +++ 2 files changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt index 5ad18cc5ad..3ad3eba98a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt @@ -32,7 +32,9 @@ ActiveSupport.halt_callback_chains_on_return_false = <%= options[:update] ? true # Configure SSL options to enable HSTS with subdomains. Previous versions had false. Rails.application.config.ssl_options = { hsts: { subdomains: true } } <%- end -%> +<%- 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 = <%= options[:update] ? true : false %> +<%- end -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 830e49a1b5..9299b9ebea 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -412,6 +412,9 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) assert_no_match(/config\.assets\.css_compressor = :sass/, content) end + assert_file "config/initializers/new_framework_defaults.rb" do |content| + assert_no_match(/unknown_asset_fallback/, content) + end end def test_generator_if_skip_action_cable_is_given -- cgit v1.2.3 From 5faa9a235c46037a3b8e4f3308fd7ccadaae8039 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 27 Oct 2016 00:13:15 +0300 Subject: Add missing `+` around a some literals. Mainly around `nil` [ci skip] --- railties/lib/rails.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 5d862e3fec..ee48043a50 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -53,7 +53,7 @@ module Rails end # Returns a Pathname object of the current Rails project, - # otherwise it returns nil if there is no project: + # otherwise it returns +nil+ if there is no project: # # Rails.root # # => # @@ -100,7 +100,7 @@ module Rails end # Returns a Pathname object of the public folder of the current - # Rails project, otherwise it returns nil if there is no project: + # Rails project, otherwise it returns +nil+ if there is no project: # # Rails.public_path # # => # -- cgit v1.2.3 From a36ef6ee3ed44e6ce1636f12da59c473dddd94bb Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 27 Oct 2016 20:13:55 +0900 Subject: Explicitly show --no-helper and --no-assets options in help message I'm sorry for causing #24168. I wasn't aware of --no-helper and --no-assets. So I'm adding them to the help message. I'm still not sure how to show `--no-test-framework` though. --- railties/lib/rails/generators/rails/controller/controller_generator.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 213de37cce..ced3c85c00 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -3,6 +3,8 @@ module Rails class ControllerGenerator < NamedBase # :nodoc: argument :actions, type: :array, default: [], banner: "action action" class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb." + class_option :helper, type: :boolean + class_option :assets, type: :boolean check_class_collision suffix: "Controller" -- cgit v1.2.3 From 83776676e54b387fc52081ff31cfd7710bae9e03 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 28 Oct 2016 20:44:58 +0200 Subject: Hide commands from API site. They're just barren on the site and confure more than guide, instead rely on the built in --help to guide users. --- railties/lib/rails/commands/application/application_command.rb | 2 +- railties/lib/rails/commands/console/console_command.rb | 2 +- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 2 +- railties/lib/rails/commands/destroy/destroy_command.rb | 4 ++-- railties/lib/rails/commands/generate/generate_command.rb | 4 ++-- railties/lib/rails/commands/help/help_command.rb | 2 +- railties/lib/rails/commands/new/new_command.rb | 2 +- railties/lib/rails/commands/plugin/plugin_command.rb | 2 +- railties/lib/rails/commands/rake/rake_command.rb | 2 +- railties/lib/rails/commands/runner/runner_command.rb | 2 +- railties/lib/rails/commands/server/server_command.rb | 4 ++-- railties/lib/rails/commands/test/test_command.rb | 4 ++-- railties/lib/rails/commands/version/version_command.rb | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/application/application_command.rb b/railties/lib/rails/commands/application/application_command.rb index 7e3a2b011d..7675d3b3d1 100644 --- a/railties/lib/rails/commands/application/application_command.rb +++ b/railties/lib/rails/commands/application/application_command.rb @@ -13,7 +13,7 @@ module Rails end module Command - class ApplicationCommand < Base + class ApplicationCommand < Base # :nodoc: hide_command! def help diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index 617066f575..62e3aa19df 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -64,7 +64,7 @@ module Rails end module Command - class ConsoleCommand < Base + class ConsoleCommand < Base # :nodoc: include EnvironmentArgument class_option :sandbox, aliases: "-s", type: :boolean, default: false, diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index d3c80da89b..54457cf78b 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -134,7 +134,7 @@ module Rails end module Command - class DbconsoleCommand < Base + class DbconsoleCommand < Base # :nodoc: include EnvironmentArgument class_option :include_password, aliases: "-p", type: :boolean, diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 5e6b7f9371..5b552b2070 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -2,8 +2,8 @@ require "rails/generators" module Rails module Command - class DestroyCommand < Base - def help # :nodoc: + class DestroyCommand < Base # :nodoc: + def help Rails::Generators.help self.class.command_name end diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index b381ca85b9..59b2febc43 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -2,8 +2,8 @@ require "rails/generators" module Rails module Command - class GenerateCommand < Base - def help # :nodoc: + class GenerateCommand < Base # :nodoc: + def help Rails::Generators.help self.class.command_name end diff --git a/railties/lib/rails/commands/help/help_command.rb b/railties/lib/rails/commands/help/help_command.rb index 5bcc4c8eee..90d37217fc 100644 --- a/railties/lib/rails/commands/help/help_command.rb +++ b/railties/lib/rails/commands/help/help_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class HelpCommand < Base + class HelpCommand < Base # :nodoc: hide_command! def help(*) diff --git a/railties/lib/rails/commands/new/new_command.rb b/railties/lib/rails/commands/new/new_command.rb index 13eedfc479..74d1fa5021 100644 --- a/railties/lib/rails/commands/new/new_command.rb +++ b/railties/lib/rails/commands/new/new_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class NewCommand < Base + class NewCommand < Base # :nodoc: def help Rails::Command.invoke :application, [ "--help" ] end diff --git a/railties/lib/rails/commands/plugin/plugin_command.rb b/railties/lib/rails/commands/plugin/plugin_command.rb index d6d9fe4400..16587ce067 100644 --- a/railties/lib/rails/commands/plugin/plugin_command.rb +++ b/railties/lib/rails/commands/plugin/plugin_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class PluginCommand < Base + class PluginCommand < Base # :nodoc: hide_command! def help diff --git a/railties/lib/rails/commands/rake/rake_command.rb b/railties/lib/rails/commands/rake/rake_command.rb index a43c884170..f03dc81117 100644 --- a/railties/lib/rails/commands/rake/rake_command.rb +++ b/railties/lib/rails/commands/rake/rake_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class RakeCommand < Base + class RakeCommand < Base # :nodoc: extend Rails::Command::Actions namespace "rake" diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 8db6da8759..27666c76b7 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class RunnerCommand < Base + class RunnerCommand < Base # :nodoc: class_option :environment, aliases: "-e", type: :string, default: Rails::Command.environment.dup, desc: "The environment for the runner to operate under (test/development/production)" diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 14cf72f483..e9538b804c 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -139,8 +139,8 @@ module Rails end module Command - class ServerCommand < Base - def help # :nodoc: + class ServerCommand < Base # :nodoc: + def help puts Rails::Server::Options.new.option_parser(Hash.new) end diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 1b2e3af9cc..7bf8f61137 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -3,8 +3,8 @@ require "rails/test_unit/minitest_plugin" module Rails module Command - class TestCommand < Base - def help # :nodoc: + class TestCommand < Base # :nodoc: + def help perform # Hand over help printing to minitest. end diff --git a/railties/lib/rails/commands/version/version_command.rb b/railties/lib/rails/commands/version/version_command.rb index 4f3fbfca1b..ac745594ee 100644 --- a/railties/lib/rails/commands/version/version_command.rb +++ b/railties/lib/rails/commands/version/version_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class VersionCommand < Base + class VersionCommand < Base # :nodoc: def perform Rails::Command.invoke :application, [ "--version" ] end -- cgit v1.2.3 From a8b996a0eee9aae455c5f82fac0baf24edb3a9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 28 Oct 2016 21:21:24 -0200 Subject: Revert "Merge pull request #23698 from meinac/add_missing_types_into_ar_model_generator_usage" This reverts commit aaf561d26cf9a879ff40190b625155015c6225da, reversing changes made to 83776676e54b387fc52081ff31cfd7710bae9e03. Reason: It is not a good idea to connect to the database on generators --- railties/lib/rails/generators/rails/model/USAGE | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index c95e523fb5..025bcf4774 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -35,7 +35,17 @@ Available field types: type. If no type is specified the string type will be used by default. You can use the following types: - <%= ActiveRecord::Base.connection.native_database_types.keys.join("\n\t") %> + integer + primary_key + decimal + float + boolean + binary + string + text + date + time + datetime You can also consider `references` as a kind of type. For instance, if you run: -- cgit v1.2.3 From fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 29 Oct 2016 01:05:58 -0200 Subject: Add more rubocop rules about whitespaces --- railties/lib/rails/application.rb | 4 ++-- railties/lib/rails/code_statistics.rb | 2 +- railties/lib/rails/command/behavior.rb | 4 ++-- railties/lib/rails/configuration.rb | 4 ++-- railties/lib/rails/console/app.rb | 4 ++-- railties/lib/rails/engine.rb | 10 +++++----- railties/lib/rails/engine/configuration.rb | 2 +- railties/lib/rails/generators.rb | 4 ++-- railties/lib/rails/generators/actions.rb | 20 ++++++++++---------- railties/lib/rails/generators/active_model.rb | 6 +++--- railties/lib/rails/generators/base.rb | 10 +++++----- railties/lib/rails/generators/generated_attribute.rb | 4 ++-- railties/lib/rails/generators/migration.rb | 2 +- railties/lib/rails/generators/named_base.rb | 2 +- .../lib/rails/generators/rails/app/app_generator.rb | 2 +- .../generators/rails/plugin/plugin_generator.rb | 4 ++-- railties/lib/rails/generators/resource_helpers.rb | 2 +- railties/lib/rails/initializable.rb | 2 +- railties/lib/rails/source_annotation_extractor.rb | 6 +++--- railties/test/app_loader_test.rb | 2 +- railties/test/application/assets_test.rb | 4 ++-- railties/test/application/configuration_test.rb | 6 +++--- .../test/application/initializers/frameworks_test.rb | 2 +- railties/test/application/initializers/hooks_test.rb | 4 ++-- railties/test/application/test_runner_test.rb | 12 ++++++------ railties/test/code_statistics_calculator_test.rb | 2 +- railties/test/commands/dbconsole_test.rb | 18 +++++++++--------- railties/test/generators/generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 16 ++++++++-------- railties/test/generators/plugin_test_runner_test.rb | 2 +- railties/test/generators/shared_generator_tests.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/path_generation_test.rb | 2 +- railties/test/railties/engine_test.rb | 4 ++-- railties/test/railties/generators_test.rb | 2 +- 35 files changed, 88 insertions(+), 88 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b01196e3ed..3b94ae4f82 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -274,7 +274,7 @@ module Rails # Sends the initializers to the +initializer+ method defined in the # Rails::Initializable module. Each Rails::Application class has its own # set of initializers, as defined by the Initializable module. - def initializer(name, opts={}, &block) + def initializer(name, opts = {}, &block) self.class.initializer(name, opts, &block) end @@ -347,7 +347,7 @@ module Rails # Initialize the application passing the given group. By default, the # group is :default - def initialize!(group=:default) #:nodoc: + def initialize!(group = :default) #:nodoc: raise "Application has been already initialized." if @initialized run_initializers(group, self) @initialized = true diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index b3d88147a5..9c4bd16aad 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -106,7 +106,7 @@ class CodeStatistics #:nodoc: code = calculate_code tests = calculate_tests - puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}" + puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f / code)}" puts "" end end diff --git a/railties/lib/rails/command/behavior.rb b/railties/lib/rails/command/behavior.rb index ce994746a4..2e8517070c 100644 --- a/railties/lib/rails/command/behavior.rb +++ b/railties/lib/rails/command/behavior.rb @@ -38,12 +38,12 @@ module Rails str2_codepoint_enumerable = str2.each_codepoint str1.each_codepoint.with_index do |char1, i| - e = i+1 + e = i + 1 str2_codepoint_enumerable.with_index do |char2, j| cost = (char1 == char2) ? 0 : 1 x = [ - d[j+1] + 1, # insertion + d[j + 1] + 1, # insertion e + 1, # deletion d[j] + cost # substitution ].min diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 7dfab969e8..fc7d4909f6 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -91,8 +91,8 @@ module Rails attr_reader :hidden_namespaces def initialize - @aliases = Hash.new { |h,k| h[k] = {} } - @options = Hash.new { |h,k| h[k] = {} } + @aliases = Hash.new { |h, k| h[k] = {} } + @options = Hash.new { |h, k| h[k] = {} } @fallbacks = {} @templates = [] @colorize_logging = true diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index 541d5e3dad..affadc8e09 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -5,7 +5,7 @@ module Rails module ConsoleMethods # reference the global "app" instance, created on demand. To recreate the # instance, pass a non-false value as the parameter. - def app(create=false) + def app(create = false) @app_integration_instance = nil if create @app_integration_instance ||= new_session do |sess| sess.host! "www.example.com" @@ -27,7 +27,7 @@ module Rails end # reloads the environment - def reload!(print=true) + def reload!(print = true) puts "Reloading..." if print Rails.application.reloader.reload! true diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 90e7c04d7c..e56f6159ad 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -436,7 +436,7 @@ module Rails # Load console and invoke the registered hooks. # Check Rails::Railtie.console for more info. - def load_console(app=self) + def load_console(app = self) require "rails/console/app" require "rails/console/helpers" run_console_blocks(app) @@ -445,14 +445,14 @@ module Rails # Load Rails runner and invoke the registered hooks. # Check Rails::Railtie.runner for more info. - def load_runner(app=self) + def load_runner(app = self) run_runner_blocks(app) self end # Load Rake, railties tasks and invoke the registered hooks. # Check Rails::Railtie.rake_tasks for more info. - def load_tasks(app=self) + def load_tasks(app = self) require "rake" run_tasks_blocks(app) self @@ -460,7 +460,7 @@ module Rails # Load Rails generators and invoke the registered hooks. # Check Rails::Railtie.generators for more info. - def load_generators(app=self) + def load_generators(app = self) require "rails/generators" run_generators_blocks(app) Rails::Generators.configure!(app.config.generators) @@ -658,7 +658,7 @@ module Rails paths["db/migrate"].existent.any? end - def self.find_root_with_flag(flag, root_path, default=nil) #:nodoc: + def self.find_root_with_flag(flag, root_path, default = nil) #:nodoc: while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") parent = File.dirname(root_path) diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 147b904679..0c40173c38 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -7,7 +7,7 @@ module Rails attr_accessor :middleware attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths - def initialize(root=nil) + def initialize(root = nil) super() @root = root @generators = app_generators.dup diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index dd16b44786..67037106e5 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -203,7 +203,7 @@ module Rails namespaces = public_namespaces namespaces.sort! - groups = Hash.new { |h,k| h[k] = [] } + groups = Hash.new { |h, k| h[k] = [] } namespaces.each do |namespace| base = namespace.split(":").first groups[base] << namespace @@ -260,7 +260,7 @@ module Rails # Receives a namespace, arguments and the behavior to invoke the generator. # It's used as the default entry point for generate, destroy and update # commands. - def self.invoke(namespace, args=ARGV, config={}) + def self.invoke(namespace, args = ARGV, config = {}) names = namespace.to_s.split(":") if klass = find_by_namespace(names.pop, names.any? && names.join(":")) args << "--help" if args.empty? && klass.arguments.any?(&:required?) diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index ab9dc019e2..5075eb1328 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -68,7 +68,7 @@ module Rails # add_source "http://gems.github.com/" do # gem "rspec-rails" # end - def add_source(source, options={}, &block) + def add_source(source, options = {}, &block) log :source, source in_root do @@ -96,7 +96,7 @@ module Rails # environment(nil, env: "development") do # "config.action_controller.asset_host = 'localhost:3000'" # end - def environment(data=nil, options={}) + def environment(data = nil, options = {}) sentinel = /class [a-z_:]+ < Rails::Application/i env_file_sentinel = /Rails\.application\.configure do/ data = yield if !data && block_given? @@ -118,7 +118,7 @@ module Rails # git :init # git add: "this.file that.rb" # git add: "onefile.rb", rm: "badfile.cxx" - def git(commands={}) + def git(commands = {}) if commands.is_a?(Symbol) run "git #{commands}" else @@ -137,7 +137,7 @@ module Rails # end # # vendor("foreign.rb", "# Foreign code is fun") - def vendor(filename, data=nil, &block) + def vendor(filename, data = nil, &block) log :vendor, filename create_file("vendor/#{filename}", data, verbose: false, &block) end @@ -150,7 +150,7 @@ module Rails # end # # lib("foreign.rb", "# Foreign code is fun") - def lib(filename, data=nil, &block) + def lib(filename, data = nil, &block) log :lib, filename create_file("lib/#{filename}", data, verbose: false, &block) end @@ -170,7 +170,7 @@ module Rails # end # # rakefile('seed.rake', 'puts "Planting seeds"') - def rakefile(filename, data=nil, &block) + def rakefile(filename, data = nil, &block) log :rakefile, filename create_file("lib/tasks/#{filename}", data, verbose: false, &block) end @@ -188,7 +188,7 @@ module Rails # end # # initializer("api.rb", "API_KEY = '123456'") - def initializer(filename, data=nil, &block) + def initializer(filename, data = nil, &block) log :initializer, filename create_file("config/initializers/#{filename}", data, verbose: false, &block) end @@ -210,7 +210,7 @@ module Rails # rake("db:migrate") # rake("db:migrate", env: "production") # rake("gems:install", sudo: true) - def rake(command, options={}) + def rake(command, options = {}) execute_command :rake, command, options end @@ -219,7 +219,7 @@ module Rails # rails("db:migrate") # rails("db:migrate", env: "production") # rails("gems:install", sudo: true) - def rails_command(command, options={}) + def rails_command(command, options = {}) execute_command :rails, command, options end @@ -276,7 +276,7 @@ module Rails # Runs the supplied command using either "rake ..." or "rails ..." # based on the executor parameter provided. - def execute_command(executor, command, options={}) + def execute_command(executor, command, options = {}) log executor, command env = options[:env] || ENV["RAILS_ENV"] || "development" sudo = options[:sudo] && RbConfig::CONFIG["host_os"] !~ /mswin|mingw/ ? "sudo " : "" diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb index 6183944bb0..2679d06fe4 100644 --- a/railties/lib/rails/generators/active_model.rb +++ b/railties/lib/rails/generators/active_model.rb @@ -39,13 +39,13 @@ module Rails # GET edit # PATCH/PUT update # DELETE destroy - def self.find(klass, params=nil) + def self.find(klass, params = nil) "#{klass}.find(#{params})" end # GET new # POST create - def self.build(klass, params=nil) + def self.build(klass, params = nil) if params "#{klass}.new(#{params})" else @@ -59,7 +59,7 @@ module Rails end # PATCH/PUT update - def update(params=nil) + def update(params = nil) "#{name}.update(#{params})" end diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 1a0420c769..c707bbfcbf 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -20,14 +20,14 @@ module Rails strict_args_position! # Returns the source root for this generator using default_source_root as default. - def self.source_root(path=nil) + def self.source_root(path = nil) @_source_root = path if path @_source_root ||= default_source_root end # Tries to get the description from a USAGE file one folder above the source # root otherwise uses a default description. - def self.desc(description=nil) + def self.desc(description = nil) return super if description @desc ||= if usage_path @@ -40,7 +40,7 @@ module Rails # Convenience method to get the namespace from the class name. It's the # same as Thor default except that the Generator at the end of the class # is removed. - def self.namespace(name=nil) + def self.namespace(name = nil) return super if name @namespace ||= super.sub(/_generator$/, "").sub(/:generators:/, ":") end @@ -195,7 +195,7 @@ module Rails end # Make class option aware of Rails::Generators.options and Rails::Generators.aliases. - def self.class_option(name, options={}) #:nodoc: + def self.class_option(name, options = {}) #:nodoc: options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc) options[:aliases] = default_aliases_for_option(name, options) options[:default] = default_value_for_option(name, options) @@ -273,7 +273,7 @@ module Rails # Use Rails default banner. def self.banner - "rails generate #{namespace.sub(/^rails:/,'')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ") + "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ") end # Sets the base_name taking into account the current class namespace. diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 61181b7b97..baed7bf1e3 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -56,7 +56,7 @@ module Rails end end - def initialize(name, type=nil, index_type=false, attr_options={}) + def initialize(name, type = nil, index_type = false, attr_options = {}) @name = name @type = type || :string @has_index = INDEX_OPTIONS.include?(index_type) @@ -151,7 +151,7 @@ module Rails end def inject_options - "".tap { |s| options_for_migration.each { |k,v| s << ", #{k}: #{v.inspect}" } } + "".tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } } end def inject_index_options diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb index 7290e235a1..0d63b9a5c9 100644 --- a/railties/lib/rails/generators/migration.rb +++ b/railties/lib/rails/generators/migration.rb @@ -52,7 +52,7 @@ module Rails # # migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb" def migration_template(source, destination, config = {}) - source = File.expand_path(find_in_source_paths(source.to_s)) + source = File.expand_path(find_in_source_paths(source.to_s)) set_migration_assigns!(destination) context = instance_eval("binding") diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index c39ea24935..45f2fba5b9 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -217,7 +217,7 @@ module Rails # If the generator is invoked with class name Admin, it will check for # the presence of "AdminDecorator". # - def self.check_class_collision(options={}) + def self.check_class_collision(options = {}) define_method :check_class_collision do name = if self.respond_to?(:controller_class_name) # for ScaffoldBase controller_class_name diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 03573b274d..d6ffa2d89d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -56,7 +56,7 @@ module Rails def app directory "app" - keep_file "app/assets/images" + keep_file "app/assets/images" empty_directory_with_keep_file "app/assets/javascripts/channels" unless options[:skip_action_cable] keep_file "app/controllers/concerns" diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 9ffeab4fbe..80afdcc726 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -270,8 +270,8 @@ task default: :test @name ||= begin # same as ActiveSupport::Inflector#underscore except not replacing '-' underscored = original_name.dup - underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') - underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + underscored.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + underscored.gsub!(/([a-z\d])([A-Z])/, '\1_\2') underscored.downcase! underscored diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index 6d80003271..a28977319a 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -73,7 +73,7 @@ module Rails end # Initialize ORM::Generators::ActiveModel to access instance methods. - def orm_instance(name=singular_table_name) + def orm_instance(name = singular_table_name) @orm_instance ||= orm_class.new(name) end end diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 81b1cd8110..a2615d5efd 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -53,7 +53,7 @@ module Rails end end - def run_initializers(group=:default, *args) + def run_initializers(group = :default, *args) return if instance_variable_defined?(:@ran) initializers.tsort_each do |initializer| initializer.run(*args) if initializer.belongs_to?(group) diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index f0df76d3f3..967e969f81 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -44,7 +44,7 @@ class SourceAnnotationExtractor # # If +options+ has a flag :tag the tag is shown as in the example above. # Otherwise the string contains just line and text. - def to_s(options={}) + def to_s(options = {}) s = "[#{line.to_s.rjust(options[:indent])}] " s << "[#{tag}] " if options[:tag] s << text @@ -66,7 +66,7 @@ class SourceAnnotationExtractor # See #find_in for a list of file extensions that will be taken into account. # # This class method is the single entry point for the rake tasks. - def self.enumerate(tag, options={}) + def self.enumerate(tag, options = {}) extractor = new(tag) dirs = options.delete(:dirs) || Annotation.directories extractor.display(extractor.find(dirs), options) @@ -126,7 +126,7 @@ class SourceAnnotationExtractor # Prints the mapping from filenames to annotations in +results+ ordered by filename. # The +options+ hash is passed to each annotation's +to_s+. - def display(results, options={}) + def display(results, options = {}) options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size results.keys.sort.each do |file| puts "#{file}:" diff --git a/railties/test/app_loader_test.rb b/railties/test/app_loader_test.rb index 7fd5c72c1c..85f5502b4d 100644 --- a/railties/test/app_loader_test.rb +++ b/railties/test/app_loader_test.rb @@ -17,7 +17,7 @@ class AppLoaderTest < ActiveSupport::TestCase end end - def write(filename, contents=nil) + def write(filename, contents = nil) FileUtils.mkdir_p(File.dirname(filename)) File.write(filename, contents) end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 741ae543e0..edd43503bf 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -475,9 +475,9 @@ module ApplicationTests class ::PostsController < ActionController::Base; end - get "/posts", {}, "HTTPS"=>"off" + get "/posts", {}, "HTTPS" => "off" assert_match('src="http://example.com/assets/application.self.js', last_response.body) - get "/posts", {}, "HTTPS"=>"on" + get "/posts", {}, "HTTPS" => "on" assert_match('src="https://example.com/assets/application.self.js', last_response.body) end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index b0f5b30174..be84cd5027 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1043,7 +1043,7 @@ module ApplicationTests app "development" - post "/posts", post: { "title" =>"zomg" } + post "/posts", post: { "title" => "zomg" } assert_equal "permitted", last_response.body end @@ -1067,7 +1067,7 @@ module ApplicationTests assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters - post "/posts", post: { "title" =>"zomg" } + post "/posts", post: { "title" => "zomg" } assert_match "We're sorry, but something went wrong", last_response.body end @@ -1107,7 +1107,7 @@ module ApplicationTests assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters - post "/posts", post: { "title" =>"zomg" }, format: "json" + post "/posts", post: { "title" => "zomg" }, format: "json" assert_equal 200, last_response.status end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index b2cd339c1a..32bce7d372 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -185,7 +185,7 @@ module ApplicationTests test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] require "#{app_path}/config/environment" - assert_nothing_raised { [1,2,3].sample } + assert_nothing_raised { [1, 2, 3].sample } end test "config.active_support.bare does not require all of ActiveSupport" do diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb index 0309d02730..36926c50ff 100644 --- a/railties/test/application/initializers/hooks_test.rb +++ b/railties/test/application/initializers/hooks_test.rb @@ -31,7 +31,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert_equal [1,2,3], $initialization_callbacks + assert_equal [1, 2, 3], $initialization_callbacks end test "hooks block works correctly with eager_load" do @@ -46,7 +46,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert_equal [1,2,3,4], $initialization_callbacks + assert_equal [1, 2, 3, 4], $initialization_callbacks end test "after_initialize runs after frameworks have been initialized" do diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index b442891769..0939587960 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -495,7 +495,7 @@ module ApplicationTests create_test_file :models, "post", pass: false # This specifically verifies TEST for backwards compatibility with rake test # as bin/rails test already supports running tests from a single file more cleanly. - output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` } + output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` } assert_match "PostTest", output, "passing TEST= should run selected test" assert_no_match "AccountTest", output, "passing TEST= should only run selected test" @@ -504,7 +504,7 @@ module ApplicationTests def test_pass_rake_options create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` } + output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` } assert_match "1 runs, 1 assertions", output assert_match "Execute test", output @@ -512,26 +512,26 @@ module ApplicationTests def test_rails_db_create_all_restores_db_connection create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` } + output = Dir.chdir(app_path) { `bin/rails db:create:all db:migrate && echo ".tables" | rails dbconsole` } assert_match "ar_internal_metadata", output, "tables should be dumped" end def test_rails_db_create_all_restores_db_connection_after_drop create_test_file :models, "account" Dir.chdir(app_path) { `bin/rails db:create:all` } # create all to avoid warnings - output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` } + output = Dir.chdir(app_path) { `bin/rails db:drop:all db:create:all db:migrate && echo ".tables" | rails dbconsole` } assert_match "ar_internal_metadata", output, "tables should be dumped" end def test_rake_passes_TESTOPTS_to_minitest create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` } + output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` } assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test" end def test_rake_passes_multiple_TESTOPTS_to_minitest create_test_file :models, "account" - output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` } + output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` } assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test" assert_match "seed=1234", output, "passing TEST= should run selected test" end diff --git a/railties/test/code_statistics_calculator_test.rb b/railties/test/code_statistics_calculator_test.rb index 2dba3c6e96..8a2f0294d0 100644 --- a/railties/test/code_statistics_calculator_test.rb +++ b/railties/test/code_statistics_calculator_test.rb @@ -52,7 +52,7 @@ class CodeStatisticsCalculatorTest < ActiveSupport::TestCase assert_equal 3, @code_statistics_calculator.classes assert_equal 4, @code_statistics_calculator.methods - code_statistics_calculator_2 = CodeStatisticsCalculator.new(2, 3, 4, 5) + code_statistics_calculator_2 = CodeStatisticsCalculator.new(2, 3, 4, 5) @code_statistics_calculator.add(code_statistics_calculator_2) assert_equal 3, @code_statistics_calculator.lines diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 2ddb269eae..0f8c5dbb79 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -15,15 +15,15 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase def test_config_with_db_config_only config_sample = { - "test"=> { - "adapter"=> "sqlite3", - "host"=> "localhost", - "port"=> "9000", - "database"=> "foo_test", - "user"=> "foo", - "password"=> "bar", - "pool"=> "5", - "timeout"=> "3000" + "test" => { + "adapter" => "sqlite3", + "host" => "localhost", + "port" => "9000", + "database" => "foo_test", + "user" => "foo", + "password" => "bar", + "pool" => "5", + "timeout" => "3000" } } app_db_config(config_sample) do diff --git a/railties/test/generators/generator_test.rb b/railties/test/generators/generator_test.rb index c4e4747468..904bade658 100644 --- a/railties/test/generators/generator_test.rb +++ b/railties/test/generators/generator_test.rb @@ -20,7 +20,7 @@ module Rails end def test_construction - klass = make_builder_class + klass = make_builder_class assert klass.start(["new", "blah"]) end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 701d3ceaf2..2b9f3ed7f2 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -212,10 +212,10 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_migration_without_timestamps ActiveRecord::Base.timestamped_migrations = false 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"] - 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 ActiveRecord::Base.timestamped_migrations = true end @@ -300,7 +300,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ assert_generated_fixture("test/fixtures/accounts.yml", - "one"=>{ "name"=>"MyString", "age"=>1 }, "two"=>{ "name"=>"MyString", "age"=>1 }) + "one" => { "name" => "MyString", "age" => 1 }, "two" => { "name" => "MyString", "age" => 1 }) end def test_fixtures_use_the_references_ids @@ -308,7 +308,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{ "product"=>"one", "cart"=>"one" }, "two"=>{ "product"=>"two", "cart"=>"two" }) + "one" => { "product" => "one", "cart" => "one" }, "two" => { "product" => "two", "cart" => "two" }) end def test_fixtures_use_the_references_ids_and_type @@ -316,15 +316,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/line_items.yml", /product: one\n product_type: Product\n cart: one/ assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{ "product"=>"one", "product_type"=>"Product", "cart"=>"one" }, - "two"=>{ "product"=>"two", "product_type"=>"Product", "cart"=>"two" }) + "one" => { "product" => "one", "product_type" => "Product", "cart" => "one" }, + "two" => { "product" => "two", "product_type" => "Product", "cart" => "two" }) end def test_fixtures_respect_reserved_yml_keywords run_generator ["LineItem", "no:integer", "Off:boolean", "ON:boolean"] assert_generated_fixture("test/fixtures/line_items.yml", - "one"=>{ "no"=>1, "Off"=>false, "ON"=>false }, "two"=>{ "no"=>1, "Off"=>false, "ON"=>false }) + "one" => { "no" => 1, "Off" => false, "ON" => false }, "two" => { "no" => 1, "Off" => false, "ON" => false }) end def test_fixture_is_skipped @@ -343,7 +343,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase ActiveRecord::Base.pluralize_table_names = false run_generator assert_generated_fixture("test/fixtures/account.yml", - "one"=>{ "name"=>"MyString", "age"=>1 }, "two"=>{ "name"=>"MyString", "age"=>1 }) + "one" => { "name" => "MyString", "age" => 1 }, "two" => { "name" => "MyString", "age" => 1 }) ensure ActiveRecord::Base.pluralize_table_names = original_pluralize_table_name end diff --git a/railties/test/generators/plugin_test_runner_test.rb b/railties/test/generators/plugin_test_runner_test.rb index 7a10a2afa9..0bdf3b2726 100644 --- a/railties/test/generators/plugin_test_runner_test.rb +++ b/railties/test/generators/plugin_test_runner_test.rb @@ -88,7 +88,7 @@ class PluginTestRunnerTest < ActiveSupport::TestCase def test_executed_only_once create_test_file "foo" - result = run_test_command("test/foo_test.rb") + result = run_test_command("test/foo_test.rb") assert_equal 1, result.scan(/1 runs, 1 assertions, 0 failures/).length end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 27b2fc8955..08b0e34fe2 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -28,7 +28,7 @@ module SharedGeneratorTests def test_plugin_new_generate_pretend run_generator ["testapp", "--pretend"] - default_files.each { |path| assert_no_file File.join("testapp",path) } + default_files.each { |path| assert_no_file File.join("testapp", path) } end def test_invalid_database_option_raises_an_error diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 6880cf306a..aa0a06faf1 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -104,7 +104,7 @@ module TestHelpers # Build an application by invoking the generator and going through the whole stack. def build_app(options = {}) @prev_rails_env = ENV["RAILS_ENV"] - ENV["RAILS_ENV"] = "development" + ENV["RAILS_ENV"] = "development" ENV["SECRET_KEY_BASE"] ||= SecureRandom.hex(16) FileUtils.rm_rf(app_path) diff --git a/railties/test/path_generation_test.rb b/railties/test/path_generation_test.rb index 579e50ac95..c0b03d0c15 100644 --- a/railties/test/path_generation_test.rb +++ b/railties/test/path_generation_test.rb @@ -38,7 +38,7 @@ class PathGenerationTest < ActiveSupport::TestCase host = uri_or_host.host unless path path ||= uri_or_host.path - params = { "PATH_INFO" => path, + params = { "PATH_INFO" => path, "REQUEST_METHOD" => method, "HTTP_HOST" => host } diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 397037a394..70a6cd90b2 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -133,7 +133,7 @@ module RailtiesTest boot_rails Dir.chdir(app_path) do - output = `bundle exec rake railties:install:migrations`.split("\n") + output = `bundle exec rake railties:install:migrations`.split("\n") assert_match(/Copied migration \d+_create_users.bukkits.rb from bukkits/, output.first) assert_match(/Copied migration \d+_create_blogs.blog_engine.rb from blog_engine/, output.last) @@ -169,7 +169,7 @@ module RailtiesTest boot_rails Dir.chdir(app_path) do - output = `bundle exec rake railties:install:migrations`.split("\n") + output = `bundle exec rake railties:install:migrations`.split("\n") assert_match(/Copied migration \d+_create_users.core_engine.rb from core_engine/, output.first) assert_match(/Copied migration \d+_create_keys.api_engine.rb from api_engine/, output.last) diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 732898d0c0..5c691b9ec4 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -29,7 +29,7 @@ module RailtiesTests `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails #{cmd}` end - def build_engine(is_mountable=false) + def build_engine(is_mountable = false) FileUtils.rm_rf(engine_path) FileUtils.mkdir_p(engine_path) -- cgit v1.2.3 From 8360d9944be602ea97aa309ad89753219e50b093 Mon Sep 17 00:00:00 2001 From: Rafael Fidelis Date: Thu, 4 Aug 2016 01:14:37 -0300 Subject: Added register_block method to register rake_tasks, generators, console & runner blocks fixing @generators var initialization pre initializing variables values Changing from var init to symbol to instance var get/set --- railties/lib/rails/railtie.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 492c519222..8b5a272c9f 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -132,27 +132,19 @@ module Rails end def rake_tasks(&blk) - @rake_tasks ||= [] - @rake_tasks << blk if blk - @rake_tasks + register_block_for(:rake_tasks, &blk) end def console(&blk) - @load_console ||= [] - @load_console << blk if blk - @load_console + register_block_for(:load_console, &blk) end def runner(&blk) - @load_runner ||= [] - @load_runner << blk if blk - @load_runner + register_block_for(:runner, &blk) end def generators(&blk) - @generators ||= [] - @generators << blk if blk - @generators + register_block_for(:generators, &blk) end def abstract_railtie? @@ -186,6 +178,17 @@ module Rails ActiveSupport::Inflector.underscore(string).tr("/", "_") end + # receives an instance variable identifier, set the variable value if is + # blank and append given block to value, which will be used later in + # `#each_registered_block(type, &block)` + def register_block_for(type, &blk) + var_name = "@#{type}" + blocks = instance_variable_get(var_name) || instance_variable_set(var_name, []) + blocks << blk if blk + blocks + end + + # If the class method does not have a method, then send the method call # to the Railtie instance. def method_missing(name, *args, &block) @@ -241,6 +244,7 @@ module Rails private + # run `&block` in every registered block in `#register_block_for` def each_registered_block(type, &block) klass = self.class while klass.respond_to?(type) -- cgit v1.2.3 From de08be6af68373f6387854960ac967611d69ec9f Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Tue, 1 Nov 2016 14:29:29 -0400 Subject: Don't put db:migrate and db:setup in binfiles if activerecord is excluded --- .../rails/generators/rails/app/templates/bin/setup | 33 -------------------- .../generators/rails/app/templates/bin/setup.tt | 35 ++++++++++++++++++++++ .../generators/rails/app/templates/bin/update | 28 ----------------- .../generators/rails/app/templates/bin/update.tt | 30 +++++++++++++++++++ railties/test/generators/app_generator_test.rb | 6 ++++ 5 files changed, 71 insertions(+), 61 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/bin/setup create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/setup.tt delete mode 100644 railties/lib/rails/generators/rails/app/templates/bin/update create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/update.tt (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup b/railties/lib/rails/generators/rails/app/templates/bin/setup deleted file mode 100644 index acae810c1a..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup +++ /dev/null @@ -1,33 +0,0 @@ -require 'pathname' -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a starting point to setup your application. - # Add necessary setup steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' - # end - - puts "\n== Preparing database ==" - system! 'bin/rails db:setup' - - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' - - puts "\n== Restarting application server ==" - system! 'bin/rails restart' -end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt new file mode 100644 index 0000000000..8635e97b76 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -0,0 +1,35 @@ +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') +<% unless options.skip_active_record -%> + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' +<% end -%> + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/update b/railties/lib/rails/generators/rails/app/templates/bin/update deleted file mode 100644 index 770a605fed..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/bin/update +++ /dev/null @@ -1,28 +0,0 @@ -require 'pathname' -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a way to update your development environment automatically. - # Add necessary update steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - puts "\n== Updating database ==" - system! 'bin/rails db:migrate' - - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' - - puts "\n== Restarting application server ==" - system! 'bin/rails restart' -end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/update.tt b/railties/lib/rails/generators/rails/app/templates/bin/update.tt new file mode 100644 index 0000000000..d385b363c6 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -0,0 +1,30 @@ +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') +<% unless options.skip_active_record -%> + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' +<% end -%> + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9299b9ebea..6c6c5613ab 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -363,6 +363,12 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "test/test_helper.rb" do |helper_content| assert_no_match(/fixtures :all/, helper_content) end + assert_file "bin/setup" do |setup_content| + assert_no_match(/db:setup/, setup_content) + end + assert_file "bin/update" do |update_content| + assert_no_match(/db:migrate/, update_content) + end assert_file "config/initializers/new_framework_defaults.rb" do |initializer_content| assert_no_match(/belongs_to_required_by_default/, initializer_content) -- cgit v1.2.3 From 9ebb3558f4bddc2af52829abd2b198bc7fab4a13 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 1 Nov 2016 19:24:07 -0400 Subject: Make `register_block_for` private --- railties/lib/rails/railtie.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index f890b1f13a..ae26501741 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -178,17 +178,6 @@ module Rails ActiveSupport::Inflector.underscore(string).tr("/", "_") end - # receives an instance variable identifier, set the variable value if is - # blank and append given block to value, which will be used later in - # `#each_registered_block(type, &block)` - def register_block_for(type, &blk) - var_name = "@#{type}" - blocks = instance_variable_get(var_name) || instance_variable_set(var_name, []) - blocks << blk if blk - blocks - end - - # If the class method does not have a method, then send the method call # to the Railtie instance. def method_missing(name, *args, &block) @@ -198,6 +187,17 @@ module Rails super end end + + private + # receives an instance variable identifier, set the variable value if is + # blank and append given block to value, which will be used later in + # `#each_registered_block(type, &block)` + def register_block_for(type, &blk) + var_name = "@#{type}" + blocks = instance_variable_get(var_name) || instance_variable_set(var_name, []) + blocks << blk if blk + blocks + end end delegate :railtie_name, to: :class -- cgit v1.2.3 From 34530f5bd566be360be4030a38b898cba97bee85 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 2 Nov 2016 10:17:22 +0900 Subject: remove warning from railtie This removes the following warnings. ```ruby rails/railties/lib/rails/railtie.rb:186: warning: instance variable @rake_tasks not initialized rails/railties/lib/rails/railtie.rb:186: warning: instance variable @rake_tasks not initialized rails/railties/lib/rails/railtie.rb:186: warning: instance variable @load_console not initialized rails/railties/lib/rails/railtie.rb:186: warning: instance variable @rake_tasks not initialized ``` --- railties/lib/rails/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index ae26501741..696db61f01 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -194,7 +194,7 @@ module Rails # `#each_registered_block(type, &block)` def register_block_for(type, &blk) var_name = "@#{type}" - blocks = instance_variable_get(var_name) || instance_variable_set(var_name, []) + blocks = instance_variable_defined?(var_name) ? instance_variable_get(var_name) : instance_variable_set(var_name, []) blocks << blk if blk blocks end -- cgit v1.2.3 From 7b0b119c500d45b9bc751e5346ad5f316dddcc29 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 2 Nov 2016 16:59:53 +0900 Subject: Use tr instead of gsub --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 80afdcc726..1d968ec8f0 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -283,7 +283,7 @@ task default: :test end def namespaced_name - @namespaced_name ||= name.gsub("-", "/") + @namespaced_name ||= name.tr("-", "/") end protected -- cgit v1.2.3 From 9d700ad6259a459f8b0c25ebaad49a095f36a814 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 5 Nov 2016 14:24:05 +0900 Subject: remove unused require YAML and ERB were removed at 971d510 --- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 54457cf78b..35e8673215 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -1,6 +1,3 @@ -require "erb" -require "yaml" - require "rails/command/environment_argument" module Rails -- cgit v1.2.3 From d2e84fa919156d5faba750e023087f12ac4ff4bb Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sat, 12 Nov 2016 15:10:59 -0500 Subject: Add test for #25248 --- railties/test/generators/app_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 6c6c5613ab..3ec99193e3 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -488,6 +488,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_coffeescript_is_skipped_if_required + run_generator [destination_root, "--skip-coffee"] + + assert_file "Gemfile" do |content| + assert_no_match(/coffee-rails/, content) + assert_match(/jquery-rails/, content) + assert_match(/uglifier/, content) + end + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" -- cgit v1.2.3 From 592c06d7cb158df07bf87246c23af24b72d13c97 Mon Sep 17 00:00:00 2001 From: Tsukuru Tanimichi Date: Mon, 14 Nov 2016 18:09:26 +0900 Subject: Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` `rails plugin new` with `--full` and `--skip-sprockets` options generates a dummy application that throws `NoMethodError`. ``` % rails plugin new my_engine -S --full --skip-gemspec % cd my_engine % bin/rails test rails aborted! NoMethodError: undefined method `assets' for # ``` --- railties/CHANGELOG.md | 4 ++++ railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index b488e4ed8e..7db7e2e34d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` + + *Tsukuru Tanimichi* + * Allow the use of listen's 3.1.x branch *Esteban Santana Santana* diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 1d968ec8f0..2186fa4ded 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -81,7 +81,7 @@ task default: :test end PASSTHROUGH_OPTIONS = [ - :skip_active_record, :skip_action_mailer, :skip_javascript, :database, + :skip_active_record, :skip_action_mailer, :skip_javascript, :skip_sprockets, :database, :javascript, :quiet, :pretend, :force, :skip ] diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 15079f2735..0fdc30ac43 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -100,6 +100,14 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end + def test_generating_adds_dummy_app_in_full_mode_without_sprockets + run_generator [destination_root, "-S", "--full"] + + assert_file "test/dummy/config/environments/production.rb" do |contents| + assert_no_match(/config\.assets/, contents) + end + end + def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files run_generator [destination_root, "-T", "--mountable", "--dummy-path", "my_dummy_app"] assert_file "Rakefile", /APP_RAKEFILE/ -- cgit v1.2.3 From efcc361b32082670aacc873b3ffa10806bf90e6c Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Fri, 18 Nov 2016 12:17:22 +0530 Subject: Use secure source for gems referencing "github" in the generated apps - New apps generated on master and latest bundler give warning about "github" source being insecure. - Use the same solution used for Rails master in the generated app's Gemfile to fix this issue. --- railties/lib/rails/generators/rails/app/templates/Gemfile | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 422217286c..f1015b16d5 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,5 +1,10 @@ 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 + <% gemfile_entries.each do |gem| -%> <% if gem.comment -%> -- cgit v1.2.3 From 064744bef6175d382d508846c790658d46e311c4 Mon Sep 17 00:00:00 2001 From: Tawan Sierek Date: Sun, 17 Jan 2016 21:41:45 +0100 Subject: Fix `ActionDispatch::IntegrationTest#open_session` Reset a new session directly after its creation in `ActionDispatch::IntegrationTest#open_session`. Reset the session to a clean state before making it available to the client's test code. Issue #22742 reports unexpected behavior of integration tests that run multiple sessions. For example an `ActionDispatch::Flash` instance is shared across multiple sessions, though a client code will rightfully assume that each new session has its own flash hash. The following test failed due to this behavior: class Issue22742Test < ActionDispatch::IntegrationTest test 'issue #22742' do integration_session # initialize first session a = open_session b = open_session refute_same(a.integration_session, b.integration_session) end end Instead of creating a new `ActionDispatch::Integration::Session` instance, the same instance is shared across all newly opened test sessions. This is due to the way how new test sessions are created in `ActionDispatch::IntegrationTest#open_session`. The already existing `ActionDispatch::IntegrationTest` instance is duplicated with `Object#dup`, This approach was introduced in commit 15c31c7639b. `Object#dup` copies the instance variables, but not the objects they reference. Therefore this issue only occurred when the current test instance had been tapped in such a way that the instance variable `@integration_session` was initialized before creating the new test session. Close #22742 [Tawan Sierek + Sina Sadeghian] --- railties/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7db7e2e34d..049a06db3a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Reset a new session directly after its creation in ActionDispatch::IntegrationTest#open_session + + Fixes Issue #22742 + + *Tawan Sierek* + * Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` *Tsukuru Tanimichi* -- cgit v1.2.3 From c79848e1e7c16d36a4af87c317422e17e04cde39 Mon Sep 17 00:00:00 2001 From: Erick Reyna Date: Thu, 17 Nov 2016 16:32:49 -0600 Subject: Fix incorrect output from rails routes when using singular resources issue #26606 Rails routes (even rake routes in previous versions) output showed incorrect routes when an application use resource :controller, implying that edit_controller_path match with controller#show. The order of the output has changed to correct this. View #26606 for more information. Added a test case, change unit test in rake to expect the new output. Since the output of resource :controller is changing, the string spected of the railties/test/application/rake_test.rb test_rails_routes_with_controller_environment had to be modified. --- .../test/application/rake/single_resource_test.rb | 33 ++++++++++++++++++++++ railties/test/application/rake_test.rb | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 railties/test/application/rake/single_resource_test.rb (limited to 'railties') diff --git a/railties/test/application/rake/single_resource_test.rb b/railties/test/application/rake/single_resource_test.rb new file mode 100644 index 0000000000..d23516d3b1 --- /dev/null +++ b/railties/test/application/rake/single_resource_test.rb @@ -0,0 +1,33 @@ +require "isolation/abstract_unit" +require "active_support/core_ext/string/strip" + +class RakeTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + end + + def teardown + teardown_app + end + + def test_singular_resource_output_in_rake_routes + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resource :post + end + RUBY + expected_output = [" Prefix Verb URI Pattern Controller#Action", + " new_post GET /post/new(.:format) posts#new", + "edit_post GET /post/edit(.:format) posts#edit", + " post GET /post(.:format) posts#show", + " PATCH /post(.:format) posts#update", + " PUT /post(.:format) posts#update", + " DELETE /post(.:format) posts#destroy", + " POST /post(.:format) posts#create\n"].join("\n") + + output = Dir.chdir(app_path) { `bin/rails routes -c PostController` } + assert_equal expected_output, output + end +end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 5fd5507453..1288d43231 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -159,13 +159,13 @@ module ApplicationTests end RUBY expected_output = [" Prefix Verb URI Pattern Controller#Action", - " admin_post POST /admin/post(.:format) admin/posts#create", " new_admin_post GET /admin/post/new(.:format) admin/posts#new", "edit_admin_post GET /admin/post/edit(.:format) admin/posts#edit", - " GET /admin/post(.:format) admin/posts#show", + " admin_post GET /admin/post(.:format) admin/posts#show", " PATCH /admin/post(.:format) admin/posts#update", " PUT /admin/post(.:format) admin/posts#update", - " DELETE /admin/post(.:format) admin/posts#destroy\n"].join("\n") + " DELETE /admin/post(.:format) admin/posts#destroy", + " POST /admin/post(.:format) admin/posts#create\n"].join("\n") output = Dir.chdir(app_path) { `bin/rails routes -c Admin::PostController` } assert_equal expected_output, output -- cgit v1.2.3 From f5e738b6042334801bfa01b4ce0d945539aa47e8 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 19 Nov 2016 15:08:16 +0900 Subject: move CHANGELOG entry to the appropriate file [ci skip] Follow up to #27098 --- railties/CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 049a06db3a..7db7e2e34d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,9 +1,3 @@ -* Reset a new session directly after its creation in ActionDispatch::IntegrationTest#open_session - - Fixes Issue #22742 - - *Tawan Sierek* - * Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` *Tsukuru Tanimichi* -- cgit v1.2.3 From b945c9ad62a0c14fffda8f08d6cf3fdc1141e3a9 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 19 Nov 2016 16:24:28 +0530 Subject: Add missing test for singular resource output in rake routes - This test was present in https://github.com/rails/rails/pull/27089 but not present on master, may be removed in merge commit? - There was discussion about moving this to `application/rake_test` so may be this happened in merge commit. - https://github.com/rails/rails/pull/27089#discussion_r88731157 --- railties/test/application/rake_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 1288d43231..cd09270df1 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -174,6 +174,26 @@ module ApplicationTests assert_equal expected_output, output end + def test_singular_resource_output_in_rake_routes + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resource :post + end + RUBY + + expected_output = [" Prefix Verb URI Pattern Controller#Action", + " new_post GET /post/new(.:format) posts#new", + "edit_post GET /post/edit(.:format) posts#edit", + " post GET /post(.:format) posts#show", + " PATCH /post(.:format) posts#update", + " PUT /post(.:format) posts#update", + " DELETE /post(.:format) posts#destroy", + " POST /post(.:format) posts#create\n"].join("\n") + + output = Dir.chdir(app_path) { `bin/rails routes -c PostController` } + assert_equal expected_output, output + end + def test_rails_routes_with_global_search_key app_file "config/routes.rb", <<-RUBY Rails.application.routes.draw do -- cgit v1.2.3 From 03fc9a49309d807bc3f83c3ad6ac33acb0053ae3 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 19 Nov 2016 21:25:36 -0500 Subject: Use existing --skip-turbolinks option for conditionals instead of checking if turbolinks is present in gemfile list --- .../rails/app/templates/app/assets/javascripts/application.js.tt | 2 +- .../rails/app/templates/app/views/layouts/application.html.erb.tt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index c88426ec06..5d633724d5 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -13,7 +13,7 @@ <% unless options[:skip_javascript] -%> //= require <%= options[:javascript] %> //= require <%= options[:javascript] %>_ujs -<% if gemfile_entries.any? { |m| m.name == "turbolinks" } -%> +<% unless options[:skip_turbolinks] -%> //= require turbolinks <% end -%> <% end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt index d51f79bd49..5460155b3e 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt @@ -7,7 +7,7 @@ <%- if options[:skip_javascript] -%> <%%= stylesheet_link_tag 'application', media: 'all' %> <%- else -%> - <%- if gemfile_entries.any? { |m| m.name == 'turbolinks' } -%> + <%- unless options[:skip_turbolinks] -%> <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%- else -%> -- cgit v1.2.3 From 5aea0952e7cb445e614652e3cd9aba71a836eed0 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 20 Nov 2016 16:02:39 +0100 Subject: Pass `rails runner` args onto file again. When making the new command insfrastructure I had missed that `bin/rails runner some_file.rb some args` would pass the extra args onto the file in `ARGV`. Now fixed by allowing the command to take extra args again, and make sure to remove the file name from `ARGV`. --- railties/lib/rails/commands/runner/runner_command.rb | 3 ++- railties/test/application/runner_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 27666c76b7..4989a7837d 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -14,7 +14,7 @@ module Rails "#{super} [<'Some.ruby(code)'> | ]" end - def perform(code_or_file = nil) + def perform(code_or_file = nil, *file_argv) unless code_or_file help exit 1 @@ -27,6 +27,7 @@ module Rails if File.exist?(code_or_file) $0 = code_or_file + ARGV.replace(file_argv) Kernel.load code_or_file else begin diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 8769703f66..7d058f6ee6 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -68,6 +68,14 @@ module ApplicationTests assert_match "bin/program_name.rb", Dir.chdir(app_path) { `bin/rails runner "bin/program_name.rb"` } end + def test_passes_extra_args_to_file + app_file "bin/program_name.rb", <<-SCRIPT + p ARGV + SCRIPT + + assert_match %w( a b ).to_s, Dir.chdir(app_path) { `bin/rails runner "bin/program_name.rb" a b` } + end + def test_with_hook add_to_config <<-RUBY runner do |app| -- cgit v1.2.3 From 7102c6ce8984c82e0ea84b039f288f72c79dcf18 Mon Sep 17 00:00:00 2001 From: Isaac Sloan Date: Fri, 28 Oct 2016 21:53:29 -0600 Subject: deep symbolize keys on secrets.yml --- railties/CHANGELOG.md | 6 ++++++ railties/lib/rails/application.rb | 4 ++-- railties/test/application/configuration_test.rb | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7db7e2e34d..7e6d3acd48 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* The config file `secrets.yml` is now loaded in with all keys as symbols. + This allows secrets files to contain more complex information without all + child keys being strings while parent keys are symbols. + + *Isaac Sloan* + * Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` *Tsukuru Tanimichi* diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 3b94ae4f82..f96432c89f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -394,8 +394,8 @@ module Rails shared_secrets = all_secrets["shared"] env_secrets = all_secrets[Rails.env] - secrets.merge!(shared_secrets.symbolize_keys) if shared_secrets - secrets.merge!(env_secrets.symbolize_keys) if env_secrets + secrets.merge!(shared_secrets.deep_symbolize_keys) if shared_secrets + secrets.merge!(env_secrets.deep_symbolize_keys) if env_secrets end # Fallback to config.secret_key_base if secrets.secret_key_base isn't set diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index be84cd5027..7e3bd26212 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -636,6 +636,20 @@ module ApplicationTests end end + test "that nested keys are symbolized the same as parents for hashes more than one level deep" do + app_file "config/secrets.yml", <<-YAML + development: + smtp_settings: + address: "smtp.example.com" + user_name: "postmaster@example.com" + password: "697361616320736c6f616e2028656c6f7265737429" + YAML + + app "development" + + assert_equal "697361616320736c6f616e2028656c6f7265737429", app.secrets.smtp_settings[:password] + end + test "protect from forgery is the default in a new app" do make_basic_app -- cgit v1.2.3 From a865e3b2620197641e6ae519647ad81098182dec Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 19 Nov 2016 18:16:28 -0500 Subject: Don't add jQuery by default in new apps and use rails-ujs as UJS adapter instead --- railties/lib/rails/generators/app_base.rb | 11 ++++++++--- .../app/assets/javascripts/application.js.tt | 4 +++- railties/test/generators/api_app_generator_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 20 ++++++++------------ railties/test/generators/plugin_generator_test.rb | 1 - 5 files changed, 20 insertions(+), 18 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 83e9c30548..2951d6c83d 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -30,7 +30,7 @@ module Rails class_option :database, type: :string, aliases: "-d", default: "sqlite3", desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})" - class_option :javascript, type: :string, aliases: "-j", default: "jquery", + class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" class_option :skip_gemfile, type: :boolean, default: false, @@ -328,8 +328,13 @@ module Rails gems = [javascript_runtime_gemfile_entry] gems << coffee_gemfile_entry unless options[:skip_coffee] - gems << GemfileEntry.version("#{options[:javascript]}-rails", nil, - "Use #{options[:javascript]} as the JavaScript library") + if options[:javascript] + gems << GemfileEntry.version("#{options[:javascript]}-rails", nil, + "Use #{options[:javascript]} as the JavaScript library") + end + + gems << GemfileEntry.github("rails-ujs", "rails/rails-ujs", nil, + "Unobstrusive JavaScript adapter for Rails") unless options[:skip_turbolinks] gems << GemfileEntry.version("turbolinks", "~> 5", diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 5d633724d5..8db5b7e075 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -11,8 +11,10 @@ // about supported directives. // <% unless options[:skip_javascript] -%> +<% if options[:javascript] -%> //= require <%= options[:javascript] %> -//= require <%= options[:javascript] %>_ujs +<% end -%> +//= require rails-ujs <% unless options[:skip_turbolinks] -%> //= require turbolinks <% end -%> diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index bbb814ef4e..cefad48f52 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -35,7 +35,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/gem 'coffee-rails'/, content) - assert_no_match(/gem 'jquery-rails'/, content) + assert_no_match(/gem 'rails-ujs'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/# gem 'jbuilder'/, content) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3ec99193e3..2d01da7f46 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -405,7 +405,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) end assert_file "Gemfile" do |content| - assert_no_match(/jquery-rails/, content) assert_no_match(/sass-rails/, content) assert_no_match(/uglifier/, content) assert_no_match(/coffee-rails/, content) @@ -448,22 +447,20 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_jquery_is_the_default_javascript_library + def test_rails_ujs_is_the_default_ujs_library run_generator assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require jquery}, contents - assert_match %r{^//= require jquery_ujs}, contents + assert_match %r{^//= require rails-ujs}, contents end - assert_gem "jquery-rails" + assert_gem "rails-ujs" end - def test_other_javascript_libraries - run_generator [destination_root, "-j", "prototype"] + def test_inclusion_of_javascript_libraries_if_required + run_generator [destination_root, "-j", "jquery"] assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require prototype}, contents - assert_match %r{^//= require prototype_ujs}, contents + assert_match %r{^//= require jquery}, contents end - assert_gem "prototype-rails" + assert_gem "jquery-rails" end def test_javascript_is_skipped_if_required @@ -479,8 +476,8 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) - assert_no_match(/jquery-rails/, content) assert_no_match(/uglifier/, content) + assert_no_match(/rails-ujs/, content) end assert_file "config/environments/production.rb" do |content| @@ -493,7 +490,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) - assert_match(/jquery-rails/, content) assert_match(/uglifier/, content) end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 0fdc30ac43..a0018dc782 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -507,7 +507,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_match("gemspec", contents) assert_match(/gem 'rails'/, contents) assert_match_sqlite3(contents) - assert_no_match(/# gem "jquery-rails"/, contents) end end -- cgit v1.2.3 From 82d683a8425f3d22c3d53af27f04151d285b684c Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 20 Nov 2016 12:15:20 -0500 Subject: Add CHANGELOG entry --- railties/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7e6d3acd48..5e5583734a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* Removed jquery-rails from default stack, instead rails-ujs is + included as default UJS adapter. + + *Guillermo Iguaran* + * The config file `secrets.yml` is now loaded in with all keys as symbols. This allows secrets files to contain more complex information without all child keys being strings while parent keys are symbols. -- cgit v1.2.3 From da1453e6bad5551dd85f9692b921e1ff770d0319 Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Thu, 24 Nov 2016 14:17:13 +0900 Subject: Remove aggressive unit test with mock. And add integration level test. --- railties/test/application/configuration_test.rb | 19 +++++++++++++++++++ railties/test/isolation/abstract_unit.rb | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7e3bd26212..c409f1ea79 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1532,5 +1532,24 @@ module ApplicationTests assert_equal :default, Rails.configuration.debug_exception_response_format end + + test "controller force_ssl declaration can be used even if session_store is disabled" do + make_basic_app do |application| + application.config.session_store :disabled + end + + class ::OmgController < ActionController::Base + force_ssl + + def index + render plain: "Yay! You're on Rails!" + end + end + + get "/" + + assert_equal 301, last_response.status + assert_equal "https://example.org/", last_response.location + end end end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index aa0a06faf1..1902eac862 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -162,7 +162,6 @@ module TestHelpers require "rails" require "action_controller/railtie" require "action_view/railtie" - require "action_dispatch/middleware/flash" @app = Class.new(Rails::Application) @app.config.eager_load = false -- cgit v1.2.3 From f0a55a7c6a7797a2a1f0359357c895ab5512e3f5 Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Thu, 24 Nov 2016 18:03:46 +0900 Subject: [ci skip] `MiniTest` -> `Minitest` MiniTest was renamed to Minitest. Already renamed on https://github.com/rails/rails/pull/13366 But slipped into on https://github.com/rails/rails/pull/18413/files#diff-6bb90a693835b0e92910b796c8b0ef59R27 --- railties/test/code_statistics_calculator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/code_statistics_calculator_test.rb b/railties/test/code_statistics_calculator_test.rb index 8a2f0294d0..1bd4225f34 100644 --- a/railties/test/code_statistics_calculator_test.rb +++ b/railties/test/code_statistics_calculator_test.rb @@ -24,7 +24,7 @@ class CodeStatisticsCalculatorTest < ActiveSupport::TestCase end end - test "count number of methods in MiniTest file" do + test "count number of methods in Minitest file" do code = <<-RUBY class FooTest < ActionController::TestCase test 'expectation' do -- cgit v1.2.3 From 93b7816eefc2ac4cfe6cd10002598d84bf3df097 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 26 Nov 2016 10:55:11 +0900 Subject: use correct variable in BacktraceCleaner test `@target_dir` variable was changed to local variable in 8e1714b. --- railties/test/backtrace_cleaner_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 17201d6f77..f71e56f323 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -15,7 +15,7 @@ class BacktraceCleanerTest < ActiveSupport::TestCase test "should format installed gems not in Gem.default_dir correctly" do target_dir = Gem.path.detect { |p| p != Gem.default_dir } # skip this test if default_dir is the only directory on Gem.path - if @target_dir + if target_dir backtrace = [ "#{target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] result = @cleaner.clean(backtrace, :all) assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0] -- cgit v1.2.3 From 4c00c6ed230e6fdc6199dfba43f6da1e741a02aa Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sun, 13 Nov 2016 22:18:14 -0500 Subject: Use YAML to serialize schema cache --- railties/test/application/rake_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index cd09270df1..d80a45a83f 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -387,14 +387,14 @@ module ApplicationTests bin/rails generate model product name:string; bin/rails db:migrate db:schema:cache:dump` end - assert File.exist?(File.join(app_path, "db", "schema_cache.dump")) + assert File.exist?(File.join(app_path, "db", "schema_cache.yml")) end def test_rake_clear_schema_cache Dir.chdir(app_path) do `bin/rails db:schema:cache:dump db:schema:cache:clear` end - assert !File.exist?(File.join(app_path, "db", "schema_cache.dump")) + assert !File.exist?(File.join(app_path, "db", "schema_cache.yml")) end def test_copy_templates -- cgit v1.2.3 From 89822e86d8da3771f5a72c2d33888af76aec9d6e Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Sun, 20 Nov 2016 16:35:37 -0500 Subject: Add package.json for Yarn if --yarn option is added --- railties/lib/rails/generators/app_base.rb | 52 ++++++++++++++++++++++ .../rails/generators/rails/app/app_generator.rb | 7 ++- .../generators/rails/app/templates/package.json | 7 +++ railties/test/generators/app_generator_test.rb | 23 ++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/package.json (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 2951d6c83d..f54604b54d 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,6 +33,9 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" + class_option :yarn, type: :boolean, default: false, + desc: "Preconfigure for assets management with Yarn" + class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile" @@ -414,6 +417,55 @@ module Rails bundle_command("install") if bundle_install? end + def run_yarn + if package_json_exist? + if yarn_path + say_status :run, "yarn install" + yarn_command("install") + else + say_status :warning, "yarn option passed but Yarn executable was not detected in the system.", :yellow + say_status :warning, "Download Yarn at https://yarnpkg.com/en/docs/install", :yellow + end + end + end + + def package_json_exist? + File.exist?("package.json") + end + + def yarn_path + commands = ["yarn"] + + if RbConfig::CONFIG["host_os"] =~ /mswin|cygwin/ + ENV["PATHEXT"].split(File::PATH_SEPARATOR).each do |ext| + commands << commands[0] + ext + end + end + + yarn_path = commands.find do |cmd| + paths = ENV["PATH"].split(File::PATH_SEPARATOR) + + path = paths.find do |p| + full_path = File.expand_path(cmd, p) + File.executable?(full_path) && File.file?(full_path) + end + + path && File.expand_path(cmd, path) + end + + yarn_path + end + + def yarn_command(command) + full_command = "#{yarn_path} #{command}" + + if options[:quiet] + system(full_command, out: File::NULL) + else + system(full_command) + end + end + def generate_spring_binstubs if bundle_install? && spring_install? bundle_command("exec spring binstub --all") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index d6ffa2d89d..03fd298fbc 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -53,6 +53,10 @@ module Rails template "gitignore", ".gitignore" end + def packagejson + template "package.json" + end + def app directory "app" @@ -205,6 +209,7 @@ module Rails build(:readme) build(:rakefile) build(:configru) + build(:packagejson) if options[:yarn] build(:gitignore) unless options[:skip_git] build(:gemfile) unless options[:skip_gemfile] end @@ -355,7 +360,7 @@ module Rails end public_task :apply_rails_template, :run_bundle - public_task :generate_spring_binstubs + public_task :run_yarn, :generate_spring_binstubs def run_after_bundle_callbacks @after_bundle_callbacks.each(&:call) diff --git a/railties/lib/rails/generators/rails/app/templates/package.json b/railties/lib/rails/generators/rails/app/templates/package.json new file mode 100644 index 0000000000..78f4a2e6b0 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/package.json @@ -0,0 +1,7 @@ +{ + "name": "<%= app_name %>", + "private": true, + "dependencies": { + "rails-ujs": "rails/rails-ujs" + } +} diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2d01da7f46..f673058de8 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -494,6 +494,11 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generator_if_yarn_option_is_given + run_generator([destination_root, "--yarn"]) + assert_file "package.json", /dependencies/ + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" @@ -614,6 +619,10 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_generates_with_bundler end + def test_generation_runs_yarn_install_with_yarn_option + assert_generates_with_yarn yarn: true + end + def test_dev_option assert_generates_with_bundler dev: true rails_path = File.expand_path("../../..", Rails.root) @@ -839,4 +848,18 @@ class AppGeneratorTest < Rails::Generators::TestCase quietly { generator.invoke_all } end end + + def assert_generates_with_yarn(options = {}) + generator([destination_root], options) + + command_check = -> command do + @install_called ||= 0 + @install_called += 1 + assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" + end + + generator.stub :yarn_command, command_check do + quietly { generator.invoke_all } + end + end end -- cgit v1.2.3 From e6730c7ffbf51c985611d9281e3d080880eb3366 Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Sun, 20 Nov 2016 16:37:06 -0500 Subject: Add node_modules path to assets load paths when --yarn option is used --- .../generators/rails/app/templates/config/initializers/assets.rb.tt | 4 ++++ railties/test/generators/app_generator_test.rb | 1 + 2 files changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index 2318cf59ff..1ba182e562 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -5,6 +5,10 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path +<%- if options[:yarn] -%> +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') +<%- end -%> # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f673058de8..d7b682c5a9 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -497,6 +497,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_yarn_option_is_given run_generator([destination_root, "--yarn"]) assert_file "package.json", /dependencies/ + assert_file "config/initializers/assets.rb", /node_modules/ end def test_inclusion_of_jbuilder -- cgit v1.2.3 From 732702b56b4fcf4df374dee123fbce3b38e7a1a0 Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Sun, 20 Nov 2016 16:37:37 -0500 Subject: Add node_modules to default gitignore --- railties/lib/rails/generators/rails/app/templates/gitignore | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 0e66cc4237..bdcbe8d629 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -21,5 +21,10 @@ !/tmp/.keep <% end -%> +<% if options[:yarn] -%> +# Ignore node modules. +/node_modules/* + +<% end -%> # Ignore Byebug command history file. .byebug_history -- cgit v1.2.3 From 9a95e13989380e59245d3d6fb0853953b806742c Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Mon, 31 Oct 2016 17:03:41 -0500 Subject: Run yarn on setup and update scripts. --- railties/lib/rails/generators/rails/app/templates/bin/setup.tt | 5 ++++- railties/lib/rails/generators/rails/app/templates/bin/update.tt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'railties') 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 8635e97b76..c82a922eef 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -16,8 +16,11 @@ chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% unless options.skip_active_record -%> +<% if options[:yarn] %> + system! 'yarn' +<% end %> +<% unless options.skip_active_record -%> # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' 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..0d8ca2f902 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -16,8 +16,11 @@ chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% unless options.skip_active_record -%> +<% if options[:yarn] %> + system! 'yarn' +<% end %> +<% unless options.skip_active_record -%> puts "\n== Updating database ==" system! 'bin/rails db:migrate' <% end -%> -- cgit v1.2.3 From ffb81ad6e3326332556e8eab867fe1a27a989bf5 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 29 Nov 2016 09:48:19 -0500 Subject: rails-ujs is now shipped with Action View --- railties/CHANGELOG.md | 4 ++-- railties/lib/rails/generators/app_base.rb | 3 --- railties/test/generators/api_app_generator_test.rb | 1 - railties/test/generators/app_generator_test.rb | 2 -- 4 files changed, 2 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 5e5583734a..4126c70163 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,5 @@ -* Removed jquery-rails from default stack, instead rails-ujs is - included as default UJS adapter. +* Removed jquery-rails from default stack, instead rails-ujs that is shipped + with Action View is included as default UJS adapter. *Guillermo Iguaran* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 2951d6c83d..2778c93429 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -333,9 +333,6 @@ module Rails "Use #{options[:javascript]} as the JavaScript library") end - gems << GemfileEntry.github("rails-ujs", "rails/rails-ujs", nil, - "Unobstrusive JavaScript adapter for Rails") - unless options[:skip_turbolinks] gems << GemfileEntry.version("turbolinks", "~> 5", "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks") diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index cefad48f52..7069a07bbe 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -35,7 +35,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/gem 'coffee-rails'/, content) - assert_no_match(/gem 'rails-ujs'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/# gem 'jbuilder'/, content) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2d01da7f46..d2818eeaf1 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -452,7 +452,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/javascripts/application.js" do |contents| assert_match %r{^//= require rails-ujs}, contents end - assert_gem "rails-ujs" end def test_inclusion_of_javascript_libraries_if_required @@ -477,7 +476,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile" do |content| assert_no_match(/coffee-rails/, content) assert_no_match(/uglifier/, content) - assert_no_match(/rails-ujs/, content) end assert_file "config/environments/production.rb" do |content| -- cgit v1.2.3 From 3b0a09c398ba90b091f3af73a370c69f640009cf Mon Sep 17 00:00:00 2001 From: Liceth Ovalles Date: Tue, 29 Nov 2016 10:08:26 -0500 Subject: Add CHANGELOG entry for --yarn option --- railties/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4126c70163..819d760433 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* Add Yarn support in new apps using --yarn option. This add a package.json + and the settings needed to get npm modules integrated in new apps. + + *Liceth Ovalles*, *Guillermo Iguaran* + * Removed jquery-rails from default stack, instead rails-ujs that is shipped with Action View is included as default UJS adapter. -- cgit v1.2.3 From 47b20c7ff74c72ade4c3c9c4a134166ebdbc400f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 29 Nov 2016 10:25:19 -0500 Subject: Let's use only vendored rails-ujs while we start to publish it to npm registry --- railties/lib/rails/generators/rails/app/templates/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/package.json b/railties/lib/rails/generators/rails/app/templates/package.json index 78f4a2e6b0..46db57dcbe 100644 --- a/railties/lib/rails/generators/rails/app/templates/package.json +++ b/railties/lib/rails/generators/rails/app/templates/package.json @@ -1,7 +1,5 @@ { "name": "<%= app_name %>", "private": true, - "dependencies": { - "rails-ujs": "rails/rails-ujs" - } + "dependencies": {} } -- cgit v1.2.3 From 5e751962b4bf1a589da4bf75632da37c0b7b44a0 Mon Sep 17 00:00:00 2001 From: Robert Glaser Date: Wed, 30 Nov 2016 09:57:42 +0100 Subject: fix typo in changelog --- railties/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 819d760433..f328df8539 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,4 +1,4 @@ -* Add Yarn support in new apps using --yarn option. This add a package.json +* Add Yarn support in new apps using --yarn option. This adds a package.json and the settings needed to get npm modules integrated in new apps. *Liceth Ovalles*, *Guillermo Iguaran* -- cgit v1.2.3 From d749bda7668041eff65f27f8395b62545216872f Mon Sep 17 00:00:00 2001 From: phoet Date: Wed, 30 Nov 2016 10:31:40 +0100 Subject: removed `@current` as it is not used --- railties/lib/rails/paths.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 1c1810dde6..10925de8b2 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -45,7 +45,6 @@ module Rails attr_accessor :path def initialize(path) - @current = nil @path = path @root = {} end -- cgit v1.2.3 From 75607a67b4f5e3fb5acf9c49353f102a4ecd9319 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 30 Nov 2016 20:57:50 +0900 Subject: use `Gem.win_platform?` to check windows Ruby platforms `Gem.win_platform?` check if it is Windows more accurately. Ref: https://github.com/ruby/ruby/blob/ruby_2_2/lib/rubygems.rb#L945..L952 --- railties/lib/rails/commands/runner/USAGE | 2 +- railties/lib/rails/generators/actions.rb | 4 ++-- railties/lib/rails/generators/app_base.rb | 2 +- railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/runner/USAGE b/railties/lib/rails/commands/runner/USAGE index dc47a35ff3..b2a6e8493d 100644 --- a/railties/lib/rails/commands/runner/USAGE +++ b/railties/lib/rails/commands/runner/USAGE @@ -8,7 +8,7 @@ Run the Ruby file located at `path/to/filename.rb` after loading the app: <%= executable %> path/to/filename.rb -<% if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ %> +<% unless Gem.win_platform? %> You can also use the runner command as a shebang line for your executables: #!/usr/bin/env <%= File.expand_path(executable) %> diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 5075eb1328..8a60560f86 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -279,13 +279,13 @@ module Rails def execute_command(executor, command, options = {}) log executor, command env = options[:env] || ENV["RAILS_ENV"] || "development" - sudo = options[:sudo] && RbConfig::CONFIG["host_os"] !~ /mswin|mingw/ ? "sudo " : "" + sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : "" in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", verbose: false) } end # Add an extension to the given name based on the platform. def extify(name) - if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ + if Gem.win_platform? "#{name}.bat" else name diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 99fc5d9525..6feb8431a7 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -433,7 +433,7 @@ module Rails def yarn_path commands = ["yarn"] - if RbConfig::CONFIG["host_os"] =~ /mswin|cygwin/ + if Gem.win_platform? ENV["PATHEXT"].split(File::PATH_SEPARATOR).each do |ext| commands << commands[0] + ext end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 03fd298fbc..5f14f989d7 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -428,7 +428,7 @@ module Rails "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 "/opt/lampp/var/mysql/mysql.sock" # xampp for linux - ].find { |f| File.exist?(f) } unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ + ].find { |f| File.exist?(f) } unless Gem.win_platform? end def get_builder_class -- cgit v1.2.3 From 3dac36bd8e26363bb10f4d2a7b21efa75d200e26 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Dec 2016 18:51:43 +0100 Subject: Yarn: Move node_modules, package.json, and yarn.lock file to vendor (#27245) Move node_modules, package.json, and yarn.lock file to vendor --- railties/CHANGELOG.md | 4 ++-- railties/lib/rails/generators/app_base.rb | 2 +- railties/lib/rails/generators/rails/app/app_generator.rb | 10 +++++++--- railties/lib/rails/generators/rails/app/templates/bin/setup.tt | 2 +- railties/lib/rails/generators/rails/app/templates/bin/yarn | 2 ++ .../rails/app/templates/config/initializers/assets.rb.tt | 2 +- railties/lib/rails/generators/rails/app/templates/gitignore | 4 +--- railties/test/generators/app_generator_test.rb | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/yarn (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index f328df8539..0188f91997 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,7 +1,7 @@ -* Add Yarn support in new apps using --yarn option. This adds a package.json +* Add Yarn support in new apps using --yarn option. This adds a yarn binstop, vendor/package.json, and the settings needed to get npm modules integrated in new apps. - *Liceth Ovalles*, *Guillermo Iguaran* + *Liceth Ovalles*, *Guillermo Iguaran*, *DHH* * Removed jquery-rails from default stack, instead rails-ujs that is shipped with Action View is included as default UJS adapter. diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 6feb8431a7..87f6f01750 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -427,7 +427,7 @@ module Rails end def package_json_exist? - File.exist?("package.json") + File.exist?("vendor/package.json") end def yarn_path diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 5f14f989d7..49d23d682a 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -54,7 +54,7 @@ module Rails end def packagejson - template "package.json" + template "package.json", "vendor/package.json" end def app @@ -155,8 +155,12 @@ module Rails end def vendor - vendor_javascripts - vendor_stylesheets + if options[:yarn] + empty_directory_with_keep_file "vendor" + else + vendor_javascripts + vendor_stylesheets + end end def vendor_javascripts 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 c82a922eef..73b0732463 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -17,7 +17,7 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') <% if options[:yarn] %> - system! 'yarn' + system! 'bin/yarn' <% end %> <% unless options.skip_active_record -%> diff --git a/railties/lib/rails/generators/rails/app/templates/bin/yarn b/railties/lib/rails/generators/rails/app/templates/bin/yarn new file mode 100644 index 0000000000..cf48e2e5b7 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/yarn @@ -0,0 +1,2 @@ +VENDOR_PATH = File.expand_path('../vendor', __dir__) +Dir.chdir(VENDOR_PATH) { exec "yarnpkg #{ARGV.join(" ")}" } diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index 1ba182e562..bf5399ac2d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -7,7 +7,7 @@ Rails.application.config.assets.version = '1.0' # Rails.application.config.assets.paths << Emoji.images_path <%- if options[:yarn] -%> # Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') +Rails.application.config.assets.paths << Rails.root.join('vendor/node_modules') <%- end -%> # Precompile additional assets. diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index bdcbe8d629..dee42ebb87 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -22,9 +22,7 @@ <% end -%> <% if options[:yarn] -%> -# Ignore node modules. -/node_modules/* +/vendor/node_modules <% end -%> -# Ignore Byebug command history file. .byebug_history diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0f73c43e0c..15a923676d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -494,7 +494,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_yarn_option_is_given run_generator([destination_root, "--yarn"]) - assert_file "package.json", /dependencies/ + assert_file "vendor/package.json", /dependencies/ assert_file "config/initializers/assets.rb", /node_modules/ end -- cgit v1.2.3 From dffeb3d70cd50b0759a7481f8e83dea5d2b9e7dd Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 2 Dec 2016 12:50:51 +0900 Subject: use yarn binstub in `bin/update` Follow up to 3dac36bd8e26363bb10f4d2a7b21efa75d200e26 --- railties/lib/rails/generators/rails/app/templates/bin/update.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') 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 0d8ca2f902..dcd80b6ce5 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -17,7 +17,7 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') <% if options[:yarn] %> - system! 'yarn' + system! 'bin/yarn' <% end %> <% unless options.skip_active_record -%> -- cgit v1.2.3 From 62462d41e87a7e63e8df37efdb092ca3ee5a5a09 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 2 Dec 2016 17:23:57 +0800 Subject: Use JavaScripts instead of Javascripts in `rake stats` --- railties/lib/rails/tasks/statistics.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index a6cdd1e99c..8265aef10b 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -8,7 +8,7 @@ STATS_DIRECTORIES = [ %w(Models app/models), %w(Mailers app/mailers), %w(Channels app/channels), - %w(Javascripts app/assets/javascripts), + %w(JavaScripts app/assets/javascripts), %w(Libraries lib/), %w(Tasks lib/tasks), %w(APIs app/apis), -- cgit v1.2.3 From fab83b9bde9ab912e29c69d4d20e6ac81b242be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Mon, 5 Dec 2016 02:11:33 +0100 Subject: Fix binstop -> binstub typo in railties changelog. [ci skip] --- railties/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 0188f91997..c445390cd3 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,4 +1,4 @@ -* Add Yarn support in new apps using --yarn option. This adds a yarn binstop, vendor/package.json, +* Add Yarn support in new apps using --yarn option. This adds a yarn binstub, vendor/package.json, and the settings needed to get npm modules integrated in new apps. *Liceth Ovalles*, *Guillermo Iguaran*, *DHH* -- cgit v1.2.3 From 5ad8da59a2ab6dca77b498698c522e930cbce20b Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Mon, 5 Dec 2016 08:45:02 +0530 Subject: Add fullstop following the pattern used in rest of the file --- .../generators/rails/app/templates/config/initializers/assets.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index bf5399ac2d..29d9df6ad4 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -3,7 +3,7 @@ # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' -# Add additional assets to the asset load path +# Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path <%- if options[:yarn] -%> # Add Yarn node_modules folder to the asset load path. -- cgit v1.2.3 From b6e49a4c0cf20fdd1b74bd0b489f87e90ddd6ad9 Mon Sep 17 00:00:00 2001 From: brchristian Date: Mon, 5 Dec 2016 16:48:25 -0800 Subject: Update puma.rb Clarifying some of the language/punctuation and removing a couple comma splices. --- .../lib/rails/generators/rails/app/templates/config/puma.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/puma.rb b/railties/lib/rails/generators/rails/app/templates/config/puma.rb index 7ee948002e..1e19380dcb 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/puma.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/puma.rb @@ -1,13 +1,13 @@ # Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers a minimum and maximum. +# The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum, this matches the default thread size of Active Record. +# and maximum; this matches the default thread size of Active Record. # threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } threads threads_count, threads_count -# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. # port ENV.fetch("PORT") { 3000 } @@ -42,9 +42,9 @@ environment ENV.fetch("RAILS_ENV") { "development" } # The code in the `on_worker_boot` will be called if you are using # clustered mode by specifying a number of `workers`. After each worker -# process is booted this block will be run, if you are using `preload_app!` -# option you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, Ruby +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby # cannot share connections between processes. # # on_worker_boot do -- cgit v1.2.3 From 0d20530e5edfd7d00fbc2a38ef5f87eca6ccc924 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 8 Dec 2016 10:33:23 -0800 Subject: Make Yarn the default, drop default vendor/asset directories (#27300) --- railties/CHANGELOG.md | 3 +- railties/lib/rails/generators/app_base.rb | 53 +--------------------- .../rails/generators/rails/app/app_generator.rb | 33 ++++---------- .../app/assets/javascripts/application.js.tt | 4 +- .../app/assets/stylesheets/application.css | 4 +- .../generators/rails/app/templates/bin/setup.tt | 4 +- .../generators/rails/app/templates/bin/update.tt | 4 +- .../app/templates/config/initializers/assets.rb.tt | 2 +- .../rails/generators/rails/app/templates/gitignore | 2 +- railties/test/generators/api_app_generator_test.rb | 1 - railties/test/generators/app_generator_test.rb | 35 +++++--------- 11 files changed, 34 insertions(+), 111 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index c445390cd3..0ba220104a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,4 @@ -* Add Yarn support in new apps using --yarn option. This adds a yarn binstub, vendor/package.json, - and the settings needed to get npm modules integrated in new apps. +* Add Yarn support in new apps with a yarn binstub and vendor/package.json. Skippable via --skip-yarn option. *Liceth Ovalles*, *Guillermo Iguaran*, *DHH* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 87f6f01750..aba68d6db2 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,8 +33,8 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" - class_option :yarn, type: :boolean, default: false, - desc: "Preconfigure for assets management with Yarn" + class_option :skip_yarn, type: :boolean, default: false, + desc: "Don't use Yarn for managing JavaScript dependencies" class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile" @@ -414,55 +414,6 @@ module Rails bundle_command("install") if bundle_install? end - def run_yarn - if package_json_exist? - if yarn_path - say_status :run, "yarn install" - yarn_command("install") - else - say_status :warning, "yarn option passed but Yarn executable was not detected in the system.", :yellow - say_status :warning, "Download Yarn at https://yarnpkg.com/en/docs/install", :yellow - end - end - end - - def package_json_exist? - File.exist?("vendor/package.json") - end - - def yarn_path - commands = ["yarn"] - - if Gem.win_platform? - ENV["PATHEXT"].split(File::PATH_SEPARATOR).each do |ext| - commands << commands[0] + ext - end - end - - yarn_path = commands.find do |cmd| - paths = ENV["PATH"].split(File::PATH_SEPARATOR) - - path = paths.find do |p| - full_path = File.expand_path(cmd, p) - File.executable?(full_path) && File.file?(full_path) - end - - path && File.expand_path(cmd, path) - end - - yarn_path - end - - def yarn_command(command) - full_command = "#{yarn_path} #{command}" - - if options[:quiet] - system(full_command, out: File::NULL) - else - system(full_command) - end - end - def generate_spring_binstubs if bundle_install? && spring_install? bundle_command("exec spring binstub --all") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 49d23d682a..20bc45fee8 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -53,10 +53,6 @@ module Rails template "gitignore", ".gitignore" end - def packagejson - template "package.json", "vendor/package.json" - end - def app directory "app" @@ -155,23 +151,12 @@ module Rails end def vendor - if options[:yarn] - empty_directory_with_keep_file "vendor" - else - vendor_javascripts - vendor_stylesheets - end - end + empty_directory_with_keep_file "vendor" - def vendor_javascripts - unless options[:skip_javascript] - empty_directory_with_keep_file "vendor/assets/javascripts" + unless options[:skip_yarn] + template "package.json", "vendor/package.json" end end - - def vendor_stylesheets - empty_directory_with_keep_file "vendor/assets/stylesheets" - end end module Generators @@ -213,9 +198,8 @@ module Rails build(:readme) build(:rakefile) build(:configru) - build(:packagejson) if options[:yarn] - build(:gitignore) unless options[:skip_git] - build(:gemfile) unless options[:skip_gemfile] + build(:gitignore) unless options[:skip_git] + build(:gemfile) unless options[:skip_gemfile] end def create_app_files @@ -276,6 +260,10 @@ module Rails def create_vendor_files build(:vendor) + + if options[:skip_yarn] + remove_file "vendor/package.json" + end end def delete_app_assets_if_api_option @@ -283,7 +271,6 @@ module Rails remove_dir "app/assets" remove_dir "lib/assets" remove_dir "tmp/cache/assets" - remove_dir "vendor/assets" end end @@ -364,7 +351,7 @@ module Rails end public_task :apply_rails_template, :run_bundle - public_task :run_yarn, :generate_spring_binstubs + public_task :generate_spring_binstubs def run_after_bundle_callbacks @after_bundle_callbacks.each(&:call) diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 8db5b7e075..25870f19c8 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -1,8 +1,8 @@ // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css index 0ebd7fe829..865300bef9 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css @@ -2,8 +2,8 @@ * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 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 73b0732463..e4ba83a129 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -16,8 +16,8 @@ chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% if options[:yarn] %> - system! 'bin/yarn' +<% unless options[:skip_yarn] %> + system('bin/yarn') # Ignore failure from yarn not being installed <% end %> <% unless options.skip_active_record -%> 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 dcd80b6ce5..cc188315a8 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -16,8 +16,8 @@ chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% if options[:yarn] %> - system! 'bin/yarn' +<% unless options[:skip_yarn] %> + system('bin/yarn') # Ignore failure from yarn not being installed <% end %> <% unless options.skip_active_record -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index 29d9df6ad4..f5d03fb117 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -<%- if options[:yarn] -%> +<%- unless options[:skip_yarn] -%> # Add Yarn node_modules folder to the asset load path. Rails.application.config.assets.paths << Rails.root.join('vendor/node_modules') <%- end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index dee42ebb87..709b341387 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -21,7 +21,7 @@ !/tmp/.keep <% end -%> -<% if options[:yarn] -%> +<% unless options[:skip_yarn] -%> /vendor/node_modules <% end -%> diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 7069a07bbe..dc2872e45e 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -108,7 +108,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase config/initializers/assets.rb config/initializers/cookies_serializer.rb lib/assets - vendor/assets test/helpers tmp/cache/assets public/404.html diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 15a923676d..d7c9ae5266 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -43,9 +43,6 @@ DEFAULT_APP_FILES = %w( test/mailers test/integration vendor - vendor/assets - vendor/assets/stylesheets - vendor/assets/javascripts tmp tmp/cache tmp/cache/assets @@ -466,7 +463,6 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-javascript"] assert_no_file "app/assets/javascripts" - assert_no_file "vendor/assets/javascripts" assert_file "app/views/layouts/application.html.erb" do |contents| assert_match(/stylesheet_link_tag\s+'application', media: 'all' %>/, contents) @@ -492,12 +488,21 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_generator_if_yarn_option_is_given - run_generator([destination_root, "--yarn"]) + def test_generator_for_yarn + run_generator([destination_root]) assert_file "vendor/package.json", /dependencies/ assert_file "config/initializers/assets.rb", /node_modules/ end + def test_generator_for_yarn_skipped + run_generator([destination_root]) + assert_no_file "vendor/package.json" + + assert_file "config/environments/production.rb" do |content| + assert_no_match(/node_modules/, content) + end + end + def test_inclusion_of_jbuilder run_generator assert_gem "jbuilder" @@ -618,10 +623,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_generates_with_bundler end - def test_generation_runs_yarn_install_with_yarn_option - assert_generates_with_yarn yarn: true - end - def test_dev_option assert_generates_with_bundler dev: true rails_path = File.expand_path("../../..", Rails.root) @@ -847,18 +848,4 @@ class AppGeneratorTest < Rails::Generators::TestCase quietly { generator.invoke_all } end end - - def assert_generates_with_yarn(options = {}) - generator([destination_root], options) - - command_check = -> command do - @install_called ||= 0 - @install_called += 1 - assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" - end - - generator.stub :yarn_command, command_check do - quietly { generator.invoke_all } - end - end end -- cgit v1.2.3 From fbd33b911acd5a4487f37dc1df2aad439c090bfa Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Fri, 9 Dec 2016 12:07:40 +0900 Subject: specify `skip_yarn` option in API-only Application (#27309) --- railties/lib/rails/generators/rails/app/app_generator.rb | 10 ++++++++-- railties/test/generators/api_app_generator_test.rb | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 20bc45fee8..a8586d56dd 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -186,9 +186,11 @@ module Rails raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}." end - # Force sprockets to be skipped when generating API only apps. + # Force sprockets and yarn to be skipped when generating API only apps. # Can't modify options hash as it's frozen by default. - self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze if options[:api] + if options[:api] + self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze + end end public_task :set_default_accessors! @@ -346,6 +348,10 @@ module Rails end end + def delete_bin_yarn_if_api_option + remove_file "bin/yarn" if options[:api] + end + def finish_template build(:leftovers) end diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index dc2872e45e..c54d9cc599 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -105,6 +105,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase %w(app/assets app/helpers app/views/layouts/application.html.erb + bin/yarn config/initializers/assets.rb config/initializers/cookies_serializer.rb lib/assets @@ -115,6 +116,8 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase public/500.html public/apple-touch-icon-precomposed.png public/apple-touch-icon.png - public/favicon.ico) + public/favicon.icon + vendor/package.json + ) end end -- cgit v1.2.3 From 23f99ed7eb602c05952e53bc14afb9e692f7053d Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Fri, 9 Dec 2016 12:08:13 +0900 Subject: fix broken tests (#27308) Follow up to 0d20530e5edfd7d00fbc2a38ef5f87eca6ccc924 --- railties/test/generators/app_generator_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index d7c9ae5266..9285a9f091 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -495,10 +495,10 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_generator_for_yarn_skipped - run_generator([destination_root]) + run_generator([destination_root, "--skip-yarn"]) assert_no_file "vendor/package.json" - assert_file "config/environments/production.rb" do |content| + assert_file "config/initializers/assets.rb" do |content| assert_no_match(/node_modules/, content) end end @@ -741,7 +741,6 @@ class AppGeneratorTest < Rails::Generators::TestCase test/helpers test/integration tmp - vendor/assets/stylesheets ) folders_with_keep.each do |folder| assert_file("#{folder}/.keep") -- cgit v1.2.3 From 8d99c896e0b3cf0e55bf90a562945fa58886b85c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 8 Dec 2016 19:48:11 -0800 Subject: Fix ability to run railties test suite --- railties/Rakefile | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/Rakefile b/railties/Rakefile index 202644fb26..680ed03f75 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -18,6 +18,7 @@ namespace :test do "lib", "#{File.dirname(__FILE__)}/../activesupport/lib", "#{File.dirname(__FILE__)}/../actionpack/lib", + "#{File.dirname(__FILE__)}/../actionview/lib", "#{File.dirname(__FILE__)}/../activemodel/lib" ] ruby "-w", "-I#{dash_i.join ':'}", file -- cgit v1.2.3 From c873746c506e193cf6294d8919d464997d54eadb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 8 Dec 2016 19:49:15 -0800 Subject: Only have Yarn bundling commented out as we cant be sure Yarn is installed --- railties/lib/rails/generators/rails/app/templates/bin/setup.tt | 3 ++- railties/lib/rails/generators/rails/app/templates/bin/update.tt | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'railties') 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 e4ba83a129..c6607dbb2b 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -17,7 +17,8 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') <% unless options[:skip_yarn] %> - system('bin/yarn') # Ignore failure from yarn not being installed + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') <% end %> <% unless options.skip_active_record -%> 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 cc188315a8..d23af018c7 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -16,10 +16,6 @@ chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% unless options[:skip_yarn] %> - system('bin/yarn') # Ignore failure from yarn not being installed - -<% end %> <% unless options.skip_active_record -%> puts "\n== Updating database ==" system! 'bin/rails db:migrate' -- cgit v1.2.3 From 872faa958398fa5aaf6b0e4cd6a8090503d6885a Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 9 Dec 2016 10:46:28 -0500 Subject: Show message if Yarn is not installed (#27312) --- railties/lib/rails/generators/rails/app/templates/bin/yarn | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/bin/yarn b/railties/lib/rails/generators/rails/app/templates/bin/yarn index cf48e2e5b7..872438cecb 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/yarn +++ b/railties/lib/rails/generators/rails/app/templates/bin/yarn @@ -1,2 +1,9 @@ VENDOR_PATH = File.expand_path('../vendor', __dir__) -Dir.chdir(VENDOR_PATH) { exec "yarnpkg #{ARGV.join(" ")}" } +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(" ")}" + rescue Errno::ENOENT + puts "Yarn executable was not detected in the system." + puts "Download Yarn at https://yarnpkg.com/en/docs/install" + end +end -- cgit v1.2.3 From 8c947eb6e95f50ae88e19c0f036bd4a3d3b2dece Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 9 Dec 2016 12:19:43 -0800 Subject: Basic --webpack delegation to new webpacker gem (#27288) --- railties/lib/rails/generators/app_base.rb | 15 +++++++++++++++ railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index aba68d6db2..2f7339e7f5 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,6 +33,9 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" + class_option :webpack, type: :boolean, default: false, + desc: "Preconfigure for app-like JavaScript with Webpack" + class_option :skip_yarn, type: :boolean, default: false, desc: "Don't use Yarn for managing JavaScript dependencies" @@ -128,6 +131,7 @@ module Rails database_gemfile_entry, webserver_gemfile_entry, assets_gemfile_entry, + webpacker_gemfile_entry, javascript_gemfile_entry, jbuilder_gemfile_entry, psych_gemfile_entry, @@ -315,6 +319,13 @@ module Rails gems end + def webpacker_gemfile_entry + if options[:webpack] + comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" + GemfileEntry.new "webpacker", "~> 0.1", comment + end + end + def jbuilder_gemfile_entry comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder" GemfileEntry.new "jbuilder", "~> 2.5", comment, {}, options[:api] @@ -414,6 +425,10 @@ module Rails bundle_command("install") if bundle_install? end + def run_webpack + rails_command "webpacker:install" + end + def generate_spring_binstubs if bundle_install? && spring_install? bundle_command("exec spring binstub --all") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a8586d56dd..19d3ba2f0f 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -357,7 +357,7 @@ module Rails end public_task :apply_rails_template, :run_bundle - public_task :generate_spring_binstubs + public_task :run_webpack, :generate_spring_binstubs def run_after_bundle_callbacks @after_bundle_callbacks.each(&:call) -- cgit v1.2.3 From ecddc0468d6cacd06faaa474d11f96f41b17ac78 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 9 Dec 2016 13:33:45 -0800 Subject: Use GitHub webpacker until closer to release --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 2f7339e7f5..187f4555a2 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -322,7 +322,7 @@ module Rails def webpacker_gemfile_entry if options[:webpack] comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" - GemfileEntry.new "webpacker", "~> 0.1", comment + GemfileEntry.github "webpacker", "rails/webpacker", nil, comment end end -- cgit v1.2.3 From c16296c79556ac660a0d7bd2df95e348a9e8df31 Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Sat, 10 Dec 2016 09:21:28 +0900 Subject: gemfile entry method need to return an empty array rather than nil (#27318) This fixes the following error when executing rails new command. ``` (erb):9:in `block in template': undefined method `comment' for nil:NilClass (NoMethodError) ``` Follow up to #27288 --- railties/lib/rails/generators/app_base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 187f4555a2..578aa23513 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -320,10 +320,10 @@ module Rails end def webpacker_gemfile_entry - if options[:webpack] - comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" - GemfileEntry.github "webpacker", "rails/webpacker", nil, comment - end + return [] unless options[:webpack] + + comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" + GemfileEntry.github "webpacker", "rails/webpacker", nil, comment end def jbuilder_gemfile_entry -- cgit v1.2.3 From c2c840fa6b66a43959901235ca7b3995528e4dac Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 10 Dec 2016 10:46:24 +0900 Subject: run `webpack` command only when webpack option is specified --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 578aa23513..576c36fc86 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -426,7 +426,7 @@ module Rails end def run_webpack - rails_command "webpacker:install" + rails_command "webpacker:install" if options[:webpack] end def generate_spring_binstubs -- cgit v1.2.3 From f1878baad5e8f6bc49d1c37dd5afb917b79985f4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 12 Dec 2016 20:28:39 +0900 Subject: :nail_care: Don't expect the caller of this method to know that the return value has an extra " " --- .../lib/rails/generators/rails/controller/controller_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index ced3c85c00..4f60e44888 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -16,7 +16,7 @@ module Rails unless options[:skip_routes] actions.reverse_each do |action| # route prepends two spaces onto the front of the string that is passed, this corrects that. - route generate_routing_code(action)[2..-1] + route generate_routing_code(action) end end end @@ -40,7 +40,7 @@ module Rails # namespace :bar do namespace_ladder = regular_class_path.each_with_index.map do |ns, i| indent(" namespace :#{ns} do\n", i * 2) - end.join + end.join[2..-1] # Create route # get 'baz/index' -- cgit v1.2.3 From edf4bff77cfc157afe7201a45c6b16652cdcceb8 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 12 Dec 2016 21:34:22 +0900 Subject: Oops! namespace_ladder can be nil here --- railties/lib/rails/generators/rails/controller/controller_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 4f60e44888..01214dc919 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -54,7 +54,7 @@ module Rails end.join # Combine the 3 parts to generate complete route entry - namespace_ladder + route + end_ladder + "#{namespace_ladder}#{route}#{end_ladder}" end end end -- cgit v1.2.3 From cfdf6e13689c67a108b1f3980f59a4e3933369c3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 12 Dec 2016 11:07:28 -0800 Subject: Add option to trigger JS framework-specific installation as part of webpack setup --- railties/CHANGELOG.md | 12 ++++++++++++ railties/lib/rails/generators/app_base.rb | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 0ba220104a..8a1a440fca 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,15 @@ +* Add Webpack support in new apps via the --webpack option, which will delegate to the rails/webpacker gem. + + To generate a new app that has Webpack dependencies configured and binstubs for webpack and webpack-watcher: + + rails new myapp --webpack + + To generate a new app that has Webpack + React configured and an example intalled: + + rails new myapp --webpack=react + + *DHH* + * Add Yarn support in new apps with a yarn binstub and vendor/package.json. Skippable via --skip-yarn option. *Liceth Ovalles*, *Guillermo Iguaran*, *DHH* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 576c36fc86..b94630de15 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,7 +33,7 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" - class_option :webpack, type: :boolean, default: false, + class_option :webpack, type: :string, default: "base", desc: "Preconfigure for app-like JavaScript with Webpack" class_option :skip_yarn, type: :boolean, default: false, @@ -426,7 +426,10 @@ module Rails end def run_webpack - rails_command "webpacker:install" if options[:webpack] + if !(webpack = options[:webpack]).nil? + rails_command "webpacker:install" + rails_command "webpacker:install:#{webpack}" unless webpack == "base" + end end def generate_spring_binstubs -- cgit v1.2.3 From 1373f9bdcf725f75832dc7401994cc76113a8a4e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 12 Dec 2016 21:10:50 +0100 Subject: Don't assign a default to `webpack`. Unintentionally makes `--webpack` implied on `rails new apper`. If passed `--webpack` Thor assigns `"webpack"` to `options[:webpack]`, so we can check for that instead of `"base"`. --- railties/lib/rails/generators/app_base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index b94630de15..15cc070e35 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,7 +33,7 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" - class_option :webpack, type: :string, default: "base", + class_option :webpack, type: :string, default: nil, desc: "Preconfigure for app-like JavaScript with Webpack" class_option :skip_yarn, type: :boolean, default: false, @@ -428,7 +428,7 @@ module Rails def run_webpack if !(webpack = options[:webpack]).nil? rails_command "webpacker:install" - rails_command "webpacker:install:#{webpack}" unless webpack == "base" + rails_command "webpacker:install:#{webpack}" unless webpack == "webpack" end end -- cgit v1.2.3 From 92dae5dfda9b72e748bb00f38603e8fda403089a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 14 Dec 2016 11:11:32 +0900 Subject: use appropriate type for `rc` option This fixes the following warning. ``` Expected boolean default value for '--rc'; got "~/.railsrc" (string) ``` --- railties/lib/rails/commands/plugin/plugin_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/plugin/plugin_command.rb b/railties/lib/rails/commands/plugin/plugin_command.rb index 16587ce067..b40ab006af 100644 --- a/railties/lib/rails/commands/plugin/plugin_command.rb +++ b/railties/lib/rails/commands/plugin/plugin_command.rb @@ -11,7 +11,7 @@ module Rails "#{executable} new [options]" end - class_option :rc, type: :boolean, default: File.join("~", ".railsrc"), + class_option :rc, type: :string, default: File.join("~", ".railsrc"), desc: "Initialize the plugin command with previous defaults. Uses .railsrc in your home directory by default." class_option :no_rc, desc: "Skip evaluating .railsrc." -- cgit v1.2.3 From a0d4d78884a6e7c89b582e9555ed2bb30db9d438 Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Wed, 14 Dec 2016 19:09:01 +0900 Subject: Remove unused method `namespaced_file_path` ``` $ git grep namespaced_file_path railties/lib/rails/generators/named_base.rb: def namespaced_file_path railties/lib/rails/generators/named_base.rb: @namespaced_file_path ||= namespaced_class_path.join("/") ``` --- railties/lib/rails/generators/named_base.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 45f2fba5b9..70f63dc672 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -90,10 +90,6 @@ module Rails @class_path end - def namespaced_file_path - @namespaced_file_path ||= namespaced_class_path.join("/") - end - def namespaced_class_path @namespaced_class_path ||= [namespaced_path] + @class_path end -- cgit v1.2.3 From fa69b2c03582f5817572050a4373e365d9071b5d Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Fri, 16 Dec 2016 20:10:21 -0500 Subject: `ARGV.shift` before calling Rails generators Gems like rspec-rails depend on `ARGV` being shifted, and `scaffold` (for example) not being the first item in `ARGV`. This should allow rspec-rails to be passing on Rails master. --- railties/lib/rails/commands/generate/generate_command.rb | 2 ++ railties/test/application/generators_test.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 59b2febc43..aa8dab71b0 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -14,6 +14,8 @@ module Rails require_application_and_environment! load_generators + ARGV.shift + Rails::Generators.invoke generator, args, behavior: :invoke, destination_root: Rails::Command.root end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0153f94504..d75577c5f6 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -169,5 +169,20 @@ module ApplicationTests assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.text.erb")) assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.html.erb")) end + + test "ARGV is mutated as expected" do + require "#{app_path}/config/environment" + Rails::Command.const_set("APP_PATH", "rails/all") + + FileUtils.cd(rails_root) do + ARGV = ["mailer", "notifier", "foo"] + Rails::Command.const_set("ARGV", ARGV) + Rails::Command.invoke :generate, ARGV + + assert_equal ["notifier", "foo"], ARGV + end + + Rails::Command.send(:remove_const, "APP_PATH") + end end end -- cgit v1.2.3 From c79c40ed82186fc5000cf5beea697b286422bcdb Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Mon, 19 Dec 2016 21:24:12 -0500 Subject: Limit length of secret being passed Very similar to PR #25758, see more in depth reasoning there. --- railties/test/application/middleware/session_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index 0e4acfdcec..959a629ede 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -173,7 +173,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 1, encryptor.decrypt_and_verify(last_response.body)["foo"] @@ -222,7 +222,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 1, encryptor.decrypt_and_verify(last_response.body)["foo"] @@ -281,7 +281,7 @@ module ApplicationTests secret = app.key_generator.generate_key("encrypted cookie") sign_secret = app.key_generator.generate_key("signed encrypted cookie") - encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret) + encryptor = ActiveSupport::MessageEncryptor.new(secret[0, ActiveSupport::MessageEncryptor.key_len], sign_secret) get "/foo/read_raw_cookie" assert_equal 2, encryptor.decrypt_and_verify(last_response.body)["foo"] -- cgit v1.2.3 From baa8c5ad0fb3f860388eeec4421ccb8afa0096a8 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 22 Dec 2016 11:01:15 +0900 Subject: quiet generators log in test This quiet the following log. ``` create app/mailers/notifier_mailer.rb invoke erb create app/views/notifier_mailer identical app/views/layouts/mailer.text.erb identical app/views/layouts/mailer.html.erb create app/views/notifier_mailer/foo.text.erb create app/views/notifier_mailer/foo.html.erb invoke test_unit create test/mailers/notifier_mailer_test.rb create test/mailers/previews/notifier_mailer_preview.rb ``` --- railties/test/application/generators_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index d75577c5f6..d2ce14f594 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -177,7 +177,7 @@ module ApplicationTests FileUtils.cd(rails_root) do ARGV = ["mailer", "notifier", "foo"] Rails::Command.const_set("ARGV", ARGV) - Rails::Command.invoke :generate, ARGV + quietly { Rails::Command.invoke :generate, ARGV } assert_equal ["notifier", "foo"], ARGV end -- cgit v1.2.3 From 21e5fd4a2a1c162ad33708d3e01b1fda165f204d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 19 Dec 2016 19:10:49 +0900 Subject: Describe what we are protecting --- railties/lib/rails/generators/named_base.rb | 2 ++ railties/lib/rails/generators/resource_helpers.rb | 2 ++ 2 files changed, 4 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 70f63dc672..7b9095c7b1 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -32,6 +32,8 @@ module Rails end end + # TODO Change this to private once we've dropped Ruby 2.2 support. + # Workaround for Ruby 2.2 "private attribute?" warning. protected attr_reader :file_name diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index a28977319a..bbfda09bb4 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -23,6 +23,8 @@ module Rails assign_controller_names!(controller_name.pluralize) end + # TODO Change this to private once we've dropped Ruby 2.2 support. + # Workaround for Ruby 2.2 "private attribute?" warning. protected attr_reader :controller_name, :controller_file_name -- cgit v1.2.3 From 10fb7211bb4e7df5b796da489df8b056b95178d4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 23:45:39 +0900 Subject: Privatize unneededly protected methods in Railties tests --- railties/test/application/loading_test.rb | 2 +- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 2 +- railties/test/generators/named_base_test.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 2 +- railties/test/rails_info_test.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 38f96f3ab9..c75a25bc6f 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -357,7 +357,7 @@ class LoadingTest < ActiveSupport::TestCase assert Rails.application.initialized? end - protected + private def setup_ar! ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 0a26897a4d..360e8e97d7 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -369,7 +369,7 @@ F assert_equal("", action(:log, :yes, "YES")) end - protected + private def action(*args, &block) capture(:stdout) { generator.send(*args, &block) } diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9285a9f091..079ee3765c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -788,7 +788,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_equal 3, @sequence_step end - protected + private def stub_rails_application(root) Rails.application.config.root = root diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 0258b3b9d7..3015b5363b 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -131,7 +131,7 @@ class NamedBaseTest < Rails::Generators::TestCase assert_name g, "admin.foos", :controller_i18n_scope end - protected + private def assert_name(generator, value, method) assert_equal value, generator.send(method) diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index a0018dc782..9921a80342 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -714,7 +714,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end - protected + private def action(*args, &block) silence(:stdout) { generator.send(*args, &block) } diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 59e79de41a..9f4c5bb025 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -54,7 +54,7 @@ class InfoTest < ActiveSupport::TestCase end end - protected + private def properties Rails::Info.properties end -- cgit v1.2.3 From 87ec7009bfdaad292a18b8bbdc9b25522bb9b1a1 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 24 Dec 2016 23:53:46 +0900 Subject: `protected` here doesn't protect anything there aren't any instance method defined in this class --- railties/lib/rails/generators.rb | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 67037106e5..28f8078a9d 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -275,38 +275,37 @@ module Rails end end - protected - def self.print_list(base, namespaces) - namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } - super - end - - # Try fallbacks for the given base. - def self.invoke_fallbacks_for(name, base) #:nodoc: - return nil unless base && fallbacks[base.to_sym] - invoked_fallbacks = [] + def self.print_list(base, namespaces) + namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } + super + end - Array(fallbacks[base.to_sym]).each do |fallback| - next if invoked_fallbacks.include?(fallback) - invoked_fallbacks << fallback + # Try fallbacks for the given base. + def self.invoke_fallbacks_for(name, base) #:nodoc: + return nil unless base && fallbacks[base.to_sym] + invoked_fallbacks = [] - klass = find_by_namespace(name, fallback) - return klass if klass - end + Array(fallbacks[base.to_sym]).each do |fallback| + next if invoked_fallbacks.include?(fallback) + invoked_fallbacks << fallback - nil + klass = find_by_namespace(name, fallback) + return klass if klass end - def self.command_type - @command_type ||= "generator" - end + nil + end - def self.lookup_paths - @lookup_paths ||= %w( rails/generators generators ) - end + def self.command_type + @command_type ||= "generator" + end - def self.file_lookup_paths - @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] - end + def self.lookup_paths + @lookup_paths ||= %w( rails/generators generators ) + end + + def self.file_lookup_paths + @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] + end end end -- cgit v1.2.3 From f9caa5a6dd99275aa9400ab64813a850a26a0386 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 24 Dec 2016 23:58:00 +0900 Subject: Prefer class << self; def over def self. --- railties/lib/rails/generators.rb | 400 +++++++++++++++++++-------------------- 1 file changed, 200 insertions(+), 200 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 28f8078a9d..04f4908f52 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -67,245 +67,245 @@ module Rails } } - def self.configure!(config) #:nodoc: - api_only! if config.api_only - no_color! unless config.colorize_logging - aliases.deep_merge! config.aliases - options.deep_merge! config.options - fallbacks.merge! config.fallbacks - templates_path.concat config.templates - templates_path.uniq! - hide_namespaces(*config.hidden_namespaces) - end + class << self + def configure!(config) #:nodoc: + api_only! if config.api_only + no_color! unless config.colorize_logging + aliases.deep_merge! config.aliases + options.deep_merge! config.options + fallbacks.merge! config.fallbacks + templates_path.concat config.templates + templates_path.uniq! + hide_namespaces(*config.hidden_namespaces) + end - def self.templates_path #:nodoc: - @templates_path ||= [] - end + def templates_path #:nodoc: + @templates_path ||= [] + end - def self.aliases #:nodoc: - @aliases ||= DEFAULT_ALIASES.dup - end + def aliases #:nodoc: + @aliases ||= DEFAULT_ALIASES.dup + end - def self.options #:nodoc: - @options ||= DEFAULT_OPTIONS.dup - end + def options #:nodoc: + @options ||= DEFAULT_OPTIONS.dup + end - # Hold configured generators fallbacks. If a plugin developer wants a - # generator group to fallback to another group in case of missing generators, - # they can add a fallback. - # - # For example, shoulda is considered a test_framework and is an extension - # of test_unit. However, most part of shoulda generators are similar to - # test_unit ones. - # - # Shoulda then can tell generators to search for test_unit generators when - # some of them are not available by adding a fallback: - # - # Rails::Generators.fallbacks[:shoulda] = :test_unit - def self.fallbacks - @fallbacks ||= {} - end + # Hold configured generators fallbacks. If a plugin developer wants a + # generator group to fallback to another group in case of missing generators, + # they can add a fallback. + # + # For example, shoulda is considered a test_framework and is an extension + # of test_unit. However, most part of shoulda generators are similar to + # test_unit ones. + # + # Shoulda then can tell generators to search for test_unit generators when + # some of them are not available by adding a fallback: + # + # Rails::Generators.fallbacks[:shoulda] = :test_unit + def fallbacks + @fallbacks ||= {} + end - # Configure generators for API only applications. It basically hides - # everything that is usually browser related, such as assets and session - # migration generators, and completely disable helpers and assets - # so generators such as scaffold won't create them. - def self.api_only! - hide_namespaces "assets", "helper", "css", "js" - - options[:rails].merge!( - api: true, - assets: false, - helper: false, - template_engine: nil - ) - - if ARGV.first == "mailer" - options[:rails].merge!(template_engine: :erb) + # Configure generators for API only applications. It basically hides + # everything that is usually browser related, such as assets and session + # migration generators, and completely disable helpers and assets + # so generators such as scaffold won't create them. + def api_only! + hide_namespaces "assets", "helper", "css", "js" + + options[:rails].merge!( + api: true, + assets: false, + helper: false, + template_engine: nil + ) + + if ARGV.first == "mailer" + options[:rails].merge!(template_engine: :erb) + end end - end - # Remove the color from output. - def self.no_color! - Thor::Base.shell = Thor::Shell::Basic - end + # Remove the color from output. + def no_color! + Thor::Base.shell = Thor::Shell::Basic + end - # Returns an array of generator namespaces that are hidden. - # Generator namespaces may be hidden for a variety of reasons. - # Some are aliased such as "rails:migration" and can be - # invoked with the shorter "migration", others are private to other generators - # such as "css:scaffold". - def self.hidden_namespaces - @hidden_namespaces ||= begin - orm = options[:rails][:orm] - test = options[:rails][:test_framework] - template = options[:rails][:template_engine] - css = options[:rails][:stylesheet_engine] - - [ - "rails", - "resource_route", - "#{orm}:migration", - "#{orm}:model", - "#{test}:controller", - "#{test}:helper", - "#{test}:integration", - "#{test}:mailer", - "#{test}:model", - "#{test}:scaffold", - "#{test}:view", - "#{test}:job", - "#{template}:controller", - "#{template}:scaffold", - "#{template}:mailer", - "#{css}:scaffold", - "#{css}:assets", - "css:assets", - "css:scaffold" - ] + # Returns an array of generator namespaces that are hidden. + # Generator namespaces may be hidden for a variety of reasons. + # Some are aliased such as "rails:migration" and can be + # invoked with the shorter "migration", others are private to other generators + # such as "css:scaffold". + def hidden_namespaces + @hidden_namespaces ||= begin + orm = options[:rails][:orm] + test = options[:rails][:test_framework] + template = options[:rails][:template_engine] + css = options[:rails][:stylesheet_engine] + + [ + "rails", + "resource_route", + "#{orm}:migration", + "#{orm}:model", + "#{test}:controller", + "#{test}:helper", + "#{test}:integration", + "#{test}:mailer", + "#{test}:model", + "#{test}:scaffold", + "#{test}:view", + "#{test}:job", + "#{template}:controller", + "#{template}:scaffold", + "#{template}:mailer", + "#{css}:scaffold", + "#{css}:assets", + "css:assets", + "css:scaffold" + ] + end end - end - class << self def hide_namespaces(*namespaces) hidden_namespaces.concat(namespaces) end alias hide_namespace hide_namespaces - end - # Show help message with available generators. - def self.help(command = "generate") - puts "Usage: rails #{command} GENERATOR [args] [options]" - puts - puts "General options:" - puts " -h, [--help] # Print generator's options and usage" - puts " -p, [--pretend] # Run but do not make any changes" - puts " -f, [--force] # Overwrite files that already exist" - puts " -s, [--skip] # Skip files that already exist" - puts " -q, [--quiet] # Suppress status output" - puts - puts "Please choose a generator below." - puts - - print_generators - end + # Show help message with available generators. + def help(command = "generate") + puts "Usage: rails #{command} GENERATOR [args] [options]" + puts + puts "General options:" + puts " -h, [--help] # Print generator's options and usage" + puts " -p, [--pretend] # Run but do not make any changes" + puts " -f, [--force] # Overwrite files that already exist" + puts " -s, [--skip] # Skip files that already exist" + puts " -q, [--quiet] # Suppress status output" + puts + puts "Please choose a generator below." + puts + + print_generators + end - def self.public_namespaces - lookup! - subclasses.map(&:namespace) - end + def public_namespaces + lookup! + subclasses.map(&:namespace) + end - def self.print_generators - sorted_groups.each { |b, n| print_list(b, n) } - end + def print_generators + sorted_groups.each { |b, n| print_list(b, n) } + end - def self.sorted_groups - namespaces = public_namespaces - namespaces.sort! + def sorted_groups + namespaces = public_namespaces + namespaces.sort! - groups = Hash.new { |h, k| h[k] = [] } - namespaces.each do |namespace| - base = namespace.split(":").first - groups[base] << namespace - end + groups = Hash.new { |h, k| h[k] = [] } + namespaces.each do |namespace| + base = namespace.split(":").first + groups[base] << namespace + end - rails = groups.delete("rails") - rails.map! { |n| n.sub(/^rails:/, "") } - rails.delete("app") - rails.delete("plugin") + rails = groups.delete("rails") + rails.map! { |n| n.sub(/^rails:/, "") } + rails.delete("app") + rails.delete("plugin") - hidden_namespaces.each { |n| groups.delete(n.to_s) } + hidden_namespaces.each { |n| groups.delete(n.to_s) } - [[ "rails", rails ]] + groups.sort.to_a - end + [[ "rails", rails ]] + groups.sort.to_a + end - # Rails finds namespaces similar to thor, it only adds one rule: - # - # Generators names must end with "_generator.rb". This is required because Rails - # looks in load paths and loads the generator just before it's going to be used. - # - # find_by_namespace :webrat, :rails, :integration - # - # Will search for the following generators: - # - # "rails:webrat", "webrat:integration", "webrat" - # - # Notice that "rails:generators:webrat" could be loaded as well, what - # Rails looks for is the first and last parts of the namespace. - def self.find_by_namespace(name, base = nil, context = nil) #:nodoc: - lookups = [] - lookups << "#{base}:#{name}" if base - lookups << "#{name}:#{context}" if context - - unless base || context - unless name.to_s.include?(?:) - lookups << "#{name}:#{name}" - lookups << "rails:#{name}" + # Rails finds namespaces similar to thor, it only adds one rule: + # + # Generators names must end with "_generator.rb". This is required because Rails + # looks in load paths and loads the generator just before it's going to be used. + # + # find_by_namespace :webrat, :rails, :integration + # + # Will search for the following generators: + # + # "rails:webrat", "webrat:integration", "webrat" + # + # Notice that "rails:generators:webrat" could be loaded as well, what + # Rails looks for is the first and last parts of the namespace. + def find_by_namespace(name, base = nil, context = nil) #:nodoc: + lookups = [] + lookups << "#{base}:#{name}" if base + lookups << "#{name}:#{context}" if context + + unless base || context + unless name.to_s.include?(?:) + lookups << "#{name}:#{name}" + lookups << "rails:#{name}" + end + lookups << "#{name}" end - lookups << "#{name}" - end - lookup(lookups) + lookup(lookups) + + namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }] + lookups.each do |namespace| - namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }] - lookups.each do |namespace| + klass = namespaces[namespace] + return klass if klass + end - klass = namespaces[namespace] - return klass if klass + invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name) end - invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name) - end + # Receives a namespace, arguments and the behavior to invoke the generator. + # It's used as the default entry point for generate, destroy and update + # commands. + def invoke(namespace, args = ARGV, config = {}) + names = namespace.to_s.split(":") + if klass = find_by_namespace(names.pop, names.any? && names.join(":")) + args << "--help" if args.empty? && klass.arguments.any?(&:required?) + klass.start(args, config) + else + options = sorted_groups.flat_map(&:last) + suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3) + msg = "Could not find generator '#{namespace}'. " + msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n" + msg << "Run `rails generate --help` for more options." + puts msg + end + end - # Receives a namespace, arguments and the behavior to invoke the generator. - # It's used as the default entry point for generate, destroy and update - # commands. - def self.invoke(namespace, args = ARGV, config = {}) - names = namespace.to_s.split(":") - if klass = find_by_namespace(names.pop, names.any? && names.join(":")) - args << "--help" if args.empty? && klass.arguments.any?(&:required?) - klass.start(args, config) - else - options = sorted_groups.flat_map(&:last) - suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3) - msg = "Could not find generator '#{namespace}'. " - msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n" - msg << "Run `rails generate --help` for more options." - puts msg + def print_list(base, namespaces) + namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } + super end - end - def self.print_list(base, namespaces) - namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } - super - end + # Try fallbacks for the given base. + def invoke_fallbacks_for(name, base) #:nodoc: + return nil unless base && fallbacks[base.to_sym] + invoked_fallbacks = [] - # Try fallbacks for the given base. - def self.invoke_fallbacks_for(name, base) #:nodoc: - return nil unless base && fallbacks[base.to_sym] - invoked_fallbacks = [] + Array(fallbacks[base.to_sym]).each do |fallback| + next if invoked_fallbacks.include?(fallback) + invoked_fallbacks << fallback - Array(fallbacks[base.to_sym]).each do |fallback| - next if invoked_fallbacks.include?(fallback) - invoked_fallbacks << fallback + klass = find_by_namespace(name, fallback) + return klass if klass + end - klass = find_by_namespace(name, fallback) - return klass if klass + nil end - nil - end - - def self.command_type - @command_type ||= "generator" - end + def command_type + @command_type ||= "generator" + end - def self.lookup_paths - @lookup_paths ||= %w( rails/generators generators ) - end + def lookup_paths + @lookup_paths ||= %w( rails/generators generators ) + end - def self.file_lookup_paths - @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] + def file_lookup_paths + @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] + end end end end -- cgit v1.2.3 From 6b049057f0e7b21235ee88900d56f99ac527eecf Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 25 Dec 2016 00:00:08 +0900 Subject: Privatize some methods that were originally protected --- railties/lib/rails/generators.rb | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 04f4908f52..e1980a42ad 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -274,38 +274,40 @@ module Rails end end - def print_list(base, namespaces) - namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } - super - end + private - # Try fallbacks for the given base. - def invoke_fallbacks_for(name, base) #:nodoc: - return nil unless base && fallbacks[base.to_sym] - invoked_fallbacks = [] + def print_list(base, namespaces) # :doc: + namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } + super + end - Array(fallbacks[base.to_sym]).each do |fallback| - next if invoked_fallbacks.include?(fallback) - invoked_fallbacks << fallback + # Try fallbacks for the given base. + def invoke_fallbacks_for(name, base) + return nil unless base && fallbacks[base.to_sym] + invoked_fallbacks = [] - klass = find_by_namespace(name, fallback) - return klass if klass - end + Array(fallbacks[base.to_sym]).each do |fallback| + next if invoked_fallbacks.include?(fallback) + invoked_fallbacks << fallback - nil - end + klass = find_by_namespace(name, fallback) + return klass if klass + end - def command_type - @command_type ||= "generator" - end + nil + end - def lookup_paths - @lookup_paths ||= %w( rails/generators generators ) - end + def command_type # :doc: + @command_type ||= "generator" + end - def file_lookup_paths - @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] - end + def lookup_paths # :doc: + @lookup_paths ||= %w( rails/generators generators ) + end + + def file_lookup_paths # :doc: + @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] + end end end end -- cgit v1.2.3 From d1daf4c31301f5f5917b877fd63a817f5f4608ed Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 19:20:01 +0900 Subject: Privatize unneededly protected methods in Railties --- railties/lib/rails/application_controller.rb | 2 +- railties/lib/rails/command.rb | 8 +-- railties/lib/rails/command/behavior.rb | 12 ++-- .../rails/commands/dbconsole/dbconsole_command.rb | 6 +- railties/lib/rails/engine.rb | 26 ++++---- railties/lib/rails/generators/actions.rb | 10 +-- .../rails/generators/actions/create_migration.rb | 6 +- railties/lib/rails/generators/app_base.rb | 30 ++++----- railties/lib/rails/generators/base.rb | 24 +++---- railties/lib/rails/generators/erb.rb | 2 +- .../generators/erb/mailer/mailer_generator.rb | 2 +- .../generators/erb/scaffold/scaffold_generator.rb | 2 +- railties/lib/rails/generators/named_base.rb | 74 +++++++++++----------- .../rails/generators/rails/app/app_generator.rb | 4 +- .../generators/rails/assets/assets_generator.rb | 2 +- .../rails/generator/generator_generator.rb | 2 +- .../generators/rails/plugin/plugin_generator.rb | 2 +- railties/lib/rails/generators/resource_helpers.rb | 2 + .../test_unit/generator/generator_generator.rb | 2 +- .../test_unit/mailer/mailer_generator.rb | 2 +- railties/lib/rails/generators/testing/behaviour.rb | 10 +-- railties/lib/rails/mailers_controller.rb | 10 +-- railties/lib/rails/rack/logger.rb | 24 ++++--- railties/lib/rails/railtie.rb | 5 +- railties/lib/rails/railtie/configurable.rb | 2 +- 25 files changed, 136 insertions(+), 135 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application_controller.rb b/railties/lib/rails/application_controller.rb index f8394b8e0a..a98e51fd28 100644 --- a/railties/lib/rails/application_controller.rb +++ b/railties/lib/rails/application_controller.rb @@ -2,7 +2,7 @@ class Rails::ApplicationController < ActionController::Base # :nodoc: self.view_paths = File.expand_path("../templates", __FILE__) layout "application" - protected + private def require_local! unless local_request? diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 6065e78fd1..ddb953543f 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -82,16 +82,16 @@ module Rails [[ "rails", rails ]] + groups.sort.to_a end - protected - def command_type + private + def command_type # :doc: @command_type ||= "command" end - def lookup_paths + def lookup_paths # :doc: @lookup_paths ||= %w( rails/commands commands ) end - def file_lookup_paths + def file_lookup_paths # :doc: @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_command.rb" ] end end diff --git a/railties/lib/rails/command/behavior.rb b/railties/lib/rails/command/behavior.rb index 2e8517070c..4a92f72f16 100644 --- a/railties/lib/rails/command/behavior.rb +++ b/railties/lib/rails/command/behavior.rb @@ -16,13 +16,13 @@ module Rails @subclasses ||= [] end - protected + private # This code is based directly on the Text gem implementation. # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher. # # Returns a value representing the "cost" of transforming str1 into str2. - def levenshtein_distance(str1, str2) + def levenshtein_distance(str1, str2) # :doc: s = str1 t = str2 n = s.length @@ -58,7 +58,7 @@ module Rails end # Prints a list of generators. - def print_list(base, namespaces) #:nodoc: + def print_list(base, namespaces) return if namespaces.empty? puts "#{base.camelize}:" @@ -71,7 +71,7 @@ module Rails # Receives namespaces in an array and tries to find matching generators # in the load path. - def lookup(namespaces) #:nodoc: + def lookup(namespaces) paths = namespaces_to_paths(namespaces) paths.each do |raw_path| @@ -91,7 +91,7 @@ module Rails end # This will try to load any command in the load path to show in help. - def lookup! #:nodoc: + def lookup! $LOAD_PATH.each do |base| Dir[File.join(base, *file_lookup_paths)].each do |path| begin @@ -107,7 +107,7 @@ module Rails # Convert namespaces to paths by replacing ":" for "/" and adding # an extra lookup. For example, "rails:model" should be searched # in both: "rails/model/model_generator" and "rails/model_generator". - def namespaces_to_paths(namespaces) #:nodoc: + def namespaces_to_paths(namespaces) paths = [] namespaces.each do |namespace| pieces = namespace.split(":") diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 35e8673215..588fb06b15 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -99,14 +99,14 @@ module Rails Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment end - protected - def configurations + private + def configurations # :doc: require APP_PATH ActiveRecord::Base.configurations = Rails.application.config.database_configuration ActiveRecord::Base.configurations end - def find_cmd_and_exec(commands, *args) + def find_cmd_and_exec(commands, *args) # :doc: commands = Array(commands) dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index e56f6159ad..2dd1fb3273 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -643,18 +643,20 @@ module Rails protected - def load_config_initializer(initializer) - ActiveSupport::Notifications.instrument("load_config_initializer.railties", initializer: initializer) do - load(initializer) - end - end - def run_tasks_blocks(*) #:nodoc: super paths["lib/tasks"].existent.sort.each { |ext| load(ext) } end - def has_migrations? #:nodoc: + private + + def load_config_initializer(initializer) # :doc: + ActiveSupport::Notifications.instrument("load_config_initializer.railties", initializer: initializer) do + load(initializer) + end + end + + def has_migrations? paths["db/migrate"].existent.any? end @@ -671,24 +673,22 @@ module Rails Pathname.new File.realpath root end - def default_middleware_stack #:nodoc: + def default_middleware_stack ActionDispatch::MiddlewareStack.new end - def _all_autoload_once_paths #:nodoc: + def _all_autoload_once_paths config.autoload_once_paths end - def _all_autoload_paths #:nodoc: + def _all_autoload_paths @_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq end - def _all_load_paths #:nodoc: + def _all_load_paths @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq end - private - def build_request(env) env.merge!(env_config) req = ActionDispatch::Request.new env diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 8a60560f86..d058d82cea 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -260,12 +260,12 @@ module Rails @after_bundle_callbacks << block end - protected + private # Define log for backwards compatibility. If just one argument is sent, # invoke say, otherwise invoke say_status. Differently from say and # similarly to say_status, this method respects the quiet? option given. - def log(*args) + def log(*args) # :doc: if args.size == 1 say args.first.to_s unless options.quiet? else @@ -276,7 +276,7 @@ module Rails # Runs the supplied command using either "rake ..." or "rails ..." # based on the executor parameter provided. - def execute_command(executor, command, options = {}) + def execute_command(executor, command, options = {}) # :doc: log executor, command env = options[:env] || ENV["RAILS_ENV"] || "development" sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : "" @@ -284,7 +284,7 @@ module Rails end # Add an extension to the given name based on the platform. - def extify(name) + def extify(name) # :doc: if Gem.win_platform? "#{name}.bat" else @@ -294,7 +294,7 @@ module Rails # Surround string with single quotes if there is no quotes. # Otherwise fall back to double quotes - def quote(value) + def quote(value) # :doc: return value.inspect unless value.is_a? String if value.include?("'") diff --git a/railties/lib/rails/generators/actions/create_migration.rb b/railties/lib/rails/generators/actions/create_migration.rb index 587c61fd42..f677e545e5 100644 --- a/railties/lib/rails/generators/actions/create_migration.rb +++ b/railties/lib/rails/generators/actions/create_migration.rb @@ -37,9 +37,9 @@ module Rails end alias :exists? :existing_migration - protected + private - def on_conflict_behavior + def on_conflict_behavior # :doc: options = base.options.merge(config) if identical? say_status :identical, :blue, relative_existing_migration @@ -60,7 +60,7 @@ module Rails end end - def say_status(status, color, message = relative_destination) + def say_status(status, color, message = relative_destination) # :doc: base.shell.say_status(status, message, color) if config[:verbose] end end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 15cc070e35..5c809807a1 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -108,9 +108,9 @@ module Rails convert_database_option_for_jruby end - protected + private - def gemfile_entry(name, *args) + def gemfile_entry(name, *args) # :doc: options = args.extract_options! version = args.first github = options[:github] @@ -126,7 +126,7 @@ module Rails self end - def gemfile_entries + def gemfile_entries # :doc: [rails_gemfile_entry, database_gemfile_entry, webserver_gemfile_entry, @@ -139,13 +139,13 @@ module Rails @extra_entries].flatten.find_all(&@gem_filter) end - def add_gem_entry_filter + def add_gem_entry_filter # :doc: @gem_filter = lambda { |next_filter, entry| yield(entry) && next_filter.call(entry) }.curry[@gem_filter] end - def builder + def builder # :doc: @builder ||= begin builder_class = get_builder_class builder_class.include(ActionMethods) @@ -153,24 +153,24 @@ module Rails end end - def build(meth, *args) + def build(meth, *args) # :doc: builder.send(meth, *args) if builder.respond_to?(meth) end - def create_root + def create_root # :doc: valid_const? empty_directory "." FileUtils.cd(destination_root) unless options[:pretend] end - def apply_rails_template + def apply_rails_template # :doc: apply rails_template if rails_template rescue Thor::Error, LoadError, Errno::ENOENT => e raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}" end - def set_default_accessors! + def set_default_accessors! # :doc: self.destination_root = File.expand_path(app_path, destination_root) self.rails_template = \ case options[:template] @@ -183,32 +183,32 @@ module Rails end end - def database_gemfile_entry + def database_gemfile_entry # :doc: return [] if options[:skip_active_record] gem_name, gem_version = gem_for_database GemfileEntry.version gem_name, gem_version, "Use #{options[:database]} as the database for Active Record" end - def webserver_gemfile_entry + def webserver_gemfile_entry # :doc: return [] if options[:skip_puma] comment = "Use Puma as the app server" GemfileEntry.new("puma", "~> 3.0", comment) end - def include_all_railties? + def include_all_railties? # :doc: options.values_at(:skip_active_record, :skip_action_mailer, :skip_test, :skip_sprockets, :skip_action_cable).none? end - def comment_if(value) + def comment_if(value) # :doc: options[value] ? "# " : "" end - def keeps? + def keeps? # :doc: !options[:skip_keeps] end - def sqlite3? + def sqlite3? # :doc: !options[:skip_active_record] && options[:database] == "sqlite3" end diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index c707bbfcbf..cc6ae3860f 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -239,11 +239,11 @@ module Rails end end - protected + private # Check whether the given class names are already taken by user # application or Ruby on Rails. - def class_collisions(*class_names) #:nodoc: + def class_collisions(*class_names) return unless behavior == :invoke class_names.flatten.each do |class_name| @@ -264,7 +264,7 @@ module Rails end # Takes in an array of nested modules and extracts the last module - def extract_last_module(nesting) + def extract_last_module(nesting) # :doc: nesting.inject(Object) do |last_module, nest| break unless last_module.const_defined?(nest, false) last_module.const_get(nest) @@ -272,12 +272,12 @@ module Rails end # Use Rails default banner. - def self.banner + def self.banner # :doc: "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ") end # Sets the base_name taking into account the current class namespace. - def self.base_name + def self.base_name # :doc: @base_name ||= begin if base = name.to_s.split("::").first base.underscore @@ -287,7 +287,7 @@ module Rails # Removes the namespaces and get the generator name. For example, # Rails::Generators::ModelGenerator will return "model" as generator name. - def self.generator_name + def self.generator_name # :doc: @generator_name ||= begin if generator = name.to_s.split("::").last generator.sub!(/Generator$/, "") @@ -298,18 +298,18 @@ module Rails # Returns the default value for the option name given doing a lookup in # Rails::Generators.options. - def self.default_value_for_option(name, options) + def self.default_value_for_option(name, options) # :doc: default_for_option(Rails::Generators.options, name, options, options[:default]) end # Returns default aliases for the option name given doing a lookup in # Rails::Generators.aliases. - def self.default_aliases_for_option(name, options) + def self.default_aliases_for_option(name, options) # :doc: default_for_option(Rails::Generators.aliases, name, options, options[:aliases]) end # Returns default for the option name given doing a lookup in config. - def self.default_for_option(config, name, options, default) + def self.default_for_option(config, name, options, default) # :doc: if generator_name && (c = config[generator_name.to_sym]) && c.key?(name) c[name] elsif base_name && (c = config[base_name.to_sym]) && c.key?(name) @@ -343,7 +343,7 @@ module Rails # Small macro to add ruby as an option to the generator with proper # default value plus an instance helper method called shebang. - def self.add_shebang_option! + def self.add_shebang_option! # :doc: class_option :ruby, type: :string, aliases: "-r", default: Thor::Util.ruby_command, desc: "Path to the Ruby binary of your choice", banner: "PATH" @@ -361,7 +361,7 @@ module Rails } end - def self.usage_path + def self.usage_path # :doc: paths = [ source_root && File.expand_path("../USAGE", source_root), default_generator_root && File.join(default_generator_root, "USAGE") @@ -369,7 +369,7 @@ module Rails paths.compact.detect { |path| File.exist? path } end - def self.default_generator_root + def self.default_generator_root # :doc: path = File.expand_path(File.join(base_name, generator_name), base_root) path if File.exist?(path) end diff --git a/railties/lib/rails/generators/erb.rb b/railties/lib/rails/generators/erb.rb index d01502002f..d5e326d6ee 100644 --- a/railties/lib/rails/generators/erb.rb +++ b/railties/lib/rails/generators/erb.rb @@ -3,7 +3,7 @@ require "rails/generators/named_base" module Erb # :nodoc: module Generators # :nodoc: class Base < Rails::Generators::NamedBase #:nodoc: - protected + private def formats [format] diff --git a/railties/lib/rails/generators/erb/mailer/mailer_generator.rb b/railties/lib/rails/generators/erb/mailer/mailer_generator.rb index f150240908..677f8041ae 100644 --- a/railties/lib/rails/generators/erb/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/erb/mailer/mailer_generator.rb @@ -26,7 +26,7 @@ module Erb # :nodoc: end end - protected + private def formats [:text, :html] diff --git a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb index 154d85f381..0d77ef21da 100644 --- a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb @@ -21,7 +21,7 @@ module Erb # :nodoc: end end - protected + private def available_views %w(index edit show new _form) diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 7b9095c7b1..e3660b012a 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -37,138 +37,140 @@ module Rails protected attr_reader :file_name + private + # FIXME: We are avoiding to use alias because a bug on thor that make # this method public and add it to the task list. - def singular_name + def singular_name # :doc: file_name end # Wrap block with namespace of current application # if namespace exists and is not skipped - def module_namespacing(&block) + def module_namespacing(&block) # :doc: content = capture(&block) content = wrap_with_namespace(content) if namespaced? concat(content) end - def indent(content, multiplier = 2) + def indent(content, multiplier = 2) # :doc: spaces = " " * multiplier content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join end - def wrap_with_namespace(content) + def wrap_with_namespace(content) # :doc: content = indent(content).chomp "module #{namespace.name}\n#{content}\nend\n" end - def inside_template + def inside_template # :doc: @inside_template = true yield ensure @inside_template = false end - def inside_template? + def inside_template? # :doc: @inside_template end - def namespace + def namespace # :doc: Rails::Generators.namespace end - def namespaced? + def namespaced? # :doc: !options[:skip_namespace] && namespace end - def file_path + def file_path # :doc: @file_path ||= (class_path + [file_name]).join("/") end - def class_path + def class_path # :doc: inside_template? || !namespaced? ? regular_class_path : namespaced_class_path end - def regular_class_path + def regular_class_path # :doc: @class_path end - def namespaced_class_path + def namespaced_class_path # :doc: @namespaced_class_path ||= [namespaced_path] + @class_path end - def namespaced_path + def namespaced_path # :doc: @namespaced_path ||= namespace.name.split("::").first.underscore end - def class_name + def class_name # :doc: (class_path + [file_name]).map!(&:camelize).join("::") end - def human_name + def human_name # :doc: @human_name ||= singular_name.humanize end - def plural_name + def plural_name # :doc: @plural_name ||= singular_name.pluralize end - def i18n_scope + def i18n_scope # :doc: @i18n_scope ||= file_path.tr("/", ".") end - def table_name + def table_name # :doc: @table_name ||= begin base = pluralize_table_names? ? plural_name : singular_name (class_path + [base]).join("_") end end - def uncountable? + def uncountable? # :doc: singular_name == plural_name end - def index_helper + def index_helper # :doc: uncountable? ? "#{plural_table_name}_index" : plural_table_name end - def show_helper + def show_helper # :doc: "#{singular_table_name}_url(@#{singular_table_name})" end - def edit_helper + def edit_helper # :doc: "edit_#{show_helper}" end - def new_helper + def new_helper # :doc: "new_#{singular_table_name}_url" end - def singular_table_name + def singular_table_name # :doc: @singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name) end - def plural_table_name + def plural_table_name # :doc: @plural_table_name ||= (pluralize_table_names? ? table_name : table_name.pluralize) end - def plural_file_name + def plural_file_name # :doc: @plural_file_name ||= file_name.pluralize end - def fixture_file_name + def fixture_file_name # :doc: @fixture_file_name ||= (pluralize_table_names? ? plural_file_name : file_name) end - def route_url + def route_url # :doc: @route_url ||= class_path.collect { |dname| "/" + dname }.join + "/" + plural_file_name end - def url_helper_prefix + def url_helper_prefix # :doc: @url_helper_prefix ||= (class_path + [file_name]).join("_") end # Tries to retrieve the application name or simply return application. - def application_name + def application_name # :doc: if defined?(Rails) && Rails.application Rails.application.class.name.split("::").first.underscore else @@ -176,20 +178,20 @@ module Rails end end - def assign_names!(name) #:nodoc: + def assign_names!(name) @class_path = name.include?("/") ? name.split("/") : name.split("::") @class_path.map!(&:underscore) @file_name = @class_path.pop end # Convert attributes array into GeneratedAttribute objects. - def parse_attributes! #:nodoc: + def parse_attributes! self.attributes = (attributes || []).map do |attr| Rails::Generators::GeneratedAttribute.parse(attr) end end - def attributes_names + def attributes_names # :doc: @attributes_names ||= attributes.each_with_object([]) do |a, names| names << a.column_name names << "password_confirmation" if a.password_digest? @@ -197,11 +199,11 @@ module Rails end end - def pluralize_table_names? + def pluralize_table_names? # :doc: !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names end - def mountable_engine? + def mountable_engine? # :doc: defined?(ENGINE_ROOT) && namespaced? end @@ -215,7 +217,7 @@ module Rails # If the generator is invoked with class name Admin, it will check for # the presence of "AdminDecorator". # - def self.check_class_collision(options = {}) + def self.check_class_collision(options = {}) # :doc: define_method :check_class_collision do name = if self.respond_to?(:controller_class_name) # for ScaffoldBase controller_class_name diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 19d3ba2f0f..070a6ac124 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -363,12 +363,12 @@ module Rails @after_bundle_callbacks.each(&:call) end - protected - def self.banner "rails new #{arguments.map(&:usage).join(' ')} [options]" end + private + # Define file as an alias to create_file for backwards compatibility. def file(*args, &block) create_file(*args, &block) diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb index 265dada2ca..95d00c2d39 100644 --- a/railties/lib/rails/generators/rails/assets/assets_generator.rb +++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb @@ -7,7 +7,7 @@ module Rails class_option :javascript_engine, desc: "Engine for JavaScripts" class_option :stylesheet_engine, desc: "Engine for Stylesheets" - protected + private def asset_name file_name diff --git a/railties/lib/rails/generators/rails/generator/generator_generator.rb b/railties/lib/rails/generators/rails/generator/generator_generator.rb index 8040ec5e7b..299a7da5f1 100644 --- a/railties/lib/rails/generators/rails/generator/generator_generator.rb +++ b/railties/lib/rails/generators/rails/generator/generator_generator.rb @@ -12,7 +12,7 @@ module Rails hook_for :test_framework - protected + private def generator_dir if options[:namespace] diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 2186fa4ded..4cf4f8cd9a 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -286,7 +286,7 @@ task default: :test @namespaced_name ||= name.tr("-", "/") end - protected + private def create_dummy_app(path = nil) dummy_path(path) if path diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index bbfda09bb4..978b053308 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -29,6 +29,8 @@ module Rails attr_reader :controller_name, :controller_file_name + private + def controller_class_path if options[:model_name] @controller_class_path diff --git a/railties/lib/rails/generators/test_unit/generator/generator_generator.rb b/railties/lib/rails/generators/test_unit/generator/generator_generator.rb index 59f8d40343..6b6e094453 100644 --- a/railties/lib/rails/generators/test_unit/generator/generator_generator.rb +++ b/railties/lib/rails/generators/test_unit/generator/generator_generator.rb @@ -12,7 +12,7 @@ module TestUnit # :nodoc: template "generator_test.rb", File.join("test/lib/generators", class_path, "#{file_name}_generator_test.rb") end - protected + private def generator_path if options[:namespace] diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb index 806279788e..67bff8e4f9 100644 --- a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -17,7 +17,7 @@ module TestUnit # :nodoc: template "preview.rb", File.join("test/mailers/previews", class_path, "#{file_name}_mailer_preview.rb") end - protected + private def file_name @_file_name ||= super.gsub(/_mailer/i, "") end diff --git a/railties/lib/rails/generators/testing/behaviour.rb b/railties/lib/rails/generators/testing/behaviour.rb index a1e5a233b9..64d641d096 100644 --- a/railties/lib/rails/generators/testing/behaviour.rb +++ b/railties/lib/rails/generators/testing/behaviour.rb @@ -82,23 +82,23 @@ module Rails Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(":")) end - protected + private - def destination_root_is_set? # :nodoc: + def destination_root_is_set? raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root end - def ensure_current_path # :nodoc: + def ensure_current_path cd current_path end # Clears all files and directories in destination. - def prepare_destination + def prepare_destination # :doc: rm_rf(destination_root) mkdir_p(destination_root) end - def migration_file_name(relative) # :nodoc: + def migration_file_name(relative) absolute = File.expand_path(relative, destination_root) dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, "") Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first diff --git a/railties/lib/rails/mailers_controller.rb b/railties/lib/rails/mailers_controller.rb index 95de998208..000ce40fbc 100644 --- a/railties/lib/rails/mailers_controller.rb +++ b/railties/lib/rails/mailers_controller.rb @@ -40,12 +40,12 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: end end - protected - def show_previews? + private + def show_previews? # :doc: ActionMailer::Base.show_previews end - def find_preview + def find_preview # :doc: candidates = [] params[:path].to_s.scan(%r{/|$}) { candidates << $` } preview = candidates.detect { |candidate| ActionMailer::Preview.exists?(candidate) } @@ -57,7 +57,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: end end - def find_preferred_part(*formats) + def find_preferred_part(*formats) # :doc: formats.each do |format| if part = @email.find_first_mime_type(format) return part @@ -69,7 +69,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: end end - def find_part(format) + def find_part(format) # :doc: if part = @email.find_first_mime_type(format) part elsif @email.mime_type == format diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index e3fee75603..0fc202910c 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -27,9 +27,9 @@ module Rails end end - protected + private - def call_app(request, env) + def call_app(request, env) # :doc: instrumenter = ActiveSupport::Notifications.instrumenter instrumenter.start "request.action_dispatch", request: request logger.info { started_request_message(request) } @@ -44,7 +44,7 @@ module Rails end # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700 - def started_request_message(request) + def started_request_message(request) # :doc: 'Started %s "%s" for %s at %s' % [ request.request_method, request.filtered_path, @@ -52,7 +52,7 @@ module Rails Time.now.to_default_s ] end - def compute_tags(request) + def compute_tags(request) # :doc: @taggers.collect do |tag| case tag when Proc @@ -65,16 +65,14 @@ module Rails end end - private - - def finish(request) - instrumenter = ActiveSupport::Notifications.instrumenter - instrumenter.finish "request.action_dispatch", request: request - end + def finish(request) + instrumenter = ActiveSupport::Notifications.instrumenter + instrumenter.finish "request.action_dispatch", request: request + end - def logger - Rails.logger - end + def logger + Rails.logger + end end end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 696db61f01..474118c0a9 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -173,8 +173,8 @@ module Rails instance.configure(&block) end - protected - def generate_railtie_name(string) #:nodoc: + private + def generate_railtie_name(string) ActiveSupport::Inflector.underscore(string).tr("/", "_") end @@ -188,7 +188,6 @@ module Rails end end - private # receives an instance variable identifier, set the variable value if is # blank and append given block to value, which will be used later in # `#each_registered_block(type, &block)` diff --git a/railties/lib/rails/railtie/configurable.rb b/railties/lib/rails/railtie/configurable.rb index 39f1f87575..2a8295426e 100644 --- a/railties/lib/rails/railtie/configurable.rb +++ b/railties/lib/rails/railtie/configurable.rb @@ -24,7 +24,7 @@ module Rails class_eval(&block) end - protected + private def method_missing(*args, &block) instance.send(*args, &block) -- cgit v1.2.3 From e8ba0c0f21e2660b90f872fa4595156ca6190c77 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 25 Dec 2016 02:29:52 +0900 Subject: "Use assert_nil if expecting nil. This will fail in minitest 6." --- railties/test/application/assets_test.rb | 2 +- railties/test/application/configuration/custom_test.rb | 2 +- railties/test/application/configuration_test.rb | 6 +++--- railties/test/application/middleware_test.rb | 4 ++-- railties/test/commands/server_test.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index edd43503bf..f38cacd6da 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -384,7 +384,7 @@ module ApplicationTests get "/assets/demo.js" assert_match "alert()", last_response.body - assert_equal nil, last_response.headers["Set-Cookie"] + assert_nil last_response.headers["Set-Cookie"] end test "files in any assets/ directories are not added to Sprockets" do diff --git a/railties/test/application/configuration/custom_test.rb b/railties/test/application/configuration/custom_test.rb index 13fc98f0d6..3c675eec71 100644 --- a/railties/test/application/configuration/custom_test.rb +++ b/railties/test/application/configuration/custom_test.rb @@ -28,7 +28,7 @@ module ApplicationTests assert_equal 3, x.payment_processing.retries assert_equal true, x.super_debugger assert_equal false, x.hyper_debugger - assert_equal nil, x.nil_debugger + assert_nil x.nil_debugger assert_nil x.i_do_not_exist.zomg end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c409f1ea79..31c3b5cf52 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -614,7 +614,7 @@ module ApplicationTests app "development" assert_equal "b3c631c314c0bbca50c1b2843150fe33", app.config.secret_token - assert_equal nil, app.secrets.secret_key_base + assert_nil app.secrets.secret_key_base assert_equal app.key_generator.class, ActiveSupport::LegacyKeyGenerator end @@ -630,7 +630,7 @@ module ApplicationTests app "development" assert_equal "", app.config.secret_token - assert_equal nil, app.secrets.secret_key_base + assert_nil app.secrets.secret_key_base assert_raise ArgumentError, /\AA secret is required/ do app.key_generator end @@ -1204,7 +1204,7 @@ module ApplicationTests application.config.session_store :disabled end - assert_equal nil, app.config.session_store + assert_nil app.config.session_store end test "default session store initializer sets session store to cookie store" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 9baf7360a5..be41dcb299 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -246,7 +246,7 @@ module ApplicationTests get "/", {}, "HTTP_IF_NONE_MATCH" => etag assert_equal 304, last_response.status assert_equal "", last_response.body - assert_equal nil, last_response.headers["Content-Type"] + assert_nil last_response.headers["Content-Type"] assert_equal "max-age=0, private, must-revalidate", last_response.headers["Cache-Control"] assert_equal etag, last_response.headers["Etag"] @@ -255,7 +255,7 @@ module ApplicationTests assert_equal "", last_response.body assert_equal "text/plain; charset=utf-8", last_response.headers["Content-Type"] assert_equal "no-cache", last_response.headers["Cache-Control"] - assert_equal nil, last_response.headers["Etag"] + assert_nil last_response.headers["Etag"] end test "ORIGINAL_FULLPATH is passed to env" do diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 391886bf33..2e8076ed2b 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -63,7 +63,7 @@ class Rails::ServerTest < ActiveSupport::TestCase args = [] options = Rails::Server::Options.new.parse!(args) merged_options = Rails::Server.new.default_options.merge(options) - assert_equal nil, merged_options[:caching] + assert_nil merged_options[:caching] end def test_caching_with_option -- cgit v1.2.3 From f27edc84dfe714869a1702206c5c6e57a0810cfc Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sun, 25 Dec 2016 16:44:39 +1030 Subject: Correct indent-accounting in controller route generation Fixes #27447 [Matthew Draper & Yuuji Yaginuma] --- .../rails/controller/controller_generator.rb | 25 ++++++++++++---------- .../test/generators/controller_generator_test.rb | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 01214dc919..06bdb8b5ce 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -16,7 +16,7 @@ module Rails unless options[:skip_routes] actions.reverse_each do |action| # route prepends two spaces onto the front of the string that is passed, this corrects that. - route generate_routing_code(action) + route indent(generate_routing_code(action), 2)[2..-1] end end end @@ -34,27 +34,30 @@ module Rails # end # end def generate_routing_code(action) - depth = regular_class_path.length + depth = 0 + lines = [] + # Create 'namespace' ladder # namespace :foo do # namespace :bar do - namespace_ladder = regular_class_path.each_with_index.map do |ns, i| - indent(" namespace :#{ns} do\n", i * 2) - end.join[2..-1] + regular_class_path.each do |ns| + lines << indent("namespace :#{ns} do\n", depth * 2) + depth += 1 + end # Create route # get 'baz/index' - route = indent(%{ get '#{file_name}/#{action}'\n}, depth * 2) + lines << indent(%{get '#{file_name}/#{action}'\n}, depth * 2) # Create `end` ladder # end # end - end_ladder = (1..depth).reverse_each.map do |i| - indent("end\n", i * 2) - end.join + until depth.zero? + depth -= 1 + lines << indent("end\n", depth * 2) + end - # Combine the 3 parts to generate complete route entry - "#{namespace_ladder}#{route}#{end_ladder}" + lines.join end end end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 9b986a636a..af86a0136f 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -65,7 +65,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_add_routes run_generator - assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/ + assert_file "config/routes.rb", /^ get 'account\/foo'/, /^ get 'account\/bar'/ end def test_skip_routes -- cgit v1.2.3 From a46b2f8911c5730c8c56d487b65f7c5627d334ee Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 26 Dec 2016 11:04:41 +0900 Subject: assert_equal takes expectation first --- railties/test/railties/engine_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 70a6cd90b2..52d691b73b 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -890,7 +890,7 @@ YAML boot_rails - assert_equal AppTemplate.railtie_namespace, AppTemplate::Engine + assert_equal AppTemplate::Engine, AppTemplate.railtie_namespace end test "properly reload routes" do -- cgit v1.2.3 From 2053229456a6e585b9c62554c4bb4adac9c9fbe2 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 27 Dec 2016 08:32:03 -0500 Subject: Remove random extra spaces from Action Pack and Railties CHANGELOG.md [ci skip] --- railties/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 8a1a440fca..0ba62f9ef7 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -5,9 +5,9 @@ rails new myapp --webpack To generate a new app that has Webpack + React configured and an example intalled: - + rails new myapp --webpack=react - + *DHH* * Add Yarn support in new apps with a yarn binstub and vendor/package.json. Skippable via --skip-yarn option. -- cgit v1.2.3 From fab3a73af4e6f10f80cfd2a9004426c432394ddc Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 27 Dec 2016 08:34:45 -0500 Subject: Add backticks to show shell command [ci skip] --- railties/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 0ba62f9ef7..26660dd873 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -2,11 +2,11 @@ To generate a new app that has Webpack dependencies configured and binstubs for webpack and webpack-watcher: - rails new myapp --webpack + `rails new myapp --webpack` To generate a new app that has Webpack + React configured and an example intalled: - rails new myapp --webpack=react + `rails new myapp --webpack=react` *DHH* -- cgit v1.2.3 From 010e246756c09f44e901f4fd8e8eab2cb3022e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 28 Dec 2016 21:53:51 -0500 Subject: Fix Rubocop violations and fix documentation visibility Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API. --- railties/lib/rails/rack/logger.rb | 76 +++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 0fc202910c..853fc26051 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -29,50 +29,50 @@ module Rails private - def call_app(request, env) # :doc: - instrumenter = ActiveSupport::Notifications.instrumenter - instrumenter.start "request.action_dispatch", request: request - logger.info { started_request_message(request) } - resp = @app.call(env) - resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) } - resp - rescue Exception - finish(request) - raise - ensure - ActiveSupport::LogSubscriber.flush_all! - end + def call_app(request, env) # :doc: + instrumenter = ActiveSupport::Notifications.instrumenter + instrumenter.start "request.action_dispatch", request: request + logger.info { started_request_message(request) } + resp = @app.call(env) + resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) } + resp + rescue Exception + finish(request) + raise + ensure + ActiveSupport::LogSubscriber.flush_all! + end - # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700 - def started_request_message(request) # :doc: - 'Started %s "%s" for %s at %s' % [ - request.request_method, - request.filtered_path, - request.ip, - Time.now.to_default_s ] - end + # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700 + def started_request_message(request) # :doc: + 'Started %s "%s" for %s at %s' % [ + request.request_method, + request.filtered_path, + request.ip, + Time.now.to_default_s ] + end - def compute_tags(request) # :doc: - @taggers.collect do |tag| - case tag - when Proc - tag.call(request) - when Symbol - request.send(tag) - else - tag + def compute_tags(request) # :doc: + @taggers.collect do |tag| + case tag + when Proc + tag.call(request) + when Symbol + request.send(tag) + else + tag + end end end - end - def finish(request) - instrumenter = ActiveSupport::Notifications.instrumenter - instrumenter.finish "request.action_dispatch", request: request - end + def finish(request) + instrumenter = ActiveSupport::Notifications.instrumenter + instrumenter.finish "request.action_dispatch", request: request + end - def logger - Rails.logger - end + def logger + Rails.logger + end end end end -- cgit v1.2.3