2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Gitlab::RequestContext do
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#client_ip' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.client_ip }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:app) { -> (env) {} }
|
|
|
|
let(:env) { Hash.new }
|
|
|
|
|
|
|
|
context 'when RequestStore::Middleware is used' do
|
2018-03-17 18:26:18 +05:30
|
|
|
around do |example|
|
2017-08-17 22:00:37 +05:30
|
|
|
RequestStore::Middleware.new(-> (env) { example.run }).call({})
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'request' do
|
|
|
|
let(:ip) { '192.168.1.11' }
|
|
|
|
|
|
|
|
before do
|
2019-03-02 22:35:43 +05:30
|
|
|
allow_any_instance_of(ActionDispatch::Request).to receive(:ip).and_return(ip)
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class.new(app).call(env)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(ip) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'before RequestContext middleware run' do
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|