Commit fa893be3 authored by Luke Duncalfe's avatar Luke Duncalfe

Remove HasIntegrations module

This module should need to be namespaced into concerns/integrations,
however, it is a module that can only be applied to projects, and the
single class method mirrors Group.without_integrations which is written
in-class.

https://gitlab.com/gitlab-org/gitlab/-/issues/330670
parent 3f51bfe0
# frozen_string_literal: true
module HasIntegrations
extend ActiveSupport::Concern
class_methods do
def without_integration(integration)
integrations = Integration
.select('1')
.where("#{Integration.table_name}.project_id = projects.id")
.where(type: integration.type)
Project
.where('NOT EXISTS (?)', integrations)
.where(pending_delete: false)
.where(archived: false)
end
end
end
......@@ -19,7 +19,6 @@ class Project < ApplicationRecord
include Presentable
include HasRepository
include HasWiki
include HasIntegrations
include CanMoveRepositoryStorage
include Routable
include GroupDescendant
......@@ -860,6 +859,18 @@ class Project < ApplicationRecord
rescue ActionController::RoutingError, URI::InvalidURIError
nil
end
def without_integration(integration)
integrations = Integration
.select('1')
.where("#{Integration.table_name}.project_id = projects.id")
.where(type: integration.type)
Project
.where('NOT EXISTS (?)', integrations)
.where(pending_delete: false)
.where(archived: false)
end
end
def initialize(attributes = nil)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe HasIntegrations do
let_it_be(:project_1) { create(:project) }
let_it_be(:project_2) { create(:project) }
let_it_be(:project_3) { create(:project) }
let_it_be(:project_4) { create(:project) }
let_it_be(:instance_integration) { create(:jira_integration, :instance) }
before do
create(:jira_integration, project: project_1, inherit_from_id: instance_integration.id)
create(:jira_integration, project: project_2, inherit_from_id: nil)
create(:jira_integration, :group, group: create(:group), inherit_from_id: nil)
create(:jira_integration, project: project_3, inherit_from_id: nil)
create(:integrations_slack, project: project_4, inherit_from_id: nil)
end
describe '.without_integration' do
it 'returns projects without integration' do
expect(Project.without_integration(instance_integration)).to contain_exactly(project_4)
end
end
end
......@@ -1864,6 +1864,20 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '.without_integration' do
it 'returns projects without the integration' do
project_1, project_2, project_3, project_4 = create_list(:project, 4)
instance_integration = create(:jira_integration, :instance)
create(:jira_integration, project: project_1, inherit_from_id: instance_integration.id)
create(:jira_integration, project: project_2, inherit_from_id: nil)
create(:jira_integration, group: create(:group), project: nil, inherit_from_id: nil)
create(:jira_integration, project: project_3, inherit_from_id: nil)
create(:integrations_slack, project: project_4, inherit_from_id: nil)
expect(Project.without_integration(instance_integration)).to contain_exactly(project_4)
end
end
context 'repository storage by default' do
let(:project) { build(:project) }
......
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