Devise + Rspec error : serialize_into_session

1,288 views
Skip to first unread message

GlennRob

unread,
Jan 20, 2010, 3:25:49 AM1/20/10
to Devise
Hi,

Im trying to get Rspec to play nice with devise, but getting this
error;

undefined method `serialize_into_session' for Symbol:Class

...devise-0.8.2/lib/devise/test_helpers.rb:69 :in `sign_in'

67 scope ||= Devise::Mapping.find_scope!(resource_or_scope)
68 resource ||= resource_or_scope
69 session["warden.user.#{scope}.key"] =
resource.class.serialize_into_session(resource)

My spec looks like this;

describe OrganizationsController do
include Devise::TestHelpers

before :each do
sign_in :user, @user
end
...

Any ideas?

Glenn

José Valim

unread,
Jan 20, 2010, 3:31:55 AM1/20/10
to plataforma...@googlegroups.com
Are you sure @user is not nil?
--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

Glenn Roberts

unread,
Jan 20, 2010, 4:02:32 AM1/20/10
to plataforma...@googlegroups.com
Yep. That was the issue.

Got past that and now hit this error, which I assume is due to the :authenticatable strategy I'm using in the User model..

uncaught throw `warden'
...devise-0.8.2/lib/devise/hooks/activatable.rb:15 :in `throw'
...
13      warden.winning_strategy.fail!(record.inactive_message)
14    else
15      throw :warden, :scope => scope, :message => record.inactive_message
16    end
17  end

Is it possible to stub out this behaviour in Rspec ? E.g.
  user.stub!(:active?).and_return true  

(that doesnt seem to work though)

José Valim

unread,
Jan 20, 2010, 4:03:33 AM1/20/10
to plataforma...@googlegroups.com
Just confirm your user after creating it:

@user.confirm!

Glenn Roberts

unread,
Jan 20, 2010, 4:13:14 AM1/20/10
to plataforma...@googlegroups.com

Ah yes. I was hunting for that method as you sent the mail. Too easy :-)

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages