2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2009-03-10 00:45:47 -04:00
|
|
|
|
|
|
|
module RouteAddedTest
|
2009-04-01 12:01:06 -04:00
|
|
|
@routes, @procs = [], []
|
2009-03-10 00:45:47 -04:00
|
|
|
def self.routes ; @routes ; end
|
2009-04-01 12:01:06 -04:00
|
|
|
def self.procs ; @procs ; end
|
|
|
|
def self.route_added(verb, path, proc)
|
2009-03-10 00:45:47 -04:00
|
|
|
@routes << [verb, path]
|
2009-04-01 12:01:06 -04:00
|
|
|
@procs << proc
|
2009-03-10 00:45:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class RouteAddedHookTest < Minitest::Test
|
2012-05-21 17:21:59 -04:00
|
|
|
setup do
|
2009-04-01 12:01:06 -04:00
|
|
|
RouteAddedTest.routes.clear
|
|
|
|
RouteAddedTest.procs.clear
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-03-10 00:45:47 -04:00
|
|
|
|
|
|
|
it "should be notified of an added route" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-03-10 00:45:47 -04:00
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-03-10 00:45:47 -04:00
|
|
|
|
|
|
|
assert_equal [["GET", "/"], ["HEAD", "/"]],
|
|
|
|
RouteAddedTest.routes
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should include hooks from superclass" do
|
|
|
|
a = Class.new(Class.new(Sinatra::Base))
|
|
|
|
b = Class.new(a)
|
|
|
|
|
|
|
|
a.register RouteAddedTest
|
|
|
|
b.class_eval { post("/sub_app_route") {} }
|
|
|
|
|
|
|
|
assert_equal [["POST", "/sub_app_route"]],
|
|
|
|
RouteAddedTest.routes
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should only run once per extension" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-03-10 00:45:47 -04:00
|
|
|
register RouteAddedTest
|
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-03-10 00:45:47 -04:00
|
|
|
|
|
|
|
assert_equal [["GET", "/"], ["HEAD", "/"]],
|
|
|
|
RouteAddedTest.routes
|
|
|
|
end
|
2012-07-18 15:07:24 -04:00
|
|
|
|
2009-04-01 12:01:06 -04:00
|
|
|
it "should pass route blocks as an argument" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-04-01 12:01:06 -04:00
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-04-01 12:01:06 -04:00
|
|
|
|
2012-07-18 15:07:24 -04:00
|
|
|
assert_kind_of Proc, RouteAddedTest.procs.first
|
2009-04-01 12:01:06 -04:00
|
|
|
end
|
2009-03-10 00:45:47 -04:00
|
|
|
end
|