Commit 7624c680 authored by Douwe Maan's avatar Douwe Maan

Update EE-specific API helpers spec

parent cfe1ff8b
......@@ -2,6 +2,8 @@ module EE
module API
module Helpers
def current_user
return @current_user if defined?(@current_user)
user = super
::Gitlab::Database::LoadBalancing::RackMiddleware
......
require 'spec_helper'
describe EE::API::Helpers do
let(:helper) { Class.new { include API::Helpers }.new }
include API::APIGuard::HelperMethods
include API::Helpers
let(:options) { {} }
let(:params) { {} }
let(:env) do
{
'rack.input' => '',
'REQUEST_METHOD' => 'GET'
}
end
let(:header) { }
before do
allow(helper).to receive(:env).and_return({})
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
describe '#current_user' do
let(:user) { build(:user, id: 42) }
before do
allow(helper).to receive(:sudo!)
end
it 'handles sticking when a user could be found' do
allow(helper).to receive(:initial_current_user).and_return(user)
allow_any_instance_of(API::Helpers).to receive(:initial_current_user).and_return(user)
expect(Gitlab::Database::LoadBalancing::RackMiddleware)
.to receive(:stick_or_unstick).with({}, :user, 42)
.to receive(:stick_or_unstick).with(env, :user, 42)
helper.current_user
current_user
end
it 'does not handle sticking if no user could be found' do
allow(helper).to receive(:initial_current_user).and_return(nil)
allow_any_instance_of(API::Helpers).to receive(:initial_current_user).and_return(nil)
expect(Gitlab::Database::LoadBalancing::RackMiddleware)
.not_to receive(:stick_or_unstick)
helper.current_user
current_user
end
it 'returns the user if one could be found' do
allow(helper).to receive(:initial_current_user).and_return(user)
allow_any_instance_of(API::Helpers).to receive(:initial_current_user).and_return(user)
expect(helper.current_user).to eq(user)
expect(current_user).to eq(user)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment