From f8e91bda9c171dd0c31dbea95ba4e9ced4ee2547 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Wed, 7 Oct 2009 09:05:54 -0500 Subject: 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 --- activemodel/test/cases/attribute_methods_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 activemodel/test/cases/attribute_methods_test.rb (limited to 'activemodel/test/cases/attribute_methods_test.rb') diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb new file mode 100644 index 0000000000..614c4a3645 --- /dev/null +++ b/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 -- cgit v1.2.3 From 4df96338ede62da8ae8c188de5454b4b6b186ff8 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Wed, 7 Oct 2009 09:06:54 -0500 Subject: Fixed behavior of attribute_methods_generated? [#3220 state:resolved] Signed-off-by: Joshua Peek --- activemodel/test/cases/attribute_methods_test.rb | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'activemodel/test/cases/attribute_methods_test.rb') diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 614c4a3645..5659dcbc48 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -4,6 +4,15 @@ class ModelWithAttributes include ActiveModel::AttributeMethods attribute_method_suffix '' + + def attributes + { :foo => 'value of foo' } + end + +private + def attribute(name) + attributes[name.to_sym] + end end class ModelWithAttributes2 @@ -17,4 +26,21 @@ class AttributeMethodsTest < ActiveModel::TestCase assert_not_equal ModelWithAttributes.send(:attribute_method_matchers), ModelWithAttributes2.send(:attribute_method_matchers) end + + test '#define_attribute_methods generates attribute methods' do + ModelWithAttributes.define_attribute_methods([:foo]) + + assert ModelWithAttributes.attribute_methods_generated? + assert ModelWithAttributes.new.respond_to?(:foo) + assert_equal "value of foo", ModelWithAttributes.new.foo + end + + test '#undefine_attribute_methods removes attribute methods' do + ModelWithAttributes.define_attribute_methods([:foo]) + ModelWithAttributes.undefine_attribute_methods + + assert !ModelWithAttributes.attribute_methods_generated? + assert !ModelWithAttributes.new.respond_to?(:foo) + assert_raises(NoMethodError) { ModelWithAttributes.new.foo } + end end -- cgit v1.2.3