aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorErnie Miller <ernie@erniemiller.org>2012-08-26 15:37:23 -0400
committerErnie Miller <ernie@erniemiller.org>2012-09-03 13:13:17 -0400
commit05136e5c0b3d7b841bdec53847879321309604d3 (patch)
tree3a7c32f3e4a1c57be059a6c2a41381b41fa0b7cf /actionpack/test
parenteb43d3d1d94c67b3bf9c0cf576cdae8380f27260 (diff)
downloadrails-05136e5c0b3d7b841bdec53847879321309604d3.tar.gz
rails-05136e5c0b3d7b841bdec53847879321309604d3.tar.bz2
rails-05136e5c0b3d7b841bdec53847879321309604d3.zip
Make enhanced routing Concerns more tell-don't-ask
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/routing/concerns_test.rb27
1 files changed, 15 insertions, 12 deletions
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|