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

Merge pull request #27604 from prathamesh-sonpatki/dont-generate-erb-views-for-api-scaffold-controller

Don't generate HTML/ERB templates for scaffold controller with --api flag
This commit is contained in:
Kasper Timm Hansen 2017-01-08 19:31:04 +01:00 committed by GitHub
commit ee47aab757
3 changed files with 18 additions and 1 deletions

View file

@ -1,3 +1,9 @@
* Don't generate HTML/ERB templates for scaffold controller with `--api` flag.
Fixes #27591.
*Prathamesh Sonpatki*
* Make `Rails.env` fall back to `development` when `RAILS_ENV` and `RACK_ENV` is an empty string.
*Daniel Deng*

View file

@ -20,7 +20,12 @@ module Rails
template template_file, File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
end
hook_for :template_engine, :test_framework, as: :scaffold
hook_for :template_engine, as: :scaffold do |template_engine|
invoke template_engine unless options.api?
end
hook_for :test_framework, as: :scaffold
# Invoke the helper using the controller name (pluralized)
hook_for :helper, as: :scaffold do |invoked|

View file

@ -230,6 +230,12 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
assert_match(/@user\.destroy/, m)
end
end
assert_no_file "app/views/users/index.html.erb"
assert_no_file "app/views/users/edit.html.erb"
assert_no_file "app/views/users/show.html.erb"
assert_no_file "app/views/users/new.html.erb"
assert_no_file "app/views/users/_form.html.erb"
end
def test_api_controller_tests