-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce user defined unique keys for aggregates
- Loading branch information
1 parent
75e153b
commit 9aa5cc9
Showing
7 changed files
with
84 additions
and
4 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -481,5 +481,36 @@ def ping | |
expect(aggregate.first.pinged).to eq(2) | ||
end | ||
end | ||
|
||
context 'with unique keys' do | ||
class DummyWithUniqueKeysCreated < Sequent::Core::Event | ||
attrs unique_keys: Object | ||
end | ||
|
||
class DummyAggregateWithUniqueKeys < Sequent::Core::AggregateRoot | ||
def initialize(id, unique_keys) | ||
super(id) | ||
apply DummyWithUniqueKeysCreated, unique_keys: | ||
end | ||
|
||
def unique_keys | ||
@unique_keys || {} | ||
end | ||
|
||
on DummyWithUniqueKeysCreated do |event| | ||
@unique_keys = event.unique_keys | ||
end | ||
end | ||
|
||
it 'enforces key uniqueness with the same scope' do | ||
dummy1 = DummyAggregateWithUniqueKeys.new(Sequent.new_uuid, {email: '[email protected]'}) | ||
dummy2 = DummyAggregateWithUniqueKeys.new(Sequent.new_uuid, {email: '[email protected]'}) | ||
Sequent.aggregate_repository.add_aggregate(dummy1) | ||
Sequent.aggregate_repository.add_aggregate(dummy2) | ||
|
||
expect { Sequent.aggregate_repository.commit(DummyCommand.new) } | ||
.to raise_error Sequent::Core::EventStore::AggregateKeyNotUniqueError | ||
end | ||
end | ||
end | ||
end |