Sha256: 7c91197f4b591673349962aede416487aa1f2eee1c1e3289ee9f3e49fbcdf93f

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require "test_helper"

class ActiveSnapshotTest < ActiveSupport::TestCase

  def test_exposes_main_module
    assert ActiveSnapshot.is_a?(Module)
  end

  def test_exposes_version
    assert ActiveSnapshot::VERSION
  end

  def test_snapshot_lifecycle
    identifier = "snapshot-1"

    klass = Post

    parent = klass.first

    original_parent_updated_at = parent.updated_at

    child = parent.comments.create!(content: :foo)
    original_child_updated_at = child.updated_at

    assert_difference ->{ ActiveSnapshot::Snapshot.count }, 1 do
      assert_difference ->{ ActiveSnapshot::SnapshotItem.count }, 2 do
        @snapshot = parent.create_snapshot!(identifier)
      end
    end

    parent.update_columns(updated_at: 1.day.from_now)

    parent.update_columns(updated_at: 1.day.from_now)

    child.destroy!

    parent.comments.create!(content: :foo)
    parent.comments.create!(content: :bar)

    assert_no_difference ->{ ActiveSnapshot::Snapshot.count } do
      assert_no_difference ->{ ActiveSnapshot::SnapshotItem.count } do
        @snapshot.restore!
      end
    end

    assert_equal 1, ActiveSnapshot::Snapshot.where(identifier: identifier).count

    parent.reload

    assert_equal 1, parent.children_to_snapshot[:comments][:records].count

    ### Test Data Chang
    assert_time_match original_parent_updated_at, parent.updated_at
    assert_time_match original_child_updated_at, parent.children_to_snapshot[:comments][:records].first.updated_at
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_snapshot-0.2.4 test/unit/active_snapshot_test.rb
active_snapshot-0.2.3 test/unit/active_snapshot_test.rb
active_snapshot-0.2.2 test/unit/active_snapshot_test.rb
active_snapshot-0.2.1 test/unit/active_snapshot_test.rb
active_snapshot-0.2.0 test/unit/active_snapshot_test.rb
active_snapshot-0.1.1 test/unit/active_snapshot_test.rb