我是rails新手,我正在使用unit:test。我有一个动作在我的控制器如何在rails 3.1和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/[email protected]/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/response.rb:67:in`assert_redirected_to”
我的猜测是,我我没有给它正确的断言检查参数
params [:app_id]和@app = TestApp.find(params [:app_id])。
我该如何编写这样的断言来检查这些属性,检查一个参数是否为空。如何找到一个给定ID的对象。
感谢忠为回答,对不起,我没有意识到你的回应,这就是为什么在几个月后接受它。 – user1014473 2012-08-03 11:21:21