对于我的生活,我不明白为什么Authlogic没有在这个集成测试中登录我。在使用此代码进行功能测试时,我没有遇到任何Authlogic记录的问题。根据authlogic rdocs(http://tinyurl.com/mb2fp2),模拟登录状态在功能&集成测试中是相同的,所以我很困惑。任何帮助深表感谢!Authlogic集成测试?
class TipsController < ApplicationController
before_filter :require_user, :only => [:destroy, :undelete]
def destroy
@tip = Tip.find(params[:id])
if can_delete?(@tip)
@tip.destroy
set_flash("good", "Tip deleted. <a href=\"#{undelete_tip_url(@tip.id)}\">Undo?</a>")
respond_to do |format|
format.html { redirect_to city_path(@tip.city)}
end
else
set_flash("bad", "Seems like you can't delete this tip, sorry.")
respond_to do |format|
format.html { render :action => "show", :id => @tip}
end
end
end
end
class DeleteTipAndRender < ActionController::IntegrationTest
context "log user in" do
setup do
@user = create_user
@tip = create_tip
end
context "delete tip" do
setup do
activate_authlogic
UserSession.create(@user)
@us = UserSession.find
post "/tips/destroy", :id => @tip.id
end
should_redirect_to("city_path(@tip.city)"){city_path(@tip.city)}
end
end
end
谢谢。从rdoc中的这一行开始: UserSession.create(users(:whoome)) 我假设我可以传递@user obj。感谢帮助! – kareem 2009-08-28 11:57:03
嗯根据本: http://rdoc.info/rdoc/binarylogic/authlogic/blob/73c4cccb38189f0e52e1e362992dfb9db7d1206f/Authlogic/Session/UnauthorizedRecord.html 我应该能够做到 UserSession.create(@user) 并让它工作... wtf。 – kareem 2009-08-31 21:47:30