1 require 'abstract_unit'
2 require 'fixtures/comment'
3 require 'fixtures/user'
4 require 'fixtures/employee'
5 require 'fixtures/hack'
7 class TestPolymorphic < Test::Unit::TestCase
8 fixtures :users, :employees, :comments, :hacks
10 def test_polymorphic_has_many
11 comments = Hack.find('andrew').comments
12 assert_equal 'andrew', comments[0].person_id
15 def test_polymorphic_has_one
16 first_comment = Hack.find('andrew').first_comment
17 assert_equal 'andrew', first_comment.person_id
20 def test_has_many_through
21 user = users(:santiago)
22 article_names = user.articles.collect { |a| a.name }.sort
23 assert_equal ['Article One', 'Article Two'], article_names
26 def test_polymorphic_has_many_through
27 user = users(:santiago)
28 assert_equal ['andrew'], user.hacks.collect { |a| a.name }.sort