LoginSignup
2
1

More than 5 years have passed since last update.

OmniauthCallbacksController をテストする

Last updated at Posted at 2014-06-23

Feature テスト

wiki の通り。

Integration Testing · intridea/omniauth Wiki

Controller テスト

request.env["omniauth.auth"] に値を設定してやる。

describe CustomDevise::OmniauthCallbacksController do

  before do
    stub_env_for_omniauth
  end

  describe "GET #facebook" do
    context "as a guest user" do
      before { get :facebook }
      it { should redirect_to my_edit_user_registration_path }
    end
  end


  def stub_env_for_omniauth(uid="1234567890")
    # devise を使っている場合
    @request.env["devise.mapping"] = Devise.mappings[:user]

    request.env["omniauth.auth"] = OmniAuth::AuthHash.new({
      "provider"=>"facebook",
      "uid"=>uid,
      ...
    })
  end
end


2
1
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
2
1