-
Notifications
You must be signed in to change notification settings - Fork 526
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
Decorator spec can't access current_user when nil #857
Comments
Ah, I see the Not sure what's going on, or how this changes things. But looking at what that does, to see if I can figure out how to make it set up a |
This seems to work if I put it in my config.before(:each, type: :decorator) do
_stub_current_scope :user, nil
end Can't actually use the This will of course define a singleton method current_user on the fly. If I then have some tests that do want a non-nil current_user, and call This does seem to work... but is all a bit hacky. Should Draper document this better and/or support this better? It seems reasonable to want devise current_user to work for nil user in decorator tests, not just for when a particular user has been mocked as logged in with |
My decorators sometimes need to access the
current_user?
helper, from devise.If I mock a current user using Devise::Test::ControllerHelpers sign_in, like so:
That works, no problem. My decorators that access current_user get back that specified user when run under the spec, all is good.
But my app has public facing pages that have no signed in user, current_user is nil.
If I run a spec that has not done a Devise::Test::ControllerHelpers
sign_in
with a user -- because I am trying to test the scenario where there is no logged_in user, current_user is nil -- and that spec tries to exersize a decorator which asks forcurrent_user
, I get the dreaded:Very simple reproduction (Devise 4.6.2, Draper 3.1.0, Rails 5.2.3):
That will raise the Devise::MissingWarden
Is there a way to set up my :decorator specs so
h.current_user
works, even when I am not mocking a logged in user, I want no logged in user?Ideally it would be something I could set up globally that would Just Work, and then specs which do want a logged in user would use Devise::Test::ControllerHelpers#sign_in as ordinary. If I need to do completely different mutually exclusive set up for "a mocked logged in user" vs "no mocked logged in user, current_user should be nil", that would be unfortunate. But would still at least get my tests possible again!
The text was updated successfully, but these errors were encountered: