Sha256: 3d3222a1e84be7d467bcebd24386a4da994e5098195f968a777cfe671aa8b7ef

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

class AnAggregate
  include Sandthorn::AggregateRoot
  def touch; touched; end
  def touched; commit; end
end

module Outer
  module Inner
    class OtherAggregate < AnAggregate; end
  end
end

describe Sandthorn do
  before(:each) {
    @aggregate = AnAggregate.new
    @aggregate.touch
    @aggregate.save
  }

  describe "::obsolete_snapshot" do
    it "retrieves a list of obsolete snapshots" do
      obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0
      expect(obsolete_aggregates).to_not be_empty
    end

    it "accepts a block that is applied to each aggregate" do
      obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0
      expect do |block|
        Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0, &block
      end.to yield_successive_args(*obsolete_aggregates)
    end

    it "only retrieves aggregates older than min_event_distance" do
      obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 10
      expect(obsolete_aggregates).to be_empty
    end

    context "when the aggregate has been declared in a module" do

      before do
        Outer::Inner::OtherAggregate.new.tap do |agg|
          agg.touch
          agg.save
        end
      end

      it "doesn't crash" do
        obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [Outer::Inner::OtherAggregate], min_event_distance: 0
        expect(obsolete_aggregates).to all(be_a_kind_of(Outer::Inner::OtherAggregate))
      end
    end
  end

  describe "::save_snapshot" do
    context "when a keyword is missing" do
      it "raises an ArgumentError" do
        expect { Sandthorn.save_snapshot }.to raise_error(ArgumentError)
      end
    end
  end

  describe "::configure" do

    it "should respond_to map_types=" do
      Sandthorn.configure do |conf|
        expect(conf).to respond_to(:map_types=)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sandthorn-0.13.0 spec/sandthorn_spec.rb
sandthorn-0.12.0 spec/sandthorn_spec.rb
sandthorn-0.11.0 spec/sandthorn_spec.rb
sandthorn-0.10.3 spec/sandthorn_spec.rb
sandthorn-0.10.2 spec/sandthorn_spec.rb
sandthorn-0.10.1 spec/sandthorn_spec.rb
sandthorn-0.10.0 spec/sandthorn_spec.rb
sandthorn-0.9.2 spec/sandthorn_spec.rb
sandthorn-0.9.1 spec/sandthorn_spec.rb