kar*_*eem 10 ruby-on-rails authlogic
对于我的生活,我不明白为什么Authlogic没有在这个集成测试中登录我.我没有遇到任何问题,Authlogic使用此代码在功能测试中登录我.根据authlogic rdocs(http://tinyurl.com/mb2fp2),模拟登录状态在功能和集成测试中是相同的,所以我很困惑.任何帮助深表感谢!
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
Run Code Online (Sandbox Code Playgroud)
小智 3
根据该user_sessions_controller
create
方法中的代码(该代码采用登录凭据的哈希值),我能够使其在集成测试中像这样工作:
UserSession.create(:email => 'someone@example.com', :password => 'password')
Run Code Online (Sandbox Code Playgroud)
但不包括:
UserSession.create(@user)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5268 次 |
最近记录: |