diff --git a/lib/api/api.rb b/lib/api/api.rb index e19ebe05f32e77cbc2844205ac7d97977705fb5f..b95912e8badb7ec101adeb7862c25142437c9c5d 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -90,6 +90,13 @@ def initialize(location_url) ) end + before do + ::Current.organization = Gitlab::Current::Organization.new( + params: {}, + user: @current_user + ).organization + end + before do set_peek_enabled_for_current_request end diff --git a/spec/requests/api/api_spec.rb b/spec/requests/api/api_spec.rb index a1f551528dbe581b30b0145bc23ac6092f50e694..018abdeed118cc03e7e89f14a6ca82872236898e 100644 --- a/spec/requests/api/api_spec.rb +++ b/spec/requests/api/api_spec.rb @@ -421,4 +421,22 @@ expect(response).to have_gitlab_http_status(:bad_request) end end + + describe 'Current Organization' do + let_it_be(:current_organization) { create(:organization) } + + before do + allow_next_instance_of(Gitlab::Current::Organization) do |instance| + allow(instance).to receive(:organization).and_return(current_organization) + end + end + + it 'sets Current Organization' do + # Test for new value of Current.organization won't work because + # it will be reset after the request is processed. + expect(Current).to receive(:organization=).with(current_organization) + + get api('/groups') + end + end end