1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add --skip-action-mailer (or -M) to rails generate

This commit is contained in:
claudiob 2014-12-31 14:10:26 +01:00
parent 4ba0e2fc22
commit b6f50b3fa8
10 changed files with 75 additions and 4 deletions

View file

@ -1,3 +1,7 @@
* Add `--skip-action-mailer` option to the app generator.
*claudiob*
* Autoload any second level directories called `app/*/concerns`.
*Alex Robbin*

View file

@ -38,6 +38,10 @@ module Rails
class_option :skip_keeps, type: :boolean, default: false,
desc: 'Skip source control .keep files'
class_option :skip_action_mailer, type: :boolean, aliases: "-M",
default: false,
desc: "Skip Action Mailer files"
class_option :skip_active_record, type: :boolean, aliases: '-O', default: false,
desc: 'Skip Active Record files'
@ -164,7 +168,7 @@ module Rails
end
def include_all_railties?
!options[:skip_active_record] && !options[:skip_test_unit] && !options[:skip_sprockets]
options.values_at(:skip_active_record, :skip_action_mailer, :skip_test_unit, :skip_sprockets).none?
end
def comment_if(value)

View file

@ -8,7 +8,7 @@ require "active_model/railtie"
require "active_job/railtie"
<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
<%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
require "action_view/railtie"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"

View file

@ -12,9 +12,11 @@ Rails.application.configure do
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
<%- unless options.skip_action_mailer? -%>
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
<%- end -%>
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

View file

@ -61,10 +61,12 @@ Rails.application.configure do
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
<%- unless options.skip_action_mailer? -%>
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
<%- end -%>
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).

View file

@ -25,11 +25,13 @@ Rails.application.configure do
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
<%- unless options.skip_action_mailer? -%>
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
<%- end -%>
# Randomize the order test cases are executed.
config.active_support.test_order = :random

View file

@ -74,7 +74,8 @@ task default: :test
end
PASSTHROUGH_OPTIONS = [
:skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
:skip_active_record, :skip_action_mailer, :skip_javascript, :database,
:javascript, :quiet, :pretend, :force, :skip
]
def generate_test_dummy(force = false)

View file

@ -6,7 +6,7 @@ require 'rails/all'
# Pick the frameworks you want:
<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
<%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
require "action_view/railtie"
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"

View file

@ -259,6 +259,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_generator_without_skips
run_generator
assert_file "config/application.rb", /\s+require\s+["']rails\/all["']/
assert_file "config/environments/development.rb" do |content|
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
end
assert_file "config/environments/test.rb" do |content|
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
end
end
def test_generator_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_no_file "config/database.yml"
@ -268,6 +282,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_generator_if_skip_action_mailer_is_given
run_generator [destination_root, "--skip-action-mailer"]
assert_file "config/application.rb", /#\s+require\s+["']action_mailer\/railtie["']/
assert_file "config/environments/development.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "config/environments/test.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
end
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
assert_no_file "config/initializers/assets.rb"

View file

@ -140,6 +140,20 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
def test_app_generator_without_skips
run_generator
assert_file "test/dummy/config/application.rb", /\s+require\s+["']rails\/all["']/
assert_file "test/dummy/config/environments/development.rb" do |content|
assert_match(/config\.action_mailer\.raise_delivery_errors = false/, content)
end
assert_file "test/dummy/config/environments/test.rb" do |content|
assert_match(/config\.action_mailer\.delivery_method = :test/, content)
end
assert_file "test/dummy/config/environments/production.rb" do |content|
assert_match(/# config\.action_mailer\.raise_delivery_errors = false/, content)
end
end
def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given
run_generator [destination_root, "--skip-active-record"]
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
@ -153,6 +167,20 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
def test_action_mailer_is_removed_from_frameworks_if_skip_action_mailer_is_given
run_generator [destination_root, "--skip-action-mailer"]
assert_file "test/dummy/config/application.rb", /#\s+require\s+["']action_mailer\/railtie["']/
assert_file "test/dummy/config/environments/development.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "test/dummy/config/environments/test.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
assert_file "test/dummy/config/environments/production.rb" do |content|
assert_no_match(/config\.action_mailer/, content)
end
end
def test_ensure_that_database_option_is_passed_to_app_generator
run_generator [destination_root, "--database", "postgresql"]
assert_file "test/dummy/config/database.yml", /postgres/