aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing/concerns_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/routing/concerns_test.rb')
-rw-r--r--actionpack/test/dispatch/routing/concerns_test.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/test/dispatch/routing/concerns_test.rb b/actionpack/test/dispatch/routing/concerns_test.rb
index 21da3bd77a..8600da32ad 100644
--- a/actionpack/test/dispatch/routing/concerns_test.rb
+++ b/actionpack/test/dispatch/routing/concerns_test.rb
@@ -1,6 +1,16 @@
require 'abstract_unit'
class RoutingConcernsTest < ActionDispatch::IntegrationTest
+ class Reviewable
+ def self.call(mapper)
+ if mapper.current_scope[:controller] == 'posts'
+ mapper.resources :reviews
+ elsif mapper.current_scope[:controller] == 'videos'
+ mapper.resources :reviews, as: :video_reviews
+ end
+ end
+ end
+
Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
app.draw do
concern :commentable do
@@ -11,8 +21,10 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest
resources :images, only: :index
end
- resources :posts, concerns: [:commentable, :image_attachable] do
- resource :video, concerns: :commentable
+ concern :reviewable, Reviewable
+
+ resources :posts, concerns: [:commentable, :image_attachable, :reviewable] do
+ resource :video, concerns: [:commentable, :reviewable]
end
resource :picture, concerns: :commentable do
@@ -63,6 +75,18 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest
assert_equal "404", @response.code
end
+ def test_accessing_callable_concern_from_resources
+ get "/posts/1/reviews/1"
+ assert_equal "200", @response.code
+ assert_equal "/posts/1/reviews/1", post_review_path(post_id: 1, id: 1)
+ end
+
+ def test_callable_concern_can_adapt_to_mapper
+ get "/posts/1/video/reviews/1"
+ assert_equal "200", @response.code
+ assert_equal "/posts/1/video/reviews/1", post_video_video_review_path(post_id: 1, id: 1)
+ end
+
def test_accessing_concern_from_a_scope
get "/videos/comments"
assert_equal "200", @response.code