Commit b200b7da authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '218252-custom-integration-projects' into 'master'

List custom integration projects

See merge request gitlab-org/gitlab!33043
parents 2a3ced54 b754f874
......@@ -36,6 +36,10 @@ module IntegrationsActions
end
end
def custom_integration_projects
Project.with_custom_integration_compared_to(integration).page(params[:page]).per(20)
end
def test
render json: {}, status: :ok
end
......
# frozen_string_literal: true
module Integration
extend ActiveSupport::Concern
class_methods do
def with_custom_integration_compared_to(integration)
custom_integrations = Service
.select('1')
.where(type: integration.type, inherit_from_id: nil)
.where('services.project_id = projects.id')
Project.where('EXISTS (?)', custom_integrations)
end
end
end
......@@ -33,6 +33,7 @@ class Project < ApplicationRecord
include OptionallySearch
include FromUnion
include IgnorableColumns
include Integration
extend Gitlab::Cache::RequestCache
extend Gitlab::ConfigHelper
......
......@@ -118,6 +118,7 @@ namespace :admin do
resources :services, only: [:index, :edit, :update]
resources :integrations, only: [:edit, :update] do
member do
get :custom_integration_projects
put :test
end
end
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
describe Admin::IntegrationsController do
let(:admin) { create(:admin) }
let(:integration) { create(:jira_service, :instance) }
before do
sign_in(admin)
......@@ -33,8 +34,6 @@ describe Admin::IntegrationsController do
end
describe '#update' do
let(:integration) { create(:jira_service, :instance) }
before do
allow(PropagateIntegrationWorker).to receive(:perform_async)
......@@ -68,4 +67,14 @@ describe Admin::IntegrationsController do
end
end
end
describe '#custom_integration_projects' do
it 'calls to get the custom integration projects' do
allow(Project).to receive_message_chain(:with_custom_integration_compared_to, :page, :per)
get :custom_integration_projects, params: { id: integration.class.to_param }
expect(Project).to have_received(:with_custom_integration_compared_to).with(integration)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integration do
let(:project_1) { create(:project) }
let(:project_2) { create(:project) }
let(:instance_integration) { create(:jira_service, :instance) }
before do
create(:jira_service, project: project_1, inherit_from_id: instance_integration.id)
create(:jira_service, project: project_2, inherit_from_id: nil)
create(:slack_service, project: project_1, inherit_from_id: nil)
end
describe '#with_custom_integration_compared_to' do
it 'returns projects with custom integrations' do
expect(Project.with_custom_integration_compared_to(instance_integration)).to contain_exactly(project_2)
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