ruby-on-railsrspecroutesjourney

Route errors in controller tests after upgrading rails and journey router


This is my route

match "/:type/:brand/:model/:plate" => "site/vehicles#show",
    :constraints => {:plate => /[a-z]{3}\d{4}/}, :as => :vehicle

It passes the route tests

# the route test passess    
it "routes to #show" do
  {:get => '/carro/volksvagen/gol-2-0/abc1234'}.should route_to(
    "site/vehicles#show",
    :type => "carro",
    :brand => "volksvagen",
    :model => "gol-2-0",
    :plate => "abc1234"
  )
end

But after upgrading rails (3.2.0 => 3.2.8 ) which also updated journey (1.0.0 => 1.0.4), the following CONTROLLER test (which IMHO should not check for routes, which it apparently did not, back in rails 3.2.0) started failing.

describe "#show" do
  it "should be success" do
    get :show, :plate => @vehicle.plate
    response.should be_success
  end
end

It raises

Site::VehiclesController#show should be success
 ActionController::RoutingError:
   No route matches {:plate=>"ABC1672", :controller=>"site/vehicles", 
                                        :action=>"show"}
   
   

And even if I complete all the route vars

describe "#show" do
  it "should be success" do
    get :show, :plate => @vehicle.plate, :model => 'model', 
        :type => 'type', :brand => 'brand'
    response.should be_success
  end
end

I get:

# No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type", 
  :brand=>"brand", :controller=>"site/vehicles", :action=>"show"}

The application still works, but I will not know when it stops, since my tests are failing.

Anyone solved/had similar issue?

I know 'not upgrading rails' could avoid getting this errors, as suggested in a similar question, but I don't think it is a solution.

Routing error when updating to Rails 3.2.6 or Rspec 2.11.0

Thank you in advance.

Edit:

vehicle  /:type/:brand/:model/:plate(.:format)   site/vehicles#show {:plate=>/[a-z]{3}\d{4}/}

Solution

  • I think your problem is in a mismatch between your regex and your test data. In your error message, I see:

    No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type", 
     :brand=>"brand", :controller=>"site/vehicles", :action=>"show"}
    

    But the route has the following regex for plate:

    :plate => /[a-z]{3}\d{4}/
    

    That requires all lower-case letters; upper case letters won't match. So you need to either fix your test data, or fix the regex in your route.