request_context_spec.rb 736 Bytes
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::RequestContext do
4
  describe '#client_ip' do
5
    subject { described_class.client_ip }
Pawel Chojnacki's avatar
Pawel Chojnacki committed
6
    let(:app) { -> (env) {} }
7 8 9
    let(:env) { Hash.new }

    context 'when RequestStore::Middleware is used' do
10
      around do |example|
Pawel Chojnacki's avatar
Pawel Chojnacki committed
11
        RequestStore::Middleware.new(-> (env) { example.run }).call({})
12 13 14 15 16 17 18
      end

      context 'request' do
        let(:ip) { '192.168.1.11' }

        before do
          allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip)
19
          described_class.new(app).call(env)
20 21 22 23 24
        end

        it { is_expected.to eq(ip) }
      end

25
      context 'before RequestContext middleware run' do
26 27 28 29 30
        it { is_expected.to be_nil }
      end
    end
  end
end