Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3d8d6c4
Revert "Revert "PoC of double serialization prevention""
mostlyobvious Jan 30, 2023
2b18c08
Revert "Revert "Pick correct serializer when testing""
mostlyobvious Jan 30, 2023
b32e4f0
Revert "Revert "Less is more""
mostlyobvious Jan 30, 2023
d0a0d73
Revert "Revert "Requirements for different column types""
mostlyobvious Jan 30, 2023
77319df
Revert "Revert "We don't introduce anything new over Value here""
mostlyobvious Jan 30, 2023
ce1d81b
Revert "Revert "Big :brain: time""
mostlyobvious Jan 30, 2023
edf2a4c
Revert "Revert "Boom, get proposed type for column from AR and act""
mostlyobvious Jan 30, 2023
709c7cd
Revert "Revert "Extract to variable""
mostlyobvious Jan 30, 2023
43e58a2
Revert "Revert "More meaningful naming""
mostlyobvious Jan 30, 2023
467b650
Revert "Revert "No idea how to achieve the same in Rails < 6.1""
mostlyobvious Jan 30, 2023
febccba
Revert "Revert "Better describing what this test is for""
mostlyobvious Jan 30, 2023
f6f739f
Revert "Revert "Document how to use json in RES 3.0""
mostlyobvious Jan 30, 2023
576650c
No more aggregate root configuration
mpraglowski Jan 5, 2021
00eff79
Remove deprecated JSONMapper
mpraglowski Jan 5, 2021
f758f1c
No more aliases on RubyEventStore consts
mostlyobvious Jan 15, 2021
b09cadb
Get rid of dubious meta-apply method handlers
mostlyobvious Jan 9, 2021
af10673
Poor way to ensure with_strategy(->{ Default }) has OnDSL
mostlyobvious Jan 9, 2021
9922b09
Refactor
mostlyobvious Jan 9, 2021
18b8ebd
Kill mutants
mostlyobvious Jan 9, 2021
52dee38
EventClassRemapping superseded by upcasting
mostlyobvious Jan 9, 2021
b016ae4
Revert "Revert "Raise ArgumentError when trying to publish nil as eve…
mostlyobvious Nov 29, 2022
102ed78
Revert "Revert "Extract assertion to separate method and call it asap""
mostlyobvious Nov 29, 2022
111ce04
Revert "Revert "Assert nil when linking events""
mostlyobvious Nov 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions aggregate_root/lib/aggregate_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative "aggregate_root/version"
require_relative "aggregate_root/configuration"
require_relative "aggregate_root/transform"
require_relative "aggregate_root/default_apply_strategy"
require_relative "aggregate_root/repository"
require_relative "aggregate_root/instrumented_repository"
Expand Down Expand Up @@ -81,7 +80,6 @@ def marshal_load(vars)
def self.with_default_apply_strategy
Module.new do
def self.included(host_class)
host_class.extend OnDSL
host_class.include AggregateRoot.with_strategy(-> { DefaultApplyStrategy.new })
end
end
Expand All @@ -90,7 +88,8 @@ def self.included(host_class)
def self.with_strategy(strategy)
Module.new do
def self.included(host_class)
host_class.extend Constructor
host_class.extend OnDSL
host_class.extend Constructor
host_class.include AggregateMethods
end

Expand Down
16 changes: 0 additions & 16 deletions aggregate_root/lib/aggregate_root/configuration.rb

This file was deleted.

31 changes: 13 additions & 18 deletions aggregate_root/lib/aggregate_root/default_apply_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,32 @@

module AggregateRoot
MissingHandler = Class.new(StandardError)
NullHandler = Proc.new {}

class DefaultApplyStrategy
def initialize(strict: true)
@strict = strict
end

def call(aggregate, event)
name = handler_name(aggregate, event)
if aggregate.respond_to?(name, true)
aggregate.method(name).call(event)
else
raise MissingHandler.new("Missing handler method #{name} on aggregate #{aggregate.class}") if strict
end
on_handler(aggregate, event.event_type)[event]
end

private

def handler_name(aggregate, event)
on_dsl_handler_name(aggregate, event.event_type) || apply_handler_name(event.event_type)
end

def on_dsl_handler_name(aggregate, event_type)
aggregate.class.on_methods[event_type] if aggregate.class.respond_to?(:on_methods)
def on_handler(aggregate, event_type)
on_method_name = aggregate.class.on_methods.fetch(event_type)
aggregate.method(on_method_name)
rescue KeyError
missing_handler(aggregate, event_type)
end

def apply_handler_name(event_type)
"apply_#{Transform.to_snake_case(event_type(event_type))}"
end

def event_type(event_type)
event_type.split(/::|\./).last
def missing_handler(aggregate, event_type)
if strict
raise MissingHandler.new("Missing handler method on aggregate #{aggregate.class} for #{event_type}")
else
NullHandler
end
end

attr_reader :strict, :on_methods
Expand Down
6 changes: 1 addition & 5 deletions aggregate_root/lib/aggregate_root/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module AggregateRoot
class Repository
def initialize(event_store = default_event_store)
def initialize(event_store)
@event_store = event_store
end

Expand All @@ -29,9 +29,5 @@ def with_aggregate(aggregate, stream_name, &block)
private

attr_reader :event_store

def default_event_store
AggregateRoot.configuration.default_event_store
end
end
end
9 changes: 0 additions & 9 deletions aggregate_root/lib/aggregate_root/transform.rb

This file was deleted.

28 changes: 13 additions & 15 deletions aggregate_root/spec/aggregate_root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ def expire

private

def apply_order_created(_event)
@status = :created
on Orders::Events::OrderCreated do |event|
@status = :created
@created_at = event.valid_at
end

def apply_order_expired(_event)
@status = :expired
on Orders::Events::OrderExpired do |event|
@status = :expired
@expired_at = event.valid_at
end
end
end

it "should have ability to apply event on itself" do
order = order_klass.new(uuid)
order_created = Orders::Events::OrderCreated.new

expect(order).to receive(:"apply_order_created").with(order_created).and_call_original
order.apply(order_created)

expect(order.status).to eq :created
expect(order.unpublished_events.to_a).to eq([order_created])
end
Expand All @@ -56,6 +57,12 @@ def apply_order_expired(_event)
expect(order.unpublished_events.to_a).to be_empty
end

it "should raise error for missing apply method based on a default apply strategy" do
order = order_klass.new(uuid)
spanish_inquisition = Orders::Events::SpanishInquisition.new
expect { order.apply(spanish_inquisition) }.to raise_error(AggregateRoot::MissingHandler, "Missing handler method on aggregate #{order_klass} for Orders::Events::SpanishInquisition")
end

it "should receive a method call based on a default apply strategy" do
order = order_klass.new(uuid)
order_created = Orders::Events::OrderCreated.new
Expand All @@ -64,15 +71,6 @@ def apply_order_expired(_event)
expect(order.status).to eq :created
end

it "should raise error for missing apply method based on a default apply strategy" do
order = order_klass.new(uuid)
spanish_inquisition = Orders::Events::SpanishInquisition.new
expect { order.apply(spanish_inquisition) }.to raise_error(
AggregateRoot::MissingHandler,
"Missing handler method apply_spanish_inquisition on aggregate #{order_klass}"
)
end

it "should ignore missing apply method based on a default non-strict apply strategy" do
klass =
Class.new { include AggregateRoot.with_strategy(-> { AggregateRoot::DefaultApplyStrategy.new(strict: false) }) }
Expand Down
4 changes: 2 additions & 2 deletions aggregate_root/spec/instrumented_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def expire

private

def apply_order_created(_event)
on Orders::Events::OrderCreated do |_event|
@status = :created
end

def apply_order_expired(_event)
on Orders::Events::OrderExpired do |_event|
@status = :expired
end
end
Expand Down
39 changes: 2 additions & 37 deletions aggregate_root/spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,16 @@ def expire

private

def apply_order_created(_event)
on Orders::Events::OrderCreated do |_event|
@status = :created
end

def apply_order_expired(_event)
on Orders::Events::OrderExpired do |_event|
@status = :expired
end
end
end

def with_default_event_store(store)
previous = AggregateRoot.configuration.default_event_store
AggregateRoot.configure { |config| config.default_event_store = store }
yield
AggregateRoot.configure { |config| config.default_event_store = previous }
end

describe "#initialize" do
it "should use default client if event_store not provided" do
with_default_event_store(event_store) do
repository = AggregateRoot::Repository.new

order = repository.load(order_klass.new(uuid), stream_name)
order_created = Orders::Events::OrderCreated.new
order.apply(order_created)
repository.store(order, stream_name)

expect(event_store.read.stream(stream_name).to_a).to eq [order_created]
end
end

it "should prefer provided event_store client" do
with_default_event_store(double(:event_store)) do
repository = AggregateRoot::Repository.new(event_store)

order = repository.load(order_klass.new(uuid), stream_name)
order_created = Orders::Events::OrderCreated.new
order.apply(order_created)
repository.store(order, stream_name)

expect(event_store.read.stream(stream_name).to_a).to eq [order_created]
end
end
end

describe "#load" do
specify do
event_store.publish(Orders::Events::OrderCreated.new, stream_name: stream_name)
Expand Down
2 changes: 0 additions & 2 deletions aggregate_root/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require "ruby_event_store"
require_relative "../../support/helpers/rspec_defaults"

RSpec.configure { |spec| spec.before(:each) { AggregateRoot.configure { |config| config.default_event_store = nil } } }

module Orders
module Events
OrderCreated = Class.new(RubyEventStore::Event)
Expand Down
12 changes: 0 additions & 12 deletions aggregate_root/spec/transform_spec.rb

This file was deleted.

20 changes: 0 additions & 20 deletions rails_event_store/lib/rails_event_store/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@
require_relative "version"
require_relative "railtie"
require_relative "browser"

module RailsEventStore
Event = RubyEventStore::Event
InMemoryRepository = RubyEventStore::InMemoryRepository
Subscriptions = RubyEventStore::Subscriptions
Projection = RubyEventStore::Projection
WrongExpectedEventVersion = RubyEventStore::WrongExpectedEventVersion
InvalidExpectedVersion = RubyEventStore::InvalidExpectedVersion
IncorrectStreamData = RubyEventStore::IncorrectStreamData
EventNotFound = RubyEventStore::EventNotFound
SubscriberNotExist = RubyEventStore::SubscriberNotExist
InvalidHandler = RubyEventStore::InvalidHandler
InvalidPageStart = RubyEventStore::InvalidPageStart
InvalidPageStop = RubyEventStore::InvalidPageStop
InvalidPageSize = RubyEventStore::InvalidPageSize
CorrelatedCommands = RubyEventStore::CorrelatedCommands
GLOBAL_STREAM = RubyEventStore::GLOBAL_STREAM
PAGE_SIZE = RubyEventStore::PAGE_SIZE
ImmediateAsyncDispatcher = RubyEventStore::ImmediateAsyncDispatcher
end
4 changes: 1 addition & 3 deletions rails_event_store/spec/active_job_scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ module RailsEventStore
it_behaves_like :scheduler, ActiveJobScheduler.new(serializer: RubyEventStore::Serializers::YAML)
it_behaves_like :scheduler, ActiveJobScheduler.new(serializer: RubyEventStore::NULL)

let(:event) do
TimeEnrichment.with(Event.new(event_id: "83c3187f-84f6-4da7-8206-73af5aca7cc8"), timestamp: Time.utc(2019, 9, 30))
end
let(:event) { TimeEnrichment.with(RubyEventStore::Event.new(event_id: "83c3187f-84f6-4da7-8206-73af5aca7cc8"), timestamp: Time.utc(2019, 9, 30)) }
let(:record) { RubyEventStore::Mappers::Default.new.event_to_record(event) }

describe "#verify" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DummyRecord < ActiveRecord::Base

it_behaves_like :dispatcher, AfterCommitAsyncDispatcher.new(scheduler: ActiveJobScheduler.new(serializer: RubyEventStore::Serializers::YAML))

let(:event) { TimeEnrichment.with(RailsEventStore::Event.new(event_id: "83c3187f-84f6-4da7-8206-73af5aca7cc8")) }
let(:event) { TimeEnrichment.with(RubyEventStore::Event.new(event_id: "83c3187f-84f6-4da7-8206-73af5aca7cc8")) }
let(:record) { RubyEventStore::Mappers::Default.new.event_to_record(event) }
let(:serialized_record) { record.serialize(RubyEventStore::Serializers::YAML).to_h.transform_keys(&:to_s) }

Expand Down
Loading