Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pass respond_with options to controller render when using a template …

…for api navigation

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit b45302d7676a5e38d82662f9068ee6d832ff2e3c 1 parent 48404a7
@joshk joshk authored josevalim committed
View
4 actionpack/lib/action_controller/metal/implicit_render.rb
@@ -10,8 +10,8 @@ def send_action(method, *args)
end
end
- def default_render
- render
+ def default_render(*args)
+ render(*args)
end
def action_method?(action_name)
View
4 actionpack/lib/action_controller/metal/mime_responds.rb
@@ -189,7 +189,7 @@ def respond_to(*mimes, &block)
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
if response = retrieve_response_from_mimes(mimes, &block)
- response.call
+ response.call(nil)
end
end
@@ -259,7 +259,7 @@ def collect_mimes_from_class_level #:nodoc:
#
def retrieve_response_from_mimes(mimes=nil, &block)
mimes ||= collect_mimes_from_class_level
- collector = Collector.new(mimes) { default_render }
+ collector = Collector.new(mimes) { |options| default_render(options || {}) }
block.call(collector) if block_given?
if format = request.negotiate_mime(collector.order)
View
2  actionpack/lib/action_controller/metal/responder.rb
@@ -187,7 +187,7 @@ def resource_location
# controller.
#
def default_render
- @default_response.call
+ @default_response.call(options)
end
# Display is just a shortcut to render a resource with the current format.
View
19 actionpack/test/controller/mime_responds_test.rb
@@ -562,6 +562,11 @@ def using_invalid_resource_with_template
respond_with(resource)
end
+ def using_options_with_template
+ @customer = resource
+ respond_with(@customer, :status => 123, :location => "http://test.host/")
+ end
+
def using_resource_with_responder
responder = proc { |c, r, o| c.render :text => "Resource name is #{r.first.name}" }
respond_with(resource, :responder => responder)
@@ -991,6 +996,20 @@ def test_using_invalid_resource_with_template
assert_equal nil, @response.location
end
+ def test_using_options_with_template
+ @request.accept = "text/xml"
+
+ post :using_options_with_template
+ assert_equal "<customer-name>david</customer-name>", @response.body
+ assert_equal 123, @response.status
+ assert_equal "http://test.host/", @response.location
+
+ put :using_options_with_template
+ assert_equal "<customer-name>david</customer-name>", @response.body
+ assert_equal 123, @response.status
+ assert_equal "http://test.host/", @response.location
+ end
+
def test_using_resource_with_responder
get :using_resource_with_responder
assert_equal "Resource name is david", @response.body
View
1  actionpack/test/fixtures/respond_with/using_options_with_template.xml.erb
@@ -0,0 +1 @@
+<customer-name><%= @customer.name %></customer-name>
Please sign in to comment.
Something went wrong with that request. Please try again.