Sha256: def547dd05788c042953df74fdbbd970044920ae215fe4d8034d2767d37bd3e9

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'airbrake/rails/action_controller_performance_breakdown_subscriber'

RSpec.describe Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber do
  let(:app) { double(Airbrake::Rails::App) }
  let(:event) { double(Airbrake::Rails::Event) }

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

  after { Airbrake::Rack::RequestStore.clear }

  context "when routes are not set in the request store" do
    before { Airbrake::Rack::RequestStore[:routes] = nil }

    it "doesn't send performance breakdown info" do
      expect(Airbrake).not_to receive(:notify_performance_breakdown)
      subject.call([])
    end
  end

  context "when there are no routes in the request store" do
    before { Airbrake::Rack::RequestStore[:routes] = {} }

    it "doesn't send performance breakdown info" do
      expect(Airbrake).not_to receive(:notify_performance_breakdown)
      subject.call([])
    end
  end

  context "when there's a route in the request store" do
    before do
      expect(event).to receive(:groups).and_return(db: 0.5, view: 0.5)
      expect(event).to receive(:method).and_return('GET')
      expect(event).to receive(:response_type).and_return(:html)
      expect(event).to receive(:time).and_return(Time.new)
    end

    context "when request store routes have extra groups" do
      before do
        Airbrake::Rack::RequestStore[:routes] = {
          '/test-route' => {
            method: 'GET',
            response_type: :html,
            groups: { http: 0.5 }
          }
        }
      end

      it "sends performance info to Airbrake with extra groups" do
        expect(Airbrake).to receive(:notify_performance_breakdown).with(
          hash_including(
            route: '/test-route',
            method: 'GET',
            response_type: :html,
            groups: { db: 0.5, view: 0.5, http: 0.5 }
          )
        )
        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_performance_breakdown_subscriber_spec.rb
airbrake-9.2.0 spec/unit/rails/action_controller_performance_breakdown_subscriber_spec.rb
airbrake-9.1.0 spec/unit/rails/action_controller_performance_breakdown_subscriber_spec.rb