Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session variable is empty on session_serializer.rb#store #374

Closed
damselem opened this issue Jul 9, 2010 · 5 comments
Closed

session variable is empty on session_serializer.rb#store #374

damselem opened this issue Jul 9, 2010 · 5 comments

Comments

@damselem
Copy link

damselem commented Jul 9, 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
end

it "should render form for a new person on GET people#new" do
  current_member.should_receive(:build_person).and_return(@person)

  get :new

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

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.[]=
/Library/Ruby/Gems/1.8/gems/warden-0.10.4/lib/warden/session_serializer.rb:25:in store' /Library/Ruby/Gems/1.8/gems/devise-1.0.8/lib/devise/test_helpers.rb:73:insign_in'
/Users/damselem/Documents/project/spec/controllers/people_controller_spec.rb:15:

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)
end

When running the test again I get:

:member

"warden.user.member.key"

Member id: 1, email: "member2@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 16:45:44"

[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]

nil

So it seems session is not initialized. Any ideas on how to fix this?

Thanks.

@josevalim
Copy link
Contributor

It is definitely an rspec issue. Where is your spec located at? spec/controllers?

@damselem
Copy link
Author

damselem commented Jul 9, 2010

yep.

@damselem
Copy link
Author

damselem commented Jul 9, 2010

Jose should I ask this question in the rspec google group?

@josevalim
Copy link
Contributor

Yeah, but this should work.

@damselem
Copy link
Author

damselem commented Jul 9, 2010

Ok. I will try in the rspec google group. Anyways, thank you very much for your help.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants