aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-08-25 13:40:56 +0200
committerPiotr Sarnacki <drogus@gmail.com>2012-08-28 11:19:37 +0200
commite1ffd82e7658195543cff9cd99c4ee79827880b7 (patch)
treeebb6f0df5ef3fa8bf1ba3fa465bfa7b08b82dc46 /actionpack
parentf4d493ed7c451f3df7602c5164a1954caa40284e (diff)
downloadrails-e1ffd82e7658195543cff9cd99c4ee79827880b7.tar.gz
rails-e1ffd82e7658195543cff9cd99c4ee79827880b7.tar.bz2
rails-e1ffd82e7658195543cff9cd99c4ee79827880b7.zip
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.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_controller/record_identifier.rb18
-rw-r--r--actionpack/test/controller/base_test.rb41
3 files changed, 57 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index ed76470596..0d79e046a1 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -203,7 +203,7 @@ module ActionController
ForceSSL,
Streaming,
DataStreaming,
- ActionView::RecordIdentifier,
+ RecordIdentifier,
HttpAuthentication::Basic::ControllerMethods,
HttpAuthentication::Digest::ControllerMethods,
HttpAuthentication::Token::ControllerMethods,
diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb
index 7b6a5bb25c..bffd2a02d0 100644
--- a/actionpack/lib/action_controller/record_identifier.rb
+++ b/actionpack/lib/action_controller/record_identifier.rb
@@ -2,7 +2,19 @@ require 'active_support/deprecation'
require 'action_view/record_identifier'
module ActionController
- RecordIdentifier = ActionView::RecordIdentifier
- ActiveSupport::Deprecation.warn "ActionController::RecordIdentifier was renamed to ActionView::RecordIdentifier. " +
- "Please use it instead. ActionController::RecordIdentifier will be removed in Rails 4.1"
+ module RecordIdentifier
+ MESSAGE = 'method will no longer be included by default in controllers since Rails 4.1. ' +
+ 'If you would like to use it in controllers, please include ' +
+ 'ActionView::RecodIdentifier module.'
+
+ def dom_id(record, prefix = nil)
+ ActiveSupport::Deprecation.warn 'dom_id ' + MESSAGE
+ ActionView::RecordIdentifier.dom_id(record, prefix)
+ end
+
+ def dom_class(record, prefix = nil)
+ ActiveSupport::Deprecation.warn 'dom_class ' + MESSAGE
+ ActionView::RecordIdentifier.dom_class(record, prefix)
+ end
+ end
end
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index b9513ccff4..9b42e7631f 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'active_support/logger'
+require 'controller/fake_models'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
# Provide some controller to run the tests on.
@@ -63,6 +64,10 @@ end
class RecordIdentifierController < ActionController::Base
end
+class RecordIdentifierWithoutDeprecationController < ActionController::Base
+ include ActionView::RecordIdentifier
+end
+
class ControllerClassTests < ActiveSupport::TestCase
def test_controller_path
@@ -81,6 +86,42 @@ class ControllerClassTests < ActiveSupport::TestCase
assert_respond_to RecordIdentifierController.new, :dom_id
assert_respond_to RecordIdentifierController.new, :dom_class
end
+
+ def test_record_identifier_is_deprecated
+ record = Comment.new
+ record.save
+
+ dom_id = nil
+ assert_deprecated 'dom_id method will no longer' do
+ dom_id = RecordIdentifierController.new.dom_id(record)
+ end
+
+ assert_equal 'comment_1', dom_id
+
+ dom_class = nil
+ assert_deprecated 'dom_class method will no longer' do
+ dom_class = RecordIdentifierController.new.dom_class(record)
+ end
+ assert_equal 'comment', dom_class
+ end
+
+ def test_no_deprecation_when_action_view_record_identifier_is_included
+ record = Comment.new
+ record.save
+
+ dom_id = nil
+ assert_not_deprecated do
+ dom_id = RecordIdentifierWithoutDeprecationController.new.dom_id(record)
+ end
+
+ assert_equal 'comment_1', dom_id
+
+ dom_class = nil
+ assert_not_deprecated do
+ dom_class = RecordIdentifierWithoutDeprecationController.new.dom_class(record)
+ end
+ assert_equal 'comment', dom_class
+ end
end
class ControllerInstanceTests < ActiveSupport::TestCase