-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
class_events are broken up into stateless_events and constructor_events
- Loading branch information
Showing
4 changed files
with
191 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'spec_helper' | ||
|
||
module Sandthorn | ||
class ConstructorEventsSpec | ||
include AggregateRoot | ||
|
||
constructor_events :created_event | ||
attr_reader :name | ||
|
||
|
||
def self.create name | ||
created_event(name) { @name = name } | ||
end | ||
|
||
end | ||
|
||
describe "::constructor_events" do | ||
|
||
let(:subject) do | ||
ConstructorEventsSpec.create("name").save | ||
end | ||
|
||
context "interface" do | ||
|
||
it "should not expose constructor_events methods" do | ||
expect(subject).not_to respond_to(:created_event) | ||
end | ||
|
||
it "should create the constructor event on the class" do | ||
expect(ConstructorEventsSpec.private_methods).to include(:created_event) | ||
end | ||
|
||
end | ||
end | ||
|
||
describe "::create" do | ||
let(:aggregate_id) do | ||
a = ConstructorEventsSpec.create("create_name") | ||
a.save | ||
a.aggregate_id | ||
end | ||
|
||
it "should create an ConstructorEventsSpec aggregate" do | ||
expect(ConstructorEventsSpec.find(aggregate_id)).to be_a ConstructorEventsSpec | ||
end | ||
|
||
it "should set instance variable in aggregate" do | ||
expect(ConstructorEventsSpec.find(aggregate_id).name).to eql "create_name" | ||
end | ||
|
||
it "should have created an created_event" do | ||
expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_name]).to eql "created_event" | ||
end | ||
|
||
it "should have set the method_args to create_name" do | ||
expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:method_args].first).to eql "create_name" | ||
end | ||
|
||
it "should have set the attribute_delta name" do | ||
expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:attribute_deltas].last[:attribute_name]).to eql "name" | ||
expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:attribute_deltas].last[:new_value]).to eql "create_name" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
require 'spec_helper' | ||
|
||
module Sandthorn | ||
class StatelessEventsSpec | ||
include AggregateRoot | ||
|
||
stateless_events :one_event, :some_other_event | ||
attr_reader :name | ||
|
||
def initialize name | ||
@name = name | ||
end | ||
|
||
# def self.call_one_event aggregate_id, hash = {}, value = 0 | ||
# one_event(aggregate_id, hash, value) | ||
# end | ||
|
||
end | ||
|
||
describe "::stateless_events" do | ||
|
||
context "interface" do | ||
|
||
it "should expose stateless_events methods" do | ||
expect(StatelessEventsSpec).to respond_to(:one_event) | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
context "when adding a stateless event to an existing aggregate" do | ||
|
||
let(:subject) do | ||
StatelessEventsSpec.new("name").save | ||
end | ||
|
||
before do | ||
StatelessEventsSpec.one_event(subject.aggregate_id, args, 1) | ||
end | ||
|
||
let(:args) do | ||
{first: "first", other: [1,2,3]} | ||
end | ||
|
||
let(:last_event) do | ||
Sandthorn.get_aggregate_events(StatelessEventsSpec, subject.aggregate_id).last | ||
end | ||
|
||
let(:reloaded_subject) do | ||
StatelessEventsSpec.find subject.aggregate_id | ||
end | ||
|
||
it "should add one_event last on the aggregate" do | ||
expect(last_event[:event_name]).to eql "one_event" | ||
end | ||
|
||
it "should not have any deltas in event" do | ||
expect(last_event[:event_args][:attribute_deltas]).to eql [] | ||
end | ||
|
||
it "should store event arguments" do | ||
expect(last_event[:event_args][:method_args].first).to eql(args) | ||
expect(last_event[:event_args][:method_args].last).to eql(1) | ||
end | ||
|
||
it "should have same name attribute after reload" do | ||
expect(subject.name).to eql(reloaded_subject.name) | ||
end | ||
end | ||
|
||
context "when adding stateless_events to none existing aggregate" do | ||
|
||
before do | ||
StatelessEventsSpec.one_event(aggregate_id, "argument_data") | ||
end | ||
|
||
let(:aggregate_id) {"none_existing_aggregate_id"} | ||
|
||
let(:events) do | ||
Sandthorn.get_aggregate_events(StatelessEventsSpec, aggregate_id) | ||
end | ||
|
||
it "should store the stateless event as the first event" do | ||
expect(events.length).to be 1 | ||
end | ||
|
||
it "should have correct aggregate_id in event" do | ||
expect(events.first[:aggregate_id]).to eql aggregate_id | ||
end | ||
|
||
it "should have event name one_event" do | ||
expect(events.first[:event_name]).to eql "one_event" | ||
end | ||
end | ||
|
||
end | ||
end |