Commit d1c142ed authored by Alper Akgun's avatar Alper Akgun

Fix remote_mirrors usage data metric

parent a9f4517a
...@@ -579,7 +579,7 @@ class Project < ApplicationRecord ...@@ -579,7 +579,7 @@ class Project < ApplicationRecord
with_issues_available_for_user(user).or(with_merge_requests_available_for_user(user)) with_issues_available_for_user(user).or(with_merge_requests_available_for_user(user))
end end
scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) } scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) }
scope :with_remote_mirrors, -> { joins(:remote_mirrors).where(remote_mirrors: { enabled: true }).distinct } scope :with_remote_mirrors, -> { joins(:remote_mirrors).where(remote_mirrors: { enabled: true }) }
scope :with_limit, -> (maximum) { limit(maximum) } scope :with_limit, -> (maximum) { limit(maximum) }
scope :with_group_runners_enabled, -> do scope :with_group_runners_enabled, -> do
......
---
title: Fix remote_mirrors usage ping metric
merge_request: 57332
author:
type: fixed
...@@ -167,7 +167,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -167,7 +167,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:key, user: user) create(:key, user: user)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true) create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false) create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
create(:remote_mirror, project: project) create(:remote_mirror, project: project, enabled: true)
another_user = create(:user)
another_project = create(:project, :repository, creator: another_user)
create(:remote_mirror, project: another_project, enabled: false)
create(:snippet, author: user) create(:snippet, author: user)
end end
...@@ -176,7 +179,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -176,7 +179,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
keys: 2, keys: 2,
merge_requests: 2, merge_requests: 2,
projects_with_disable_overriding_approvers_per_merge_request: 2, projects_with_disable_overriding_approvers_per_merge_request: 2,
projects_without_disable_overriding_approvers_per_merge_request: 4, projects_without_disable_overriding_approvers_per_merge_request: 6,
remote_mirrors: 2, remote_mirrors: 2,
snippets: 2 snippets: 2
) )
...@@ -185,7 +188,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -185,7 +188,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
keys: 1, keys: 1,
merge_requests: 1, merge_requests: 1,
projects_with_disable_overriding_approvers_per_merge_request: 1, projects_with_disable_overriding_approvers_per_merge_request: 1,
projects_without_disable_overriding_approvers_per_merge_request: 2, projects_without_disable_overriding_approvers_per_merge_request: 3,
remote_mirrors: 1, remote_mirrors: 1,
snippets: 1 snippets: 1
) )
......
...@@ -1351,6 +1351,34 @@ RSpec.describe Project, factory_default: :keep do ...@@ -1351,6 +1351,34 @@ RSpec.describe Project, factory_default: :keep do
end end
end end
describe '.with_remote_mirrors' do
let_it_be(:project) { create(:project, :repository) }
subject { described_class.with_remote_mirrors }
context 'when some remote mirrors are enabled for the project' do
let!(:remote_mirror) { create(:remote_mirror, project: project, enabled: true) }
it "returns a project" do
is_expected.to eq([project])
end
end
context 'when some remote mirrors exists but disabled for the project' do
let!(:remote_mirror) { create(:remote_mirror, project: project, enabled: false) }
it "returns a project" do
is_expected.to be_empty
end
end
context 'when no remote mirrors exist for the project' do
it "returns an empty list" do
is_expected.to be_empty
end
end
end
describe '.with_active_jira_services' do describe '.with_active_jira_services' do
it 'returns the correct project' do it 'returns the correct project' do
active_jira_service = create(:jira_service) active_jira_service = create(:jira_service)
......
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