Skip to content

Commit

Permalink
Merge pull request #110 from RailsEventStore/apply_returns_events
Browse files Browse the repository at this point in the history
apply returns applied events
  • Loading branch information
mostlyobvious authored Sep 14, 2017
2 parents 65e8007 + fc60b7c commit 0582188
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 5 additions & 3 deletions aggregate_root/lib/aggregate_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
require 'aggregate_root/default_apply_strategy'

module AggregateRoot
def apply(event)
apply_strategy.(self, event)
unpublished_events << event
def apply(*events)
events.each do |event|
apply_strategy.(self, event)
unpublished_events << event
end
end

def load(stream_name, event_store: default_event_store)
Expand Down
21 changes: 20 additions & 1 deletion aggregate_root/spec/aggregate_root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,23 @@
order.apply(order_created)
expect(order.status).to eq :created
end
end

it "should return applied events" do
order = Order.new
created = Orders::Events::OrderCreated.new
expired = Orders::Events::OrderExpired.new

applied = order.apply(created, expired)
expect(applied).to eq([created, expired])
end

it "should return only applied events" do
order = Order.new
created = Orders::Events::OrderCreated.new
order.apply(created)

expired = Orders::Events::OrderExpired.new
applied = order.apply(expired)
expect(applied).to eq([expired])
end
end

0 comments on commit 0582188

Please sign in to comment.