开发者

Rails controller testing - Validation errors do not raise a HTTP error response

I have an ActionController derived Test which sends a 'post' request to the controller under test with incorrect data. The controller tries to create a new object and save it. The model has validation methods that get triggered on save and they generate a validation error detecting the incorrect data sent by test.

So far so good. Now, controller verifies that the HTTP response status is failure by using assert_response :failure. Howev开发者_如何转开发er, the test fails at this step saying:

Expected response to be a <:failure>, but was <200>

The @obj.errors is correctly populated with the validation error but somehow the HTTP response is always 200.

Any clues?


What does your controller code do? The usual way to handle validation errors in Rails is to send a 200 OK response (e.g. with render :action => 'new'). The response contains the form (populated with the submitted parameters) along with the validation error messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜