master
 1module HttpAuthentication
 2  def http_login(user, user_session =
 3                 build(:user_session, id: SecureRandom.uuid, user: user))
 4    allow(controller).to receive(:current_user).and_return(user)
 5    allow(controller).to receive(:current_session).and_return(user_session)
 6    session[:user_id] = user_session.id
 7  end
 8
 9  def api_login(user)
10    http_login(user)
11  end
12end