我正在尝试运行整合测试,测试用户使用订单控制器的编辑操作后发送的电子邮件,以指定产品的发货日期。
这是我到目前为止所做的:
# the user visits the order edit page
get "orders/#{order.id}/edit"
assert_response :success
# the user submits the edit form with a shipped_on date
# a nonredirect response is returned
post_via_redirect "/orders/#{order.id}/edit",
order: {
ship_date: "2014-3-13 20:20:20"
}
assert_response :success
#check that the user was redirected to edit template
assert_template "edit"
我认为这不起作用,因为我正在发出POST请求,而不是PUT请求。所以我的问题是,如何向更新操作提出PUT请求并传递通常在通过浏览器提交的表单中的新信息。
答案 0 :(得分:1)
方法put_via_redirect
,因此可以在您的测试中使用。
有关该方法的更多信息有http://apidock.com/rails/ActionController/Integration/Session/put_via_redirect