From a3ea4b757d7d6fc3016f769d537ee1f6e93b30c2 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 27 Jun 2020 12:48:12 +0100 Subject: [PATCH] Merge decorator into the class brought from spree --- .../core/controller_helpers/respond_with.rb | 13 +++++---- .../respond_with_decorator.rb | 28 ------------------- 2 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 lib/spree/core/controller_helpers/respond_with_decorator.rb diff --git a/lib/spree/core/controller_helpers/respond_with.rb b/lib/spree/core/controller_helpers/respond_with.rb index e85777cb74..5e83391d78 100644 --- a/lib/spree/core/controller_helpers/respond_with.rb +++ b/lib/spree/core/controller_helpers/respond_with.rb @@ -1,21 +1,24 @@ module ActionController class Base def respond_with(*resources, &block) - raise "In order to use respond_with, first you need to declare the formats your " << - "controller responds to in the class level" if self.class.mimes_for_respond_to.empty? + if self.class.mimes_for_respond_to.empty? + raise "In order to use respond_with, first you need to declare the formats your " \ + "controller responds to in the class level" + end if collector = retrieve_collector_from_mimes(&block) options = resources.size == 1 ? {} : resources.extract_options! - if defined_response = collector.response and !Spree::BaseController.spree_responders.keys.include?(self.class.to_s.to_sym) + # Fix spree issues #3531 and #2210 (patch provided by leiyangyou) + if (defined_response = collector.response) && !Spree::BaseController.spree_responders[self.class.to_s.to_sym].try(:[], action_name.to_sym) if action = options.delete(:action) - render :action => action + render action: action else defined_response.call end else # The action name is needed for processing - options.merge!(:action_name => action_name.to_sym) + options[:action_name] = action_name.to_sym # If responder is not specified then pass in Spree::Responder (options.delete(:responder) || Spree::Responder).call(self, resources, options) end diff --git a/lib/spree/core/controller_helpers/respond_with_decorator.rb b/lib/spree/core/controller_helpers/respond_with_decorator.rb deleted file mode 100644 index 522247ea01..0000000000 --- a/lib/spree/core/controller_helpers/respond_with_decorator.rb +++ /dev/null @@ -1,28 +0,0 @@ -module ActionController - class Base - def respond_with(*resources, &block) - if self.class.mimes_for_respond_to.empty? - raise "In order to use respond_with, first you need to declare the formats your " \ - "controller responds to in the class level" - end - - if collector = retrieve_collector_from_mimes(&block) - options = resources.size == 1 ? {} : resources.extract_options! - - # Fix spree issues #3531 and #2210 (patch provided by leiyangyou) - if (defined_response = collector.response) && !Spree::BaseController.spree_responders[self.class.to_s.to_sym].try(:[], action_name.to_sym) - if action = options.delete(:action) - render action: action - else - defined_response.call - end - else - # The action name is needed for processing - options[:action_name] = action_name.to_sym - # If responder is not specified then pass in Spree::Responder - (options.delete(:responder) || Spree::Responder).call(self, resources, options) - end - end - end - end -end