mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
More thorough JSON tests. Use application/json by default, per rfc4627. References #4185.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5695 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -2,10 +2,12 @@ Mime::Type.register "*/*", :all
|
||||
Mime::Type.register "text/plain", :text
|
||||
Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml )
|
||||
Mime::Type.register "text/javascript", :js, %w( application/javascript application/x-javascript )
|
||||
Mime::Type.register "text/x-json", :json, %w( application/x-json )
|
||||
Mime::Type.register "text/calendar", :ics
|
||||
Mime::Type.register "text/csv", :csv
|
||||
Mime::Type.register "application/xml", :xml, %w( text/xml application/x-xml )
|
||||
Mime::Type.register "application/rss+xml", :rss
|
||||
Mime::Type.register "application/atom+xml", :atom
|
||||
Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml )
|
||||
Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml )
|
||||
|
||||
# http://www.ietf.org/rfc/rfc4627.txt
|
||||
Mime::Type.register "application/json", :json, %w( text/x-json )
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user