Sha256: 481b46cab520e6435041e696eb266f7dbb02c98fe59f964220ca24aeb3b19389

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'airbrake/rails/action_controller_notify_subscriber'

RSpec.describe Airbrake::Rails::ActionControllerNotifySubscriber do
  after { Airbrake::Rack::RequestStore.clear }

  describe "#call" do
    let(:event) { double(Airbrake::Rails::Event) }

    before do
      allow(Airbrake::Rails::Event).to receive(:new).and_return(event)
    end

    context "when there are no routes in the request store" do
      it "doesn't notify requests" do
        expect(Airbrake).not_to receive(:notify_request)
        subject.call([])
      end
    end

    context "when there's a route in the request store" do
      before do
        Airbrake::Rack::RequestStore[:routes] = {
          '/test-route' => { method: 'GET', response_type: :html }
        }

        expect(event).to receive(:method).and_return('GET')
        expect(event).to receive(:status_code).and_return(200)
        expect(event).to receive(:time).and_return(Time.now)
      end

      it "sends request info to Airbrake" do
        expect(Airbrake).to receive(:notify_request).with(
          hash_including(
            method: 'GET',
            route: '/test-route',
            status_code: 200
          )
        )
        subject.call([])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
airbrake-9.2.1 spec/unit/rails/action_controller_notify_subscriber_spec.rb
airbrake-9.2.0 spec/unit/rails/action_controller_notify_subscriber_spec.rb
airbrake-9.1.0 spec/unit/rails/action_controller_notify_subscriber_spec.rb