Clean view context when controller changes #799
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When we reassign controller it is the right thing to do to clear current view context stored in request store. Consider a case when view context was built before the request was made (usage of
h
helper in class level context). View context is built from default controller and has no information about the request. During first requestDraper::ViewContext.current.controller
will be different thanDraper::ViewContext.controller
.Testing
Example Rails app. Use
h.content_tag
in class context of some decorator, make this class be eagerly loaded.Perform some request that will execute some decorator to refer to e.g.
request.env
values that are set up by some middleware (e.g. warden manager).See that
env
is missing that key.With that fix, view_context is regenerated when a controller is already available.
To-Dos