提交 9f7d3c51 编写于 作者: S Sergey Nartimov

remove deprecated underscore versions of attribute methods

上级 52c214f7
......@@ -16,7 +16,6 @@ module AttributeMethods #:nodoc:
include TimeZoneConversion
include Dirty
include Serialization
include DeprecatedUnderscoreRead
# Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example,
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
......
require 'active_support/concern'
require 'active_support/deprecation'
module ActiveRecord
module AttributeMethods
module DeprecatedUnderscoreRead
extend ActiveSupport::Concern
included do
attribute_method_prefix "_"
end
module ClassMethods
protected
def define_method__attribute(attr_name)
# Do nothing, let it hit method missing instead.
end
end
protected
def _attribute(attr_name)
ActiveSupport::Deprecation.warn(
"You have called '_#{attr_name}'. This is deprecated. Please use " \
"either '#{attr_name}' or read_attribute('#{attr_name}')."
)
read_attribute(attr_name)
end
end
end
end
......@@ -102,7 +102,6 @@ def test_set_attributes_with_block
def test_respond_to?
topic = Topic.find(1)
assert_respond_to topic, "title"
assert_respond_to topic, "_title"
assert_respond_to topic, "title?"
assert_respond_to topic, "title="
assert_respond_to topic, :title
......@@ -114,19 +113,12 @@ def test_respond_to?
assert !topic.respond_to?(:nothingness)
end
def test_deprecated_underscore_method
topic = Topic.find(1)
assert_equal topic.title, assert_deprecated { topic._title }
end
def test_respond_to_with_custom_primary_key
keyboard = Keyboard.create
assert_not_nil keyboard.key_number
assert_equal keyboard.key_number, keyboard.id
assert keyboard.respond_to?('key_number')
assert keyboard.respond_to?('_key_number')
assert keyboard.respond_to?('id')
assert keyboard.respond_to?('_id')
end
# Syck calls respond_to? before actually calling initialize
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册