mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Dynamically insert handlers. Fixes #376
This commit is contained in:
parent
dbbe05a610
commit
1d056b203b
7 changed files with 73 additions and 20 deletions
|
@ -26,6 +26,7 @@ describe "Config" do
|
|||
it "adds a custom handler" do
|
||||
config = Kemal.config
|
||||
config.add_handler CustomTestHandler.new
|
||||
Kemal.config.setup
|
||||
config.handlers.size.should eq(6)
|
||||
end
|
||||
|
||||
|
|
|
@ -112,9 +112,6 @@ describe "Handler" do
|
|||
"Post"
|
||||
end
|
||||
add_handler PostOnlyHandler.new
|
||||
request = HTTP::Request.new("POST", "/only")
|
||||
client_response = call_request_on_app(request)
|
||||
client_response.body.should eq "OnlyPost"
|
||||
add_handler PostExcludeHandler.new
|
||||
request = HTTP::Request.new("POST", "/only")
|
||||
client_response = call_request_on_app(request)
|
||||
|
@ -124,6 +121,7 @@ describe "Handler" do
|
|||
it "adds a handler at given position" do
|
||||
post_handler = PostOnlyHandler.new
|
||||
add_handler post_handler, 1
|
||||
Kemal.config.setup
|
||||
Kemal.config.handlers[1].should eq post_handler
|
||||
end
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ describe "Macros" do
|
|||
describe "#add_handler" do
|
||||
it "adds a custom handler" do
|
||||
add_handler CustomTestHandler.new
|
||||
Kemal.config.setup
|
||||
Kemal.config.handlers.size.should eq 6
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +25,6 @@ describe "Macros" do
|
|||
it "sets a custom logger" do
|
||||
config = Kemal::Config::INSTANCE
|
||||
logger CustomLogHandler.new
|
||||
config.handlers[4].should be_a(CustomLogHandler)
|
||||
config.logger.should be_a(CustomLogHandler)
|
||||
end
|
||||
end
|
||||
|
@ -119,6 +119,7 @@ describe "Macros" do
|
|||
describe "#gzip" do
|
||||
it "adds HTTP::CompressHandler to handlers" do
|
||||
gzip true
|
||||
Kemal.config.setup
|
||||
Kemal.config.handlers[4].should be_a(HTTP::CompressHandler)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,6 +64,7 @@ def call_request_on_app(request)
|
|||
end
|
||||
|
||||
def build_main_handler
|
||||
Kemal.config.setup
|
||||
main_handler = Kemal.config.handlers.first
|
||||
current_handler = main_handler
|
||||
Kemal.config.handlers.each_with_index do |handler, index|
|
||||
|
@ -76,7 +77,6 @@ end
|
|||
Spec.before_each do
|
||||
config = Kemal.config
|
||||
config.env = "development"
|
||||
config.setup
|
||||
end
|
||||
|
||||
Spec.after_each do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue