Sha256: 49ad3c3b8d2bba04ea4a5b0abdb94e2941660eee7ada29f68cf90fbbfe984bc3

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require_relative "test_helper"

class ArchiveDependentsOptionTest < ActiveSupport::TestCase

  test "archive_dependents option will leave dependent archival records alone when parent is archived" do
    archival = IgnoreDependentsArchival.create!
    child = archival.ignorable_dependents.create!

    assert archival.archival?
    assert child.archival?

    archival.archive!

    assert archival.reload.archived?
    assert_not child.reload.archived?
  end

  test "archive_dependents option will leave dependent archival records alone when parent is unarchived" do
    archival = IgnoreDependentsArchival.create!
    child = archival.ignorable_dependents.create!

    assert archival.archival?
    assert child.archival?

    # This is simulating an unlikely scenario where the option has been added after records have been
    # archived as a set but we want to unarchive after adding the option.
    archival.archive!
    child.update!(archived_at: archival.archived_at, archive_number: archival.archive_number)

    archival.unarchive!

    assert_not archival.reload.archived?
    assert child.reload.archived?
  end

  test "archive_dependents option will work normally if set to true" do
    archival = ExplicitActOnDependentsArchival.create!
    child = archival.nonignorable_dependents.create!

    assert archival.archival?
    assert child.archival?

    archival.archive!

    assert archival.reload.archived?
    assert child.reload.archived?

    archival.unarchive!

    assert_not archival.reload.archived?
    assert_not child.reload.archived?
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
archival_record-3.0.1 test/archive_dependents_option_test.rb
archival_record-3.0.0 test/archive_dependents_option_test.rb