diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-11 17:50:21 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-11 17:50:21 -0400 |
commit | 84b6212a4ccdd4b5d6f1bc2f716e274738bb9d83 (patch) | |
tree | f721522e6227128187089b6b0f792a55b51e1441 /railties | |
parent | c85789ff59e6aef0b3bb39a7d1552e4137e24002 (diff) | |
parent | 62499cb6e088c3bc32a9396322c7473a17a28640 (diff) | |
download | rails-84b6212a4ccdd4b5d6f1bc2f716e274738bb9d83.tar.gz rails-84b6212a4ccdd4b5d6f1bc2f716e274738bb9d83.tar.bz2 rails-84b6212a4ccdd4b5d6f1bc2f716e274738bb9d83.zip |
Merge pull request #30116 from yhirano55/skip_unused_components_when_running_rails_command_in_plugin
Skip unused components when running `bin/rails` in Rails plugin
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt | 15 | ||||
-rw-r--r-- | railties/test/generators/plugin_generator_test.rb | 14 |
3 files changed, 32 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 509b8d20e3..335c0f227f 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Skip unused components when running `bin/rails` in Rails plugin. + + *Yoshiyuki Hirano* + * Add git_source to `Gemfile` for plugin generator. *Yoshiyuki Hirano* diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt index aed5adf8ee..b3264509fc 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt @@ -11,5 +11,20 @@ APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +<% if include_all_railties? -%> require 'rails/all' +<% else -%> +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +<%= comment_if :skip_active_record %>require "active_record/railtie" +require "action_controller/railtie" +<%= comment_if :skip_action_mailer %>require "action_mailer/railtie" +require "action_view/railtie" +require "active_storage/engine" +<%= comment_if :skip_action_cable %>require "action_cable/engine" +<%= comment_if :skip_sprockets %>require "sprockets/railtie" +<%= comment_if :skip_test %>require "rails/test_unit/railtie" +<% end -%> require 'rails/engine/commands' diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 6637c329c8..01a9168f38 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -75,6 +75,18 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_file "bin/rails" end + def test_generating_in_full_mode_with_almost_of_all_skip_options + run_generator [destination_root, "--full", "-M", "-O", "-C", "-S", "-T"] + assert_file "bin/rails" do |content| + assert_no_match(/\s+require\s+["']rails\/all["']/, content) + end + assert_file "bin/rails", /#\s+require\s+["']active_record\/railtie["']/ + assert_file "bin/rails", /#\s+require\s+["']action_mailer\/railtie["']/ + assert_file "bin/rails", /#\s+require\s+["']action_cable\/engine["']/ + assert_file "bin/rails", /#\s+require\s+["']sprockets\/railtie["']/ + assert_file "bin/rails", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + end + def test_generating_test_files_in_full_mode run_generator [destination_root, "--full"] assert_directory "test/integration/" @@ -325,7 +337,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "app/views" assert_file "app/helpers" assert_file "app/mailers" - assert_file "bin/rails" + assert_file "bin/rails", /\s+require\s+["']rails\/all["']/ assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ |