Question

I am trying to get a handle on how nested routes work with Rspec. I have one of these:

class SupportController < ResourceController
   # stuff happens

   def support_override
      customer = Customer.find_by_id(params[:id])
      customer.override( params[:override_key] )
      redirect_to("support")
   end
 end

We have a route:

resources :support do 
  member do
    # loads of paths

    get  'support_override/:override_key' => 'support#support_override' 
  end
end       

And the route passes a test:

it "should route GET support/1/support_override/ABCDEF to suport#support_override" do
  { get: '/support/1/support_override/ABCDEF'}.should route_to(controller: 'support', action: 'support_override', id: '1', override_key: 'ABCDEF' )
  end

However when I try to test the logic in rspec:

describe SupportController do
   # various levels of context and FactoryGirl calls

   it "can reach override url" do
     get :support_override, { :id=> @customer.id, :override_key="123" }
     response.should redirect_to("support")
     end

end

I get the following response:

Failure/Error: Unable to find matching line from backtrace AbstractController::ActionNotFound: The action 'support_override' could not be found for SupportController

I have no doubt that the problem is with my understanding of how rspec works with nested routes, but I can't see any way to figure out what path Rspec is actually seeking and consequently it's hard to know what I need to change and I'm having trouble locating the relevant documentation.

Is there a way to find what path is being created by the test or can anyone offer guidance on how exactly the path creation works in this situation?

Était-ce utile?

La solution

Since, you haven't shared the complete SupportController code, I cannot pin-point exact error. BUT there are two possibilities:

  1. You have defined support_override under private/protected by mistake.
  2. You have closed the class SupportController before support_override method definition, by mistake

Your action must always be public so that its accessible.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top