Skip to content

Commit

Permalink
Remove action_controller.perform_caching from api app's configs
Browse files Browse the repository at this point in the history
As suggested in rails#35602 (comment), because we don't provide view caching and doesn't include `ActionController::Caching` for api apps, we should also avoid generating

```ruby
config.action_controller.perform_caching = true
```

for those api apps. So it won't confuse people.

**But because `perform_caching` will be `true` if not set, the behavior of the app would still be the same without these configs.**
  • Loading branch information
st0012 committed Apr 23, 2019
1 parent 6a4eb3e commit d63f938
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Rails.application.configure do
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
<%- unless options.api? -%>
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

<%- end -%>
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Rails.application.configure do

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
<%- unless options.api? -%>
config.action_controller.perform_caching = true
<%- end -%>

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
Expand Down
7 changes: 7 additions & 0 deletions railties/test/generators/api_app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def test_api_modified_files

assert_file "config/application.rb", /config\.api_only = true/
assert_file "app/controllers/application_controller.rb", /ActionController::API/

assert_file "config/environments/development.rb" do |content|
assert_no_match(/action_controller\.perform_caching = true/, content)
end
assert_file "config/environments/production.rb" do |content|
assert_no_match(/action_controller\.perform_caching = true/, content)
end
end

def test_generator_if_skip_action_cable_is_given
Expand Down

0 comments on commit d63f938

Please sign in to comment.