aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-04 22:07:07 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-13 00:01:57 +0100
commit8b8b7143efe2e0bac5bcfe90264e4baa66bdb532 (patch)
tree00da82fcb091b7de3c1e117d6d243231e3321773 /activemodel/test/cases
parent8d59e0b2633c26f9de8942a2d676afe39b0ee3f8 (diff)
downloadrails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.tar.gz
rails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.tar.bz2
rails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.zip
Use an empty AttributeMethodMatcher by default.
This means that attribute methods which don't exist will get generated when define_attribute_methods is called, so we don't have to use hacks like `attribute_method_suffix ''`.
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index 9840e3364c..95a7098ba4 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -24,7 +24,16 @@ end
class ModelWithAttributes2
include ActiveModel::AttributeMethods
+ attr_accessor :attributes
+
attribute_method_suffix '_test'
+
+private
+ def attribute(name)
+ attributes[name.to_s]
+ end
+
+ alias attribute_test attribute
end
class ModelWithAttributesWithSpaces
@@ -129,4 +138,12 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert !ModelWithAttributes.new.respond_to?(:foo)
assert_raises(NoMethodError) { ModelWithAttributes.new.foo }
end
+
+ test 'acessing a suffixed attribute' do
+ m = ModelWithAttributes2.new
+ m.attributes = { 'foo' => 'bar' }
+
+ assert_equal 'bar', m.foo
+ assert_equal 'bar', m.foo_test
+ end
end