Search code examples
ruby-on-railsroutesfunctional-testing

For some reason named route is not working in Functional Test


Inside of my Quizzes Controller functional test :

post :statements

Returns ->

ActionController::RoutingError: No route matches {:controller=>"quizzes", :action=>"statements"}

But my routes rake as so :

quizzes_statements  /quizzes/statements(.:format)  quizzes#statements {:any=>[:OPTIONS, :POST]}

My routes.rb looks like so :

match '/quizzes/statements' => 'quizzes#statements', any: [:OPTIONS, :POST]

And if I run this within my test :

extend Rails.application.routes.url_helpers
quizzes_statements_path

Returns :

=> "/quizzes/statements"

But if I do :

post quizzes_statements_path

I get the same error :

ActionController::RoutingError: No route matches {:controller=>"quizzes", :action=>"/quizzes/statements"}

Anyone know what might be happening here?


Solution

  • Use this:

    match '/quizzes/statements' => 'quizzes#statements', via: [:options, :post]