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

Cache compiled view templates when running tests by default #38269

Merged
merged 1 commit into from
Jan 21, 2020
Merged

Cache compiled view templates when running tests by default #38269

merged 1 commit into from
Jan 21, 2020

Conversation

jorgemanrubia
Copy link
Contributor

@jorgemanrubia jorgemanrubia commented Jan 21, 2020

Summary

When generating a new app without --skip-spring, caching classes is disabled in environments/test.rb. This implicitly disables caching view templates too. This change enables template caching by adding this to the generated environments/test.rb:

config.action_view.cache_template_loading = true

Other Information

I think disabling compiled templates caching was an unintended side effect of this commit.

We detected this problem because we were getting intermittent errors of this kind when running our suite of system tests:

undefined method `_app_views_layouts__nav_html_erb___3890178213482634628_149140

Investigating a little bit, we saw that the reason was that ActionView::CacheExpiry was clearing the cache when the list of view paths was modified during test execution. This was happening when referencing a mailer class that was using #append_view_path (loading that class was modifying the list of paths). I haven't been able to reproduce this problem with a simple app yet (to open a bug), but this tweak fixed the issue for us and I believe it's a better default for Rails.

cc @kaspth

@rails-bot rails-bot bot added the railties label Jan 21, 2020
When generating a new app without `--skip-spring`, caching classes was
disabled in `environments/test.rb`. This was implicitly disabling caching
view templates too. This change will enable view template caching by adding
this to the generated `environments/test.rb`:

    config.action_view.cache_template_loading = true

See 65344f2
@kaspth kaspth merged commit 6878863 into rails:master Jan 21, 2020
kaspth added a commit that referenced this pull request Jan 21, 2020
…tests

Cache compiled view templates when running tests by default
@kaspth
Copy link
Contributor

kaspth commented Jan 21, 2020

Perfect, thanks @jorgemanrubia 🙌 Backported to 6-0-stable in 77aea57

@kaspth
Copy link
Contributor

kaspth commented Jan 21, 2020

cc @fxn just for the record, since you were the author on the original commit 😊

@fxn
Copy link
Member

fxn commented Jan 21, 2020

🙌

@jorgemanrubia jorgemanrubia deleted the cache-view-templates-in-tests branch January 21, 2020 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants