diff options
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/record_identifier.rb | 18 | ||||
-rw-r--r-- | actionpack/test/controller/base_test.rb | 41 |
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 |