All specs passing

This commit is contained in:
sdogruyol 2016-04-12 20:00:37 +03:00
parent 0a162a602b
commit 40ab34c63d
3 changed files with 10 additions and 10 deletions

View file

@ -186,5 +186,5 @@ describe "Kemal::Middleware::Filters" do
end
class FilterTest
property modified
property modified : String?
end

View file

@ -5,7 +5,7 @@ module Kemal
@ssl : OpenSSL::SSL::Context
property host_binding, ssl, port, env, public_folder, logging,
always_rescue, error_handler, serve_static, run
always_rescue, serve_static, run
def initialize
@host_binding = "0.0.0.0"
@ -15,8 +15,8 @@ module Kemal
@public_folder = "./public"
@logging = true
@logger = nil
@error_handler = nil
@always_rescue = true
@error_handler = uninitialized Kemal::CommonExceptionHandler
@run = false
@ssl = uninitialized OpenSSL::SSL::Context
end
@ -62,7 +62,7 @@ module Kemal
private def setup_error_handler
if @always_rescue
@error_handler ||= Kemal::CommonExceptionHandler::INSTANCE
@error_handler ||= Kemal::CommonExceptionHandler.new
HANDLERS.insert(1, @error_handler.not_nil!)
end
end

View file

@ -23,7 +23,7 @@ module Kemal::Middleware
# :nodoc: This shouldn't be called directly, it's not private because I need to call it for testing purpose since I can't call the macros in the spec.
# It adds the block for the corresponding verb/path/type combination to the tree.
def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> _)
def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> String)
lookup = lookup_filters_for_path_type(verb, path, type)
if lookup.found? && lookup.payload.is_a?(Array(Block))
(lookup.payload as Array(Block)) << Block.new(&block)
@ -33,12 +33,12 @@ module Kemal::Middleware
end
# This can be called directly but it's simpler to just use the macros, it will check if another filter is not already defined for this verb/path/type and proceed to call `add_route_filter`
def before(verb, path = "*", &block : HTTP::Server::Context -> _)
def before(verb, path = "*", &block : HTTP::Server::Context -> String)
_add_route_filter verb, path, :before, &block
end
# This can be called directly but it's simpler to just use the macros, it will check if another filter is not already defined for this verb/path/type and proceed to call `add_route_filter`
def after(verb, path = "*", &block : HTTP::Server::Context -> _)
def after(verb, path = "*", &block : HTTP::Server::Context -> String)
_add_route_filter verb, path, :after, &block
end
@ -68,9 +68,9 @@ module Kemal::Middleware
end
class Block
property block : (HTTP::Server::Context -> )
property block : (HTTP::Server::Context -> String)
def initialize(&@block : HTTP::Server::Context -> _)
def initialize(&@block : HTTP::Server::Context -> String)
end
def call(context)
@ -86,7 +86,7 @@ end
ALL_METHODS = %w(get post put patch delete all)
{% for type in ["before", "after"] %}
{% for method in ALL_METHODS %}
def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> _)
def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> String)
Kemal::Middleware::Filter::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
end
{% end %}