aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb11
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt2
-rw-r--r--railties/test/generators/api_app_generator_test.rb9
3 files changed, 21 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 6197b85bb6..d05fb55212 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -188,6 +188,10 @@ module Rails
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
end
+
+ # Force sprockets to be skipped when generating http only app.
+ # Can't modify options hash as it's frozen by default.
+ self.options = options.merge(skip_sprockets: true).freeze if options[:api]
end
public_task :set_default_accessors!
@@ -273,6 +277,13 @@ module Rails
end
end
+ def delete_non_api_initializers_if_api_option
+ if options[:api]
+ remove_file 'config/initializers/session_store.rb'
+ remove_file 'config/initializers/cookies_serializer.rb'
+ end
+ end
+
def finish_template
build(:leftovers)
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
index 94f612c3dd..0fc1514684 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
@@ -1,5 +1,6 @@
# Be sure to restart your server when you modify this file.
+<%- unless options[:api] -%>
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
@@ -7,6 +8,7 @@
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
+<%- end -%>
<%- unless options.skip_active_record? -%>
# To enable root element in JSON for ActiveRecord objects.
diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb
index d7121da45f..3c0c8054a4 100644
--- a/railties/test/generators/api_app_generator_test.rb
+++ b/railties/test/generators/api_app_generator_test.rb
@@ -38,6 +38,10 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
assert_no_match(/gem 'jquery-rails'/, content)
assert_no_match(/gem 'sass-rails'/, content)
end
+
+ assert_file "config/initializers/wrap_parameters.rb" do |content|
+ assert_no_match(/wrap_parameters/, content)
+ end
assert_file "app/controllers/application_controller.rb", /ActionController::API/
end
@@ -70,7 +74,10 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
end
def skipped_files
- %w(vendor/assets
+ %w(config/initializers/assets.rb
+ config/initializers/cookies_serializer.rb
+ config/initializers/session_store.rb
+ vendor/assets
tmp/cache/assets)
end
end