[rspec-devel] controller.session not same as session?

David Chelimsky dchelimsky at gmail.com
Wed Nov 8 05:01:49 EST 2006


On 11/7/06, Brandon Keepers <brandon at collectiveidea.com> wrote:
> The spec:
>
> context "A user logging out" do
>    fixtures :users
>    controller_name :account
>
>    setup do
>      login_as :quentin
>      users(:quentin).remember_me
>      request.cookies["auth_token"] = cookie_for(:quentin)
>    end
>
>    def logout
>      get :logout
>    end
>
>    specify "should unset :user in session" do
>      logout
>      controller.session[:user].should_be_nil
>    end
>
>    specify "should unset :user in controller.session" do
>      logout
>      controller.session[:user].should_be_nil
>    end
> end
>
> The result:
>
> A user logging out
> - should unset :user in controller.session
> - should unset :user in session (FAILED - 1)
> - should be redirected
> - should delete remember_me token
>
> 1)
> Spec::Expectations::ExpectationNotMetError in 'A user logging out
> should unset :user in session'
> 1 should be nil
> ./spec/controllers/account_controller_spec.rb:149:in `should
> unset :user in session'
>
> Throwing a breakpoint in and examining the two reveals:
>
>  >> session
> => #<ActionController::TestSession:0x3a8e794 @attributes={:user=>1,
> "flash"=>{}}>
>  >> controller.session
> => #<ActionController::TestSession:0x3a797e0 @attributes=
> {:return_to=>nil, "flash"=>{:notice=>"You have been logged out."}}>
>  >>
>
> Am I doing something wrong?

The spec names say "session" and "controller.session", but both are
coded to go after "controller.session". Since each spec gets run in a
brand new instance of the context, it makes sense that these would be
two different objects.

What doesn't make sense is that one passes and one fails.

Would you kindly file a bug?

FYI - The following spec passes for me in isolation and integration modes:

  specify "session should be the same object as controller session" do
    get 'some_action'
    session.should_equal controller.session
  end

Thanks,
David

>
> Brandon
>
>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>
>
>


More information about the rspec-devel mailing list