diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-29 09:53:02 +0200 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-07-29 12:06:02 -0700 |
commit | b51632d34d99ee9cae3287c60887b25fdf7a3618 (patch) | |
tree | 19fc353a3f83f220a1f5999f026d35b6dbeae41f /actionpack/test/dispatch | |
parent | 7e280c3bff8ac25f1c1938aeaeb1d0b4c0fbb726 (diff) | |
download | rails-b51632d34d99ee9cae3287c60887b25fdf7a3618.tar.gz rails-b51632d34d99ee9cae3287c60887b25fdf7a3618.tar.bz2 rails-b51632d34d99ee9cae3287c60887b25fdf7a3618.zip |
Improve request test coverage by adding formats and negotiate_mime tests.
Signed-off-by: Yehuda Katz <wycats@gmail.com>
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 3a85db8aa5..948eeeb001 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -396,10 +396,49 @@ class RequestTest < ActiveSupport::TestCase assert_equal({"bar" => 2}, request.query_parameters) end + test "formats" do + request = stub_request 'HTTP_ACCEPT' => 'text/html' + request.expects(:parameters).at_least_once.returns({}) + assert_equal [ Mime::HTML ], request.formats + + request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8' + request.expects(:parameters).at_least_once.returns({}) + assert_equal with_set(Mime::XML, Mime::HTML), request.formats + + begin + ActionController::Base.use_accept_header, old = + false, ActionController::Base.use_accept_header + + request = stub_request + request.expects(:parameters).at_least_once.returns({ :format => :txt }) + assert_equal with_set(Mime::TEXT), request.formats + ensure + ActionController::Base.use_accept_header = old + end + end + + test "negotiate_mime" do + request = stub_request 'HTTP_ACCEPT' => 'text/html' + request.expects(:parameters).at_least_once.returns({}) + + assert_equal nil, request.negotiate_mime([Mime::XML, Mime::JSON]) + assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::HTML]) + assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::ALL]) + + request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8' + request.expects(:parameters).at_least_once.returns({}) + assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV]) + assert_equal Mime::CSV, request.negotiate_mime([Mime::CSV, Mime::YAML]) + end + protected def stub_request(env={}) ActionDispatch::Request.new(env) end + def with_set(*args) + args + Mime::SET + end + end |