testing omniauth controller callbacks behavior with rspec

2,511 vistas
Ir al primer mensaje no leído

Soe Moe

no leída,
22 ene 2011, 6:04:46 a.m.22/1/2011
para Devise
Hi all,

I'm using devise+omniauthable to integrate with facebook. I have the
following class to handle the facebook callback.

class Users::OauthCallbacksController <
Devise::OmniauthCallbacksController
def facebook
omniauth = env["omniauth.auth"]
# application logic to handle facebook
end
end


I want to test the application logic inside the facebook method with
rspec.

What is the correct way to mock env["omniauth.auth"]?

Thanks,
Soe Moe

Andrés Mejía

no leída,
22 ene 2011, 7:58:55 a.m.22/1/2011
para plataforma...@googlegroups.com
I'm not using RSpec but here's how I mocked it:

Soe Moe

no leída,
23 ene 2011, 8:14:38 a.m.23/1/2011
para Devise
Thanks Andrés,

With your help, I can make it work now. :)

Andrés Mejía

no leída,
23 ene 2011, 8:24:51 a.m.23/1/2011
para plataforma...@googlegroups.com
Hi Soe,

Can you post your solution with RSpec here so others can benefit from it in the future?

Thanks!

Andrés

Soe Moe

no leída,
23 ene 2011, 9:22:31 p.m.23/1/2011
para Devise
Sure, Andrés. :)

here it is..

https://gist.github.com/792715

Thanks,
Soe Moe

Leandro

no leída,
22 mar 2011, 10:27:13 a.m.22/3/2011
para Devise
Please, can anyone help me?

I'm trying to do the same with this spec:

require 'spec_helper'

describe Users::OmniauthCallbacksController do
it "should handle twitter callback" do
get :twitter
end
end

but hen I run my spec I get the error message:

Failures:

1) Users::OmniauthCallbacksController should handle twitter callback
Failure/Error: get :twitter
AbstractController::ActionNotFound:
Could not find devise mapping for path "/users/auth/twitter/
callback"
# ./spec/controllers/users/omniauth_callbacks_controller_spec.rb:
9:in `block (2 levels) in <top (required)>'

Finished in 0.90308 seconds

Leandro

no leída,
22 mar 2011, 10:35:58 a.m.22/3/2011
para Devise
Solved. I had forgotten to define env.

[]'s

On Jan 23, 11:22 pm, Soe Moe <soemoetunl...@gmail.com> wrote:

Wolfram Arnold, RubyFocus

no leída,
10 abr 2011, 7:51:00 p.m.10/4/2011
para Devise
Using OmniAuth 0.2.0's mocks, this can even get a little simpler:

require 'spec_helper'

describe OmniauthCallbacksController do
include Devise::TestHelpers

before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
end

it 'should authenticate and identify user if user is known' do
get :twitter
response.should be_redirect
end
end

and in spec_helper.rb, you set:

OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:twitter, {
:user_info => {:name => "Joe Smith", :nickname => 'joesmith'}, :uid
=> '123456790'
})

George Ardeleanu

no leída,
10 abr 2011, 9:33:57 p.m.10/4/2011
para plataforma...@googlegroups.com
Is it possible to also use this OmniAuth test_mode approach for a
request spec, or is it only intended to be used in a controller spec ?
I have tried to get it working myself in a request spec, but run into
multiple issues. Wanted to make sure it was possible even.

thanks,
george .

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos