aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-12 23:58:20 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-13 00:02:33 +0100
commitc89e1c7bdefa2489f6ebd04862a426b7200bf494 (patch)
treea02cf3ec4e28636ec387af96fc67030b456da8c8 /activemodel/test/cases/attribute_methods_test.rb
parent6d8dbeca6b0e676145ecdbba38f2fe56b74b4f8f (diff)
downloadrails-c89e1c7bdefa2489f6ebd04862a426b7200bf494.tar.gz
rails-c89e1c7bdefa2489f6ebd04862a426b7200bf494.tar.bz2
rails-c89e1c7bdefa2489f6ebd04862a426b7200bf494.zip
Add an attribute_missing method to ActiveModel::AttributeMethods.
This can be overloaded by implementors if necessary.
Diffstat (limited to 'activemodel/test/cases/attribute_methods_test.rb')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index 198e4c3c06..e655c7a1af 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -187,4 +187,19 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert m.respond_to?(:protected_method)
assert m.respond_to?(:protected_method, true)
end
+
+ test 'should use attribute_missing to dispatch a missing attribute' do
+ m = ModelWithAttributes2.new
+ m.attributes = { 'foo' => 'bar' }
+
+ def m.attribute_missing(match, *args, &block)
+ match
+ end
+
+ match = m.foo_test
+
+ assert_equal 'foo', match.attr_name
+ assert_equal 'attribute_test', match.target
+ assert_equal 'foo_test', match.method_name
+ end
end