提交 f8e91bda 编写于 作者: S Sam Pohlenz 提交者: Joshua Peek

Don't share attribute matchers between classes [#3216 state:resolved]

Allows separate models that include ActiveModel::AttributeMethods to
use different sets of attribute matchers.
Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 3916f034
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/class/inheritable_attributes'
module ActiveModel
class MissingAttributeError < NoMethodError
end
......@@ -219,7 +222,7 @@ def method_missing_target
end
def attribute_method_matchers #:nodoc:
@@attribute_method_matchers ||= []
read_inheritable_attribute(:attribute_method_matchers) || write_inheritable_attribute(:attribute_method_matchers, [])
end
end
......
require 'cases/helper'
class ModelWithAttributes
include ActiveModel::AttributeMethods
attribute_method_suffix ''
end
class ModelWithAttributes2
include ActiveModel::AttributeMethods
attribute_method_suffix '_test'
end
class AttributeMethodsTest < ActiveModel::TestCase
test 'unrelated classes should not share attribute method matchers' do
assert_not_equal ModelWithAttributes.send(:attribute_method_matchers),
ModelWithAttributes2.send(:attribute_method_matchers)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册