Sha256: 68124c6bf364c453c5d172b6b22f9806b5cc3c232d35430a5d4d83d7777a3614

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require_relative "test_helper"

class PolymorphicTest < ActiveSupport::TestCase

  test "archive item with polymorphic association" do
    archival = Archival.create!
    poly = archival.polys.create!
    archival.archive!

    assert archival.reload.archived?
    assert poly.reload.archived?
  end

  test "does not archive polymorphic association of different item with same id" do
    archival = Archival.create!
    another_polys_holder = AnotherPolysHolder.create!(id: archival.id)
    poly = another_polys_holder.polys.create!
    archival.archive!

    assert_not poly.reload.archived?
  end

  test "unarchive item with polymorphic association" do
    archive_attributes = {
      archive_number: "test",
      archived_at: Time.now.utc
    }
    archival = Archival.create!(archive_attributes)
    poly = archival.polys.create!(archive_attributes)
    archival.unarchive!

    assert_not archival.reload.archived?
    assert_not poly.reload.archived?
  end

  test "does not unarchive polymorphic association of different item with same id" do
    archive_attributes = {
      archive_number: "test",
      archived_at: Time.now.utc
    }

    archival = Archival.create!(archive_attributes)
    another_polys_holder = AnotherPolysHolder.create!(archive_attributes.merge(id: archival.id))
    poly = another_polys_holder.polys.create!(archive_attributes)
    archival.unarchive!

    assert poly.reload.archived?
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
archival_record-4.0.0 test/polymorphic_test.rb
archival_record-3.0.1 test/polymorphic_test.rb
archival_record-3.0.0 test/polymorphic_test.rb