aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/attribute_methods_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-10-06 00:25:07 +0000
committerRick Olson <technoweenie@gmail.com>2007-10-06 00:25:07 +0000
commit5b2e8b1eb1731e987faa233dc03e83c221cfcda5 (patch)
tree0eaf4449eee8b31e7e48f9f29068e4fb5ef81c81 /activerecord/test/attribute_methods_test.rb
parent24c2457a26983c323f0c90d175c00453d853f3b6 (diff)
downloadrails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.tar.gz
rails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.tar.bz2
rails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.zip
Fix that ActiveRecord would create attribute methods and override custom attribute getters if the method is also defined in Kernel.methods. [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7749 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/attribute_methods_test.rb')
-rwxr-xr-xactiverecord/test/attribute_methods_test.rb39
1 files changed, 38 insertions, 1 deletions
diff --git a/activerecord/test/attribute_methods_test.rb b/activerecord/test/attribute_methods_test.rb
index c031d78357..f16b264c35 100755
--- a/activerecord/test/attribute_methods_test.rb
+++ b/activerecord/test/attribute_methods_test.rb
@@ -53,6 +53,43 @@ class AttributeMethodsTest < Test::Unit::TestCase
topic = Topic.create("content" => myobj)
topic.freeze
assert_equal myobj, topic.content
-
+ end
+
+ def test_kernel_methods_not_implemented_in_activerecord
+ %w(test name display y).each do |method|
+ assert_equal false, ActiveRecord::Base.instance_method_already_implemented?(method), "##{method} is defined"
+ end
+ end
+
+ def test_primary_key_implemented
+ assert_equal true, Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
+ end
+
+ def test_defined_kernel_methods_implemented_in_model
+ %w(test name display y).each do |method|
+ klass = Class.new ActiveRecord::Base
+ klass.class_eval "def #{method}() 'defined #{method}' end"
+ assert_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
+ end
+ end
+
+ def test_defined_kernel_methods_implemented_in_model_abstract_subclass
+ %w(test name display y).each do |method|
+ abstract = Class.new ActiveRecord::Base
+ abstract.class_eval "def #{method}() 'defined #{method}' end"
+ abstract.abstract_class = true
+ klass = Class.new abstract
+ assert_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
+ end
+ end
+
+ def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_model
+ %w(save create_or_update).each do |method|
+ klass = Class.new ActiveRecord::Base
+ klass.class_eval "def #{method}() 'defined #{method}' end"
+ assert_raises ActiveRecord::DangerousAttributeError do
+ klass.instance_method_already_implemented?(method)
+ end
+ end
end
end