對於我的生活,我不明白爲什麼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