[rspec-users] Simple Association Redirect on delete

Charley charley.stran at gmail.com
Sun Feb 27 22:57:47 EST 2011

So am fairly new to rspec and am trying to get the hang of it, but
have run into a few issues I cant figure out. Several times in my code
I have model that belongs to a parent, when the model is deleted,
instead of redirecting to the index action, it redirects to the show
action for its parent model. Simple enough. The code in my application
currently properly handles this, but I dont know how to make the test
handle it. For example I have this basic auto-generated test.

it "redirects to the bugs list" do
  Bug.stub(:find) { mock_bug }
  delete :destroy, :id => "1"
  response.should redirect_to(bugs_url)

This fails for obvious reasons. A bug belongs to a project so the
redirect should go to the projects_url("someproject_id_I_dont_know")

I am sure this is a fairly simple and common thing. Can anyone help
put me on the right path?

More information about the rspec-users mailing list