aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorSam Goldstein <sgrock@gmail.com>2009-07-08 11:45:26 -0700
committerMichael Koziarski <michael@koziarski.com>2009-07-09 16:44:30 +1200
commitd60d7edce462f4602bfc9996689087a235b034c9 (patch)
treeb56c9b8d07a87959fb8fbd746450537e46690ffb /activerecord/test/cases/attribute_methods_test.rb
parent579250ea467ac406a5897dc2187c7959bf343b4f (diff)
downloadrails-d60d7edce462f4602bfc9996689087a235b034c9.tar.gz
rails-d60d7edce462f4602bfc9996689087a235b034c9.tar.bz2
rails-d60d7edce462f4602bfc9996689087a235b034c9.zip
Make it so AR attributes which conflict with object-private methods (e.g. system) don't 'randomly' cause NoMethodErrors
Previously if you called this attribute before others, you'd get exceptions. But if it was the second-or-subsequent attribute you retrieved you'd get the correct behaviour. Signed-off-by: Michael Koziarski <michael@koziarski.com> [#2808 state:committed]
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 17ed302465..183be1e2f9 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -277,6 +277,22 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title => "Ants in pants" } }
end
+ def test_read_attribute_overwrites_private_method_not_considered_implemented
+ # simulate a model with a db column that shares its name an inherited
+ # private method (e.g. Object#system)
+ #
+ Object.class_eval do
+ private
+ def title; "private!"; end
+ end
+ assert !@target.instance_method_already_implemented?(:title)
+ topic = @target.new
+ assert_equal nil, topic.title
+
+ Object.send(:undef_method, :title) # remove test method from object
+ end
+
+
private
def time_related_columns_on_topic
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)