routing_concerns
routing_concerns copied to clipboard
`assert_recognizes` does not seem to work well with `routing_concerns`
# config/routes.rb
RoutingConcerns::Application.routes.draw do
concern :commentable do
resources :comments
end
resources :posts, concerns: [:commentable]
end
# test/routes/posts_routing_test.rb
require "test_helper"
class PostsRoutingTest < ActionController::TestCase
test "routes the list of posts" do
assert_recognizes({ controller: "posts", action: "index" }, "/posts")
end
end
generates the error:
1) Failure:
test_routes_the_list_of_posts(PostsRoutingTest) [test/routing/posts_routing_test.rb:5]:
The recognized options <{"concerns"=>[:commentable], "action"=>"index", "controller"=>"posts"}> did not match <{"controller"=>"posts", "action"=>"index"}>, difference: <{"concerns"=>[:commentable]}>.
<{"controller"=>"posts", "action"=>"index"}> expected but was
<{"concerns"=>[:commentable], "action"=>"index", "controller"=>"posts"}>.
I have the same issue. Any quick fix can be made to workaround this bug?
Found a fix. Instead of using concerns param in the resources or resource methods use concerns as a method in the resource block.
resources :posts do
concerns :commentable
end
Will work.