Skip to content

Commit

Permalink
Merge pull request #1296 from tomelm/fix-prefers-plaintext
Browse files Browse the repository at this point in the history
Call the correct accepts_html? method for prefer_plaintext
  • Loading branch information
rafaelfranca committed Sep 13, 2018
1 parent 957f596 commit 216b7ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/show_exceptions.rb
Expand Up @@ -46,7 +46,7 @@ def call(env)
end

def prefers_plaintext?(env)
!accepts_html(env)
!accepts_html?(env)
end

def accepts_html?(env)
Expand Down
13 changes: 13 additions & 0 deletions test/spec_show_exceptions.rb
Expand Up @@ -77,4 +77,17 @@ def show_exceptions(app)
assert_match(res, /ShowExceptions/)
assert_match(res, /unknown location/)
end

it "knows to prefer plaintext for non-html" do
# We don't need an app for this
exc = Rack::ShowExceptions.new(nil)

[
[{ "HTTP_ACCEPT" => "text/plain" }, true],
[{ "HTTP_ACCEPT" => "text/foo" }, true],
[{ "HTTP_ACCEPT" => "text/html" }, false]
].each do |env, expected|
assert_equal(expected, exc.prefers_plaintext?(env))
end
end
end

0 comments on commit 216b7ca

Please sign in to comment.