LoginSignup
11
11

More than 5 years have passed since last update.

OmniAuthでrequest specを書く(rspec)

Last updated at Posted at 2014-08-16

ちょっとハマったのでメモ。

omniauth-identityの場合

sessions_controller.rb
class SessionsController < ApplicationController
  def create
    user = User.find(env["omniauth.auth"]["uid"])
    session[:user_id] = user.id
    redirect_to expenses_url, notice: "Signed in!"
  end
end
spec_helper.rb
OmniAuth.config.test_mode = true
login_helper.rb
def login(user, password)
  OmniAuth.config.mock_auth[:identity] = { 'provider' => 'identity', 'uid' => user.id }
  post '/auth/identity/callback', screen_name: user.screen_name, password: password
end

あとは各specからbefore { login(user, password) }とかするだけ。

twitterとかの認証も同じ感じでできるはず。

参考

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11