Sha256: 0ee5b01363797c6265a68f2677e8863d939924c3206507b8537ef4ee128e772b

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

RSpec.describe Airbrake::Rack::HttpHeadersFilter do
  def env_for(url, opts = {})
    Rack::MockRequest.env_for(url, opts)
  end

  let(:notice) do
    Airbrake.build_notice('oops').tap do |notice|
      notice.stash[:rack_request] = Rack::Request.new(env_for(uri, opts))
    end
  end

  let(:headers) do
    {
      'HTTP_HOST' => 'example.com',
      'CONTENT_TYPE' => 'text/html',
      'CONTENT_LENGTH' => 100500
    }
  end

  let(:uri) { '/' }
  let(:opts) { headers.dup }

  it "preserves data that already has been added to the context" do
    notice[:context]['SOME_KEY'] = 'SOME_VALUE'
    subject.call(notice)
    expect(notice[:context]['SOME_KEY']).to eq('SOME_VALUE')
  end

  context "when CONTENT_TYPE, CONTENT_LENGTH and HTTP_* headers are present" do
    it "adds them to the context hash" do
      subject.call(notice)
      expect(notice[:context][:headers]).to eq(headers)
    end
  end

  context "when unexpected headers are present" do
    let(:opts) { headers.dup.merge('X-SOME-HEADER' => 'value') }

    it "adds them to the context hash" do
      subject.call(notice)
      expect(notice[:context][:headers]).to eq(headers)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
airbrake-8.2.1 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.2.0 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.1.4 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.1.3 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.1.2 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.1.1 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.1.0 spec/unit/rack/http_headers_filter_spec.rb
airbrake-8.0.1 spec/unit/rack/http_headers_filter_spec.rb