Skip to content

Commit

Permalink
added mapp_aggregate_type_to_event_store and mapp_aggregate_types_to_…
Browse files Browse the repository at this point in the history
…event_store to event_stores
  • Loading branch information
hallgren committed Sep 25, 2015
1 parent b2e0df2 commit 4816c56
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/sandthorn/event_stores.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def stores
store_map.values
end

def mapp_aggregate_type_to_event_store(aggregate_type, event_store)
aggregate_type.event_store(event_store)
end

def mapp_aggregate_types_to_event_store(array = [])
array.each do |item|
mapp_aggregate_type_to_event_store(item[:aggregate_type], item[:event_store]) if(item[:aggregate_type] && item[:event_store])
end
end

private

attr_reader :store_map
Expand Down
39 changes: 39 additions & 0 deletions spec/event_stores_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Sandthorn
describe EventStores do
let(:stores) { EventStores.new }

before do
class AnAggregate
include Sandthorn::AggregateRoot
end
end


describe "#initialize" do
context "when given a single event_store" do
it "sets it as the default event store" do
Expand Down Expand Up @@ -77,5 +84,37 @@ module Sandthorn
expect(stores[:foo]).to eq(store)
end
end

describe "#mapp_aggregate_type_to_event_store" do

let(:klass) {
class AnAggregate
include Sandthorn::AggregateRoot
end
}

it "mapps the aggregate_type to the event_store" do
store = double
stores.add(:foo, store)
stores.mapp_aggregate_type_to_event_store(klass, :foo)
expect(klass.event_store).to eq(:foo)
end
end

describe "#mapp_aggregate_types_to_event_store" do

let(:klass) {
class AnAggregate
include Sandthorn::AggregateRoot
end
}

it "mapps an array of aggregate_types to event_stores" do
store = double
stores.add(:foo, store)
stores.mapp_aggregate_types_to_event_store([{ aggregate_type: klass, event_store: :foo }])
expect(klass.event_store).to eq(:foo)
end
end
end
end
3 changes: 2 additions & 1 deletion spec/get_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AnAggregate

class AnotherAggregate
include Sandthorn::AggregateRoot
event_store :other
event_store :should_override_this
end

describe Sandthorn do
Expand Down Expand Up @@ -66,6 +66,7 @@ def setup_secondary_db
url = "sqlite://spec/db/other_db.sqlite3"
driver = SandthornDriverSequel.driver_from_url(url: url)
Sandthorn.event_stores.add(:other, driver)
Sandthorn.event_stores.mapp_aggregate_type_to_event_store(AnotherAggregate, :other)
migrator = SandthornDriverSequel::Migration.new url: url
SandthornDriverSequel.migrate_db url: url
migrator.send(:clear_for_test)
Expand Down

0 comments on commit 4816c56

Please sign in to comment.