views:

340

answers:

1

It seems my rspec route for :controller => 'phones', :action => 'edit' works...it should be 'phones/123/edit', and IS according to rspec tests and rake routes. But when I create a redirect_to expectation, the expectation fails.

Here's the routes test for the url:

    it "maps #edit" do
      route_for(:controller => "phones", :action => "edit", :id => "1").should == "/phones/1/edit"
    end #THIS TEST PASSES

Here's the expectation that fails:

    put :update, :id => "1", :phone => {}
    response.should redirect_to :controller => 'phones', :action => 'edit'

And this is the message I get in the tests:

expected redirect to {:controller=>"phones", :action=>"edit"},
got redirect to "http://test.host/phones/1089/edit" # BUT THIS THE URL I WAS EXPECTING!

What the schiznits?

+1  A: 

The reason this is failing is that you are missing the id in your expectation. It should be:

response.should redirect_to :controller => 'phones', :action => 'edit', :id=>1
Pelle
Close enough...I artually ended up having to use the mock_phone.id like this: response.should redirect_to :controller => 'phones', :action => 'edit', :id=>wock_phone.idThanks Pell! By the way, have I seen you around anywhere? I get a feeling I've seen you on Github or some other forums.
btelles