1
0
Fork 0
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:
Sam Pohlenz 2009-10-07 09:05:54 -05:00 committed by Joshua Peek
parent 3916f0340e
commit f8e91bda9c
2 changed files with 24 additions and 1 deletions

View file

@ -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

View 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