ruby-on-rails – 使用Authlogic进行集成测试?
发布时间:2020-12-16 22:01:50 所属栏目:百科 来源:网络整理
导读:对于我的生活我不明白为什么Authlogic没有登录我在这个集成测试.我没有任何问题w / Authlogic登录我的功能测试使用这个代码.根据authlogic rdocs( http://tinyurl.com/mb2fp2),模拟登录状态在功能集成测试,所以我很困惑.任何帮助深表感谢! class TipsContro
对于我的生活我不明白为什么Authlogic没有登录我在这个集成测试.我没有任何问题w / 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 解决方法
基于“用户会话控制器”创建方法中的代码,该方法采用了登录凭据的哈希,我可以在我的集成测试中使其工作:
UserSession.create(:email =>’someone@example.com’,:password =>’密码’) 但不是: UserSession.create(@user) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读