aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-10-10 17:15:11 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-10-10 17:15:11 +0100
commit66ee2654ff243f03595a402fa15e1eea1b5b45be (patch)
tree3f1055e03082f0c767719e8cba5155e4207779e0 /activemodel/test/cases/attribute_methods_test.rb
parentdd2779e1b83b4d867d47dd286ec0c919f5df12a9 (diff)
parentb9ce8216fa849a47ad0b0f99fa510e226a23c12e (diff)
downloadrails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.gz
rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.bz2
rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activemodel/test/cases/attribute_methods_test.rb')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
new file mode 100644
index 0000000000..5659dcbc48
--- /dev/null
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -0,0 +1,46 @@
+require 'cases/helper'
+
+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
+ 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
+
+ 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