Question

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?

Was it helpful?

Solution

Use this:

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

OTHER TIPS

In controller(functional) tests you can only reach actions within this controller, expressed by symbol.

e.g.

post :statements
get :index

Note get, post in functional tests are totally different methods from what in integration tests, though they have same name. You can use named path in integration tests without any problem. e.g.

post statement_path

So the fix is, do not used named path in your functional tests. get/post to action directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top