From a39c7505bd69e9da0a122fbb8fe20612390c57ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 24 Feb 2010 19:17:24 +0100 Subject: Cleanup render callstack and make render(:json => {}, :status => 401) work again. --- .../lib/action_controller/metal/rendering.rb | 37 ++++++++-------------- actionpack/test/controller/render_json_test.rb | 10 ++++++ 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 6518a464e2..b90c054e98 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -12,21 +12,13 @@ module ActionController end def render(*args) - if response_body - raise ::AbstractController::DoubleRenderError - end - + raise ::AbstractController::DoubleRenderError if response_body args << {} unless args.last.is_a?(Hash) super(*args) self.content_type ||= args.last[:_template].mime_type.to_s response_body end - def render_to_body(options) - _process_options(options) - super - end - private def _render_partial(options) @@ -35,24 +27,10 @@ module ActionController super end - def _determine_template(options) - if options.key?(:text) && options[:text].respond_to?(:to_text) - options[:text] = options[:text].to_text - end - super - end - def format_for_text formats.first end - def _process_options(options) - status, content_type, location = options.values_at(:status, :content_type, :location) - self.status = status if status - self.content_type = content_type if content_type - self.headers["Location"] = url_for(location) if location - end - def _normalize_options(action=nil, options={}, &blk) case action when NilClass @@ -64,12 +42,25 @@ module ActionController options.merge! :partial => action end + if options.key?(:text) && options[:text].respond_to?(:to_text) + options[:text] = options[:text].to_text + end + if options[:status] options[:status] = Rack::Utils.status_code(options[:status]) end options[:update] = blk if block_given? + + _process_options(options) options end + + def _process_options(options) + status, content_type, location = options.values_at(:status, :content_type, :location) + self.status = status if status + self.content_type = content_type if content_type + self.headers["Location"] = url_for(location) if location + end end end diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index 3938fc7061..2580ada88b 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -18,6 +18,10 @@ class RenderJsonTest < ActionController::TestCase render :json => ActiveSupport::JSON.encode(:hello => 'world') end + def render_json_hello_world_with_status + render :json => ActiveSupport::JSON.encode(:hello => 'world'), :status => 401 + end + def render_json_hello_world_with_callback render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert' end @@ -58,6 +62,12 @@ class RenderJsonTest < ActionController::TestCase assert_equal 'application/json', @response.content_type end + def test_render_json_with_status + get :render_json_hello_world_with_status + assert_equal '{"hello":"world"}', @response.body + assert_equal 401, @response.status + end + def test_render_json_with_callback get :render_json_hello_world_with_callback assert_equal 'alert({"hello":"world"})', @response.body -- cgit v1.2.3