I'm trying to make it so when a model is created via created action it redirects to its show action. That part works fine, but I can't get my functional test to behave. These tests have been modified from what the scaffold provides.
def setup
@thing = Factory(:thing)
assert(@thing.id, "Virtual fixture not valid.")
end
def test_create_valid
Thing.any_instance.stubs(:valid?).returns(true)
post :create
assert_redirected_to @thing
end
I'm using factory_girl in setup. When I run my tests I get this:
Expected response to be a redirect to http://test.host/thing/2 but was a redirect to http://test.host/thing/3.
I've done something very similar with my update action in this controller and the test looks the same, but it works. I'm a little confused as to what's going on.
Edit: Maximiliano points out below that this is probably because this creates a new record in the database, so it redirects to that one. How can I find the new record just created with the create post request?