Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
spohlenz authored and josh committed Oct 7, 2009
1 parent 3916f03 commit f8e91bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion activemodel/lib/active_model/attribute_methods.rb
@@ -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
Expand Down Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions activemodel/test/cases/attribute_methods_test.rb
@@ -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

0 comments on commit f8e91bd

Please sign in to comment.