Skip to content

Instantly share code, notes, and snippets.

@Papipo
Created June 16, 2014 11:02
Show Gist options
  • Save Papipo/7ad951ca08b41f2e2b25 to your computer and use it in GitHub Desktop.
Save Papipo/7ad951ca08b41f2e2b25 to your computer and use it in GitHub Desktop.
require "event_sourcing/command"
require "aggregates/mathtrade"
module Commands
RequestMathtrade = EventSourcing::Command.new(:mathtrade_id, :wantlist) do |event_store|
stream = event_store.get_stream(mathtrade_id)
mathtrade = Aggregates::Mathtrade.new(stream.events)
event_store.append(mathtrade_id, stream.version, mathtrade.request(wantlist: wantlist))
end
end
require "unit_helper"
require "commands/mathtrade"
describe Commands::RequestMathtrade do
let(:command) { Commands::RequestMathtrade.new(mathtrade_id: "some-id", wantlist: wantlist) }
describe "execute" do
let(:wantlist) { double("Wantlist") }
let(:event_store) { double("EventStore") }
let(:mathtrade) { instance_double("Aggregates::Mathtrade") }
let(:history) { double("History") }
let(:event) { double("Event")}
let(:stream) { double("Stream", events: history, version: 123)}
before do
allow(event_store).to receive(:get_stream).with("some-id").and_return(stream)
allow(Aggregates::Mathtrade).to receive(:new).with(history).and_return(mathtrade)
allow(mathtrade).to receive(:request).with(wantlist: wantlist).and_return(event)
end
after { command.execute(event_store) }
it "appends to the event store whatever the aggregate returns" do
expect(event_store).to receive(:append).with("some-id", 123, event)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment