aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorChris Eppstein <chris@eppsteins.net>2010-11-05 10:28:35 +0800
committerJosé Valim <jose.valim@gmail.com>2010-11-06 06:56:36 +0800
commitb1667c7c2c1aba4a2adb5f36ad9499c01763655d (patch)
tree46911924dd1177ca0b6a59a10bac44f242e8dfa5 /actionpack
parent06d518a32398a4dc7564f45aa19575ea7fa702da (diff)
downloadrails-b1667c7c2c1aba4a2adb5f36ad9499c01763655d.tar.gz
rails-b1667c7c2c1aba4a2adb5f36ad9499c01763655d.tar.bz2
rails-b1667c7c2c1aba4a2adb5f36ad9499c01763655d.zip
Correctly handle the case of an API response that returns a hash by treating a single hash argument as the resource instead of as options.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb16
2 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index c6d4c6d936..f7dd0dcb69 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -227,7 +227,7 @@ module ActionController #:nodoc:
"controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if response = retrieve_response_from_mimes(&block)
- options = resources.extract_options!
+ options = resources.size == 1 ? {} : resources.extract_options!
options.merge!(:default_response => response)
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index a898ef76e5..b6ce9f7d34 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -487,6 +487,10 @@ class RespondWithController < ActionController::Base
respond_with(resource)
end
+ def using_hash_resource
+ respond_with({:result => resource})
+ end
+
def using_resource_with_block
respond_with(resource) do |format|
format.csv { render :text => "CSV" }
@@ -587,6 +591,18 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
+ def test_using_hash_resource
+ @request.accept = "application/xml"
+ get :using_hash_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <name>david</name>\n</hash>\n", @response.body
+
+ @request.accept = "application/json"
+ get :using_hash_resource
+ assert_equal "application/json", @response.content_type
+ assert_equal %Q[{"result":["david",13]}], @response.body
+ end
+
def test_using_resource_with_block
@request.accept = "*/*"
get :using_resource_with_block