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


#1

Hello,

I wanted to ask if someone could explain something to me.
I have a Category model with only name:string created using
resource_controller. I have no problem creating new, editing and/or
deleting. When I create new or edit/update, I am redirected to the new/
edited record. So, everything is as usual.

I have 2 tests for: test_should_create_category and
test_should_update_category that include:
assert_redirected_to category_path(assigns(:category))
But when running the test I get:
Expected response to be a <:redirect>, but was <200>

The thing I don’t understand is that I do get redirected – so why is
the test failing?

Thanks,
Elle


#2

On Apr 4, 4:42 am, elle removed_email_address@domain.invalid wrote:

I have 2 tests for: test_should_create_category and
test_should_update_category that include:
assert_redirected_to category_path(assigns(:category))
But when running the test I get:
Expected response to be a <:redirect>, but was <200>

The thing I don’t understand is that I do get redirected – so why is
the test failing?

Well for the real answer step through your code in the debugger, but
I’d guess its something like a failing validation because your test
isn’t posting the right parameters.

Fred


#3

Installed debugger and re-looked at my tests. I didn’t assign values
for new category and for update category => therefore, the tests
failed.
All good now. Thanks Fred once again :slight_smile:

Elle

On Apr 4, 8:33 pm, Frederick C. removed_email_address@domain.invalid