routing_concerns icon indicating copy to clipboard operation
routing_concerns copied to clipboard

`assert_recognizes` does not seem to work well with `routing_concerns`

Open alindeman opened this issue 12 years ago • 2 comments

# 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"}>.

alindeman avatar Jan 24 '13 02:01 alindeman

I have the same issue. Any quick fix can be made to workaround this bug?

dmitry avatar Jul 21 '14 13:07 dmitry

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.

dmitry avatar Jul 21 '14 13:07 dmitry