提交 eb43d3d1 编写于 作者: E Ernie Miller

Fix concerns not executing block in mapper

Also, add documentation for alternate usage.
上级 4037e31d
......@@ -1606,15 +1606,32 @@ def name_for_action(as, action) #:nodoc:
# concerns :commentable
# end
module Concerns
# Define a routing concern using a name.
# Define a routing concern using a name. If a second parameter is
# supplied, it should respond to call, which will receive the mapper
# as a parameter, allowing for customized behavior based on the current
# scope.
#
# concern :commentable do
# resources :comments
# end
#
# # - or -
#
# class Commentable
# def self.call(mapper)
# if mapper.current_scope[:controller] == 'videos'
# mapper.resources :video_comments, as: :comments
# else
# mapper.resources :comments
# end
# end
# end
#
# concern :commentable, Commentable
#
# Any routing helpers can be used inside a concern.
def concern(name, callable = nil, &block)
@concerns[name] = callable || block
@concerns[name] = callable || lambda { |m| m.instance_eval(&block) }
end
# Use the named concerns
......
......@@ -103,4 +103,14 @@ def test_with_an_invalid_concern_name
assert_equal "No concern named foo was found!", e.message
end
def test_concerns_executes_block_in_context_of_current_mapper
mapper = ActionDispatch::Routing::Mapper.new(ActionDispatch::Routing::RouteSet.new)
mapper.concern :test_concern do
resources :things
return self
end
assert_equal mapper, mapper.concerns(:test_concern)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册