From 05136e5c0b3d7b841bdec53847879321309604d3 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Sun, 26 Aug 2012 15:37:23 -0400 Subject: Make enhanced routing Concerns more tell-don't-ask --- actionpack/test/dispatch/routing/concerns_test.rb | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing/concerns_test.rb b/actionpack/test/dispatch/routing/concerns_test.rb index 0289f38ba7..9f37701656 100644 --- a/actionpack/test/dispatch/routing/concerns_test.rb +++ b/actionpack/test/dispatch/routing/concerns_test.rb @@ -2,19 +2,15 @@ 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 + def self.call(mapper, options = {}) + mapper.resources :reviews, options end end Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - concern :commentable do - resources :comments + concern :commentable do |options| + resources :comments, options end concern :image_attachable do @@ -24,7 +20,9 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest concern :reviewable, Reviewable resources :posts, concerns: [:commentable, :image_attachable, :reviewable] do - resource :video, concerns: [:commentable, :reviewable] + resource :video, concerns: :commentable do + concerns :reviewable, as: :video_reviews + end end resource :picture, concerns: :commentable do @@ -32,7 +30,7 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest end scope "/videos" do - concerns :commentable + concerns :commentable, except: :destroy end end end @@ -75,13 +73,13 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest assert_equal "404", @response.code end - def test_accessing_callable_concern_from_resources + def test_accessing_callable_concern_ 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 + def test_callable_concerns_accept_options 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) @@ -92,6 +90,11 @@ class RoutingConcernsTest < ActionDispatch::IntegrationTest assert_equal "200", @response.code end + def test_concerns_accept_options + delete "/videos/comments/1" + assert_equal "404", @response.code + end + def test_with_an_invalid_concern_name e = assert_raise ArgumentError do ActionDispatch::Routing::RouteSet.new.tap do |app| -- cgit v1.2.3