Sha256: 521e26b2c0b833bc58a75a7ec07930fbd65390e3d3ddc35356f9b0494ad0aa52

Contents?: true

Size: 891 Bytes

Versions: 7

Compression:

Stored size: 891 Bytes

Contents

require 'abstract_unit'
require 'fixtures/comment'
require 'fixtures/article'
require 'fixtures/reading'
require 'fixtures/user'
require 'fixtures/employee'
require 'fixtures/hack'

class TestPolymorphic < ActiveSupport::TestCase
  fixtures :users, :employees, :comments, :hacks
  
  def test_polymorphic_has_many
    comments = Hack.find('andrew').comments
    assert_equal 'andrew', comments[0].person_id
  end

  def test_polymorphic_has_one
    first_comment = Hack.find('andrew').first_comment
    assert_equal 'andrew', first_comment.person_id
  end

  def test_has_many_through
    user = users(:santiago)
    article_names = user.articles.collect { |a| a.name }.sort
    assert_equal ['Article One', 'Article Two'], article_names
  end

  def test_polymorphic_has_many_through
    user = users(:santiago)
    assert_equal ['andrew'], user.hacks.collect { |a| a.name }.sort
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
composite_primary_keys-3.0.9 test/test_polymorphic.rb
composite_primary_keys-3.0.8 test/test_polymorphic.rb
composite_primary_keys-3.0.7 test/test_polymorphic.rb
composite_primary_keys-3.0.4 test/test_polymorphic.rb
composite_primary_keys-3.0.3 test/test_polymorphic.rb
composite_primary_keys-3.0.0.b3 test/test_polymorphic.rb
composite_primary_keys-3.0.0.b2 test/test_polymorphic.rb