Sha256: 4a6028fc7114e30bfce3d79c7569882ef62b7092a24b4146dcd7bc2e4dfb7f4a

Contents?: true

Size: 943 Bytes

Versions: 9

Compression:

Stored size: 943 Bytes

Contents

RSpec.describe Airbrake::Rack::UserFilter 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('/', {}))
    end
  end

  let(:user_payload) { { username: 'bingo' } }
  let(:user) { Airbrake::Rack::User.new(double(user_payload)) }

  it "delegates extraction of the current user information" do
    expect(Airbrake::Rack::User).to receive(:extract).and_return(user)
    subject.call(notice)
    expect(notice[:context][:user]).to eq(user_payload)
  end

  context "when no current user is found" do
    let(:user) { Airbrake::Rack::User.new(double) }

    it "does not include the user key in the payload" do
      expect(Airbrake::Rack::User).to receive(:extract).and_return(user)
      subject.call(notice)
      expect(notice[:context].keys).not_to include(:user)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
airbrake-9.2.1 spec/unit/rack/user_filter_spec.rb
airbrake-9.2.0 spec/unit/rack/user_filter_spec.rb
airbrake-9.1.0 spec/unit/rack/user_filter_spec.rb
airbrake-9.0.2 spec/unit/rack/user_filter_spec.rb
airbrake-9.0.1 spec/unit/rack/user_filter_spec.rb
airbrake-9.0.0 spec/unit/rack/user_filter_spec.rb
airbrake-8.3.2 spec/unit/rack/user_filter_spec.rb
airbrake-8.3.1 spec/unit/rack/user_filter_spec.rb
airbrake-8.3.0 spec/unit/rack/user_filter_spec.rb