Skip to content
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

Do we have any rspec helpers to sign_in an user? #577

Closed
ingolfured opened this issue Mar 17, 2016 · 2 comments
Closed

Do we have any rspec helpers to sign_in an user? #577

ingolfured opened this issue Mar 17, 2016 · 2 comments

Comments

@ingolfured
Copy link
Contributor

In devise, we can sign in a user using sign_in(user). Is there anything similar that comes with this gem? If not, what's the best way to authenticate / disable the authentication when I'm testing?

@ingolfured
Copy link
Contributor Author

Looks like #521 solves it. However, I'm creating a helper method in my support file.

def token_sign_in user
  auth_headers = user.create_new_auth_token
  request.headers.merge!(auth_headers)
end

Thanks!

@danielmockaitis
Copy link

danielmockaitis commented Jan 11, 2018

If anyone is using Rspec requests, you can define @ingolfured method above but instead return the auth_header

def token_sign_in user
    return user.create_new_auth_token
end

Then on any call you want to have an authenticated user just define the headers
before { get "/api/v1/_______", headers: token_sign_in(user) }

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

No branches or pull requests

2 participants