用于编辑/更新的Rails集成测试

时间:2014-03-13 18:54:21

标签: ruby-on-rails-4 integration-testing

我正在尝试运行整合测试,测试用户使用订单控制器的编辑操作后发送的电子邮件,以指定产品的发货日期。

这是我到目前为止所做的:

# 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请求并传递通常在通过浏览器提交的表单中的新信息。

1 个答案:

答案 0 :(得分:1)

方法put_via_redirect,因此可以在您的测试中使用。

有关该方法的更多信息有http://apidock.com/rails/ActionController/Integration/Session/put_via_redirect