Added proc as argument for #route_added hook

This commit is contained in:
TJ Holowaychuk 2009-04-01 09:01:06 -07:00 committed by Ryan Tomayko
parent 87bf495b11
commit d6ceeb0b56
2 changed files with 18 additions and 4 deletions

View File

@ -733,7 +733,7 @@ module Sinatra
lambda { unbound_method.bind(self).call }
end
invoke_hook(:route_added, verb, path)
invoke_hook(:route_added, verb, path, block)
(routes[verb] ||= []).
push([pattern, keys, conditions, block]).last

View File

@ -1,15 +1,20 @@
require File.dirname(__FILE__) + '/helper'
module RouteAddedTest
@routes = []
@routes, @procs = [], []
def self.routes ; @routes ; end
def self.route_added(verb, path)
def self.procs ; @procs ; end
def self.route_added(verb, path, proc)
@routes << [verb, path]
@procs << proc
end
end
class RouteAddedHookTest < Test::Unit::TestCase
setup { RouteAddedTest.routes.clear }
setup {
RouteAddedTest.routes.clear
RouteAddedTest.procs.clear
}
it "should be notified of an added route" do
mock_app(Class.new(Sinatra::Base)) {
@ -42,4 +47,13 @@ class RouteAddedHookTest < Test::Unit::TestCase
assert_equal [["GET", "/"], ["HEAD", "/"]],
RouteAddedTest.routes
end
it "should pass route blocks as an argument" do
mock_app(Class.new(Sinatra::Base)) {
register RouteAddedTest
get('/') {}
}
assert_kind_of Proc, RouteAddedTest.procs.first
end
end