test delegation of Sinatra.register and Sinatra.helpers

This commit is contained in:
Konstantin Haase 2011-03-31 13:02:04 +02:00
parent cacd473801
commit cbe5d15d42
2 changed files with 15 additions and 3 deletions

View File

@ -1518,11 +1518,11 @@ module Sinatra
# Extend the top-level DSL with the modules provided. # Extend the top-level DSL with the modules provided.
def self.register(*extensions, &block) def self.register(*extensions, &block)
Application.register(*extensions, &block) Delegator.target.register(*extensions, &block)
end end
# Include the helper modules provided in Sinatra's request context. # Include the helper modules provided in Sinatra's request context.
def self.helpers(*extensions, &block) def self.helpers(*extensions, &block)
Application.helpers(*extensions, &block) Delegator.target.helpers(*extensions, &block)
end end
end end

View File

@ -46,7 +46,7 @@ class DelegatorTest < Test::Unit::TestCase
def delegate(&block) def delegate(&block)
assert Sinatra::Delegator.target != Sinatra::Application assert Sinatra::Delegator.target != Sinatra::Application
Object.new.extend(Sinatra::Delegator).instance_eval(&block) Object.new.extend(Sinatra::Delegator).instance_eval(&block) if block
Sinatra::Delegator.target Sinatra::Delegator.target
end end
@ -88,6 +88,18 @@ class DelegatorTest < Test::Unit::TestCase
assert_equal '', response.body assert_equal '', response.body
end end
it "registers extensions with the delegation target" do
app, mixin = mirror, Module.new
Sinatra.register mixin
assert_equal app.last_call, ["register", mixin.to_s ]
end
it "registers helpers with the delegation target" do
app, mixin = mirror, Module.new
Sinatra.helpers mixin
assert_equal app.last_call, ["helpers", mixin.to_s ]
end
delegates 'get' delegates 'get'
delegates 'patch' delegates 'patch'
delegates 'put' delegates 'put'