How to write an rspec test in Rails 3 to check if a user is signed using authlogic after creating it?

I am migrating my application from a user authentication mechanism to authlogic, and it’s hard for me to figure out how to verify that a new user has logged in after creating it. My old test was as follows:

describe UsersController do
.
.
.
before(:each) do
  activate_authlogic
  @attr = { :username => "New User", :email => "user@example.com",
    :password => "foobar", :password_confirmation => "foobar" }
end
.
.
.
 it "should sign the user in" do
    post :create, :user => @attr
    controller.should be_signed_in
 end

where is signed_in? defined in app / helpers / user_sessions_helper.rb and included in the application controller:

# check for a signed in user. returns true if current_user is not nil.        
def signed_in?
  !current_user.nil?
end

I expect this test to pass, but signed_in? returns false. Any ideas? I assume that I should ask for a UserSession if: the user is logged in, but I'm not sure how authlogic allows me to do this.

Any hints, tips or tricks are welcome.

+3
source share
1 answer

, - , :)

it "should sign the user in" do
    post :create, :user => @attr
    @user_session = UserSession.find
    @user_session.user.should_not == nil
end

, , , , , , , . , .

0

All Articles