Commit 054632af authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch '330670-remove-has-integrations-module' into 'master'

Remove HasIntegrations module

See merge request gitlab-org/gitlab!74331
parents f5ed38fa fa893be3
# 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 ...@@ -19,7 +19,6 @@ class Project < ApplicationRecord
include Presentable include Presentable
include HasRepository include HasRepository
include HasWiki include HasWiki
include HasIntegrations
include CanMoveRepositoryStorage include CanMoveRepositoryStorage
include Routable include Routable
include GroupDescendant include GroupDescendant
...@@ -860,6 +859,18 @@ class Project < ApplicationRecord ...@@ -860,6 +859,18 @@ class Project < ApplicationRecord
rescue ActionController::RoutingError, URI::InvalidURIError rescue ActionController::RoutingError, URI::InvalidURIError
nil nil
end 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 end
def initialize(attributes = nil) 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 ...@@ -1864,6 +1864,20 @@ RSpec.describe Project, factory_default: :keep do
end end
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 context 'repository storage by default' do
let(:project) { build(:project) } 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