提交 038574a5 编写于 作者: C Carlos Antonio da Silva

Deprecate direct calls to AC::RecordIdentifier.dom_id and dom_class

Also add some generic tests to ensure they're properly deprecated.
上级 f5aa4d9a
......@@ -492,10 +492,13 @@
*Richard Schneeman*
* Deprecate availbility of `ActionView::RecordIdentifier` in controllers by default.
It's view specific and can be easily included in controller manually if someone
really needs it. RecordIdentifier will be removed from `ActionController::Base`
in Rails 4.1. *Piotr Sarnacki*
* Deprecate availability of `ActionView::RecordIdentifier` in controllers by default.
It's view specific and can be easily included in controllers manually if someone
really needs it. Also deprecate calling `ActionController::RecordIdentifier.dom_id` and
`dom_class` directly, in favor of `ActionView::RecordIdentifier.dom_id` and `dom_class`.
`RecordIdentifier` will be removed from `ActionController::Base` in Rails 4.1.
*Piotr Sarnacki*
* Fix `ActionView::RecordIdentifier` to work as a singleton. *Piotr Sarnacki*
......
......@@ -2,17 +2,29 @@
module ActionController
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::RecordIdentifier module.'
MODULE_MESSAGE = 'Calling ActionController::RecordIdentifier.%s is deprecated and ' \
'will be removed in Rails 4.1, please call using ActionView::RecordIdentifier instead.'
INSTANCE_MESSAGE = '%s 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::RecordIdentifier module.'
def dom_id(record, prefix = nil)
ActiveSupport::Deprecation.warn('dom_id ' + MESSAGE)
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_id')
ActionView::RecordIdentifier.dom_id(record, prefix)
end
def dom_class(record, prefix = nil)
ActiveSupport::Deprecation.warn('dom_class ' + MESSAGE)
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_class')
ActionView::RecordIdentifier.dom_class(record, prefix)
end
def self.dom_id(record, prefix = nil)
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_id')
ActionView::RecordIdentifier.dom_id(record, prefix)
end
def self.dom_class(record, prefix = nil)
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_class')
ActionView::RecordIdentifier.dom_class(record, prefix)
end
end
......
require 'abstract_unit'
require 'controller/fake_models'
class ControllerRecordIdentifierTest < ActiveSupport::TestCase
include ActionController::RecordIdentifier
def setup
@record = Comment.new
end
def test_dom_id_deprecation
assert_deprecated /dom_id method will no longer be included by default in controllers/ do
dom_id(@record)
end
end
def test_dom_class_deprecation
assert_deprecated /dom_class method will no longer be included by default in controllers/ do
dom_class(@record)
end
end
def test_dom_id_from_module_deprecation
assert_deprecated /Calling ActionController::RecordIdentifier.dom_id is deprecated/ do
ActionController::RecordIdentifier.dom_id(@record)
end
end
def test_dom_class_from_module_deprecation
assert_deprecated /Calling ActionController::RecordIdentifier.dom_class is deprecated/ do
ActionController::RecordIdentifier.dom_class(@record)
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册