Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/lucky/error_handling_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
private class ShortAndStoutError < Exception
include Lucky::HttpRespondable

def http_error_code
def http_error_code : Int32
418
end
end
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/lucky/secure_headers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/raw_log_formatter.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct RawLogFormatter < Dexter::Formatters::BaseLogFormatter
def format(data)
def format(data) : Nil
io << data
end
end
2 changes: 1 addition & 1 deletion src/lucky/error_action.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/exception_page.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Lucky::ExceptionPage < ExceptionPage
def styles
def styles : ExceptionPage::Styles
Styles.new(accent: lucky_green)
end

Expand Down
2 changes: 1 addition & 1 deletion src/lucky/exceptions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/lucky/page_helpers/time_helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/lucky/pretty_log_formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/lucky/routable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down