Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate HTML/ERB templates for scaffold controller with --api flag #27604

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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