2011-05-11 07:44:02 +00:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2009-03-10 04:45:47 +00:00
|
|
|
|
|
|
|
module RouteAddedTest
|
2009-04-01 16:01:06 +00:00
|
|
|
@routes, @procs = [], []
|
2009-03-10 04:45:47 +00:00
|
|
|
def self.routes ; @routes ; end
|
2009-04-01 16:01:06 +00:00
|
|
|
def self.procs ; @procs ; end
|
|
|
|
def self.route_added(verb, path, proc)
|
2009-03-10 04:45:47 +00:00
|
|
|
@routes << [verb, path]
|
2009-04-01 16:01:06 +00:00
|
|
|
@procs << proc
|
2009-03-10 04:45:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-10 19:30:47 +00:00
|
|
|
class RouteAddedHookTest < Minitest::Test
|
2012-05-21 21:21:59 +00:00
|
|
|
setup do
|
2009-04-01 16:01:06 +00:00
|
|
|
RouteAddedTest.routes.clear
|
|
|
|
RouteAddedTest.procs.clear
|
2012-05-21 21:21:59 +00:00
|
|
|
end
|
2009-03-10 04:45:47 +00:00
|
|
|
|
|
|
|
it "should be notified of an added route" do
|
2012-05-21 21:21:59 +00:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-03-10 04:45:47 +00:00
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 21:21:59 +00:00
|
|
|
end
|
2009-03-10 04:45:47 +00: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 21:21:59 +00:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-03-10 04:45:47 +00:00
|
|
|
register RouteAddedTest
|
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 21:21:59 +00:00
|
|
|
end
|
2009-03-10 04:45:47 +00:00
|
|
|
|
|
|
|
assert_equal [["GET", "/"], ["HEAD", "/"]],
|
|
|
|
RouteAddedTest.routes
|
|
|
|
end
|
2012-07-18 19:07:24 +00:00
|
|
|
|
2009-04-01 16:01:06 +00:00
|
|
|
it "should pass route blocks as an argument" do
|
2012-05-21 21:21:59 +00:00
|
|
|
mock_app(Class.new(Sinatra::Base)) do
|
2009-04-01 16:01:06 +00:00
|
|
|
register RouteAddedTest
|
|
|
|
get('/') {}
|
2012-05-21 21:21:59 +00:00
|
|
|
end
|
2009-04-01 16:01:06 +00:00
|
|
|
|
2012-07-18 19:07:24 +00:00
|
|
|
assert_kind_of Proc, RouteAddedTest.procs.first
|
2009-04-01 16:01:06 +00:00
|
|
|
end
|
2009-03-10 04:45:47 +00:00
|
|
|
end
|