aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb24
-rw-r--r--actionpack/test/controller/render_test.rb10
2 files changed, 22 insertions, 12 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 8f1c56710f..c4d8709fc3 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -170,18 +170,26 @@ class MimeControllerTest < Test::Unit::TestCase
get :just_xml
assert_response 406
end
-
+
def test_json_or_yaml
get :json_or_yaml
assert_equal 'JSON', @response.body
-
- @request.env["HTTP_ACCEPT"] = "text/yaml"
- get :json_or_yaml
- assert_equal 'YAML', @response.body
-
- @request.env["HTTP_ACCEPT"] = "text/x-json"
- get :json_or_yaml
+
+ get :json_or_yaml, :format => 'json'
assert_equal 'JSON', @response.body
+
+ get :json_or_yaml, :format => 'yaml'
+ assert_equal 'YAML', @response.body
+
+ { 'YAML' => %w(text/yaml),
+ 'JSON' => %w(application/json text/x-json)
+ }.each do |body, content_types|
+ content_types.each do |content_type|
+ @request.env['HTTP_ACCEPT'] = content_type
+ get :json_or_yaml
+ assert_equal body, @response.body
+ end
+ end
end
def test_js_or_anything
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 3cff829f8a..b223862c9e 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -38,11 +38,11 @@ class TestController < ActionController::Base
def render_text_hello_world
render_text "hello world"
end
-
+
def render_json_hello_world
render_json({:hello => 'world'}.to_json)
end
-
+
def render_json_hello_world_with_callback
render_json({:hello => 'world'}.to_json, 'alert')
end
@@ -171,15 +171,17 @@ class RenderTest < Test::Unit::TestCase
get :render_text_hello_world
assert_equal "hello world", @response.body
end
-
+
def test_do_with_render_json
get :render_json_hello_world
assert_equal '{hello: "world"}', @response.body
+ assert_equal 'application/json', @response.content_type
end
-
+
def test_do_with_render_json_with_callback
get :render_json_hello_world_with_callback
assert_equal 'alert({hello: "world"})', @response.body
+ assert_equal 'application/json', @response.content_type
end
def test_do_with_render_custom_code