mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
3916f0340e
commit
f8e91bda9c
2 changed files with 24 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
|||
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 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def attribute_method_matchers #:nodoc:
|
||||
@@attribute_method_matchers ||= []
|
||||
read_inheritable_attribute(:attribute_method_matchers) || write_inheritable_attribute(:attribute_method_matchers, [])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
20
activemodel/test/cases/attribute_methods_test.rb
Normal file
20
activemodel/test/cases/attribute_methods_test.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
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
|
Loading…
Reference in a new issue