Search code examples
ruby-on-railsrubyroutesrspecactioncontroller

Rspec redirect_to routes are failing expectations (or misparsed?), how come?


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?


Solution

  • 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