Sha256: ccd910f22db31a4ac04446ec6b5075bb7714d83ec956bc946213d4eadfa7a2c4

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

require 'abstract_unit'
require 'fixtures/comment'
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

4 entries across 4 versions & 2 rubygems

Version Path
kovyrin-composite_primary_keys-2.3.2 test/test_polymorphic.rb
composite_primary_keys-2.3.5.1 test/test_polymorphic.rb
composite_primary_keys-2.3.5 test/test_polymorphic.rb
composite_primary_keys-2.3.2 test/test_polymorphic.rb