Module: RailsJwtAuth::Spec::Helpers

Defined in:
lib/rails_jwt_auth/spec/helpers.rb

Instance Method Summary collapse

Instance Method Details

#sign_in(user) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rails_jwt_auth/spec/helpers.rb', line 12

def (user)
  request.env['warden'] = RailsJwtAuth::Strategies::Jwt.new request.env
  allow(request.env['warden']).to receive(:authenticate!).and_return(user)
  allow(controller).to receive(:current_user).and_return(user)

  user.auth_tokens = []
  token = user.regenerate_auth_token
  request.env['HTTP_AUTHORIZATION'] = RailsJwtAuth::Jwt::Manager.encode(auth_token: token)
end

#sign_outObject



7
8
9
10
# File 'lib/rails_jwt_auth/spec/helpers.rb', line 7

def sign_out
  request.env['warden'] = RailsJwtAuth::Strategies::Jwt.new request.env
  allow(request.env['warden']).to receive(:authenticate!).and_raise(RailsJwtAuth::Errors::NotAuthorized)
end