1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

add test for super-ing to association methods

This commit is contained in:
Josh Susser 2011-11-15 23:30:25 -08:00
parent 7cba6a3784
commit 9cdf33af0b

View file

@ -276,7 +276,7 @@ class OverridingAssociationsTest < ActiveRecord::TestCase
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
@ -284,4 +284,14 @@ class GeneratedMethodsTest < ActiveRecord::TestCase
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