spec/adapter_spec.rb in sidekiq-bus-0.7.0 vs spec/adapter_spec.rb in sidekiq-bus-0.8.0

- old
+ new

@@ -1,14 +1,54 @@ +# frozen_string_literal: true + require 'spec_helper' -describe "adapter is set" do +describe 'adapter is set' do it "should call it's enabled! method on init" do QueueBus.send(:reset) expect_any_instance_of(adapter_under_test_class).to receive(:enabled!) - instance = adapter_under_test_class.new + adapter_under_test_class.new QueueBus.send(:reset) end - it "should be defaulting to Data from spec_helper" do + it 'should be defaulting to Data from spec_helper' do expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true) + end + + describe '.setup_heartbeat!' do + context 'when already setup' do + before { QueueBus.heartbeat! } + + it 'does not change schedule' do + expect { QueueBus.heartbeat! } + .not_to(change { Sidekiq.get_schedule('sidekiqbus_heartbeat') }) + end + + it 'has the schedule for every minute' do + expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['every']) + .to eq '1min' + end + + it 'has scheduled the queue bus worker' do + expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['class']) + .to eq ::QueueBus::Worker.name + end + + it 'will run the heartbeat proxy' do + expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['args']) + .to eq [{ bus_class_proxy: 'QueueBus::Heartbeat' }.to_json] + end + + it 'will enqueue to bus_incoming' do + expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['queue']) + .to eq 'bus_incoming' + end + end + + context 'when it does not exist' do + it 'sets the schedule' do + expect { QueueBus.heartbeat! } + .to(change { Sidekiq.get_schedule('sidekiqbus_heartbeat') }) + end + end end end