Permalink
Browse files

add test for super-ing to association methods

  • Loading branch information...
1 parent 7cba6a3 commit 9cdf33af0bc46fde1ad50346b8271251c2b4aa69 @joshsusser joshsusser committed Nov 16, 2011
Showing with 12 additions and 2 deletions.
  1. +12 −2 activerecord/test/cases/associations_test.rb
@@ -276,12 +276,22 @@ def test_has_one_association_redefinition_reflections_should_differ_and_not_inhe
end
class GeneratedMethodsTest < ActiveRecord::TestCase
- fixtures :developers, :computers
+ fixtures :developers, :computers, :posts, :comments
def test_association_methods_override_attribute_methods_of_same_name
assert_equal(developers(:david), computers(:workstation).developer)
# this next line will fail if the attribute methods module is generated lazily
# after the association methods module is generated
assert_equal(developers(:david), computers(:workstation).developer)
assert_equal(developers(:david).id, computers(:workstation)[:developer])
end
-end
+
+ def test_model_method_overrides_association_method
+ Post.class_eval <<-"RUBY"
+ has_one :first_comment, :class_name => 'Comment', :order => 'id ASC'
+ def first_comment
+ super.body
+ end
+ RUBY
+ assert_equal(comments(:greetings).body, posts(:welcome).first_comment)
+ end
+end

0 comments on commit 9cdf33a

Please sign in to comment.