I keep getting a routing error when testing a Rails 3.0 application with Rspec 3. It can't detect the route I'm using for my get request. Here's what my files look like:
routes.rb
resources :proficiency_tests do
member do
resource :lag_components, only: [:edit, :update]
end
end
running rake:routes returns:
edit_lag_components GET /proficiency_tests/:id/lag_components/edit(.:format) {:action=>"edit", :controller=>"lag_components"}
lag_components PUT /proficiency_tests/:id/lag_components(.:format) {:action=>"update", :controller=>"lag_components"}
controller is in:
app
|---controllers
|---lag_components_controller.rb
Nothing special about the way the controller is set up.
spec is in:
spec
|---controllers
|---lag_components_controller.rb
tests are set up like this:
require 'spec_helper'
describe LagSubmissionsController do
describe 'GET #edit' do
let(:proficiency_test) { create :proficiency_test }
it 'redirects' do
*tests*
end
end
end
Here is what I have tried and what the error messages have been:
get(:edit, id: proficiency_test.id)
# => No route matches {:id=>11259, :controller=>"lag_submissions", :action=>"edit"}
get(:edit, id: proficiency_test.id, use_route: :edit_lag_components)
# => No route matches {:id=>11260, :controller=>"lag_submissions", :action=>"edit"}
get("/proficiency_tests/#{proficiency_test.id}/lag_components/edit")
# => No route matches {:controller=>"lag_submissions", :action=>"/proficiency_tests/11258/lag_components/edit"}
The last one is particularly intriguing, because that is the exact route I use in the browser to render the edit
page:
Does anyone know what's going on and why it can't find that route? Unfortunately, it's an older application and I can't change the routes around.