summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-20 09:55:51 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-20 09:55:51 +0000
commite8d2c2579383897a1dd7f9debd359abe8ae8373d (patch)
treec42be41678c2586d49a75cabce89322082698334 /spec/finders
parentfc845b37ec3a90aaa719975f607740c22ba6a113 (diff)
downloadgitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/alert_management/alerts_finder_spec.rb1
-rw-r--r--spec/finders/bulk_imports/entities_finder_spec.rb84
-rw-r--r--spec/finders/bulk_imports/imports_finder_spec.rb34
-rw-r--r--spec/finders/ci/commit_statuses_finder_spec.rb2
-rw-r--r--spec/finders/ci/runners_finder_spec.rb27
-rw-r--r--spec/finders/container_repositories_finder_spec.rb35
-rw-r--r--spec/finders/deployments_finder_spec.rb3
-rw-r--r--spec/finders/environments/environments_finder_spec.rb31
-rw-r--r--spec/finders/events_finder_spec.rb1
-rw-r--r--spec/finders/group_descendants_finder_spec.rb1
-rw-r--r--spec/finders/groups_finder_spec.rb1
-rw-r--r--spec/finders/merge_requests_finder_spec.rb38
-rw-r--r--spec/finders/milestones_finder_spec.rb93
-rw-r--r--spec/finders/packages/conan/package_file_finder_spec.rb1
-rw-r--r--spec/finders/packages/go/module_finder_spec.rb1
-rw-r--r--spec/finders/packages/group_packages_finder_spec.rb1
-rw-r--r--spec/finders/packages/nuget/package_finder_spec.rb2
-rw-r--r--spec/finders/packages/package_file_finder_spec.rb1
-rw-r--r--spec/finders/packages/package_finder_spec.rb1
-rw-r--r--spec/finders/projects_finder_spec.rb34
-rw-r--r--spec/finders/template_finder_spec.rb2
-rw-r--r--spec/finders/todos_finder_spec.rb2
-rw-r--r--spec/finders/user_recent_events_finder_spec.rb2
23 files changed, 315 insertions, 83 deletions
diff --git a/spec/finders/alert_management/alerts_finder_spec.rb b/spec/finders/alert_management/alerts_finder_spec.rb
index 3a88db5d854..7fcbc7b20a1 100644
--- a/spec/finders/alert_management/alerts_finder_spec.rb
+++ b/spec/finders/alert_management/alerts_finder_spec.rb
@@ -266,6 +266,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'assignee username given' do
let_it_be(:assignee) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert, project: project, assignees: [assignee]) }
+
let(:params) { { assignee_username: username } }
context 'with valid assignee_username' do
diff --git a/spec/finders/bulk_imports/entities_finder_spec.rb b/spec/finders/bulk_imports/entities_finder_spec.rb
new file mode 100644
index 00000000000..e053011b60d
--- /dev/null
+++ b/spec/finders/bulk_imports/entities_finder_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe BulkImports::EntitiesFinder do
+ let_it_be(:user) { create(:user) }
+
+ let_it_be(:user_import_1) { create(:bulk_import, user: user) }
+ let_it_be(:started_entity_1) { create(:bulk_import_entity, :started, bulk_import: user_import_1) }
+ let_it_be(:finished_entity_1) { create(:bulk_import_entity, :finished, bulk_import: user_import_1) }
+ let_it_be(:failed_entity_1) { create(:bulk_import_entity, :failed, bulk_import: user_import_1) }
+
+ let_it_be(:user_import_2) { create(:bulk_import, user: user) }
+ let_it_be(:started_entity_2) { create(:bulk_import_entity, :started, bulk_import: user_import_2) }
+ let_it_be(:finished_entity_2) { create(:bulk_import_entity, :finished, bulk_import: user_import_2) }
+ let_it_be(:failed_entity_2) { create(:bulk_import_entity, :failed, bulk_import: user_import_2) }
+
+ let_it_be(:not_user_import) { create(:bulk_import) }
+ let_it_be(:started_entity_3) { create(:bulk_import_entity, :started, bulk_import: not_user_import) }
+ let_it_be(:finished_entity_3) { create(:bulk_import_entity, :finished, bulk_import: not_user_import) }
+ let_it_be(:failed_entity_3) { create(:bulk_import_entity, :failed, bulk_import: not_user_import) }
+
+ subject { described_class.new(user: user) }
+
+ describe '#execute' do
+ it 'returns a list of import entities associated with user' do
+ expect(subject.execute)
+ .to contain_exactly(
+ started_entity_1, finished_entity_1, failed_entity_1,
+ started_entity_2, finished_entity_2, failed_entity_2
+ )
+ end
+
+ context 'when bulk import is specified' do
+ subject { described_class.new(user: user, bulk_import: user_import_1) }
+
+ it 'returns a list of import entities filtered by bulk import' do
+ expect(subject.execute)
+ .to contain_exactly(
+ started_entity_1, finished_entity_1, failed_entity_1
+ )
+ end
+
+ context 'when specified import is not associated with user' do
+ subject { described_class.new(user: user, bulk_import: not_user_import) }
+
+ it 'does not return entities' do
+ expect(subject.execute).to be_empty
+ end
+ end
+ end
+
+ context 'when status is specified' do
+ subject { described_class.new(user: user, status: 'failed') }
+
+ it 'returns a list of import entities filtered by status' do
+ expect(subject.execute)
+ .to contain_exactly(
+ failed_entity_1, failed_entity_2
+ )
+ end
+
+ context 'when invalid status is specified' do
+ subject { described_class.new(user: user, status: 'invalid') }
+
+ it 'does not filter entities by status' do
+ expect(subject.execute)
+ .to contain_exactly(
+ started_entity_1, finished_entity_1, failed_entity_1,
+ started_entity_2, finished_entity_2, failed_entity_2
+ )
+ end
+ end
+ end
+
+ context 'when bulk import and status are specified' do
+ subject { described_class.new(user: user, bulk_import: user_import_2, status: 'finished') }
+
+ it 'returns matched import entities' do
+ expect(subject.execute).to contain_exactly(finished_entity_2)
+ end
+ end
+ end
+end
diff --git a/spec/finders/bulk_imports/imports_finder_spec.rb b/spec/finders/bulk_imports/imports_finder_spec.rb
new file mode 100644
index 00000000000..aac83c86c84
--- /dev/null
+++ b/spec/finders/bulk_imports/imports_finder_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe BulkImports::ImportsFinder do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:started_import) { create(:bulk_import, :started, user: user) }
+ let_it_be(:finished_import) { create(:bulk_import, :finished, user: user) }
+ let_it_be(:not_user_import) { create(:bulk_import) }
+
+ subject { described_class.new(user: user) }
+
+ describe '#execute' do
+ it 'returns a list of imports associated with user' do
+ expect(subject.execute).to contain_exactly(started_import, finished_import)
+ end
+
+ context 'when status is specified' do
+ subject { described_class.new(user: user, status: 'started') }
+
+ it 'returns a list of import entities filtered by status' do
+ expect(subject.execute).to contain_exactly(started_import)
+ end
+
+ context 'when invalid status is specified' do
+ subject { described_class.new(user: user, status: 'invalid') }
+
+ it 'does not filter entities by status' do
+ expect(subject.execute).to contain_exactly(started_import, finished_import)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/finders/ci/commit_statuses_finder_spec.rb b/spec/finders/ci/commit_statuses_finder_spec.rb
index 05a1a98cfe0..2e26e38f4b4 100644
--- a/spec/finders/ci/commit_statuses_finder_spec.rb
+++ b/spec/finders/ci/commit_statuses_finder_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe Ci::CommitStatusesFinder, '#execute' do
context 'tag refs' do
let_it_be(:tags) { TagsFinder.new(project.repository, {}).execute }
+
let(:subject) { described_class.new(project, project.repository, user, tags).execute }
context 'no pipelines' do
@@ -131,6 +132,7 @@ RSpec.describe Ci::CommitStatusesFinder, '#execute' do
context 'CI pipelines visible to' do
let_it_be(:tags) { TagsFinder.new(project.repository, {}).execute }
+
let(:subject) { described_class.new(project, project.repository, user, tags).execute }
before do
diff --git a/spec/finders/ci/runners_finder_spec.rb b/spec/finders/ci/runners_finder_spec.rb
index 250a85dde30..7f05947ac48 100644
--- a/spec/finders/ci/runners_finder_spec.rb
+++ b/spec/finders/ci/runners_finder_spec.rb
@@ -7,12 +7,29 @@ RSpec.describe Ci::RunnersFinder do
let_it_be(:admin) { create(:user, :admin) }
describe '#execute' do
- context 'with empty params' do
- it 'returns all runners' do
- runner1 = create :ci_runner, active: true
- runner2 = create :ci_runner, active: false
+ context 'with 2 runners' do
+ let_it_be(:runner1) { create(:ci_runner, active: true) }
+ let_it_be(:runner2) { create(:ci_runner, active: false) }
+
+ context 'with empty params' do
+ it 'returns all runners' do
+ expect(Ci::Runner).to receive(:with_tags).and_call_original
+ expect(described_class.new(current_user: admin, params: {}).execute).to match_array [runner1, runner2]
+ end
+ end
- expect(described_class.new(current_user: admin, params: {}).execute).to match_array [runner1, runner2]
+ context 'with preload param set to :tag_name true' do
+ it 'requests tags' do
+ expect(Ci::Runner).to receive(:with_tags).and_call_original
+ expect(described_class.new(current_user: admin, params: { preload: { tag_name: true } }).execute).to match_array [runner1, runner2]
+ end
+ end
+
+ context 'with preload param set to :tag_name false' do
+ it 'does not request tags' do
+ expect(Ci::Runner).not_to receive(:with_tags)
+ expect(described_class.new(current_user: admin, params: { preload: { tag_name: false } }).execute).to match_array [runner1, runner2]
+ end
end
end
diff --git a/spec/finders/container_repositories_finder_spec.rb b/spec/finders/container_repositories_finder_spec.rb
index 983f6dba28b..5d449d1b811 100644
--- a/spec/finders/container_repositories_finder_spec.rb
+++ b/spec/finders/container_repositories_finder_spec.rb
@@ -7,11 +7,14 @@ RSpec.describe ContainerRepositoriesFinder do
let_it_be(:guest) { create(:user) }
let_it_be(:group) { create(:group) }
- let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:project_repository) { create(:container_repository, name: 'my_image', project: project) }
+
let(:params) { {} }
before do
+ project.project_feature.update!(container_registry_access_level: ProjectFeature::PRIVATE)
+
group.add_reporter(reporter)
project.add_reporter(reporter)
end
@@ -76,6 +79,14 @@ RSpec.describe ContainerRepositoriesFinder do
it_behaves_like 'with name search'
it_behaves_like 'with sorting'
+
+ context 'when project has container registry disabled' do
+ before do
+ project.project_feature.update!(container_registry_access_level: ProjectFeature::DISABLED)
+ end
+
+ it { is_expected.to match_array([other_repository]) }
+ end
end
context 'when subject_type is project' do
@@ -85,6 +96,14 @@ RSpec.describe ContainerRepositoriesFinder do
it_behaves_like 'with name search'
it_behaves_like 'with sorting'
+
+ context 'when project has container registry disabled' do
+ before do
+ project.project_feature.update!(container_registry_access_level: ProjectFeature::DISABLED)
+ end
+
+ it { is_expected.to be nil }
+ end
end
context 'with invalid subject_type' do
@@ -95,9 +114,19 @@ RSpec.describe ContainerRepositoriesFinder do
end
context 'with unauthorized user' do
- subject { described_class.new(user: guest, subject: group).execute }
+ subject { described_class.new(user: guest, subject: subject_type).execute }
- it { is_expected.to be nil }
+ context 'when subject_type is group' do
+ let(:subject_type) { group }
+
+ it { is_expected.to be nil }
+ end
+
+ context 'when subject_type is project' do
+ let(:subject_type) { project }
+
+ it { is_expected.to be nil }
+ end
end
end
end
diff --git a/spec/finders/deployments_finder_spec.rb b/spec/finders/deployments_finder_spec.rb
index bd03b254f40..6d9d0c33de3 100644
--- a/spec/finders/deployments_finder_spec.rb
+++ b/spec/finders/deployments_finder_spec.rb
@@ -68,6 +68,7 @@ RSpec.describe DeploymentsFinder do
context 'at project scope' do
let_it_be(:project) { create(:project, :public, :test_repo) }
+
let(:base_params) { { project: project } }
describe 'filtering' do
@@ -76,6 +77,7 @@ RSpec.describe DeploymentsFinder do
let_it_be(:deployment_2) { create(:deployment, :success, project: project, updated_at: 47.hours.ago) }
let_it_be(:deployment_3) { create(:deployment, :success, project: project, updated_at: 4.days.ago) }
let_it_be(:deployment_4) { create(:deployment, :success, project: project, updated_at: 1.hour.ago) }
+
let(:params) { { **base_params, updated_before: 1.day.ago, updated_after: 3.days.ago, order_by: :updated_at } }
it 'returns deployments with matched updated_at' do
@@ -268,6 +270,7 @@ RSpec.describe DeploymentsFinder do
let_it_be(:group_project_1) { create(:project, :public, :test_repo, group: group) }
let_it_be(:group_project_2) { create(:project, :public, :test_repo, group: group) }
let_it_be(:subgroup_project_1) { create(:project, :public, :test_repo, group: subgroup) }
+
let(:base_params) { { group: group } }
describe 'ordering' do
diff --git a/spec/finders/environments/environments_finder_spec.rb b/spec/finders/environments/environments_finder_spec.rb
index 68c0c524478..71d10ceb5d3 100644
--- a/spec/finders/environments/environments_finder_spec.rb
+++ b/spec/finders/environments/environments_finder_spec.rb
@@ -3,9 +3,11 @@
require 'spec_helper'
RSpec.describe Environments::EnvironmentsFinder do
- let(:project) { create(:project, :repository) }
- let(:user) { project.creator }
- let(:environment) { create(:environment, :available, project: project) }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { project.creator }
+ let_it_be(:environment) { create(:environment, :available, project: project) }
+ let_it_be(:environment_stopped) { create(:environment, :stopped, name: 'test2', project: project) }
+ let_it_be(:environment_available) { create(:environment, :available, name: 'test3', project: project) }
before do
project.add_maintainer(user)
@@ -13,18 +15,18 @@ RSpec.describe Environments::EnvironmentsFinder do
describe '#execute' do
context 'with states parameter' do
- let(:stopped_environment) { create(:environment, :stopped, project: project) }
+ let_it_be(:stopped_environment) { create(:environment, :stopped, project: project) }
it 'returns environments with the requested state' do
result = described_class.new(project, user, states: 'available').execute
- expect(result).to contain_exactly(environment)
+ expect(result).to contain_exactly(environment, environment_available)
end
it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: %w(available stopped)).execute
- expect(result).to contain_exactly(environment, stopped_environment)
+ expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
end
it 'raises exception when requested state is invalid' do
@@ -37,25 +39,30 @@ RSpec.describe Environments::EnvironmentsFinder do
it 'returns environments with the requested state' do
result = described_class.new(project, user, states: :available).execute
- expect(result).to contain_exactly(environment)
+ expect(result).to contain_exactly(environment, environment_available)
end
it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: [:available, :stopped]).execute
- expect(result).to contain_exactly(environment, stopped_environment)
+ expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
end
end
end
context 'with search and states' do
- let(:environment2) { create(:environment, :stopped, name: 'test2', project: project) }
- let(:environment3) { create(:environment, :available, name: 'test3', project: project) }
-
it 'searches environments by name and state' do
result = described_class.new(project, user, search: 'test', states: :available).execute
- expect(result).to contain_exactly(environment3)
+ expect(result).to contain_exactly(environment_available)
+ end
+ end
+
+ context 'with id' do
+ it 'searches environments by name and state' do
+ result = described_class.new(project, user, search: 'test', environment_ids: [environment_available.id]).execute
+
+ expect(result).to contain_exactly(environment_available)
end
end
end
diff --git a/spec/finders/events_finder_spec.rb b/spec/finders/events_finder_spec.rb
index fe2e449f03d..5ecd38cd9cc 100644
--- a/spec/finders/events_finder_spec.rb
+++ b/spec/finders/events_finder_spec.rb
@@ -22,6 +22,7 @@ RSpec.describe EventsFinder do
let!(:other_developer_event) { create(:event, :created, project: project1, author: other_user, target: opened_merge_request3 ) }
let_it_be(:public_project) { create(:project, :public, creator_id: user.id, namespace: user.namespace) }
+
let(:confidential_issue) { create(:closed_issue, confidential: true, project: public_project, author: user) }
let!(:confidential_event) { create(:event, :closed, project: public_project, author: user, target: confidential_issue) }
diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb
index 3c3bb13a629..01c6eb05907 100644
--- a/spec/finders/group_descendants_finder_spec.rb
+++ b/spec/finders/group_descendants_finder_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe GroupDescendantsFinder do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
+
let(:params) { {} }
subject(:finder) do
diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb
index d69720ae98e..481e2983dd7 100644
--- a/spec/finders/groups_finder_spec.rb
+++ b/spec/finders/groups_finder_spec.rb
@@ -180,6 +180,7 @@ RSpec.describe GroupsFinder do
let_it_be(:internal_sub_subgroup) { create(:group, :internal, parent: public_subgroup) }
let_it_be(:private_sub_subgroup) { create(:group, :private, parent: public_subgroup) }
let_it_be(:public_sub_subgroup) { create(:group, :public, parent: public_subgroup) }
+
let(:params) { { include_parent_descendants: true, parent: parent_group } }
context 'with nil parent' do
diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb
index 3b835d366db..c2ea918449c 100644
--- a/spec/finders/merge_requests_finder_spec.rb
+++ b/spec/finders/merge_requests_finder_spec.rb
@@ -520,6 +520,44 @@ RSpec.describe MergeRequestsFinder do
end
end
+ context 'filtering by approved by' do
+ let(:params) { { approved_by_usernames: user2.username } }
+
+ before do
+ create(:approval, merge_request: merge_request3, user: user2)
+ end
+
+ it 'returns merge requests approved by that user' do
+ merge_requests = described_class.new(user, params).execute
+
+ expect(merge_requests).to contain_exactly(merge_request3)
+ end
+
+ context 'not filter' do
+ let(:params) { { not: { approved_by_usernames: user2.username } } }
+
+ it 'returns merge requests not approved by that user' do
+ merge_requests = described_class.new(user, params).execute
+
+ expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request4, merge_request5)
+ end
+ end
+
+ context 'when filtering by author and not approved by' do
+ let(:params) { { not: { approved_by_usernames: user2.username }, author_username: user.username } }
+
+ before do
+ merge_request4.update!(author: user2)
+ end
+
+ it 'returns merge requests authored by user and not approved by user2' do
+ merge_requests = described_class.new(user, params).execute
+
+ expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request5)
+ end
+ end
+ end
+
context 'filtering by created_at/updated_at' do
let(:new_project) { create(:project, forked_from_project: project1) }
diff --git a/spec/finders/milestones_finder_spec.rb b/spec/finders/milestones_finder_spec.rb
index 6e486671132..8b26599cbfa 100644
--- a/spec/finders/milestones_finder_spec.rb
+++ b/spec/finders/milestones_finder_spec.rb
@@ -3,46 +3,68 @@
require 'spec_helper'
RSpec.describe MilestonesFinder do
- let(:now) { Time.now }
- let(:group) { create(:group) }
- let(:project_1) { create(:project, namespace: group) }
- let(:project_2) { create(:project, namespace: group) }
- let!(:milestone_1) { create(:milestone, group: group, title: 'one test', start_date: now - 1.day, due_date: now) }
- let!(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
- let!(:milestone_3) { create(:milestone, project: project_1, state: 'active', start_date: now + 2.days, due_date: now + 3.days) }
- let!(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
-
- it 'returns milestones for projects' do
- result = described_class.new(project_ids: [project_1.id, project_2.id], state: 'all').execute
-
- expect(result).to contain_exactly(milestone_3, milestone_4)
- end
+ let_it_be(:now) { Date.current }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project_1) { create(:project, namespace: group) }
+ let_it_be(:project_2) { create(:project, namespace: group) }
+ let_it_be(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
+ let_it_be(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
+
+ context 'without filters' do
+ let_it_be(:milestone_1) { create(:milestone, group: group, start_date: now - 1.day, due_date: now) }
+ let_it_be(:milestone_3) { create(:milestone, project: project_1, state: 'active', start_date: now + 2.days) }
+ let_it_be(:milestone_5) { create(:milestone, group: group, due_date: now - 2.days) }
+
+ it 'returns milestones for projects' do
+ result = described_class.new(project_ids: [project_1.id, project_2.id], state: 'all').execute
+
+ expect(result).to contain_exactly(milestone_3, milestone_4)
+ end
- it 'returns milestones for groups' do
- result = described_class.new(group_ids: group.id, state: 'all').execute
+ it 'returns milestones for groups' do
+ result = described_class.new(group_ids: group.id, state: 'all').execute
- expect(result).to contain_exactly(milestone_1, milestone_2)
- end
-
- context 'milestones for groups and project' do
- let(:result) do
- described_class.new(project_ids: [project_1.id, project_2.id], group_ids: group.id, state: 'all').execute
+ expect(result).to contain_exactly(milestone_5, milestone_1, milestone_2)
end
- it 'returns milestones for groups and projects' do
- expect(result).to contain_exactly(milestone_1, milestone_2, milestone_3, milestone_4)
+ context 'milestones for groups and project' do
+ let(:extra_params) {{}}
+ let(:result) do
+ described_class.new({ project_ids: [project_1.id, project_2.id], group_ids: group.id, state: 'all' }.merge(extra_params)).execute
+ end
+
+ it 'returns milestones for groups and projects' do
+ expect(result).to contain_exactly(milestone_5, milestone_1, milestone_2, milestone_3, milestone_4)
+ end
+
+ it 'orders milestones by due date', :aggregate_failures do
+ expect(result.first).to eq(milestone_5)
+ expect(result.second).to eq(milestone_1)
+ expect(result.third).to eq(milestone_2)
+ end
+
+ context 'when grouping and sorting by expired_last' do
+ let(:extra_params) { { sort: :expired_last_due_date_asc } }
+
+ it 'current milestones are returned first, then milestones without due date followed by expired milestones, sorted by due date in ascending order' do
+ expect(result).to eq([milestone_1, milestone_2, milestone_4, milestone_3, milestone_5])
+ end
+ end
end
- it 'orders milestones by due date' do
- milestone = create(:milestone, group: group, due_date: now - 2.days)
+ describe '#find_by' do
+ it 'finds a single milestone' do
+ finder = described_class.new(project_ids: [project_1.id], state: 'all')
- expect(result.first).to eq(milestone)
- expect(result.second).to eq(milestone_1)
- expect(result.third).to eq(milestone_2)
+ expect(finder.find_by(iid: milestone_3.iid)).to eq(milestone_3)
+ end
end
end
context 'with filters' do
+ let_it_be(:milestone_1) { create(:milestone, group: group, state: 'closed', title: 'one test', start_date: now - 1.day, due_date: now) }
+ let_it_be(:milestone_3) { create(:milestone, project: project_1, state: 'closed', start_date: now + 2.days, due_date: now + 3.days) }
+
let(:params) do
{
project_ids: [project_1.id, project_2.id],
@@ -51,11 +73,6 @@ RSpec.describe MilestonesFinder do
}
end
- before do
- milestone_1.close
- milestone_3.close
- end
-
it 'filters by id' do
params[:ids] = [milestone_1.id, milestone_2.id]
@@ -118,12 +135,4 @@ RSpec.describe MilestonesFinder do
end
end
end
-
- describe '#find_by' do
- it 'finds a single milestone' do
- finder = described_class.new(project_ids: [project_1.id], state: 'all')
-
- expect(finder.find_by(iid: milestone_3.iid)).to eq(milestone_3)
- end
- end
end
diff --git a/spec/finders/packages/conan/package_file_finder_spec.rb b/spec/finders/packages/conan/package_file_finder_spec.rb
index d0c9efa1418..c2f445c58f7 100644
--- a/spec/finders/packages/conan/package_file_finder_spec.rb
+++ b/spec/finders/packages/conan/package_file_finder_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe ::Packages::Conan::PackageFileFinder do
let_it_be(:package) { create(:conan_package) }
let_it_be(:package_file) { package.package_files.first }
+
let(:package_file_name) { package_file.file_name }
let(:params) { {} }
diff --git a/spec/finders/packages/go/module_finder_spec.rb b/spec/finders/packages/go/module_finder_spec.rb
index e5c8827fc8d..a93fd855529 100644
--- a/spec/finders/packages/go/module_finder_spec.rb
+++ b/spec/finders/packages/go/module_finder_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Packages::Go::ModuleFinder do
let_it_be(:project) { create :project }
let_it_be(:other_project) { create :project }
+
let(:finder) { described_class.new project, module_name }
shared_examples 'an invalid path' do
diff --git a/spec/finders/packages/group_packages_finder_spec.rb b/spec/finders/packages/group_packages_finder_spec.rb
index 29b2f0fffd7..d7f62bdfbb4 100644
--- a/spec/finders/packages/group_packages_finder_spec.rb
+++ b/spec/finders/packages/group_packages_finder_spec.rb
@@ -129,6 +129,7 @@ RSpec.describe Packages::GroupPackagesFinder do
context 'with package_name' do
let_it_be(:named_package) { create(:maven_package, project: project, name: 'maven') }
+
let(:params) { { package_name: package_name } }
context 'as complete name' do
diff --git a/spec/finders/packages/nuget/package_finder_spec.rb b/spec/finders/packages/nuget/package_finder_spec.rb
index 59cca2d06dc..4ad02ce7da8 100644
--- a/spec/finders/packages/nuget/package_finder_spec.rb
+++ b/spec/finders/packages/nuget/package_finder_spec.rb
@@ -11,6 +11,7 @@ RSpec.describe Packages::Nuget::PackageFinder do
let_it_be(:package3) { create(:nuget_package, name: 'Another.Dummy.Package', project: project) }
let_it_be(:other_package_1) { create(:nuget_package, name: package1.name, version: package1.version) }
let_it_be(:other_package_2) { create(:nuget_package, name: package1.name, version: package2.version) }
+
let(:package_name) { package1.name }
let(:package_version) { nil }
let(:limit) { 50 }
@@ -57,6 +58,7 @@ RSpec.describe Packages::Nuget::PackageFinder do
let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) }
let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) }
let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) }
+
let(:limit) { 2 }
it { is_expected.to match_array([package5, package6]) }
diff --git a/spec/finders/packages/package_file_finder_spec.rb b/spec/finders/packages/package_file_finder_spec.rb
index ab58f75fcae..8014f04d917 100644
--- a/spec/finders/packages/package_file_finder_spec.rb
+++ b/spec/finders/packages/package_file_finder_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Packages::PackageFileFinder do
let_it_be(:package) { create(:maven_package) }
let_it_be(:package_file) { package.package_files.first }
+
let(:package_file_name) { package_file.file_name }
let(:params) { {} }
diff --git a/spec/finders/packages/package_finder_spec.rb b/spec/finders/packages/package_finder_spec.rb
index 2bb4f05a41d..1b0c88a4771 100644
--- a/spec/finders/packages/package_finder_spec.rb
+++ b/spec/finders/packages/package_finder_spec.rb
@@ -25,6 +25,7 @@ RSpec.describe ::Packages::PackageFinder do
context 'processing packages' do
let_it_be(:nuget_package) { create(:nuget_package, :processing, project: project) }
+
let(:package_id) { nuget_package.id }
it 'are not returned' do
diff --git a/spec/finders/projects_finder_spec.rb b/spec/finders/projects_finder_spec.rb
index b8b5e2c3bb7..21b5b2f6130 100644
--- a/spec/finders/projects_finder_spec.rb
+++ b/spec/finders/projects_finder_spec.rb
@@ -31,10 +31,6 @@ RSpec.describe ProjectsFinder do
let(:use_cte) { true }
let(:finder) { described_class.new(params: params.merge(use_cte: use_cte), current_user: current_user, project_ids_relation: project_ids_relation) }
- before do
- stub_feature_flags(project_finder_similarity_sort: false)
- end
-
subject { finder.execute }
shared_examples 'ProjectFinder#execute examples' do
@@ -368,32 +364,28 @@ RSpec.describe ProjectsFinder do
end
describe 'sorting' do
+ let_it_be(:more_projects) do
+ [
+ create(:project, :internal, group: group, name: 'projA', path: 'projA'),
+ create(:project, :internal, group: group, name: 'projABC', path: 'projABC'),
+ create(:project, :internal, group: group, name: 'projAB', path: 'projAB')
+ ]
+ end
+
context 'when sorting by a field' do
let(:params) { { sort: 'name_asc' } }
- it { is_expected.to eq([internal_project, public_project]) }
+ it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:name] }) }
end
context 'when sorting by similarity' do
let(:params) { { sort: 'similarity', search: 'pro' } }
- let_it_be(:internal_project2) do
- create(:project, :internal, group: group, name: 'projA', path: 'projA')
- end
-
- let_it_be(:internal_project3) do
- create(:project, :internal, group: group, name: 'projABC', path: 'projABC')
- end
-
- let_it_be(:internal_project4) do
- create(:project, :internal, group: group, name: 'projAB', path: 'projAB')
- end
-
- before do
- stub_feature_flags(project_finder_similarity_sort: current_user)
- end
+ it { is_expected.to eq([more_projects[0], more_projects[2], more_projects[1]]) }
+ end
- it { is_expected.to eq([internal_project2, internal_project4, internal_project3]) }
+ context 'when no sort is provided' do
+ it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:id] }.reverse) }
end
end
diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb
index b7339288c51..97eecf8a89d 100644
--- a/spec/finders/template_finder_spec.rb
+++ b/spec/finders/template_finder_spec.rb
@@ -123,6 +123,7 @@ RSpec.describe TemplateFinder do
describe '#execute' do
let_it_be(:project) { nil }
+
let(:params) { {} }
subject(:result) { described_class.new(type, project, params).execute }
@@ -149,6 +150,7 @@ RSpec.describe TemplateFinder do
describe '#template_names' do
let_it_be(:project) { nil }
+
let(:params) { {} }
subject(:result) { described_class.new(type, project, params).template_names.values.flatten.map { |el| OpenStruct.new(el) } }
diff --git a/spec/finders/todos_finder_spec.rb b/spec/finders/todos_finder_spec.rb
index 577ad80ede1..5611a67e977 100644
--- a/spec/finders/todos_finder_spec.rb
+++ b/spec/finders/todos_finder_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe TodosFinder do
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:merge_request) { create(:merge_request, source_project: project) }
+
let(:finder) { described_class }
before_all do
@@ -153,6 +154,7 @@ RSpec.describe TodosFinder do
context 'by groups' do
context 'with subgroups' do
let_it_be(:subgroup) { create(:group, parent: group) }
+
let!(:todo3) { create(:todo, user: user, group: subgroup, target: issue) }
it 'returns todos from subgroups when filtered by a group' do
diff --git a/spec/finders/user_recent_events_finder_spec.rb b/spec/finders/user_recent_events_finder_spec.rb
index 5a9243d150d..74c563b9bf6 100644
--- a/spec/finders/user_recent_events_finder_spec.rb
+++ b/spec/finders/user_recent_events_finder_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe UserRecentEventsFinder do
let!(:internal_event) { create(:event, project: internal_project, author: project_owner) }
let!(:public_event) { create(:event, project: public_project, author: project_owner) }
let_it_be(:issue) { create(:issue, project: public_project) }
+
let(:limit) { nil }
let(:params) { { limit: limit } }
@@ -43,6 +44,7 @@ RSpec.describe UserRecentEventsFinder do
context 'events from multiple users' do
let_it_be(:second_user, reload: true) { create(:user) }
let_it_be(:private_project_second_user) { create(:project, :private, creator: second_user) }
+
let(:internal_project_second_user) { create(:project, :internal, creator: second_user) }
let(:public_project_second_user) { create(:project, :public, creator: second_user) }
let!(:private_event_second_user) { create(:event, project: private_project_second_user, author: second_user) }