Skip to content


Browse files Browse the repository at this point in the history
Skip unused components when running in Rails plugin
  • Loading branch information
yhirano55 committed Aug 8, 2017
1 parent 220049f commit 62499cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions railties/
@@ -1,3 +1,7 @@
* Skip unused components when running `bin/rails` in Rails plugin.

*Yoshiyuki Hirano*

* Deprecate support of use `Rails::Application` subclass to start Rails server.

*Yuji Yaginuma*
Expand Down
15 changes: 15 additions & 0 deletions railties/lib/rails/generators/rails/plugin/templates/bin/
Expand Up @@ -9,5 +9,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'
14 changes: 13 additions & 1 deletion railties/test/generators/plugin_generator_test.rb
Expand Up @@ -75,6 +75,18 @@ def test_generating_without_options
assert_no_file "bin/rails"

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)
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["']/

def test_generating_test_files_in_full_mode
run_generator [destination_root, "--full"]
assert_directory "test/integration/"
Expand Down Expand Up @@ -277,7 +289,7 @@ def test_creating_engine_in_full_mode
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"/
Expand Down

0 comments on commit 62499cb

Please sign in to comment.