Skip to content

Commit

Permalink
Rack 2.1 (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jan 14, 2020
1 parent 29ab743 commit 525d16e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
12 changes: 11 additions & 1 deletion lib/hanami/action/rack.rb
Expand Up @@ -83,6 +83,12 @@ module Rack
# The key that returns router parsed body from the Rack env
ROUTER_PARSED_BODY = 'router.parsed_body'.freeze

# This is the root directory for `#unsafe_send_file`
#
# @since x.x.x
# @api private
FILE_SYSTEM_ROOT = Pathname.new("/").freeze

# Override Ruby's hook for modules.
# It includes basic Hanami::Action modules to the given class.
#
Expand Down Expand Up @@ -353,7 +359,11 @@ def send_file(path)
# end
# end
def unsafe_send_file(path)
directory = self.class.configuration.root_directory if Pathname.new(path).relative?
directory = if Pathname.new(path).relative?
self.class.configuration.root_directory
else
FILE_SYSTEM_ROOT
end

_send_file(
File.new(path, directory).call(@_env)
Expand Down
18 changes: 9 additions & 9 deletions spec/integration/hanami/controller/mime_type_spec.rb
Expand Up @@ -21,7 +21,7 @@ class Default
include Hanami::Action

def call(_params)
self.body = format
self.body = format.to_s
end
end

Expand All @@ -32,7 +32,7 @@ class Configuration
configuration.default_charset 'ISO-8859-1'

def call(_params)
self.body = format
self.body = format.to_s
end
end

Expand All @@ -41,7 +41,7 @@ class Custom

def call(_params)
self.format = :xml
self.body = format
self.body = format.to_s
end
end

Expand All @@ -51,7 +51,7 @@ class Latin
def call(_params)
self.charset = 'latin1'
self.format = :html
self.body = format
self.body = format.to_s
end
end

Expand All @@ -64,7 +64,7 @@ def call(_params)
headers['X-AcceptXml'] = accept?('application/xml').to_s
headers['X-AcceptJson'] = accept?('text/json').to_s

self.body = format
self.body = format.to_s
end
end

Expand All @@ -75,7 +75,7 @@ class CustomFromAccept
accept :json, :custom

def call(_params)
self.body = format
self.body = format.to_s
end
end

Expand Down Expand Up @@ -105,7 +105,7 @@ class DefaultResponse
configuration.default_response_format :json

def call(_params)
self.body = configuration.default_request_format
self.body = configuration.default_request_format.to_s
end
end

Expand Down Expand Up @@ -135,7 +135,7 @@ class ContentType

def call(_params)
self.format = :json
self.body = format
self.body = format.to_s
end
end

Expand All @@ -146,7 +146,7 @@ class DefaultAndContentType

def call(_params)
self.format = :json
self.body = format
self.body = format.to_s
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/hanami/action/cookies_spec.rb
Expand Up @@ -31,14 +31,14 @@
action = SetCookiesWithOptionsAction.new(expires: tomorrow)
_, headers, = action.call({})

expect(headers).to eq("Content-Type" => "application/octet-stream; charset=utf-8", "Set-Cookie" => "kukki=yum%21; domain=hanamirb.org; path=/controller; expires=#{tomorrow.gmtime.rfc2822}; secure; HttpOnly")
expect(headers).to eq("Content-Type" => "application/octet-stream; charset=utf-8", "Set-Cookie" => "kukki=yum%21; domain=hanamirb.org; path=/controller; expires=#{tomorrow.httpdate}; secure; HttpOnly")
end

it "removes cookies" do
action = RemoveCookiesAction.new
_, headers, = action.call("HTTP_COOKIE" => "foo=bar;rm=me")

expect(headers).to eq("Content-Type" => "application/octet-stream; charset=utf-8", "Set-Cookie" => "rm=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000")
expect(headers).to eq("Content-Type" => "application/octet-stream; charset=utf-8", "Set-Cookie" => "rm=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT")
end

it "iterates cookies" do
Expand Down Expand Up @@ -75,7 +75,7 @@
_, headers, = action.call({})
max_age = 120
expect(headers["Set-Cookie"]).to include("max-age=#{max_age}")
expect(headers["Set-Cookie"]).to include("expires=#{(Time.now + max_age).gmtime.rfc2822}")
expect(headers["Set-Cookie"]).to include("expires=#{(Time.now + max_age).httpdate}")
end
end
end
Expand Down

0 comments on commit 525d16e

Please sign in to comment.