2012-09-22 11 views

Respuesta

6

Recomendaría una alternativa, más simple approach. ¿Qué ocurre si prueba el controlador de devolución de llamada directamente para ver cómo reacciona a diferentes valores que se le pasan en omniauth.auth o si env ["omniauth.auth"] falta o es incorrecto? Los siguientes redireccionamientos equivaldrían a probar el complemento omniauth, que no prueba SU sistema.

Por ejemplo, esto es lo que tenemos en nuestras pruebas (estos son solo algunos ejemplos, tenemos muchos más que verifican otras variaciones de hash omniauth y el estado del usuario antes del inicio de sesión, como el estado de la invitación, usuario inhabilitación de la cuenta por los administradores, etc.):

describe Users::OmniauthCallbacksController do 
    before :each do 
    # This a Devise specific thing for functional tests. See https://github.com/plataformatec/devise/issues/608 
    request.env["devise.mapping"] = Devise.mappings[:user] 
    end 
    describe ".create" do 

    it "should redirect back to sign_up page with an error when omniauth.auth is missing" do 
     @controller.stub!(:env).and_return({"some_other_key" => "some_other_value"}) 
     get :facebook 
     flash[:error].should be 
     flash[:error].should match /Unexpected response from Facebook\./ 
     response.should redirect_to new_user_registration_url 
    end 

    it "should redirect back to sign_up page with an error when provider is missing" do 
     stub_env_for_omniauth(nil) 
     get :facebook 
     flash[:error].should be 
     flash[:error].should match /Unexpected response from Facebook: Provider information is missing/ 
     response.should redirect_to new_user_registration_url 
    end 
    end 
end 

con stub_env_for_omniauth método definido de la siguiente manera:

def stub_env_for_omniauth(provider = "facebook", uid = "1234567", email = "[email protected]", name = "John Doe") 
    env = { "omniauth.auth" => { "provider" => provider, "uid" => uid, "info" => { "email" => email, "name" => name } } } 
    @controller.stub!(:env).and_return(env) 
    env 
end 
+0

¿no debería el 'stub_env_for_omniauth' retorno método OmniAuth :: AuthHash objeto, en lugar de un hash ? – user3021270

Cuestiones relacionadas