Sha256: 06e36eed5d5d70a5af9d4034bed5ee81856cd2518fa85431068f4a1593cc56b3

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

require File.expand_path('../abstract_unit', __FILE__)

class TestPolymorphic < ActiveSupport::TestCase
  fixtures :articles, :departments, :employees, :users, :comments

  def test_has_many
    user = users(:santiago)
    comments = user.comments
    assert_equal(user.id, comments[0].person_id)
  end

  def test_has_one
    user = users(:santiago)
    first_comment = user.first_comment
    assert_equal(user.id, first_comment.person_id)
  end

  def test_has_many_through
    department = departments(:accounting)
    comment = comments(:employee_comment)

    assert_equal(1, department.comments.size)
    assert_equal(comment, department.comments[0])
  end

  def test_has_many_through_2
    article = articles(:second)

    user = users(:santiago)
    assert_equal(user, article.user_commentators[0])

    user = users(:drnic)
    assert_equal(user, article.user_commentators[1])
  end

  def test_clear_has_many_through
    article = articles(:second)

    assert_equal(2, article.comments.size)
    article.user_commentators = []
    assert_equal(0, article.comments.size)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.6 test/test_polymorphic.rb
composite_primary_keys-13.0.7 test/test_polymorphic.rb
composite_primary_keys-13.0.6 test/test_polymorphic.rb
composite_primary_keys-14.0.5 test/test_polymorphic.rb
composite_primary_keys-13.0.5 test/test_polymorphic.rb
composite_primary_keys-13.0.4 test/test_polymorphic.rb
composite_primary_keys-14.0.4 test/test_polymorphic.rb
composite_primary_keys-14.0.3 test/test_polymorphic.rb
composite_primary_keys-13.0.3 test/test_polymorphic.rb
composite_primary_keys-14.0.2 test/test_polymorphic.rb
composite_primary_keys-13.0.2 test/test_polymorphic.rb
composite_primary_keys-14.0.1 test/test_polymorphic.rb