@user = FactoryGirl.create(:user)
@user2 = FactoryGirl.create(:user)
@request.env["devise.mapping"] = Devise.mappings[:user]
controller.current_user.should be_nil
post :create, :user => {email: @user.email, password: @user.test_pass}
flash[:alert].should be_nil
controller.should(respond_to(:current_user))
controller.current_user.should_not be_nil
post :create, :user => {email: @user2.email, password: @user2.test_pass}
flash[:alert].should be_nil
controller.should(respond_to(:current_user))
controller.current_user.should == @user2
最后一个失败。它仍然是@user,而不是@user2。
编辑:
如果我这样做,这是注销用户并清除会话的公平方式吗?
class SessionsController < Devise::SessionsController
def create
if warden.authenticated?(:user)
sign_out(current_user)
end
super
end
end