Permalink
Browse files

Added proc as argument for #route_added hook

  • Loading branch information...
1 parent 87bf495 commit d6ceeb0b5690abcddbb14db135df530a4083d10b @tj tj committed with rtomayko Apr 1, 2009
Showing with 18 additions and 4 deletions.
  1. +1 −1 lib/sinatra/base.rb
  2. +17 −3 test/route_added_hook_test.rb
View
@@ -733,7 +733,7 @@ def route(verb, path, opts={}, &block)
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
@@ -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

0 comments on commit d6ceeb0

Please sign in to comment.