spec/event_spec.rb in reactor-0.19.0 vs spec/event_spec.rb in reactor-1.0.0

- old
+ new

@@ -23,10 +23,11 @@ class OtherWorker include Sidekiq::Worker end describe Reactor::Event do + before { stub_reactor_subscribers } let(:model) { ArbitraryModel.create! } let(:event_name) { :user_did_this } describe 'encoding' do @@ -75,36 +76,44 @@ }.to_not raise_exception ENV['RACK_ENV'] = 'development' end end + + describe 'using injected validator block' do + before { Reactor.validator -> (_event) {raise 'InvalidEvent'} } + after { Reactor.validator Reactor::BASE_VALIDATOR } + + it 'gets called and yields flow control' do + expect { + Reactor::Event.publish(:something) + }.to raise_error(RuntimeError, 'InvalidEvent') + end + end end describe 'perform' do - # before do - # allow(Reactor::Event). - # end let(:event_name) { :barfed } it 'fires all subscribers' do expect(Reactor::StaticSubscribers::ArbitraryModel::BarfedHandler). - to receive(:perform_async).with(hash_including(actor_id: model.id.to_s)) + to receive(:perform_where_needed).with(hash_including(actor_id: model.id.to_s)) Reactor::Event.perform(event_name, actor_id: model.id.to_s, actor_type: model.class.to_s) end it 'sets a fired_at key in event data' do expect(Reactor::StaticSubscribers::ArbitraryModel::BarfedHandler). - to receive(:perform_async).with(hash_including(fired_at: anything)) + to receive(:perform_where_needed).with(hash_including(fired_at: a_kind_of(Time))) Reactor::Event.perform(event_name, actor_id: model.id.to_s, actor_type: model.class.to_s) end describe 'when subscriber throws exception', :sidekiq do it 'doesnt matter because it runs in a separate worker process' do expect { Reactor::Event.perform( - 'barfed', + event_name, somethin: 'up', actor_id: model.id.to_s, actor_type: model.class.to_s ) }.to_not raise_exception