Permalink
Browse files

Merge pull request #1004 from ujifgc/route-action

Add request.action to implement #843
  • Loading branch information...
dariocravero committed Jan 12, 2013
2 parents 33cf159 + ea2d10a commit 0715970da782aa57d0058a86b75b9b35f2523e03
Showing with 21 additions and 1 deletion.
  1. +6 −1 padrino-core/lib/padrino-core/application/routing.rb
  2. +15 −0 padrino-core/test/test_routing.rb
@@ -11,6 +11,9 @@ class Sinatra::Request
def controller
route_obj && route_obj.controller
end
def action
route_obj && route_obj.action
end
end
##
@@ -62,7 +65,7 @@ def process_destination_path(path, env)
# @private
class Route
attr_accessor :use_layout, :controller, :cache, :cache_key, :cache_expires_in
attr_accessor :use_layout, :controller, :action, :cache, :cache_key, :cache_expires_in
def before_filters(&block)
@_before_filters ||= []
@@ -557,6 +560,7 @@ def route(verb, path, *args, &block)
route_options = options.dup
route_options[:provides] = @_provides if @_provides
path, *route_options[:with] = path if path.is_a?(Array)
action = path
path, name, options, route_options = *parse_route(path, route_options, verb)
options.reverse_merge!(@_conditions) if @_conditions
@@ -573,6 +577,7 @@ def route(verb, path, *args, &block)
# HTTPRouter route construction
route = router.add(path, route_options)
route.name(name) if name
route.action = action
priority_name = options.delete(:priority) || :normal
priority = ROUTE_PRIORITY[priority_name] or raise("Priority #{priority_name} not recognized, try #{ROUTE_PRIORITY.keys.join(', ')}")
route.cache = options.key?(:cache) ? options.delete(:cache) : @_cache
@@ -371,6 +371,21 @@ class FooError < RuntimeError; end
assert_equal "mini", body
end
should "should inject the action name into the request" do
mock_app do
controller :posts do
get('/omnomnom(/:id)') { request.action.inspect }
controller :mini do
get([:a, :b, :c]) { request.action.inspect }
end
end
end
get "/posts/omnomnom"
assert_equal "\"/omnomnom(/:id)\"", body
get "/mini/a/b/c"
assert_equal ":a", body
end
should "support not_found" do
mock_app do
not_found do

0 comments on commit 0715970

Please sign in to comment.