Sha256: 8fc87aad811ce62bc9a52fd1dfa000ad1d05ddab72e136d006b8dd4f7b03f8b4

Contents?: true

Size: 1.57 KB

Versions: 7

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

class DbSubscriber < Reactor::Subscriber
  attr_accessor :was_called

  on_fire do
    self.was_called = true
  end
end

describe Reactor::Workers::DatabaseSubscriberWorker do
  let(:event_name) { :fire_db_subscriber }
  let(:data) { Hash[unused: :data] }
  let!(:db_subscriber) { DbSubscriber.create!(event_name: event_name) }

  let(:instance) { described_class.new }

  describe '#perform' do

    subject { instance.perform(db_subscriber.id, data) }

    context 'when should_perform? is false' do
      before { allow_any_instance_of(DbSubscriber).to receive(:should_perform?).and_return(false) }

      it { is_expected.to eq(:__perform_aborted__) }
    end

    context 'when should_perform? is true' do
      before do
        allow(instance).to receive(:should_perform?).and_return(true)
      end

      it 'fires subscriber' do
        expect(Reactor::Subscriber).to receive(:fire).with(db_subscriber.id, data)
        subject
      end
    end

  end

  describe '#should_perform?' do
    subject { instance.should_perform? }

    context 'in test mode' do
      context 'when subscriber is not enabled' do
        it { is_expected.to eq(false) }
      end

      context 'when subscriber is enabled' do
        it 'should equal true' do
          Reactor.with_subscriber_enabled Reactor::Subscriber do
            expect(subject).to eq(true)
          end
        end
      end
    end

    context 'outside test mode' do
      before do
        allow(Reactor).to receive(:test_mode?).and_return(false)
      end

      it { is_expected.to eq(true) }
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reactor-0.18.0 spec/workers/database_subscriber_worker_spec.rb
reactor-0.17.0 spec/workers/database_subscriber_worker_spec.rb
reactor-0.16.1 spec/workers/database_subscriber_worker_spec.rb
reactor-0.16.0 spec/workers/database_subscriber_worker_spec.rb
reactor-0.15.1 spec/workers/database_subscriber_worker_spec.rb
reactor-0.15.0 spec/workers/database_subscriber_worker_spec.rb
reactor-0.14.0 spec/workers/database_subscriber_worker_spec.rb