Sha256: e6f56d328d23522c48a072a5f8792313051d031f38bbe31e91a0312bb02bb200

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

module Sandthorn
  class EventsSpec
    include AggregateRoot

    events :name_changed, :some_other_event, :third_event
    attr_reader :name

    def change_name(name)
      if @name != name
        name_changed(name) { @name = name }
      end
    end

    def some_other one, two
      some_other_event one, two
    end

    def old_way_event event_params
      commit event_params
    end
  end

  describe "::events" do

    let(:subject) do
      EventsSpec.new.extend EventInspector
    end

    it "should not expose events methods" do
      expect(subject).not_to respond_to(:name_changed)
    end
    
    it "should make the events methods private" do
      expect(subject.private_methods).to include(:name_changed)
    end

    describe ".change_name" do
    
      before do
        subject.change_name "new name"
      end

      it "should set the name instance variable" do
        expect(subject.name).to eql "new name"
      end
    
      it "should store the event params as methods args" do
        expect(subject.has_event?(:name_changed)).to be_truthy
      end

      it "should store the args to the event" do
        expect(subject.aggregate_events[1][:event_args][:method_args][0][0]).to eql("new name")
      end
    end

    describe ".some_other" do
    
      before do
        subject.some_other 1, 2
      end
    
      it "should store the event" do
        expect(subject.has_event?(:some_other_event)).to be_truthy
      end

      it "should store the args to the event" do
        expect(subject.aggregate_events[1][:event_args][:method_args][0]).to eql([1,2])
      end
    end

    describe ".old_way_event" do
      
      before do
        subject.old_way_event "hej"
      end

      it "should store the event the old way" do
        expect(subject.has_event?(:old_way_event)).to be_truthy
      end

      it "should store the args to the event" do
        expect(subject.aggregate_events[1][:event_args][:method_args][0][0]).to eql("hej")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sandthorn-0.10.0 spec/aggregate_events_spec.rb