From 24226c51f075ed8d8e721cdefb6d2661c0a1f53a Mon Sep 17 00:00:00 2001
From: Godfrey Chan <godfreykfc@gmail.com>
Date: Sun, 17 Aug 2014 11:54:09 -0700
Subject: Raise a more helpful error for people who are using these extracted
 features

---
 .../lib/action_controller/metal/mime_responds.rb   | 17 +++++++++++-
 actionpack/test/controller/mime/responder_test.rb  | 30 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 actionpack/test/controller/mime/responder_test.rb

(limited to 'actionpack')

diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index a533f03b6d..f5565947aa 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -5,6 +5,21 @@ module ActionController #:nodoc:
   module MimeResponds
     extend ActiveSupport::Concern
 
+    module ClassMethods
+      def respond_to(*)
+        raise NoMethodError, "The controller-level `respond_to' feature has " \
+          "been extracted to the `responder` gem. Add it to your Gemfile to " \
+          "continue using this feature. Consult the Rails upgrade guide for " \
+          "details."
+      end
+    end
+
+    def respond_with(*)
+      raise NoMethodError, "The `respond_with' feature has been extracted " \
+        "to the `responder` gem. Add it to your Gemfile to continue using " \
+        "this feature. Consult the Rails upgrade guide for details."
+    end
+
     # Without web-service support, an action which collects the data for displaying a list of people
     # might look something like this:
     #
@@ -165,7 +180,7 @@ module ActionController #:nodoc:
     #     format.html.phone { redirect_to progress_path }
     #     format.html.none  { render "trash" }
     #   end
-    # 
+    #
     # Variants also support common `any`/`all` block that formats have.
     #
     # It works for both inline:
diff --git a/actionpack/test/controller/mime/responder_test.rb b/actionpack/test/controller/mime/responder_test.rb
new file mode 100644
index 0000000000..6201af3299
--- /dev/null
+++ b/actionpack/test/controller/mime/responder_test.rb
@@ -0,0 +1,30 @@
+require 'abstract_unit'
+require 'controller/fake_models'
+
+class ResponderTest < ActionController::TestCase
+  def test_class_level_respond_to
+    e = assert_raises(NoMethodError) do
+      Class.new(ActionController::Base) do
+        respond_to :json
+      end
+    end
+
+    assert_includes e.message, '`responder` gem'
+  end
+
+  def test_respond_with
+    klass = Class.new(ActionController::Base) do
+      def index
+        respond_with Customer.new("david", 13)
+      end
+    end
+
+    @controller = klass.new
+
+    e = assert_raises(NoMethodError) do
+      get :index
+    end
+
+    assert_includes e.message, '`responder` gem'
+  end
+end
-- 
cgit v1.2.3