[rspec-users] Simple Association Redirect on delete

2011-02-28 Thread Charley
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)
end

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?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Simple Association Redirect on delete

2011-02-28 Thread Charley
I am not sure if I am properly using the respond to call as you
suggested. Here is what I tried:
it "redirects to the bugs parent project" do
  Bug.stub(:find) { mock_bug }
  mock_bug.should respond_to :project_id
  delete :destroy, :id => "1"
  response.should redirect_to(project_path(:id =>
mock_bug.project_id))
end

And here is the failure message:
1) BugsController DELETE destroy redirects to the bugs parent project
 Failure/Error: delete :destroy, :id => "1"
 ActionController::RoutingError:
 No route matches
{:action=>"show", :controller=>"projects", :id=>#}

In case it would illustrate my situation better, here is my action:
 def destroy
@bug = Bug.find(params[:id])
bugs_project = @bug.project_id
@bug.destroy

respond_to do |format|
  format.html { redirect_to(project_url(bugs_project)) }
  format.xml  { head :ok }
end
  end

Any ideas?



On Feb 28, 8:21 am, Craig Demyanovich  wrote:
> On Sun, Feb 27, 2011 at 10:57 PM, Charley  wrote:
>
> ...
>
> > it "redirects to the bugs list" do
> >  Bug.stub(:find) { mock_bug }
> >  delete :destroy, :id => "1"
> >  response.should redirect_to(bugs_url)
> > end
>
> > 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?
>
> Make the mock_bug respond to project_id. Then verify that the request's
> response goes to project_path(:id => mock_bug.project_id).
>
> Regards,
> Craig
>
> ___
> rspec-users mailing list
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users