Skip to content
This repository
Browse code

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
commit 44587b7faeb2bf2962e9a2e824c341ff1e3f9add 2 parents 61a31f3 + 0c4990b
Joshua Peek josh authored
11 actionpack/lib/action_controller/metal/responder.rb
@@ -102,9 +102,14 @@ def initialize(controller, resources, options={})
102 102 # not defined, call to_format.
103 103 #
104 104 def self.call(*args)
105   - responder = new(*args)
106   - method = :"to_#{responder.format}"
107   - responder.respond_to?(method) ? responder.send(method) : responder.to_format
  105 + new(*args).respond
  106 + end
  107 +
  108 + # Main entry point for responder responsible to dispatch to the proper format.
  109 + #
  110 + def respond
  111 + method = :"to_#{format}"
  112 + respond_to?(method) ? send(method) : to_format
108 113 end
109 114
110 115 # HTML format does not render the resource, it always attempt to render a
1  actionpack/test/controller/caching_test.rb
@@ -640,6 +640,7 @@ def test_fragment_for_logging
640 640
641 641 assert fragment_computed
642 642 assert_equal 'generated till now -> ', buffer
  643 + ActiveSupport::Notifications.notifier.wait
643 644 assert_equal [:fragment_exist?, :write_fragment], events.map(&:first)
644 645 end
645 646
17 actionpack/test/controller/mime_responds_test.rb
@@ -507,6 +507,13 @@ def using_resource_with_action
507 507 end
508 508 end
509 509
  510 + def using_responder_with_respond
  511 + responder = Class.new(ActionController::Responder) do
  512 + def respond; @controller.render :text => "respond #{format}"; end
  513 + end
  514 + respond_with(Customer.new("david", 13), :responder => responder)
  515 + end
  516 +
510 517 protected
511 518
512 519 def _render_js(js, options)
@@ -735,6 +742,16 @@ def render(params={})
735 742 assert_equal "foo - #{[:html].to_s}", @controller.response_body
736 743 end
737 744
  745 + def test_respond_as_responder_entry_point
  746 + @request.accept = "text/html"
  747 + get :using_responder_with_respond
  748 + assert_equal "respond html", @response.body
  749 +
  750 + @request.accept = "application/xml"
  751 + get :using_responder_with_respond
  752 + assert_equal "respond xml", @response.body
  753 + end
  754 +
738 755 def test_clear_respond_to
739 756 @controller = InheritedRespondWithController.new
740 757 @request.accept = "text/html"

0 comments on commit 44587b7

Please sign in to comment.
Something went wrong with that request. Please try again.