views:

294

answers:

1

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. However, 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?

+2  A: 

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.

Phil Ross
Yup, this is indeed by design. Controller doesnt do anything fancy and the HTTP response should be 200 since the request itself was correct albeit with invalid data.Thanks for confirming this.
bhavinb