diff options
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/alert_management/alerts_finder_spec.rb | 298 | ||||
-rw-r--r-- | spec/finders/ci/daily_build_group_report_results_finder_spec.rb | 72 | ||||
-rw-r--r-- | spec/finders/ci/job_artifacts_finder_spec.rb (renamed from spec/finders/artifacts_finder_spec.rb) | 2 | ||||
-rw-r--r-- | spec/finders/container_repositories_finder_spec.rb | 29 | ||||
-rw-r--r-- | spec/finders/design_management/designs_finder_spec.rb | 105 | ||||
-rw-r--r-- | spec/finders/design_management/versions_finder_spec.rb | 129 | ||||
-rw-r--r-- | spec/finders/fork_projects_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/freeze_periods_finder_spec.rb | 59 | ||||
-rw-r--r-- | spec/finders/issues_finder_spec.rb | 50 | ||||
-rw-r--r-- | spec/finders/members_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 11 | ||||
-rw-r--r-- | spec/finders/metrics/users_starred_dashboards_finder_spec.rb | 55 | ||||
-rw-r--r-- | spec/finders/projects/serverless/functions_finder_spec.rb | 1 | ||||
-rw-r--r-- | spec/finders/releases_finder_spec.rb | 11 | ||||
-rw-r--r-- | spec/finders/todos_finder_spec.rb | 4 |
15 files changed, 773 insertions, 59 deletions
diff --git a/spec/finders/alert_management/alerts_finder_spec.rb b/spec/finders/alert_management/alerts_finder_spec.rb new file mode 100644 index 00000000000..c6d2d0ad4ef --- /dev/null +++ b/spec/finders/alert_management/alerts_finder_spec.rb @@ -0,0 +1,298 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe AlertManagement::AlertsFinder, '#execute' do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:alert_1) { create(:alert_management_alert, :all_fields, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) } + let_it_be(:alert_2) { create(:alert_management_alert, :all_fields, :ignored, project: project, events: 1, severity: :critical) } + let_it_be(:alert_3) { create(:alert_management_alert, :all_fields) } + let(:params) { {} } + + describe '#execute' do + subject { described_class.new(current_user, project, params).execute } + + context 'user is not a developer or above' do + it { is_expected.to be_empty } + end + + context 'user is developer' do + before do + project.add_developer(current_user) + end + + context 'empty params' do + it { is_expected.to contain_exactly(alert_1, alert_2) } + end + + context 'iid given' do + let(:params) { { iid: alert_1.iid } } + + it { is_expected.to match_array(alert_1) } + + context 'unknown iid' do + let(:params) { { iid: 'unknown' } } + + it { is_expected.to be_empty } + end + end + + context 'status given' do + let(:params) { { status: AlertManagement::Alert::STATUSES[:resolved] } } + + it { is_expected.to match_array(alert_1) } + + context 'with an array of statuses' do + let(:alert_3) { create(:alert_management_alert) } + let(:params) { { status: [AlertManagement::Alert::STATUSES[:resolved]] } } + + it { is_expected.to match_array(alert_1) } + end + + context 'with no alerts of status' do + let(:params) { { status: AlertManagement::Alert::STATUSES[:acknowledged] } } + + it { is_expected.to be_empty } + end + + context 'with an empty status array' do + let(:params) { { status: [] } } + + it { is_expected.to match_array([alert_1, alert_2]) } + end + + context 'with an nil status' do + let(:params) { { status: nil } } + + it { is_expected.to match_array([alert_1, alert_2]) } + end + end + + describe 'sorting' do + context 'when sorting by created' do + context 'sorts alerts ascending' do + let(:params) { { sort: 'created_asc' } } + + it { is_expected.to eq [alert_1, alert_2] } + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'created_desc' } } + + it { is_expected.to eq [alert_2, alert_1] } + end + end + + context 'when sorting by updated' do + context 'sorts alerts ascending' do + let(:params) { { sort: 'updated_asc' } } + + it { is_expected.to eq [alert_1, alert_2] } + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'updated_desc' } } + + it { is_expected.to eq [alert_2, alert_1] } + end + end + + context 'when sorting by start time' do + context 'sorts alerts ascending' do + let(:params) { { sort: 'start_time_asc' } } + + it { is_expected.to eq [alert_1, alert_2] } + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'start_time_desc' } } + + it { is_expected.to eq [alert_2, alert_1] } + end + end + + context 'when sorting by end time' do + context 'sorts alerts ascending' do + let(:params) { { sort: 'end_time_asc' } } + + it { is_expected.to eq [alert_1, alert_2] } + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'end_time_desc' } } + + it { is_expected.to eq [alert_2, alert_1] } + end + end + + context 'when sorting by events count' do + let_it_be(:alert_count_6) { create(:alert_management_alert, project: project, events: 6) } + let_it_be(:alert_count_3) { create(:alert_management_alert, project: project, events: 3) } + + context 'sorts alerts ascending' do + let(:params) { { sort: 'events_count_asc' } } + + it { is_expected.to eq [alert_2, alert_1, alert_count_3, alert_count_6] } + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'events_count_desc' } } + + it { is_expected.to eq [alert_count_6, alert_count_3, alert_1, alert_2] } + end + end + + context 'when sorting by severity' do + let_it_be(:alert_critical) { create(:alert_management_alert, project: project, severity: :critical) } + let_it_be(:alert_high) { create(:alert_management_alert, project: project, severity: :high) } + let_it_be(:alert_medium) { create(:alert_management_alert, project: project, severity: :medium) } + let_it_be(:alert_low) { create(:alert_management_alert, project: project, severity: :low) } + let_it_be(:alert_info) { create(:alert_management_alert, project: project, severity: :info) } + let_it_be(:alert_unknown) { create(:alert_management_alert, project: project, severity: :unknown) } + + context 'sorts alerts ascending' do + let(:params) { { sort: 'severity_asc' } } + + it do + is_expected.to eq [ + alert_2, + alert_critical, + alert_1, + alert_high, + alert_medium, + alert_low, + alert_info, + alert_unknown + ] + end + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'severity_desc' } } + + it do + is_expected.to eq [ + alert_unknown, + alert_info, + alert_low, + alert_medium, + alert_1, + alert_high, + alert_critical, + alert_2 + ] + end + end + end + + context 'when sorting by status' do + let_it_be(:alert_triggered) { create(:alert_management_alert, project: project) } + let_it_be(:alert_acknowledged) { create(:alert_management_alert, :acknowledged, project: project) } + let_it_be(:alert_resolved) { create(:alert_management_alert, :resolved, project: project) } + let_it_be(:alert_ignored) { create(:alert_management_alert, :ignored, project: project) } + + context 'sorts alerts ascending' do + let(:params) { { sort: 'status_asc' } } + + it do + is_expected.to eq [ + alert_triggered, + alert_acknowledged, + alert_1, + alert_resolved, + alert_2, + alert_ignored + ] + end + end + + context 'sorts alerts descending' do + let(:params) { { sort: 'status_desc' } } + + it do + is_expected.to eq [ + alert_2, + alert_ignored, + alert_1, + alert_resolved, + alert_acknowledged, + alert_triggered + ] + end + end + end + end + end + + context 'search query given' do + let_it_be(:alert) do + create(:alert_management_alert, + :with_fingerprint, + title: 'Title', + description: 'Desc', + service: 'Service', + monitoring_tool: 'Monitor' + ) + end + + before do + alert.project.add_developer(current_user) + end + + subject { described_class.new(current_user, alert.project, params).execute } + + context 'searching title' do + let(:params) { { search: alert.title } } + + it { is_expected.to match_array([alert]) } + end + + context 'searching description' do + let(:params) { { search: alert.description } } + + it { is_expected.to match_array([alert]) } + end + + context 'searching service' do + let(:params) { { search: alert.service } } + + it { is_expected.to match_array([alert]) } + end + + context 'searching monitoring tool' do + let(:params) { { search: alert.monitoring_tool } } + + it { is_expected.to match_array([alert]) } + end + + context 'searching something else' do + let(:params) { { search: alert.fingerprint } } + + it { is_expected.to be_empty } + end + + context 'empty search' do + let(:params) { { search: ' ' } } + + it { is_expected.to match_array([alert]) } + end + end + end + + describe '.counts_by_status' do + subject { described_class.counts_by_status(current_user, project, params) } + + before do + project.add_developer(current_user) + end + + it { is_expected.to match({ 2 => 1, 3 => 1 }) } # one resolved and one ignored + + context 'when filtering params are included' do + let(:params) { { status: AlertManagement::Alert::STATUSES[:resolved] } } + + it { is_expected.to match({ 2 => 1 }) } # one resolved + end + end +end diff --git a/spec/finders/ci/daily_build_group_report_results_finder_spec.rb b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb new file mode 100644 index 00000000000..3000ef650d3 --- /dev/null +++ b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::DailyBuildGroupReportResultsFinder do + describe '#execute' do + let(:project) { create(:project, :private) } + let(:ref_path) { 'refs/heads/master' } + let(:limit) { nil } + + def create_daily_coverage(group_name, coverage, date) + create( + :ci_daily_build_group_report_result, + project: project, + ref_path: ref_path, + group_name: group_name, + data: { 'coverage' => coverage }, + date: date + ) + end + + let!(:rspec_coverage_1) { create_daily_coverage('rspec', 79.0, '2020-03-09') } + let!(:karma_coverage_1) { create_daily_coverage('karma', 89.0, '2020-03-09') } + let!(:rspec_coverage_2) { create_daily_coverage('rspec', 95.0, '2020-03-10') } + let!(:karma_coverage_2) { create_daily_coverage('karma', 92.0, '2020-03-10') } + let!(:rspec_coverage_3) { create_daily_coverage('rspec', 97.0, '2020-03-11') } + let!(:karma_coverage_3) { create_daily_coverage('karma', 99.0, '2020-03-11') } + + subject do + described_class.new( + current_user: current_user, + project: project, + ref_path: ref_path, + start_date: '2020-03-09', + end_date: '2020-03-10', + limit: limit + ).execute + end + + context 'when current user is allowed to download project code' do + let(:current_user) { project.owner } + + it 'returns all matching results within the given date range' do + expect(subject).to match_array([ + karma_coverage_2, + rspec_coverage_2, + karma_coverage_1, + rspec_coverage_1 + ]) + end + + context 'and limit is specified' do + let(:limit) { 2 } + + it 'returns limited number of matching results within the given date range' do + expect(subject).to match_array([ + karma_coverage_2, + rspec_coverage_2 + ]) + end + end + end + + context 'when current user is not allowed to download project code' do + let(:current_user) { create(:user) } + + it 'returns an empty result' do + expect(subject).to be_empty + end + end + end +end diff --git a/spec/finders/artifacts_finder_spec.rb b/spec/finders/ci/job_artifacts_finder_spec.rb index b956e2c9515..3e701ba87fa 100644 --- a/spec/finders/artifacts_finder_spec.rb +++ b/spec/finders/ci/job_artifacts_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ArtifactsFinder do +describe Ci::JobArtifactsFinder do let(:project) { create(:project) } describe '#execute' do diff --git a/spec/finders/container_repositories_finder_spec.rb b/spec/finders/container_repositories_finder_spec.rb index 08c241186d6..d0c91a8f734 100644 --- a/spec/finders/container_repositories_finder_spec.rb +++ b/spec/finders/container_repositories_finder_spec.rb @@ -6,18 +6,35 @@ describe ContainerRepositoriesFinder do let_it_be(:reporter) { create(:user) } let_it_be(:guest) { create(:user) } - let(:group) { create(:group) } - let(:project) { create(:project, group: group) } - let!(:project_repository) { create(:container_repository, project: project) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:project_repository) { create(:container_repository, name: 'my_image', project: project) } + let(:params) { {} } before do group.add_reporter(reporter) project.add_reporter(reporter) end + shared_examples 'with name search' do + let_it_be(:not_searched_repository) do + create(:container_repository, name: 'foo_bar_baz', project: project) + end + + %w[my_image my_imag _image _imag].each do |name| + context "with name set to #{name}" do + let(:params) { { name: name } } + + it { is_expected.to contain_exactly(project_repository)} + + it { is_expected.not_to include(not_searched_repository)} + end + end + end + describe '#execute' do context 'with authorized user' do - subject { described_class.new(user: reporter, subject: subject_object).execute } + subject { described_class.new(user: reporter, subject: subject_object, params: params).execute } context 'when subject_type is group' do let(:subject_object) { group } @@ -28,12 +45,16 @@ describe ContainerRepositoriesFinder do end it { is_expected.to match_array([project_repository, other_repository]) } + + it_behaves_like 'with name search' end context 'when subject_type is project' do let(:subject_object) { project } it { is_expected.to match_array([project_repository]) } + + it_behaves_like 'with name search' end context 'with invalid subject_type' do diff --git a/spec/finders/design_management/designs_finder_spec.rb b/spec/finders/design_management/designs_finder_spec.rb new file mode 100644 index 00000000000..04bd0ad0a45 --- /dev/null +++ b/spec/finders/design_management/designs_finder_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DesignManagement::DesignsFinder do + include DesignManagementTestHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:design1) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design2) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design3) { create(:design, :with_file, issue: issue, versions_count: 1) } + let(:params) { {} } + + subject(:designs) { described_class.new(issue, user, params).execute } + + describe '#execute' do + context 'when user can not read designs of an issue' do + it 'returns no results' do + is_expected.to be_empty + end + end + + context 'when user can read designs of an issue' do + before do + project.add_developer(user) + end + + context 'when design management feature is disabled' do + it 'returns no results' do + is_expected.to be_empty + end + end + + context 'when design management feature is enabled' do + before do + enable_design_management + end + + it 'returns the designs' do + is_expected.to contain_exactly(design1, design2, design3) + end + + context 'when argument is the ids of designs' do + let(:params) { { ids: [design1.id] } } + + it { is_expected.to eq([design1]) } + end + + context 'when argument is the filenames of designs' do + let(:params) { { filenames: [design2.filename] } } + + it { is_expected.to eq([design2]) } + end + + context 'when passed empty array' do + context 'for filenames' do + let(:params) { { filenames: [] } } + + it { is_expected.to be_empty } + end + + context "for ids" do + let(:params) { { ids: [] } } + + it { is_expected.to be_empty } + end + end + + describe 'returning designs that existed at a particular given version' do + let(:all_versions) { issue.design_collection.versions.ordered } + let(:first_version) { all_versions.last } + let(:second_version) { all_versions.second } + + context 'when argument is the first version' do + let(:params) { { visible_at_version: first_version } } + + it { is_expected.to eq([design1]) } + end + + context 'when arguments are version and id' do + context 'when id is absent at version' do + let(:params) { { visible_at_version: first_version, ids: [design2.id] } } + + it { is_expected.to eq([]) } + end + + context 'when id is present at version' do + let(:params) { { visible_at_version: second_version, ids: [design2.id] } } + + it { is_expected.to eq([design2]) } + end + end + + context 'when argument is the second version' do + let(:params) { { visible_at_version: second_version } } + + it { is_expected.to contain_exactly(design1, design2) } + end + end + end + end + end +end diff --git a/spec/finders/design_management/versions_finder_spec.rb b/spec/finders/design_management/versions_finder_spec.rb new file mode 100644 index 00000000000..11d53d0d630 --- /dev/null +++ b/spec/finders/design_management/versions_finder_spec.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DesignManagement::VersionsFinder do + include DesignManagementTestHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:design_1) { create(:design, :with_file, issue: issue, versions_count: 1) } + let_it_be(:design_2) { create(:design, :with_file, issue: issue, versions_count: 1) } + let(:version_1) { design_1.versions.first } + let(:version_2) { design_2.versions.first } + let(:design_or_collection) { issue.design_collection } + let(:params) { {} } + + let(:finder) { described_class.new(design_or_collection, user, params) } + + subject(:versions) { finder.execute } + + describe '#execute' do + shared_examples 'returns no results' do + it 'returns no results when passed a DesignCollection' do + expect(design_or_collection).is_a?(DesignManagement::DesignCollection) + is_expected.to be_empty + end + + context 'when passed a Design' do + let(:design_or_collection) { design_1 } + + it 'returns no results when passed a Design' do + is_expected.to be_empty + end + end + end + + context 'when user cannot read designs of an issue' do + include_examples 'returns no results' + end + + context 'when user can read designs of an issue' do + before do + project.add_developer(user) + end + + context 'when design management feature is disabled' do + include_examples 'returns no results' + end + + context 'when design management feature is enabled' do + before do + enable_design_management + end + + describe 'passing a DesignCollection or a Design for the initial scoping' do + it 'returns the versions scoped to the DesignCollection' do + expect(design_or_collection).is_a?(DesignManagement::DesignCollection) + is_expected.to eq(issue.design_collection.versions.ordered) + end + + context 'when passed a Design' do + let(:design_or_collection) { design_1 } + + it 'returns the versions scoped to the Design' do + is_expected.to eq(design_1.versions) + end + end + end + + describe 'returning versions earlier or equal to a version' do + context 'when argument is the first version' do + let(:params) { { earlier_or_equal_to: version_1 }} + + it { is_expected.to eq([version_1]) } + end + + context 'when argument is the second version' do + let(:params) { { earlier_or_equal_to: version_2 }} + + it { is_expected.to contain_exactly(version_1, version_2) } + end + end + + describe 'returning versions by SHA' do + context 'when argument is the first version' do + let(:params) { { sha: version_1.sha } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when argument is the second version' do + let(:params) { { sha: version_2.sha } } + + it { is_expected.to contain_exactly(version_2) } + end + end + + describe 'returning versions by ID' do + context 'when argument is the first version' do + let(:params) { { version_id: version_1.id } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when argument is the second version' do + let(:params) { { version_id: version_2.id } } + + it { is_expected.to contain_exactly(version_2) } + end + end + + describe 'mixing id and sha' do + context 'when arguments are consistent' do + let(:params) { { version_id: version_1.id, sha: version_1.sha } } + + it { is_expected.to contain_exactly(version_1) } + end + + context 'when arguments are in-consistent' do + let(:params) { { version_id: version_1.id, sha: version_2.sha } } + + it { is_expected.to be_empty } + end + end + end + end + end +end diff --git a/spec/finders/fork_projects_finder_spec.rb b/spec/finders/fork_projects_finder_spec.rb index 2fba53a74a0..02ce17ac907 100644 --- a/spec/finders/fork_projects_finder_spec.rb +++ b/spec/finders/fork_projects_finder_spec.rb @@ -14,7 +14,7 @@ describe ForkProjectsFinder do let(:private_fork_member) { create(:user) } before do - stub_feature_flags(object_pools: { enabled: false, thing: source_project }) + stub_feature_flags(object_pools: source_project) private_fork.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) private_fork.add_developer(private_fork_member) diff --git a/spec/finders/freeze_periods_finder_spec.rb b/spec/finders/freeze_periods_finder_spec.rb new file mode 100644 index 00000000000..4ff356b85b7 --- /dev/null +++ b/spec/finders/freeze_periods_finder_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe FreezePeriodsFinder do + subject(:finder) { described_class.new(project, user).execute } + + let(:project) { create(:project, :private) } + let(:user) { create(:user) } + let!(:freeze_period_1) { create(:ci_freeze_period, project: project, created_at: 2.days.ago) } + let!(:freeze_period_2) { create(:ci_freeze_period, project: project, created_at: 1.day.ago) } + + shared_examples_for 'returns nothing' do + specify do + is_expected.to be_empty + end + end + + shared_examples_for 'returns freeze_periods ordered by created_at asc' do + it 'returns freeze_periods ordered by created_at' do + expect(subject.count).to eq(2) + expect(subject.pluck('id')).to eq([freeze_period_1.id, freeze_period_2.id]) + end + end + + context 'when user is a maintainer' do + before do + project.add_maintainer(user) + end + + it_behaves_like 'returns freeze_periods ordered by created_at asc' + end + + context 'when user is a guest' do + before do + project.add_guest(user) + end + + it_behaves_like 'returns nothing' + end + + context 'when user is a developer' do + before do + project.add_developer(user) + end + + it_behaves_like 'returns nothing' + end + + context 'when user is not a project member' do + it_behaves_like 'returns nothing' + + context 'when project is public' do + let(:project) { create(:project, :public) } + + it_behaves_like 'returns nothing' + end + end +end diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index baf40861a6e..7493fafb5cc 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -132,26 +132,6 @@ describe IssuesFinder do end end - context 'filtering by NOT group_id' do - let(:params) { { not: { group_id: group.id } } } - - context 'when include_subgroup param not set' do - it 'returns all other group issues' do - expect(issues).to contain_exactly(issue2, issue3, issue4) - end - end - - context 'when include_subgroup param is true', :nested_groups do - before do - params[:include_subgroups] = true - end - - it 'returns all other group and subgroup issues' do - expect(issues).to contain_exactly(issue2, issue3) - end - end - end - context 'filtering by author ID' do let(:params) { { author_id: user2.id } } @@ -292,12 +272,12 @@ describe IssuesFinder do context 'using NOT' do let(:params) { { not: { milestone_title: Milestone::Upcoming.name } } } - it 'returns issues not in upcoming milestones for each project or group' do - target_issues = @created_issues.reject do |issue| - issue.milestone&.due_date && issue.milestone.due_date > Date.current - end + @created_issues.select { |issue| issue.milestone&.title == '8.9' } + it 'returns issues not in upcoming milestones for each project or group, but must have a due date' do + target_issues = @created_issues.select do |issue| + issue.milestone&.due_date && issue.milestone.due_date <= Date.current + end - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, *target_issues) + expect(issues).to contain_exactly(*target_issues) end end end @@ -343,9 +323,9 @@ describe IssuesFinder do let(:params) { { not: { milestone_title: Milestone::Started.name } } } it 'returns issues not in the started milestones for each project' do - target_issues = Issue.where.not(milestone: Milestone.started) + target_issues = Issue.where(milestone: Milestone.not_started) - expect(issues).to contain_exactly(issue2, issue3, issue4, *target_issues) + expect(issues).to contain_exactly(*target_issues) end end end @@ -452,14 +432,6 @@ describe IssuesFinder do it 'returns issues with title and description match for search term' do expect(issues).to contain_exactly(issue1, issue2) end - - context 'using NOT' do - let(:params) { { not: { search: 'git' } } } - - it 'returns issues with no title and description match for search term' do - expect(issues).to contain_exactly(issue3, issue4) - end - end end context 'filtering by issue term in title' do @@ -468,14 +440,6 @@ describe IssuesFinder do it 'returns issues with title match for search term' do expect(issues).to contain_exactly(issue1) end - - context 'using NOT' do - let(:params) { { not: { search: 'git', in: 'title' } } } - - it 'returns issues with no title match for search term' do - expect(issues).to contain_exactly(issue2, issue3, issue4) - end - end end context 'filtering by issues iids' do diff --git a/spec/finders/members_finder_spec.rb b/spec/finders/members_finder_spec.rb index f6df727f7db..d77548c6fd0 100644 --- a/spec/finders/members_finder_spec.rb +++ b/spec/finders/members_finder_spec.rb @@ -110,7 +110,7 @@ describe MembersFinder, '#execute' do project.add_maintainer(user3) member3 = project.add_maintainer(user4) - result = described_class.new(project, user2).execute(params: { search: user4.name }) + result = described_class.new(project, user2, params: { search: user4.name }).execute expect(result).to contain_exactly(member3) end @@ -120,7 +120,7 @@ describe MembersFinder, '#execute' do member2 = project.add_maintainer(user3) member3 = project.add_maintainer(user4) - result = described_class.new(project, user2).execute(params: { sort: 'id_desc' }) + result = described_class.new(project, user2, params: { sort: 'id_desc' }).execute expect(result).to eq([member3, member2, member1]) end diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 42211f7ac9d..b6f2c7bb992 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -174,15 +174,16 @@ describe MergeRequestsFinder do deployment1 = create( :deployment, project: project_with_repo, - sha: project_with_repo.commit.id, - merge_requests: [merge_request1, merge_request2] + sha: project_with_repo.commit.id ) - create( + deployment2 = create( :deployment, project: project_with_repo, - sha: project_with_repo.commit.id, - merge_requests: [merge_request3] + sha: project_with_repo.commit.id ) + deployment1.link_merge_requests(MergeRequest.where(id: [merge_request1.id, merge_request2.id])) + deployment2.link_merge_requests(MergeRequest.where(id: merge_request3.id)) + params = { deployment_id: deployment1.id } merge_requests = described_class.new(user, params).execute diff --git a/spec/finders/metrics/users_starred_dashboards_finder_spec.rb b/spec/finders/metrics/users_starred_dashboards_finder_spec.rb new file mode 100644 index 00000000000..c32b8c2d335 --- /dev/null +++ b/spec/finders/metrics/users_starred_dashboards_finder_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Metrics::UsersStarredDashboardsFinder do + describe '#execute' do + subject(:starred_dashboards) { described_class.new(user: user, project: project, params: params).execute } + + let_it_be(:user) { create(:user) } + let(:project) { create(:project) } + let(:dashboard_path) { 'config/prometheus/common_metrics.yml' } + let(:params) { {} } + + context 'there are no starred dashboard records' do + it 'returns empty array' do + expect(starred_dashboards).to be_empty + end + end + + context 'with annotation records' do + let!(:starred_dashboard_1) { create(:metrics_users_starred_dashboard, user: user, project: project) } + let!(:starred_dashboard_2) { create(:metrics_users_starred_dashboard, user: user, project: project, dashboard_path: dashboard_path) } + let!(:other_project_dashboard) { create(:metrics_users_starred_dashboard, user: user, dashboard_path: dashboard_path) } + let!(:other_user_dashboard) { create(:metrics_users_starred_dashboard, project: project, dashboard_path: dashboard_path) } + + context 'user without read access to project' do + it 'returns empty relation' do + expect(starred_dashboards).to be_empty + end + end + + context 'user with read access to project' do + before do + project.add_reporter(user) + end + + it 'loads starred dashboards' do + expect(starred_dashboards).to contain_exactly starred_dashboard_1, starred_dashboard_2 + end + + context 'when the dashboard_path filter is present' do + let(:params) do + { + dashboard_path: dashboard_path + } + end + + it 'loads filtered starred dashboards' do + expect(starred_dashboards).to contain_exactly starred_dashboard_2 + end + end + end + end + end +end diff --git a/spec/finders/projects/serverless/functions_finder_spec.rb b/spec/finders/projects/serverless/functions_finder_spec.rb index 4e9f3d371ce..1f0e3cd2eda 100644 --- a/spec/finders/projects/serverless/functions_finder_spec.rb +++ b/spec/finders/projects/serverless/functions_finder_spec.rb @@ -48,6 +48,7 @@ describe Projects::Serverless::FunctionsFinder do expect(function_finder.knative_installed).to be false end end + context 'when project level cluster is present and enabled' do it_behaves_like 'before first deployment' do let(:cluster) { create(:cluster, :project, :provided_by_gcp, enabled: true) } diff --git a/spec/finders/releases_finder_spec.rb b/spec/finders/releases_finder_spec.rb index 3da5ee47b6b..cb4e5fed816 100644 --- a/spec/finders/releases_finder_spec.rb +++ b/spec/finders/releases_finder_spec.rb @@ -5,10 +5,11 @@ require 'spec_helper' describe ReleasesFinder do let(:user) { create(:user) } let(:project) { create(:project, :repository) } + let(:params) { {} } let(:repository) { project.repository } let(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') } let(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') } - let(:finder) { described_class.new(project, user) } + let(:finder) { described_class.new(project, user, params) } before do v1_0_0.update_attribute(:released_at, 2.days.ago) @@ -64,6 +65,14 @@ describe ReleasesFinder do expect(subject).to eq([v1_1_0]) end end + + context 'when a tag parameter is passed' do + let(:params) { { tag: 'v1.0.0' } } + + it 'only returns the release with the matching tag' do + expect(subject).to eq([v1_0_0]) + end + end end end end diff --git a/spec/finders/todos_finder_spec.rb b/spec/finders/todos_finder_spec.rb index a35c3a954e7..87650835b05 100644 --- a/spec/finders/todos_finder_spec.rb +++ b/spec/finders/todos_finder_spec.rb @@ -260,9 +260,9 @@ describe TodosFinder do it 'returns the expected types' do expected_result = if Gitlab.ee? - %w[Epic Issue MergeRequest] + %w[Epic Issue MergeRequest DesignManagement::Design] else - %w[Issue MergeRequest] + %w[Issue MergeRequest DesignManagement::Design] end expect(described_class.todo_types).to contain_exactly(*expected_result) |