2017-02-06 12:48:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Gitlab::RequestContext do
|
2017-02-06 12:48:46 +00:00
|
|
|
describe '#client_ip' do
|
2017-07-25 17:09:00 +00:00
|
|
|
subject { described_class.client_ip }
|
2017-02-16 10:21:30 +00:00
|
|
|
let(:app) { -> (env) {} }
|
2017-02-06 12:48:46 +00:00
|
|
|
let(:env) { Hash.new }
|
|
|
|
|
|
|
|
context 'when RequestStore::Middleware is used' do
|
|
|
|
around(:each) do |example|
|
2017-02-16 10:21:30 +00:00
|
|
|
RequestStore::Middleware.new(-> (env) { example.run }).call({})
|
2017-02-06 12:48:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'request' do
|
|
|
|
let(:ip) { '192.168.1.11' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip)
|
2017-07-25 17:09:00 +00:00
|
|
|
described_class.new(app).call(env)
|
2017-02-06 12:48:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(ip) }
|
|
|
|
end
|
|
|
|
|
2017-03-03 17:10:22 +00:00
|
|
|
context 'before RequestContext middleware run' do
|
2017-02-06 12:48:46 +00:00
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|