I'm porting my app from a custom authentication mechanism to authlogic and I'm having trouble figuring out how to test that a new user is logged in after it is created. My old test was the following:
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 signed_in? is defined in app/helpers/user_sessions_helper.rb and is 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'm expecting this test to pass but signed_in? is returning false. Any ideas? My guess is that I should be asking UserSessio开发者_Go百科n if :user is signed in but I'm not sure how authlogic allows me to do this.
Any hints, tips, or tricks would be greatly appreciated.
I've managed to write a test that passes - now I just have to figure out if the logic in the test is correct :)
it "should sign the user in" do
post :create, :user => @attr
@user_session = UserSession.find
@user_session.user.should_not == nil
end
This at least checks that there is a user signed in, but it doesn't show that the user, that was just created, is signed in. I think it needs a little more work.
精彩评论