【问题标题】:How to rspec test redirect_to with session variable如何使用会话变量 rspec 测试 redirect_to
【发布时间】:2011-10-22 11:29:06
【问题描述】:

这是Customers 控制器的update 操作中的一行代码。如何在 RSpec 中测试redirect_to

 redirect_to session[('page' + session[:page_step].to_s).to_sym], :notice => 'Customer was updated successfaully!'

有什么想法吗?谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 rspec2


    【解决方案1】:
    it "redirects to the next step" do
      # assign the current step
      session[:page_step] = "next"
    
      put :update
      response.should redirect_to("pagenext")
    end
    

    另请注意,您的代码中有错字:successfaully。您可以将代码简化为

    redirect_to session[:"page#{session[:page_step]}"], :notice => 'Customer was updated successfully!'
    

    【讨论】:

      猜你喜欢
      • 2015-03-25
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 2017-10-04
      • 2011-01-26
      • 1970-01-01
      相关资源
      最近更新 更多