Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 e1ffd82e7658195543cff9cd99c4ee79827880b7 1 parent f4d493e
@drogus drogus authored
View
2  actionpack/lib/action_controller/base.rb
@@ -203,7 +203,7 @@ def self.without_modules(*modules)
ForceSSL,
Streaming,
DataStreaming,
- ActionView::RecordIdentifier,
+ RecordIdentifier,
HttpAuthentication::Basic::ControllerMethods,
HttpAuthentication::Digest::ControllerMethods,
HttpAuthentication::Token::ControllerMethods,
View
18 actionpack/lib/action_controller/record_identifier.rb
@@ -2,7 +2,19 @@
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
View
41 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 @@ def url_options
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 @@ def test_record_identifier
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
Please sign in to comment.
Something went wrong with that request. Please try again.