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 end
class FilterTest class FilterTest
property modified property modified : String?
end end

View File

@ -5,7 +5,7 @@ module Kemal
@ssl : OpenSSL::SSL::Context @ssl : OpenSSL::SSL::Context
property host_binding, ssl, port, env, public_folder, logging, property host_binding, ssl, port, env, public_folder, logging,
always_rescue, error_handler, serve_static, run always_rescue, serve_static, run
def initialize def initialize
@host_binding = "0.0.0.0" @host_binding = "0.0.0.0"
@ -15,8 +15,8 @@ module Kemal
@public_folder = "./public" @public_folder = "./public"
@logging = true @logging = true
@logger = nil @logger = nil
@error_handler = nil
@always_rescue = true @always_rescue = true
@error_handler = uninitialized Kemal::CommonExceptionHandler
@run = false @run = false
@ssl = uninitialized OpenSSL::SSL::Context @ssl = uninitialized OpenSSL::SSL::Context
end end
@ -62,7 +62,7 @@ module Kemal
private def setup_error_handler private def setup_error_handler
if @always_rescue if @always_rescue
@error_handler ||= Kemal::CommonExceptionHandler::INSTANCE @error_handler ||= Kemal::CommonExceptionHandler.new
HANDLERS.insert(1, @error_handler.not_nil!) HANDLERS.insert(1, @error_handler.not_nil!)
end end
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. # :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. # 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) lookup = lookup_filters_for_path_type(verb, path, type)
if lookup.found? && lookup.payload.is_a?(Array(Block)) if lookup.found? && lookup.payload.is_a?(Array(Block))
(lookup.payload as Array(Block)) << Block.new(&block) (lookup.payload as Array(Block)) << Block.new(&block)
@ -33,12 +33,12 @@ module Kemal::Middleware
end 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` # 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 _add_route_filter verb, path, :before, &block
end 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` # 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 _add_route_filter verb, path, :after, &block
end end
@ -68,9 +68,9 @@ module Kemal::Middleware
end end
class Block 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 end
def call(context) def call(context)
@ -86,7 +86,7 @@ end
ALL_METHODS = %w(get post put patch delete all) ALL_METHODS = %w(get post put patch delete all)
{% for type in ["before", "after"] %} {% for type in ["before", "after"] %}
{% for method in ALL_METHODS %} {% 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) Kemal::Middleware::Filter::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
end end
{% end %} {% end %}