Skip to content

Commit

Permalink
Merge pull request #27604 from prathamesh-sonpatki/dont-generate-erb-…
Browse files Browse the repository at this point in the history
…views-for-api-scaffold-controller

Don't generate HTML/ERB templates for scaffold controller with --api flag
  • Loading branch information
kaspth committed Jan 8, 2017
2 parents 80bf338 + b05fec0 commit ee47aab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
@@ -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*
Expand Down
Expand Up @@ -20,7 +20,12 @@ def create_controller_files
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|
Expand Down
Expand Up @@ -230,6 +230,12 @@ def test_api_only_generates_a_proper_api_controller
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
Expand Down

0 comments on commit ee47aab

Please sign in to comment.