使用Authlogic进行测试时,有没有办法注销并登录其他用户?
以下测试用例失败
class MessagesControllerTest < ActionController::TestCase
setup :activate_authlogic
should "sender send a message and recipient delete it" do
@sender = Factory(:user, :login => 'sender')
@recipient = Factory(:user, :login => 'recipient')
UserSession.create(@sender)
post :create, :user_id => @recipient.id, :message => Factory.attributes_for(:message)
assert_equal @sender, assigns(:current_user)
UserSession.create(@recipient)
post :destroy, :user_id => @recipient.id, :message => @message
assert_equal @recipient, assigns(:current_user)
end
end
疯狂的是请求会话参数看起来不错......
# UserSession.create(@sender)
"user_credentials"=> "605a73e0f1b4dcecf5495d549b9d33eb6d3197f3a1fdb033c86bca456a0a0c75a42b63c924edb5d071f6d748aea3870f312a908eb501e6814c69abdab9bbf387",
"user_credentials_id"=>1
# UserSession.create(@recipient)
"user_credentials"=> "e14363b2065b7202e766205e807d6b531e230a136c70ea13c0853c7c0f275fb95f0185b9f17a934483cadda693e50956d1bfda8c820895f574a06861479af18c",
"flash"=>{:notice=>"Message was successfully created."},
"user_credentials_id"=>2
答案 0 :(得分:0)
session = UserSession.create(@sender)
和session.destroy
呢?