master
 1module Authentication
 2  def http_login(user)
 3    new_session = UserSession.new
 4    allow(controller).to receive(:user_session).and_return(new_session)
 5    allow(controller).to receive(:current_user).and_return(user)
 6    allow(controller).to receive(:current_user?).and_return(true)
 7  end
 8
 9  def api_login(user)
10    encoded_credentials = ActionController::HttpAuthentication::Token.
11      encode_credentials(user.authentication_token)
12    request.env["HTTP_AUTHORIZATION"] = encoded_credentials
13  end
14
15  module Capybara
16    def http_login(user)
17      LoginPage.new.visit_page.login_with(email: user.email, password: "password")
18    end
19  end
20end