Changeset 8342
- Timestamp:
- 12/09/07 22:11:37 (7 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/render_test.rb (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8341 r8342 1 1 *SVN* 2 3 * render :xml and :json preserve custom content types. #10388 [jmettraux, Chu Yeow] 2 4 3 5 * Refactor Action View template handlers. #10437 [Josh Peek] trunk/actionpack/lib/action_controller/base.rb
r8335 r8342 874 874 875 875 elsif xml = options[:xml] 876 response.content_type = Mime::XML876 response.content_type ||= Mime::XML 877 877 render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status]) 878 878 … … 880 880 json = json.to_json unless json.is_a?(String) 881 881 json = "#{options[:callback]}(#{json})" unless options[:callback].blank? 882 response.content_type = Mime::JSON882 response.content_type ||= Mime::JSON 883 883 render_for_text(json, options[:status]) 884 884 trunk/actionpack/test/controller/render_test.rb
r8011 r8342 45 45 end 46 46 47 def render_json_with_custom_content_type 48 render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript' 49 end 50 47 51 def render_symbol_json 48 52 render :json => {:hello => 'world'}.to_json … … 64 68 @name = "David" 65 69 render :template => "test/hello" 70 end 71 72 def render_xml_with_custom_content_type 73 render :xml => "<blah/>", :content_type => "application/atomsvc+xml" 66 74 end 67 75 … … 200 208 end 201 209 202 def test_ do_with_render210 def test_render 203 211 get :render_hello_world 204 212 assert_template "test/hello_world" 205 213 end 206 214 207 def test_ do_with_render_from_variable215 def test_render_from_variable 208 216 get :render_hello_world_from_variable 209 217 assert_equal "hello david", @response.body 210 218 end 211 219 212 def test_ do_with_render_action220 def test_render_action 213 221 get :render_action_hello_world 214 222 assert_template "test/hello_world" 215 223 end 216 224 217 def test_ do_with_render_action_with_symbol225 def test_render_action_with_symbol 218 226 get :render_action_hello_world_with_symbol 219 227 assert_template "test/hello_world" 220 228 end 221 229 222 def test_ do_with_render_text230 def test_render_text 223 231 get :render_text_hello_world 224 232 assert_equal "hello world", @response.body 225 233 end 226 234 227 def test_ do_with_render_json235 def test_render_json 228 236 get :render_json_hello_world 229 237 assert_equal '{"hello": "world"}', @response.body … … 231 239 end 232 240 233 def test_ do_with_render_json_with_callback241 def test_render_json_with_callback 234 242 get :render_json_hello_world_with_callback 235 243 assert_equal 'alert({"hello": "world"})', @response.body … … 237 245 end 238 246 239 def test_do_with_render_symbol_json 247 def test_render_json_with_custom_content_type 248 get :render_json_with_custom_content_type 249 assert_equal '{"hello": "world"}', @response.body 250 assert_equal 'text/javascript', @response.content_type 251 end 252 253 def test_render_symbol_json 240 254 get :render_symbol_json 241 255 assert_equal '{"hello": "world"}', @response.body … … 243 257 end 244 258 245 def test_ do_with_render_custom_code259 def test_render_custom_code 246 260 get :render_custom_code 247 261 assert_response 404 … … 249 263 end 250 264 251 def test_ do_with_render_nothing_with_appendix265 def test_render_nothing_with_appendix 252 266 get :render_nothing_with_appendix 253 267 assert_response 200 … … 270 284 get :render_xml_hello 271 285 assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body 286 assert_equal "application/xml", @response.content_type 272 287 end 273 288 … … 436 451 end 437 452 453 def test_should_render_xml_but_keep_custom_content_type 454 get :render_xml_with_custom_content_type 455 assert_equal "application/atomsvc+xml", @response.content_type 456 end 457 438 458 protected 439 459