drapergem / draper

Decorators/View-Models for Rails Applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clearing Draper::ViewContext in RSpec

mapreal19 opened this issue · comments

I had an issue with some specs not clearing the ViewContext and hence having undefined h.current_user. It doesn't make sense to clear for every type of spec?

[:decorator, :controller, :mailer].each do |type|

The issue you are experiencing is actually due to the view context not being cleared after certain spec types. See the documentation in this pull request, as well as the referenced issue for more detail. Are you using decorators inside of jobs? That would be a scenario where the view context was built without current_user accessible and subsequent tests would fail.

Not using decorators inside jobs but it was a similar scenario. Thanks for the PR! I'll be useful for others.

Perfect. Glad we could help.