Comments (5)
Thanks for you quick reply and assignment.
Did you expect a subscription to exist without explicitly defining it?
The subscriber get initialised within the RailsEventStore initializer like this
Rails.configuration.event_store.tap do |store|
store.subscribe(OnHubCompanyUpdated::SyncCompany.new, to: [HubCompanyUpdated])
store.subscribe_to_all_events(RailsEventStore::LinkByEventType.new)
store.subscribe_to_all_events(RailsEventStore::LinkByCorrelationId.new)
store.subscribe_to_all_events(RailsEventStore::LinkByCausationId.new)
end
I expect the subscriber to exist in my spec and I think it does exist as I have binding.pry inside the matcher and I get this
tes [3] pry(#<RubyEventStore::RSpec::HaveSubscribedToEvents>)> event_store.subscribers_for(expected.first)
[#<OnHubCompanyUpdated::SyncCompany:0x00000001201f6e88>, ...]
The test is
expect(OnHubCompanyUpdated::SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
What do you mean by "definition is different than in docs"
If i initialize the subscriber without .new
Rails.configuration.event_store.tap do |store|
store.subscribe(OnHubCompanyUpdated::SyncCompany, to: [HubCompanyUpdated])
end
the matcher works, and the expectation pass, but in RailsEventStore documentation, the instructions to add a subscriber is like this
event_store.subscribe(OrderNotifier.new, to: [OrderCancelled])
from rails_event_store.
Hey @remoteweb, thanks for posting!
I'm not sure if I get it. Did you expect a subscription to exist without explicitly defining it?
What do you mean by "definition is different than in docs"?
from rails_event_store.
Thanks, now I get it. Will review this assertion definition soon.
from rails_event_store.
Minimal code to reproduce your case:
it 'got subscribed' do
event_store.within do
expect(SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
end.subscribe(SyncCompany, to: [HubCompanyUpdated]).call
end
⬆️ this test passes 🟢
it 'got subscribed' do
event_store.within do
expect(SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
end.subscribe(SyncCompany.new, to: [HubCompanyUpdated]).call
end
⬆️ this one fails 🔴
It is tricky, but I do not consider this as an issue. In the second case, you pass a certain instance of SyncCompany class to subscribe
method. To test this subscription properly, you should pass the same instance to the assertion.
it 'got subscribed' do
handler = SyncCompany.new
event_store.within do
expect(handler).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
end.subscribe(handler, to: [HubCompanyUpdated]).call
end
⬆️ this test passes 🟢
If you don't care about a stateful handler, you should rather pass a class to the subscribe
method.
The difference between those two is described in this section of the documentation.
Perhaps the documentation should focus more on stateless subscription handlers, as they are the norm. Thank you for pointing it out.
from rails_event_store.
🙏 Thanks for the time put in to add this great explanation. I was falsely expecting the spec helpers to handle all cases by default and I missed to understand properly all different handler configurations.
from rails_event_store.
Related Issues (20)
- Migration guide to RailsEventStore::JSONClient HOT 3
- Create new release for `ruby_event_store-rom` HOT 1
- can't write unknown attribute `event_id` HOT 2
- ruby_event_store-browser 2.10 undefined method `match?' for nil:NilClass HOT 4
- Making the broker configurable HOT 3
- Unsupported adapter when running migration (2.11.1) HOT 6
- NoMethodError when using `RubyEventStore::RSpec::Publish` matcher with `InMemoryRepository` and preceding events HOT 3
- Documentation on Postgres jsonb serialization is not consistent HOT 1
- Projection does three (3) queries where it could be doing one (1) HOT 3
- Browser timezone HOT 3
- Allow to define source of default streams when publishing events HOT 3
- Document our approach to semver and backwards compatibility
- The provided template for existing rails application doesn't work for rails_event_store 2.14.0 and rails 7.1.2 HOT 2
- Allow specifying index HOT 2
- InvalidAuthenticityToken HOT 2
- Timezones not working (for me)
- Generated migration is not Strong Migrations compatible HOT 2
- Potential issue with expected version while publishing events HOT 1
- JSONB variant should make use of GIN indexes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails_event_store.