2009-09-19 13:10:41 -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
|
|
|
|
render :text => self.formats.inspect
|
|
|
|
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-04 04:35:06 -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-04 04:35:06 -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
|