[rspec-users] Devise: session variable is empty on session_serializer.rb#store

Daniel Salmeron Amselem daniel.amselem at gmail.com
Fri Jul 9 14:45:59 EDT 2010

I've been trying to test a very simple action on a controller with
this setup:

rspec 1.3.0
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
Rails 2.3.8
devise 1.0.8

And this is the test:

    before :each do
      @member = Factory.create(:member)
      sign_in @member
      @person = Person.new

    it "should render form for a new person on GET people#new" do

      get :new

      assigns[:person].should == @person
      response.should be_success
      response.should render_template("new")

This test creates a user, which is stored in the database with a
correct password. Running this test results in this error:

NoMethodError in 'PeopleController Methods should render form for a
new person on GET people#new'
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]=
session_serializer.rb:25:in `store'
73:in `sign_in'

Finished in 0.625754 seconds

23 examples, 1 failure

I wen to /Library/Ruby/Gems/1.8/gems/warden-0.10.4/lib/warden/
session_serializer.rb and I changed the file in order to print out
some values:

   def store(user, scope)
      return unless user
      p scope
      p key_for(scope)
      p user
      p serialize(user)
      p session
      session[key_for(scope)] = serialize(user)

When running the test again I get:



Member id: 1, email: "member2 at hv_club.com", encrypted_password:
"c79e5e4790643b284002bf6ad8045f53ff900afc", password_salt:
"Rim9LiyKARU1SHQCWIb0", confirmation_token: nil, confirmed_at: nil,
confirmation_sent_at: nil, reset_password_token: nil, remember_token:
nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at:
nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip:
nil, created_at: "2010-07-09 16:45:44", updated_at: "2010-07-09

[Member(id: integer, email: string, encrypted_password: string,
password_salt: string, confirmation_token: string, confirmed_at:
datetime, confirmation_sent_at: datetime, reset_password_token:
string, remember_token: string, remember_created_at: datetime,
sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at:
datetime, current_sign_in_ip: string, last_sign_in_ip: string,
created_at: datetime, updated_at: datetime), 1]


So it seems session is not initialized. Any ideas on how to fix this?
BTW, I already contacted Jose Valim through GitHub and he recommended
me to post my question in this group. http://github.com/plataformatec/devise/issues/issue/374


More information about the rspec-users mailing list