diff --git a/spec/lucky/error_handling_spec.cr b/spec/lucky/error_handling_spec.cr index f7e84cbac..c634de8b7 100644 --- a/spec/lucky/error_handling_spec.cr +++ b/spec/lucky/error_handling_spec.cr @@ -11,7 +11,7 @@ end private class ShortAndStoutError < Exception include Lucky::HttpRespondable - def http_error_code + def http_error_code : Int32 418 end end @@ -20,11 +20,11 @@ private class InvalidParam < Lucky::Exceptions::InvalidParam end private class FakeErrorAction < Lucky::ErrorAction - def handle_error(error : FakeError) + def handle_error(error : FakeError) : Lucky::Response head status: 404 end - def handle_error(error : Exception) + def handle_error(error : Exception) : Lucky::Response plain_text "Oops" end end diff --git a/spec/lucky/secure_headers_spec.cr b/spec/lucky/secure_headers_spec.cr index ef33623b3..37363e43b 100644 --- a/spec/lucky/secure_headers_spec.cr +++ b/spec/lucky/secure_headers_spec.cr @@ -9,7 +9,7 @@ class FrameGuardRoutes::WithSameorigin < Lucky::Action plain_text "test" end - def frame_guard_value + def frame_guard_value : String "sameorigin" end end @@ -21,7 +21,7 @@ class FrameGuardRoutes::WithDeny < Lucky::Action plain_text "test" end - def frame_guard_value + def frame_guard_value : String "deny" end end @@ -33,7 +33,7 @@ class FrameGuardRoutes::WithURL < Lucky::Action plain_text "test" end - def frame_guard_value + def frame_guard_value : String "https://tacotrucks.food" end end @@ -45,7 +45,7 @@ class FrameGuardRoutes::WithBadValue < Lucky::Action plain_text "test" end - def frame_guard_value + def frame_guard_value : String "hax0rz" end end diff --git a/spec/support/raw_log_formatter.cr b/spec/support/raw_log_formatter.cr index 548616099..634ca9a15 100644 --- a/spec/support/raw_log_formatter.cr +++ b/spec/support/raw_log_formatter.cr @@ -1,5 +1,5 @@ struct RawLogFormatter < Dexter::Formatters::BaseLogFormatter - def format(data) + def format(data) : Nil io << data end end diff --git a/src/lucky/error_action.cr b/src/lucky/error_action.cr index 9b43347c3..4d30afd9e 100644 --- a/src/lucky/error_action.cr +++ b/src/lucky/error_action.cr @@ -30,7 +30,7 @@ abstract class Lucky::ErrorAction head, render, redirect, json, text, etc. Example: - def handle_error(error : Exception) + def handle_error(error : Exception) : Lucky::Response # Returns a Lucky::Response # Could also be render, json, text, etc. head status: 500 diff --git a/src/lucky/exception_page.cr b/src/lucky/exception_page.cr index bb18d16ed..310b231aa 100644 --- a/src/lucky/exception_page.cr +++ b/src/lucky/exception_page.cr @@ -1,5 +1,5 @@ class Lucky::ExceptionPage < ExceptionPage - def styles + def styles : ExceptionPage::Styles Styles.new(accent: lucky_green) end diff --git a/src/lucky/exceptions.cr b/src/lucky/exceptions.cr index 88410b3f3..38fb757f6 100644 --- a/src/lucky/exceptions.cr +++ b/src/lucky/exceptions.cr @@ -24,7 +24,7 @@ module Lucky "Required param \"#{param_name}\" with value \"#{param_value}\" couldn't be parsed to a \"#{param_type}\"" end - def http_error_code + def http_error_code : Int32 HTTP::Status::UNPROCESSABLE_ENTITY.value end end diff --git a/src/lucky/page_helpers/time_helpers.cr b/src/lucky/page_helpers/time_helpers.cr index a594e2a42..c8195c0d0 100644 --- a/src/lucky/page_helpers/time_helpers.cr +++ b/src/lucky/page_helpers/time_helpers.cr @@ -19,13 +19,13 @@ module Lucky::TimeHelpers case distance when 1...27 then distance == 1 ? "a day" : "#{distance} days" when 27...60 then "about a month" - when 60...365 then "#{(distance / 30).round} months" + when 60...365 then "#{(distance / 30).round.to_i} months" when 365...730 "about a year" when 730...1460 - "over #{(distance / 365).round} years" + "over #{(distance / 365).round.to_i} years" else - "almost #{(distance / 365).round} years" + "almost #{(distance / 365).round.to_i} years" end end diff --git a/src/lucky/pretty_log_formatter.cr b/src/lucky/pretty_log_formatter.cr index 90244a1f2..a0a4d792c 100644 --- a/src/lucky/pretty_log_formatter.cr +++ b/src/lucky/pretty_log_formatter.cr @@ -84,7 +84,7 @@ struct Lucky::PrettyLogFormatter < Dexter::Formatters::BaseLogFormatter AnyOtherDataFormatter, ] - def format(data : NamedTuple) : Void + def format(data : NamedTuple) : Nil MESSAGE_FORMATTERS.each do |message_formatter| result = message_formatter.new(io, severity).format(data) break unless result.is_a?(MessageFormatter::Continue) diff --git a/src/lucky/routable.cr b/src/lucky/routable.cr index e72fdf077..62d32c73b 100644 --- a/src/lucky/routable.cr +++ b/src/lucky/routable.cr @@ -234,7 +234,7 @@ module Lucky::Routable anchor.try do |value| path += "#" - path += URI.escape(value) + path += URI.encode_www_form(value) end Lucky::RouteHelper.new {{ method }}, path @@ -257,9 +257,9 @@ module Lucky::Routable {% for part in path_parts %} path << "/" {% if part.starts_with?(":") %} - path << URI.escape({{ part.gsub(/:/, "").id }}.to_param) + path << URI.encode_www_form({{ part.gsub(/:/, "").id }}.to_param) {% else %} - path << URI.escape({{ part }}) + path << URI.encode_www_form({{ part }}) {% end %} {% end %} end