2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2009-09-03 15:58:43 -04:00
|
|
|
|
|
|
|
module ContentNegotiation
|
|
|
|
# This has no layout and it works
|
|
|
|
class BasicController < ActionController::Base
|
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2009-10-15 19:27:26 -04:00
|
|
|
"content_negotiation/basic/hello.html.erb" => "Hello world <%= request.formats.first.to_s %>!"
|
2009-09-03 15:58:43 -04:00
|
|
|
)]
|
2010-11-28 16:40:32 -05:00
|
|
|
|
|
|
|
def all
|
2016-08-07 19:05:28 -04:00
|
|
|
render plain: formats.inspect
|
2010-11-28 16:40:32 -05:00
|
|
|
end
|
2009-09-03 15:58:43 -04:00
|
|
|
end
|
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class TestContentNegotiation < Rack::TestCase
|
2009-09-03 15:58:43 -04:00
|
|
|
test "A */* Accept header will return HTML" do
|
2015-01-29 09:19:41 -05:00
|
|
|
get "/content_negotiation/basic/hello", headers: { "HTTP_ACCEPT" => "*/*" }
|
2009-09-03 15:58:43 -04:00
|
|
|
assert_body "Hello world */*!"
|
|
|
|
end
|
2010-11-28 16:40:32 -05:00
|
|
|
|
|
|
|
test "Not all mimes are converted to symbol" do
|
2015-01-29 09:19:41 -05:00
|
|
|
get "/content_negotiation/basic/all", headers: { "HTTP_ACCEPT" => "text/plain, mime/another" }
|
2010-11-28 16:40:32 -05:00
|
|
|
assert_body '[:text, "mime/another"]'
|
|
|
|
end
|
2009-09-03 15:58:43 -04:00
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|