Sha256: 473f5ad7fba9cfda4b91bf4cc5fee53601ff20072dec0df8a3c357e3778efa00

Contents?: true

Size: 1.26 KB

Versions: 41

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'spec/support/rack_test'
require 'spec/support/events'
require 'routemaster/drain/terminator'

describe Routemaster::Drain::Terminator do
  let(:app) { described_class.new }
  let(:listener) { double }

  let(:perform) do
    post '/whatever', '', 'routemaster.payload' => payload
  end

  before do
    app.subscribe(listener, prefix: true)
  end
  

  context 'when a payload is present' do
    let(:payload) { [double('event')] } 

    it 'responds 204' do
      perform
      expect(last_response.status).to eq(204)
    end

    it 'broadcasts :events_received' do
      expect(listener).to receive(:on_events_received).with(payload)
      perform
    end
  end

  context 'when a payload is present but empty' do
    let(:payload) { [] } 

    it 'responds 204' do
      perform
      expect(last_response.status).to eq(204)
    end

    it 'does not broadcast :events_received' do
      expect(listener).not_to receive(:on_events_received)
      perform
    end
  end

  context 'when there is no payload' do
    let(:payload) { nil } 

    it 'responds 400' do
      perform
      expect(last_response.status).to eq(400)
    end

    it 'does not broadcast' do
      expect(listener).not_to receive(:on_events_received)
      perform
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
routemaster-drain-3.7.1 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.7.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.8 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.7 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.6 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.5 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.4 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.3 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.2 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.1 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.6.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.5.1 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.5.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.4.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.3.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.2.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.1.0 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.0.3 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.0.2 spec/routemaster/drain/terminator_spec.rb
routemaster-drain-3.0.1 spec/routemaster/drain/terminator_spec.rb