mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Remove unnecessary code from define_read_method and add assertion to make sure the underscored version is actually generated
This commit is contained in:
@@ -70,13 +70,10 @@ module ActiveRecord
|
||||
if cache_attribute?(attr_name)
|
||||
access_code = "@attributes_cache['#{attr_name}'] ||= (#{access_code})"
|
||||
end
|
||||
if symbol =~ /^[a-zA-Z_]\w*[!?=]?$/
|
||||
generated_attribute_methods.module_eval("def _#{symbol}; #{access_code}; end; alias #{symbol} _#{symbol}", __FILE__, __LINE__)
|
||||
else
|
||||
generated_attribute_methods.module_eval do
|
||||
define_method("_#{symbol}") { eval(access_code) }
|
||||
alias_method(symbol, "_#{symbol}")
|
||||
end
|
||||
|
||||
generated_attribute_methods.module_eval do
|
||||
define_method("_#{attr_name}") { eval(access_code) }
|
||||
alias_method(attr_name, "_#{attr_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,6 +77,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user