Skip to content
This repository
Browse code

Deprecate AV::RecordIdentifier in controllers

Methods provided by RecordIdentifier are not widely used in controllers
nowadays as they're view specific (this is probably a legacy left after
RJS rendering directly in controllers). However if people still need to
use it, it's trivial to include ActionView::RecordIdentifier by
themselves.
  • Loading branch information...
commit 135310aea10a305ae25bca1e56f7313cd7dd218a 1 parent 2a7a33e
Piotr Sarnacki authored
2  actionpack/lib/action_controller/base.rb
@@ -203,7 +203,7 @@ def self.without_modules(*modules)
203 203
       ForceSSL,
204 204
       Streaming,
205 205
       DataStreaming,
206  
-      ActionView::RecordIdentifier,
  206
+      RecordIdentifier,
207 207
       HttpAuthentication::Basic::ControllerMethods,
208 208
       HttpAuthentication::Digest::ControllerMethods,
209 209
       HttpAuthentication::Token::ControllerMethods,
18  actionpack/lib/action_controller/record_identifier.rb
@@ -2,7 +2,19 @@
2 2
 require 'action_view/record_identifier'
3 3
 
4 4
 module ActionController
5  
-  RecordIdentifier = ActionView::RecordIdentifier
6  
-  ActiveSupport::Deprecation.warn "ActionController::RecordIdentifier was renamed to ActionView::RecordIdentifier. " +
7  
-                                  "Please use it instead. ActionController::RecordIdentifier will be removed in Rails 4.1"
  5
+  module RecordIdentifier
  6
+    MESSAGE = 'method will no longer be included by default in controllers since Rails 4.1. ' +
  7
+              'If you would like to use it in controllers, please include ' +
  8
+              'ActionView::RecodIdentifier module.'
  9
+
  10
+    def dom_id(record, prefix = nil)
  11
+      ActiveSupport::Deprecation.warn 'dom_id ' + MESSAGE
  12
+      ActionView::RecordIdentifier.dom_id(record, prefix)
  13
+    end
  14
+
  15
+    def dom_class(record, prefix = nil)
  16
+      ActiveSupport::Deprecation.warn 'dom_class ' + MESSAGE
  17
+      ActionView::RecordIdentifier.dom_class(record, prefix)
  18
+    end
  19
+  end
8 20
 end
41  actionpack/test/controller/base_test.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'abstract_unit'
2 2
 require 'active_support/logger'
  3
+require 'controller/fake_models'
3 4
 require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
4 5
 
5 6
 # Provide some controller to run the tests on.
@@ -63,6 +64,10 @@ def url_options
63 64
 class RecordIdentifierController < ActionController::Base
64 65
 end
65 66
 
  67
+class RecordIdentifierWithoutDeprecationController < ActionController::Base
  68
+  include ActionView::RecordIdentifier
  69
+end
  70
+
66 71
 class ControllerClassTests < ActiveSupport::TestCase
67 72
 
68 73
   def test_controller_path
@@ -81,6 +86,42 @@ def test_record_identifier
81 86
     assert_respond_to RecordIdentifierController.new, :dom_id
82 87
     assert_respond_to RecordIdentifierController.new, :dom_class
83 88
   end
  89
+
  90
+  def test_record_identifier_is_deprecated
  91
+    record = Comment.new
  92
+    record.save
  93
+
  94
+    dom_id = nil
  95
+    assert_deprecated 'dom_id method will no longer' do
  96
+      dom_id = RecordIdentifierController.new.dom_id(record)
  97
+    end
  98
+
  99
+    assert_equal 'comment_1', dom_id
  100
+
  101
+    dom_class = nil
  102
+    assert_deprecated 'dom_class method will no longer' do
  103
+      dom_class = RecordIdentifierController.new.dom_class(record)
  104
+    end
  105
+    assert_equal 'comment', dom_class
  106
+  end
  107
+
  108
+  def test_no_deprecation_when_action_view_record_identifier_is_included
  109
+    record = Comment.new
  110
+    record.save
  111
+
  112
+    dom_id = nil
  113
+    assert_not_deprecated do
  114
+      dom_id = RecordIdentifierWithoutDeprecationController.new.dom_id(record)
  115
+    end
  116
+
  117
+    assert_equal 'comment_1', dom_id
  118
+
  119
+    dom_class = nil
  120
+    assert_not_deprecated do
  121
+      dom_class = RecordIdentifierWithoutDeprecationController.new.dom_class(record)
  122
+    end
  123
+    assert_equal 'comment', dom_class
  124
+  end
84 125
 end
85 126
 
86 127
 class ControllerInstanceTests < ActiveSupport::TestCase

0 notes on commit 135310a

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