Created
January 22, 2011 12:56
-
-
Save mejibyte/791105 to your computer and use it in GitHub Desktop.
Test Omniauth Callback Controllers in Devise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'test_helper' | |
class Users::OmniauthCallbacksControllerTest < ActionController::TestCase | |
context "Facebook callback" do | |
setup do | |
# This a Devise specific thing for functional tests. See https://github.com/plataformatec/devise/issues/closed#issue/608 | |
request.env["devise.mapping"] = Devise.mappings[:user] | |
end | |
should "sign in when it's called with a valid user" do | |
u = users(:andmej) | |
@controller.expects(:env).returns("omniauth.auth" => { "extra" => { "user_hash" => { "email" => u.email, "name" => u.name, "id" => u.facebook_uid } } }) | |
get :facebook | |
assert_redirected_to root_path | |
assert_match flash[:notice], /You have signed in through Facebook/ | |
end | |
should "store the OmniAuth hash in the session and redirect to the new user page when it's called with an invalid user" do | |
env = { "omniauth.auth" => { "extra" => { "user_hash" => { "email" => "[email protected]", :id => "1234" } } } } | |
@controller.expects(:env).twice.returns(env) | |
get :facebook | |
assert_equal session["devise.facebook_data"], env["omniauth.auth"] | |
assert_redirected_to new_user_registration_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment