Commit ee701f75 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'ajk-multiple-memoized-helpers-rubocop' into 'master'

Enable RSpec/MultipleMemoizedHelpers by default

See merge request gitlab-org/gitlab!55211
parents e3bc67fa 04b3cd95
......@@ -90,6 +90,17 @@ RSpec/FilePath:
- 'ee/spec/frontend/fixtures/*'
- 'spec/requests/api/v3/*'
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 28
AllowSubject: true
Exclude:
- 'spec/migrations/**/*.rb'
- 'spec/lib/gitlab/background_migration/populate_project_snippet_statistics_spec.rb'
- 'spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb'
- 'ee/spec/lib/ee/gitlab/background_migration/populate_uuids_for_security_findings_spec.rb'
- 'ee/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb'
Naming/FileName:
ExpectMatchingDefinition: true
Exclude:
......
......@@ -463,11 +463,6 @@ RSpec/ExpectChange:
RSpec/ExpectInHook:
Enabled: false
# Offense count: 16403
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 40
# Offense count: 2352
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
......
......@@ -334,15 +334,15 @@ RSpec.describe Boards::Issues::MoveService, services: true do
let(:subgroup) { create(:group, parent: group) }
let(:subgroup_project) { create(:project, namespace: subgroup) }
let(:params) { { board_id: board1.id, from_list_id: label_list1.id, to_list_id: label_list1.id } }
let(:issue) { create(:labeled_issue, project: subgroup_project, labels: [bug, development]) }
let(:issue0) { create(:labeled_issue, project: subgroup_project, labels: [bug, development]) }
let(:issue1) { create(:labeled_issue, project: project, labels: [bug, development]) }
let(:issue2) { create(:labeled_issue, project: project, labels: [bug, development]) }
it 'sorts issues included in subgroups' do
reorder_issues(params, issues: [issue, issue0, issue1, issue2])
labels = [bug, development]
issue = create(:labeled_issue, project: subgroup_project, labels: labels)
issue0 = create(:labeled_issue, project: subgroup_project, labels: labels)
issue1 = create(:labeled_issue, project: project, labels: labels)
issue2 = create(:labeled_issue, project: project, labels: labels)
params = { board_id: board1.id, from_list_id: label_list1.id, to_list_id: label_list1.id }
reorder_issues(params, issues: [issue, issue0, issue1, issue2])
described_class.new(parent, user, params).execute(issue)
expect(issue.relative_position).to be_between(issue0.relative_position, issue1.relative_position)
......
......@@ -2,6 +2,7 @@
require 'spec_helper'
# rubocop: disable RSpec/MultipleMemoizedHelpers
RSpec.describe Security::MergeReportsService, '#execute' do
let(:scanner_1) { build(:ci_reports_security_scanner, external_id: 'scanner-1', name: 'Scanner 1') }
let(:scanner_2) { build(:ci_reports_security_scanner, external_id: 'scanner-2', name: 'Scanner 2') }
......@@ -338,3 +339,4 @@ RSpec.describe Security::MergeReportsService, '#execute' do
end
end
end
# rubocop: enable RSpec/MultipleMemoizedHelpers
......@@ -2,6 +2,7 @@
require 'spec_helper'
# rubocop: disable RSpec/MultipleMemoizedHelpers
RSpec.describe Gitlab::SidekiqMiddleware::ServerMetrics do
context "with worker attribution" do
subject { described_class.new }
......@@ -287,3 +288,4 @@ RSpec.describe Gitlab::SidekiqMiddleware::ServerMetrics do
end
end
end
# rubocop: enable RSpec/MultipleMemoizedHelpers
......@@ -4,40 +4,41 @@ require 'spec_helper'
RSpec.describe Boards::Issues::ListService do
describe '#execute' do
context 'when parent is a project' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board) { create(:board, project: project) }
let(:m1) { create(:milestone, project: project) }
let(:m2) { create(:milestone, project: project) }
let(:bug) { create(:label, project: project, name: 'Bug') }
let(:development) { create(:label, project: project, name: 'Development') }
let(:testing) { create(:label, project: project, name: 'Testing') }
let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
let(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
let(:p3) { create(:label, title: 'P3', project: project, priority: 3) }
let!(:backlog) { create(:backlog_list, board: board) }
let!(:list1) { create(:list, board: board, label: development, position: 0) }
let!(:list2) { create(:list, board: board, label: testing, position: 1) }
let!(:closed) { create(:closed_list, board: board) }
let_it_be(:user) { create(:user) }
let!(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) }
let!(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2]) }
let!(:reopened_issue1) { create(:issue, :opened, project: project, title: 'Reopened Issue 1' ) }
let!(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, development]) }
let!(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) }
let!(:list1_issue3) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1]) }
let!(:list2_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [testing]) }
let!(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug], closed_at: 1.day.ago) }
let!(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3], closed_at: 2.days.ago) }
let!(:closed_issue3) { create(:issue, :closed, project: project, closed_at: 1.week.ago) }
let!(:closed_issue4) { create(:labeled_issue, :closed, project: project, labels: [p1], closed_at: 1.year.ago) }
let!(:closed_issue5) { create(:labeled_issue, :closed, project: project, labels: [development], closed_at: 2.years.ago) }
context 'when parent is a project' do
let_it_be(:project) { create(:project, :empty_repo) }
let_it_be(:board) { create(:board, project: project) }
let_it_be(:m1) { create(:milestone, project: project) }
let_it_be(:m2) { create(:milestone, project: project) }
let_it_be(:bug) { create(:label, project: project, name: 'Bug') }
let_it_be(:development) { create(:label, project: project, name: 'Development') }
let_it_be(:testing) { create(:label, project: project, name: 'Testing') }
let_it_be(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
let_it_be(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
let_it_be(:p3) { create(:label, title: 'P3', project: project, priority: 3) }
let_it_be(:backlog) { create(:backlog_list, board: board) }
let_it_be(:list1) { create(:list, board: board, label: development, position: 0) }
let_it_be(:list2) { create(:list, board: board, label: testing, position: 1) }
let_it_be(:closed) { create(:closed_list, board: board) }
let_it_be(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) }
let_it_be(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2]) }
let_it_be(:reopened_issue1) { create(:issue, :opened, project: project, title: 'Reopened Issue 1' ) }
let_it_be(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, development]) }
let_it_be(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) }
let_it_be(:list1_issue3) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1]) }
let_it_be(:list2_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [testing]) }
let_it_be(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug], closed_at: 1.day.ago) }
let_it_be(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3], closed_at: 2.days.ago) }
let_it_be(:closed_issue3) { create(:issue, :closed, project: project, closed_at: 1.week.ago) }
let_it_be(:closed_issue4) { create(:labeled_issue, :closed, project: project, labels: [p1], closed_at: 1.year.ago) }
let_it_be(:closed_issue5) { create(:labeled_issue, :closed, project: project, labels: [development], closed_at: 2.years.ago) }
let(:parent) { project }
......@@ -48,14 +49,16 @@ RSpec.describe Boards::Issues::ListService do
it_behaves_like 'issues list service'
context 'when project is archived' do
let(:project) { create(:project, :archived) }
before do
project.update!(archived: true)
end
it_behaves_like 'issues list service'
end
end
# rubocop: disable RSpec/MultipleMemoizedHelpers
context 'when parent is a group' do
let(:user) { create(:user) }
let(:project) { create(:project, :empty_repo, namespace: group) }
let(:project1) { create(:project, :empty_repo, namespace: group) }
let(:project_archived) { create(:project, :empty_repo, :archived, namespace: group) }
......@@ -104,7 +107,7 @@ RSpec.describe Boards::Issues::ListService do
group.add_developer(user)
end
context 'and group has no parent' do
context 'when the group has no parent' do
let(:parent) { group }
let(:group) { create(:group) }
let(:board) { create(:board, group: group) }
......@@ -112,7 +115,7 @@ RSpec.describe Boards::Issues::ListService do
it_behaves_like 'issues list service'
end
context 'and group is an ancestor' do
context 'when the group is an ancestor' do
let(:parent) { create(:group) }
let(:group) { create(:group, parent: parent) }
let!(:backlog) { create(:backlog_list, board: board) }
......@@ -125,5 +128,6 @@ RSpec.describe Boards::Issues::ListService do
it_behaves_like 'issues list service'
end
end
# rubocop: enable RSpec/MultipleMemoizedHelpers
end
end
......@@ -4,9 +4,9 @@ require 'spec_helper'
RSpec.describe Labels::PromoteService do
describe '#execute' do
let!(:user) { create(:user) }
let_it_be(:user) { create(:user) }
context 'project without group' do
context 'without a group' do
let!(:project_1) { create(:project) }
let!(:project_label_1_1) { create(:label, project: project_1) }
......@@ -18,40 +18,40 @@ RSpec.describe Labels::PromoteService do
end
end
context 'project with group' do
let!(:promoted_label_name) { "Promoted Label" }
let!(:untouched_label_name) { "Untouched Label" }
let!(:promoted_description) { "Promoted Description" }
let!(:promoted_color) { "#0000FF" }
let!(:label_2_1_priority) { 1 }
let!(:label_3_1_priority) { 2 }
context 'with a group' do
let_it_be(:promoted_label_name) { "Promoted Label" }
let_it_be(:untouched_label_name) { "Untouched Label" }
let_it_be(:promoted_description) { "Promoted Description" }
let_it_be(:promoted_color) { "#0000FF" }
let_it_be(:label_2_1_priority) { 1 }
let_it_be(:label_3_1_priority) { 2 }
let!(:group_1) { create(:group) }
let!(:group_2) { create(:group) }
let_it_be(:group_1) { create(:group) }
let_it_be(:group_2) { create(:group) }
let!(:project_1) { create(:project, namespace: group_1) }
let!(:project_2) { create(:project, namespace: group_1) }
let!(:project_3) { create(:project, namespace: group_1) }
let!(:project_4) { create(:project, namespace: group_2) }
let_it_be(:project_1) { create(:project, :repository, namespace: group_1) }
let_it_be(:project_2) { create(:project, :repository, namespace: group_1) }
let_it_be(:project_3) { create(:project, :repository, namespace: group_1) }
let_it_be(:project_4) { create(:project, :repository, namespace: group_2) }
# Labels/issues can't be lazily created so we might as well eager initialize
# all other objects too since we use them inside
let!(:project_label_1_1) { create(:label, project: project_1, name: promoted_label_name, color: promoted_color, description: promoted_description) }
let!(:project_label_1_2) { create(:label, project: project_1, name: untouched_label_name) }
let!(:project_label_2_1) { create(:label, project: project_2, priority: label_2_1_priority, name: promoted_label_name, color: "#FF0000") }
let!(:project_label_3_1) { create(:label, project: project_3, priority: label_3_1_priority, name: promoted_label_name) }
let!(:project_label_3_2) { create(:label, project: project_3, priority: 1, name: untouched_label_name) }
let!(:project_label_4_1) { create(:label, project: project_4, name: promoted_label_name) }
let_it_be(:project_label_1_1) { create(:label, project: project_1, name: promoted_label_name, color: promoted_color, description: promoted_description) }
let_it_be(:project_label_1_2) { create(:label, project: project_1, name: untouched_label_name) }
let_it_be(:project_label_2_1) { create(:label, project: project_2, priority: label_2_1_priority, name: promoted_label_name, color: "#FF0000") }
let_it_be(:project_label_3_1) { create(:label, project: project_3, priority: label_3_1_priority, name: promoted_label_name) }
let_it_be(:project_label_3_2) { create(:label, project: project_3, priority: 1, name: untouched_label_name) }
let_it_be(:project_label_4_1) { create(:label, project: project_4, name: promoted_label_name) }
let!(:issue_1_1) { create(:labeled_issue, project: project_1, labels: [project_label_1_1, project_label_1_2]) }
let!(:issue_1_2) { create(:labeled_issue, project: project_1, labels: [project_label_1_2]) }
let!(:issue_2_1) { create(:labeled_issue, project: project_2, labels: [project_label_2_1]) }
let!(:issue_4_1) { create(:labeled_issue, project: project_4, labels: [project_label_4_1]) }
let_it_be(:issue_1_1) { create(:labeled_issue, project: project_1, labels: [project_label_1_1, project_label_1_2]) }
let_it_be(:issue_1_2) { create(:labeled_issue, project: project_1, labels: [project_label_1_2]) }
let_it_be(:issue_2_1) { create(:labeled_issue, project: project_2, labels: [project_label_2_1]) }
let_it_be(:issue_4_1) { create(:labeled_issue, project: project_4, labels: [project_label_4_1]) }
let!(:merge_3_1) { create(:labeled_merge_request, source_project: project_3, target_project: project_3, labels: [project_label_3_1, project_label_3_2]) }
let_it_be(:merge_3_1) { create(:labeled_merge_request, source_project: project_3, target_project: project_3, labels: [project_label_3_1, project_label_3_2]) }
let!(:issue_board_2_1) { create(:board, project: project_2) }
let!(:issue_board_list_2_1) { create(:list, board: issue_board_2_1, label: project_label_2_1) }
let_it_be(:issue_board_2_1) { create(:board, project: project_2) }
let_it_be(:issue_board_list_2_1) { create(:list, board: issue_board_2_1, label: project_label_2_1) }
let(:new_label) { group_1.labels.find_by(title: promoted_label_name) }
......@@ -82,8 +82,8 @@ RSpec.describe Labels::PromoteService do
expect { service.execute(project_label_1_1) }.to change { Subscription.count }.from(4).to(3)
expect(new_label.subscribed?(user)).to be_truthy
expect(new_label.subscribed?(user2)).to be_truthy
expect(new_label).to be_subscribed(user)
expect(new_label).to be_subscribed(user2)
end
it 'recreates priorities' do
......@@ -165,12 +165,12 @@ RSpec.describe Labels::PromoteService do
service.execute(project_label_1_1)
Label.reflect_on_all_associations.each do |association|
expect(project_label_1_1.send(association.name).any?).to be_falsey
expect(project_label_1_1.send(association.name).reset).not_to be_any
end
end
end
context 'if there is an existing identical group label' do
context 'when there is an existing identical group label' do
let!(:existing_group_label) { create(:group_label, group: group_1, title: project_label_1_1.title ) }
it 'uses the existing group label' do
......@@ -187,7 +187,7 @@ RSpec.describe Labels::PromoteService do
it_behaves_like 'promoting a project label to a group label'
end
context 'if there is no existing identical group label' do
context 'when there is no existing identical group label' do
let(:existing_group_label) { nil }
it 'recreates the label as a group label' do
......
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