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

- old
+ new

@@ -6,11 +6,11 @@ class Cat < Pet end end -class ArbitraryModel < ActiveRecord::Base +class ArbitraryModel < ApplicationRecord on_event :barfed, handler_name: :bad do raise 'UNEXPECTED!' end @@ -58,42 +58,58 @@ it 'generates and assigns a UUID to the event' do expect(Reactor::Event).to receive(:perform_async).with(event_name, 'actor_id' => '1', 'event' => :user_did_this, 'uuid' => uuid) Reactor::Event.publish(:user_did_this, actor_id: '1') end - end - describe 'perform' do - before do - Reactor::Subscriber.create(event_name: :user_did_this) - Reactor.enable_test_mode_subscriber(Reactor::Subscriber) - end + context 'when in a production rails console' do + it 'requires a second argument srsly: true' do + stub_const('Rails::Console', Class.new) + ENV['RACK_ENV'] = 'production' - after do - Reactor::Subscriber.destroy_all - Reactor.enable_test_mode_subscriber(Reactor::Subscriber) + expect { + Reactor::Event.publish(:thing) + }.to raise_exception(ArgumentError) + + expect { + Reactor::Event.publish(:thing, srsly: true) + }.to_not raise_exception + + ENV['RACK_ENV'] = 'development' + end end + end + describe 'perform' do + # before do + # allow(Reactor::Event). + # end + let(:event_name) { :barfed } + it 'fires all subscribers' do - expect_any_instance_of(Reactor::Subscriber).to receive(:fire).with(hash_including(actor_id: model.id.to_s)) + expect(Reactor::StaticSubscribers::ArbitraryModel::BarfedHandler). + to receive(:perform_async).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_any_instance_of(Reactor::Subscriber).to receive(:fire).with(hash_including(fired_at: anything)) - Reactor::Event.perform(event_name, actor_id: model.id.to_s, actor_type: model.class.to_s) - end + expect(Reactor::StaticSubscribers::ArbitraryModel::BarfedHandler). + to receive(:perform_async).with(hash_including(fired_at: anything)) - it 'works with the legacy .process method, too' do - expect_any_instance_of(Reactor::Subscriber).to receive(:fire).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 describe 'when subscriber throws exception', :sidekiq do - let(:barfing_event) { Reactor::Event.perform('barfed', somethin: 'up', actor_id: model.id.to_s, actor_type: model.class.to_s) } - it 'doesnt matter because it runs in a separate worker process' do - expect { barfing_event }.to_not raise_exception + expect { + Reactor::Event.perform( + 'barfed', + somethin: 'up', + actor_id: model.id.to_s, + actor_type: model.class.to_s + ) + }.to_not raise_exception end end end describe 'reschedule', :sidekiq do