Skip to content

clear cached templates between specs #864

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

Merged
merged 1 commit into from
Dec 6, 2013
Merged

clear cached templates between specs #864

merged 1 commit into from
Dec 6, 2013

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Dec 6, 2013

One of our cukes was failing because Rails caches templates and the differing
format seems not to be enough to invalidate it automatically, I'm going to
open a Rails patch for this but in the mean time this fixes that cuke.

@@ -152,6 +152,9 @@ def _include_controller_helpers
view.lookup_context.prefixes << _controller_path
end

# fixes bug with differing formats
view.lookup_context.view_paths.map(&:clear_cache)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be each(&:clear_cache), which I think makes more sense since you aren't storing the array returning by map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why I used map, I'll change it when the build finishes... (I want to see the state of it after)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woop! Green, I'll change this now then, wait for a second green then merge :)

One of our cukes was failing because Rails caches templates and the
differing format seems not to be enough to invalidate it automatically,
I'm going to open a Rails patch for this but in the mean time this fixes
that cuke.
JonRowe added a commit that referenced this pull request Dec 6, 2013
clear cached templates between specs
@JonRowe JonRowe merged commit e338e8d into master Dec 6, 2013
@JonRowe JonRowe deleted the fixup_view_caching branch December 6, 2013 02:52
@alindeman alindeman mentioned this pull request Dec 8, 2013
3 tasks
JonRowe added a commit that referenced this pull request Dec 14, 2013
clear cached templates between specs

Fixes the 2-99 build, see #864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Aug 27, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs
by about 50%. I think it’s sensible to use the view cache during
test because it’s normally on between requests in other environments,
and it looks like it was only turned off to work around this caching
issue.

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Aug 27, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs
by about 50%. I think it’s sensible to use the view cache during
test because it’s normally on between requests in other environments,
and it looks like it was only turned off to work around this caching
issue.

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
Rails expects the format to be a symbol. It filters formats against
`Mime::SET.symbols` so formats which are unknown (or are known but are
of an unexpected type) are not used in a cache keys for the Rails'
`ActionView::Resolver::Cache`. This made the view cache unusable when
there was multiple templates with the same name but different format
and was the the reason the cache was disabled in [1].

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs by 50%.

I think it’s sensible to use the view resolver cache during tests because
it’s normally on between requests in other environments including when
creating tests with  `ActionView::TestCase` in a new Rails application.
It looks like it was only turned off in rspec-rails to work around this
caching issue.

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
Rails expects the format to be a symbol. It filters formats against
`Mime::SET.symbols` so formats which are unknown (or are known but are
of an unexpected type) are not used in a cache keys for the Rails'
`ActionView::Resolver::Cache`. This made the view cache unusable when
there was multiple templates with the same name but different format
and was the the reason the cache was disabled in [1].

This isn't the only way of fixing this problem- for example Rails could
be changed to ensure symbols aren't compared with strings as was
suggested in [2], but I feel that it's rspec-rails' responsibility
to work with the existing Rails API.

[1] rspec#864
[2] rails/rails#13461
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs by 50%.

I think it’s sensible to use the view resolver cache during tests because
it’s normally on between requests in other environments including when
creating tests with  `ActionView::TestCase` in a new Rails application.
It looks like it was only turned off in rspec-rails to work around this
caching issue.

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
Rails expects value of the `:format` option be a symbol. It filters
formats against `Mime::SET.symbols` so formats which are unknown
(or are known but are of an unexpected type) are not used in cache keys
for the Rails' `ActionView::Resolver::Cache`. This made the resolver
cache unusable when there was multiple templates with the same name but
different formats and was the reason the cache was disabled in
rspec-rails [1].

This isn't the only way of fixing this problem- for example Rails could
be changed to ensure symbols aren't compared with strings as was
suggested in [2], but I feel that it's rspec-rails' responsibility
to work with the existing Rails API.

[1] rspec#864
[2] rails/rails#13461
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 2, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs by 50%.

I think it’s sensible to use the view resolver cache during tests because
it’s normally on between requests in other environments including when
creating tests with `ActionView::TestCase` in a new Rails application.
It looks like it was only turned off in rspec-rails to work around this
caching issue.

I haven't added any test coverage in this change since it feels like
it would be testing a negative (the resolver cache isn't cleared).

[1] rspec#864
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 21, 2015
Rails expects value of the `:format` option be a symbol. It filters
formats against `Mime::SET.symbols` so formats which are unknown
(or are known but are of an unexpected type) are not used in cache keys
for the Rails' `ActionView::Resolver::Cache`. This made the resolver
cache unusable when there was multiple templates with the same name but
different formats and was the reason the cache was disabled in
rspec-rails [1].

This isn't the only way of fixing this problem- for example Rails could
be changed to ensure symbols aren't compared with strings as was
suggested in [2], but I feel that it's rspec-rails' responsibility
to work with the existing Rails API.

[1] rspec#864
[2] rails/rails#13461
zetter added a commit to futurelearn/rspec-rails that referenced this pull request Sep 21, 2015
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs by 50%.

I think it’s sensible to use the view resolver cache during tests because
it’s normally on between requests in other environments including when
creating tests with `ActionView::TestCase` in a new Rails application.
It looks like it was only turned off in rspec-rails to work around this
caching issue.

I haven't added any test coverage in this change since it feels like
it would be testing a negative (the resolver cache isn't cleared).

[1] rspec#864
sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this pull request Mar 15, 2019
Rails expects value of the `:format` option be a symbol. It filters
formats against `Mime::SET.symbols` so formats which are unknown
(or are known but are of an unexpected type) are not used in cache keys
for the Rails' `ActionView::Resolver::Cache`. This made the resolver
cache unusable when there was multiple templates with the same name but
different formats and was the reason the cache was disabled in
rspec-rails [1].

This isn't the only way of fixing this problem- for example Rails could
be changed to ensure symbols aren't compared with strings as was
suggested in [2], but I feel that it's rspec-rails' responsibility
to work with the existing Rails API.

[1] rspec#864
[2] rails/rails#13461
sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this pull request Mar 15, 2019
The caching was turned off in [1] because different formats were being
cached under the same key. I believe the need to do this was removed
in the previous commit.

This reduces the time it takes to run FutureLearn’s view specs by 50%.

I think it’s sensible to use the view resolver cache during tests because
it’s normally on between requests in other environments including when
creating tests with `ActionView::TestCase` in a new Rails application.
It looks like it was only turned off in rspec-rails to work around this
caching issue.

I haven't added any test coverage in this change since it feels like
it would be testing a negative (the resolver cache isn't cleared).

[1] rspec#864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants