diff options
author | Sam Pohlenz <sam@sampohlenz.com> | 2009-10-07 09:06:54 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-10-07 09:07:39 -0500 |
commit | 4df96338ede62da8ae8c188de5454b4b6b186ff8 (patch) | |
tree | ae9fe8297d28d0a72750db082ce629c80e67d74d /activemodel/test/cases | |
parent | f8e91bda9c171dd0c31dbea95ba4e9ced4ee2547 (diff) | |
download | rails-4df96338ede62da8ae8c188de5454b4b6b186ff8.tar.gz rails-4df96338ede62da8ae8c188de5454b4b6b186ff8.tar.bz2 rails-4df96338ede62da8ae8c188de5454b4b6b186ff8.zip |
Fixed behavior of attribute_methods_generated? [#3220 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/attribute_methods_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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 |