Closed rastogiachyut closed 7 years ago
@waiting-for-dev How do I set env['PATH_INFO']?
What is subject
? env['PATH_INFO']
is set by rack, you don't have to set it.
Doesn't seem a warden-jwt_auth
issue. Please, don't hesitate to add more comments if you come back with more information pointing at the opposite.
@waiting-for-dev I am using devise-jwt for authentication, is there some additional configuration required for running my tests?
The above code is a test for a controller(a feature test), subject here refers to the controller being tested, devise injects the method current_user into it using controller_helpers.
@waiting-for-dev I am using devise-jwt for authentication, is there some additional configuration required for running my tests?
No, not additional configuration is needed. If you want to mock an authenticated request through devise-jwt
, just generate the token and add it to the request headers. You can use UserEncoder for that.
The above code is a test for a controller(a feature test), subject here refers to the controller being tested, devise injects the method current_user into it using controller_helpers.
devise-jwt
doesn't interfere with devise
defined controller helpers, so I guess you have some problem with devise
itself or with your test configuration.
@waiting-for-dev I guess this happens because the request didn't come through a route, so when devise-jwt tries to match the route, it fires an error, is it possible to "turn off" devise-jwt for tests?
Not sure what you are trying to do, but I guess that if you are trying to mock requests your best bet is to try with rack-test.
@waiting-for-dev
Looks like I have to do:
request.env['PATH_INFO'] = ""
before I call subject.current_user, since this library doesn't handle the case when
env['PATH_INFO'] == nil
and throws an error. I think this should be done cause:
1) Nobody sets there request.env['PATH_INFO'] by default.
2) I shouldn't have to set it when I don't care about its value, so long as it doesn't throw an error.
3) When writing feature tests, one shouldn't have to care about what happens outside of the controllers code(or in the back ground code implicitly), thus routes or request.env keys are not set generally.
We just need to add a .to_s
to ensure a string is passed to match. Making a PR for this.
Oks. Following the conversation there, then.
I am doing the following in my tests:
and I get an error as mentioned below: