From dee595ce04b65d27294912faff146ed402ded6d1 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 15 Jan 2012 12:06:50 +0100 Subject: Fix stack level too deep when model does not have attributes method. Without that patch when using ActiveModel::AttributeMethods in a class that does not respond to `attributes` method, stack level too deep error will be raised on non existing method. While documentation is clear that you need to define `attributes` method in order to use AttributeMethods module, `stack level too deep` is rather obscure and hard to debug, therefore we should try to not break `method_missing` if someone forgets about defining `attributes`. --- activemodel/test/cases/attribute_methods_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 90f9b78334..ff60100c08 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -76,7 +76,15 @@ private end end +class ModelWithouAttributesMethod + include ActiveModel::AttributeMethods +end + class AttributeMethodsTest < ActiveModel::TestCase + test 'method missing works correctly even if attributes method is not defined' do + assert_raises(NoMethodError) { ModelWithouAttributesMethod.new.foo } + end + test 'unrelated classes should not share attribute method matchers' do assert_not_equal ModelWithAttributes.send(:attribute_method_matchers), ModelWithAttributes2.send(:attribute_method_matchers) -- cgit v1.2.3