我是 Rails 测试的新手,我正在使用 unit:test。我的控制器中有一个动作
def save_campaign
unless params[:app_id].blank?
@app = TestApp.find(params[:app_id])
if params[:test_app]
@app.update_attributes(params[:test_app])
end
flash[:notice] = "Your Registration Process is completed"
redirect_to "/dashboard"
else
redirect_to root_path
end
end
我的测试用例如下
test "should save campagin " do
assert_difference('TestApp.count', 0) do
post :save_campaign, test_app: @test_app.attributes
end
assert_redirected_to "/dashboard"
end
end
这个方法是一个post方法。运行此测试时,它失败并显示一条消息
“应该保存campagin(0.07s)预期的响应是重定向到 http://test.host/dashboard但重定向到http://test.host//home/nouman/.rvm/gems/ruby-1.9 .2-p290@global/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/response.rb:67:in `assert_redirected_to'
我的猜测是我没有给出正确的断言来检查参数
参数[:app_id] 和@app = TestApp.find(params[:app_id])。
我如何编写这样的断言来检查这些属性,检查参数是否为空。1 如何找到具有给定 id 的对象。