Commit 30e15f0d authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'rails-save-bang-19' into 'master'

Fix Rails/SaveBang offenses for spec/services/merge_requests/*

See merge request gitlab-org/gitlab!41315
parents 5bfc7a57 986b3580
...@@ -793,9 +793,6 @@ Rails/SaveBang: ...@@ -793,9 +793,6 @@ Rails/SaveBang:
- 'ee/spec/services/groups/autocomplete_service_spec.rb' - 'ee/spec/services/groups/autocomplete_service_spec.rb'
- 'ee/spec/services/ldap_group_reset_service_spec.rb' - 'ee/spec/services/ldap_group_reset_service_spec.rb'
- 'ee/spec/services/lfs/unlock_file_service_spec.rb' - 'ee/spec/services/lfs/unlock_file_service_spec.rb'
- 'ee/spec/services/merge_requests/approval_service_spec.rb'
- 'ee/spec/services/merge_requests/remove_approval_service_spec.rb'
- 'ee/spec/services/merge_requests/update_blocks_service_spec.rb'
- 'ee/spec/services/merge_trains/refresh_merge_request_service_spec.rb' - 'ee/spec/services/merge_trains/refresh_merge_request_service_spec.rb'
- 'ee/spec/services/quick_actions/interpret_service_spec.rb' - 'ee/spec/services/quick_actions/interpret_service_spec.rb'
- 'ee/spec/services/slash_commands/global_slack_handler_spec.rb' - 'ee/spec/services/slash_commands/global_slack_handler_spec.rb'
...@@ -1181,14 +1178,6 @@ Rails/SaveBang: ...@@ -1181,14 +1178,6 @@ Rails/SaveBang:
- 'spec/services/issuable/clone/attributes_rewriter_spec.rb' - 'spec/services/issuable/clone/attributes_rewriter_spec.rb'
- 'spec/services/issuable/common_system_notes_service_spec.rb' - 'spec/services/issuable/common_system_notes_service_spec.rb'
- 'spec/services/labels/promote_service_spec.rb' - 'spec/services/labels/promote_service_spec.rb'
- 'spec/services/members/destroy_service_spec.rb'
- 'spec/services/merge_requests/build_service_spec.rb'
- 'spec/services/merge_requests/conflicts/list_service_spec.rb'
- 'spec/services/merge_requests/create_service_spec.rb'
- 'spec/services/merge_requests/merge_service_spec.rb'
- 'spec/services/merge_requests/post_merge_service_spec.rb'
- 'spec/services/merge_requests/refresh_service_spec.rb'
- 'spec/services/merge_requests/update_service_spec.rb'
- 'spec/services/milestones/destroy_service_spec.rb' - 'spec/services/milestones/destroy_service_spec.rb'
- 'spec/services/milestones/promote_service_spec.rb' - 'spec/services/milestones/promote_service_spec.rb'
- 'spec/services/milestones/transfer_service_spec.rb' - 'spec/services/milestones/transfer_service_spec.rb'
......
---
title: Fix Rails/SaveBang offenses for */spec/services/merge_requests/*
merge_request: 41315
author: Rajendra Kadam
type: other
...@@ -133,8 +133,8 @@ RSpec.describe MergeRequests::ApprovalService do ...@@ -133,8 +133,8 @@ RSpec.describe MergeRequests::ApprovalService do
context 'when project requires force auth for approval' do context 'when project requires force auth for approval' do
before do before do
project.update(require_password_to_approve: true) project.update!(require_password_to_approve: true)
user.update(password: 'password') user.update!(password: 'password')
end end
context 'when password not specified' do context 'when password not specified' do
it 'does not update the approvals' do it 'does not update the approvals' do
......
...@@ -18,7 +18,7 @@ RSpec.describe MergeRequests::RemoveApprovalService do ...@@ -18,7 +18,7 @@ RSpec.describe MergeRequests::RemoveApprovalService do
before do before do
project.add_developer(create(:user)) project.add_developer(create(:user))
merge_request.update!(approvals_before_merge: 2) merge_request.update!(approvals_before_merge: 2)
merge_request.approvals.create(user: user) merge_request.approvals.create!(user: user)
end end
it 'removes the approval' do it 'removes the approval' do
...@@ -54,7 +54,7 @@ RSpec.describe MergeRequests::RemoveApprovalService do ...@@ -54,7 +54,7 @@ RSpec.describe MergeRequests::RemoveApprovalService do
let(:notification_service) { NotificationService.new } let(:notification_service) { NotificationService.new }
before do before do
merge_request.approvals.create(user: user) merge_request.approvals.create!(user: user)
allow(service).to receive(:notification_service).and_return(notification_service) allow(service).to receive(:notification_service).and_return(notification_service)
end end
......
...@@ -42,7 +42,7 @@ RSpec.describe MergeRequests::UpdateBlocksService do ...@@ -42,7 +42,7 @@ RSpec.describe MergeRequests::UpdateBlocksService do
{ {
remove_hidden: remove_hidden, remove_hidden: remove_hidden,
references: refs, references: refs,
update: update update: update # rubocop: disable Rails/SaveBang
} }
end end
......
...@@ -192,8 +192,8 @@ RSpec.describe Members::DestroyService do ...@@ -192,8 +192,8 @@ RSpec.describe Members::DestroyService do
context 'with an access requester' do context 'with an access requester' do
before do before do
group_project.update(request_access_enabled: true) group_project.update!(request_access_enabled: true)
group.update(request_access_enabled: true) group.update!(request_access_enabled: true)
group_project.request_access(member_user) group_project.request_access(member_user)
group.request_access(member_user) group.request_access(member_user)
end end
......
...@@ -514,7 +514,7 @@ RSpec.describe MergeRequests::BuildService do ...@@ -514,7 +514,7 @@ RSpec.describe MergeRequests::BuildService do
let(:target_project) { create(:project, :public, :repository) } let(:target_project) { create(:project, :public, :repository) }
before do before do
target_project.update(visibility_level: Gitlab::VisibilityLevel::PRIVATE) target_project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end end
it 'sets the target_project correctly' do it 'sets the target_project correctly' do
......
...@@ -36,7 +36,7 @@ RSpec.describe MergeRequests::Conflicts::ListService do ...@@ -36,7 +36,7 @@ RSpec.describe MergeRequests::Conflicts::ListService do
it 'returns a falsey value when the MR does not support new diff notes' do it 'returns a falsey value when the MR does not support new diff notes' do
merge_request = create_merge_request('conflict-resolvable') merge_request = create_merge_request('conflict-resolvable')
merge_request.merge_request_diff.update(start_commit_sha: nil) merge_request.merge_request_diff.update!(start_commit_sha: nil)
expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey
end end
......
...@@ -440,7 +440,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do ...@@ -440,7 +440,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do
context "when issuable feature is private" do context "when issuable feature is private" do
before do before do
project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE, project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE,
merge_requests_access_level: ProjectFeature::PRIVATE) merge_requests_access_level: ProjectFeature::PRIVATE)
end end
...@@ -448,7 +448,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do ...@@ -448,7 +448,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do
levels.each do |level| levels.each do |level|
it "removes not authorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do it "removes not authorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do
project.update(visibility_level: level) project.update!(visibility_level: level)
opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] } opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] }
merge_request = described_class.new(project, user, opts).execute merge_request = described_class.new(project, user, opts).execute
......
...@@ -176,7 +176,7 @@ RSpec.describe MergeRequests::MergeService do ...@@ -176,7 +176,7 @@ RSpec.describe MergeRequests::MergeService do
end end
it 'does not close issue' do it 'does not close issue' do
jira_tracker.update(jira_issue_transition_id: nil) jira_tracker.update!(jira_issue_transition_id: nil)
expect_any_instance_of(JiraService).not_to receive(:transition_issue) expect_any_instance_of(JiraService).not_to receive(:transition_issue)
...@@ -389,7 +389,7 @@ RSpec.describe MergeRequests::MergeService do ...@@ -389,7 +389,7 @@ RSpec.describe MergeRequests::MergeService do
error_message = 'Failed to squash. Should be done manually' error_message = 'Failed to squash. Should be done manually'
allow_any_instance_of(MergeRequests::SquashService).to receive(:squash!).and_return(nil) allow_any_instance_of(MergeRequests::SquashService).to receive(:squash!).and_return(nil)
merge_request.update(squash: true) merge_request.update!(squash: true)
service.execute(merge_request) service.execute(merge_request)
...@@ -403,7 +403,7 @@ RSpec.describe MergeRequests::MergeService do ...@@ -403,7 +403,7 @@ RSpec.describe MergeRequests::MergeService do
error_message = 'another squash is already in progress' error_message = 'another squash is already in progress'
allow_any_instance_of(MergeRequest).to receive(:squash_in_progress?).and_return(true) allow_any_instance_of(MergeRequest).to receive(:squash_in_progress?).and_return(true)
merge_request.update(squash: true) merge_request.update!(squash: true)
service.execute(merge_request) service.execute(merge_request)
...@@ -421,7 +421,7 @@ RSpec.describe MergeRequests::MergeService do ...@@ -421,7 +421,7 @@ RSpec.describe MergeRequests::MergeService do
%w(semi-linear ff).each do |merge_method| %w(semi-linear ff).each do |merge_method|
it "logs and saves error if merge is #{merge_method} only" do it "logs and saves error if merge is #{merge_method} only" do
merge_method = 'rebase_merge' if merge_method == 'semi-linear' merge_method = 'rebase_merge' if merge_method == 'semi-linear'
merge_request.project.update(merge_method: merge_method) merge_request.project.update!(merge_method: merge_method)
error_message = 'Only fast-forward merge is allowed for your project. Please update your source branch' error_message = 'Only fast-forward merge is allowed for your project. Please update your source branch'
allow(service).to receive(:execute_hooks) allow(service).to receive(:execute_hooks)
......
...@@ -50,7 +50,7 @@ RSpec.describe MergeRequests::PostMergeService do ...@@ -50,7 +50,7 @@ RSpec.describe MergeRequests::PostMergeService do
end end
it 'marks MR as merged regardless of errors when closing issues' do it 'marks MR as merged regardless of errors when closing issues' do
merge_request.update(target_branch: 'foo') merge_request.update!(target_branch: 'foo')
allow(project).to receive(:default_branch).and_return('foo') allow(project).to receive(:default_branch).and_return('foo')
issue = create(:issue, project: project) issue = create(:issue, project: project)
......
...@@ -621,7 +621,7 @@ RSpec.describe MergeRequests::RefreshService do ...@@ -621,7 +621,7 @@ RSpec.describe MergeRequests::RefreshService do
before do before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled) stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
@fork_project.destroy @fork_project.destroy!
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature') service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs reload_mrs
end end
......
...@@ -415,7 +415,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do ...@@ -415,7 +415,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do
merge_request.milestone = create(:milestone, project: project) merge_request.milestone = create(:milestone, project: project)
merge_request.save merge_request.save!
perform_enqueued_jobs do perform_enqueued_jobs do
update_merge_request(milestone_id: "") update_merge_request(milestone_id: "")
...@@ -639,7 +639,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do ...@@ -639,7 +639,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
context 'updating asssignee_ids' do context 'updating asssignee_ids' do
it 'does not update assignee when assignee_id is invalid' do it 'does not update assignee when assignee_id is invalid' do
merge_request.update(assignee_ids: [user.id]) merge_request.update!(assignee_ids: [user.id])
update_merge_request(assignee_ids: [-1]) update_merge_request(assignee_ids: [-1])
...@@ -647,7 +647,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do ...@@ -647,7 +647,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
end end
it 'unassigns assignee when user id is 0' do it 'unassigns assignee when user id is 0' do
merge_request.update(assignee_ids: [user.id]) merge_request.update!(assignee_ids: [user.id])
update_merge_request(assignee_ids: [0]) update_merge_request(assignee_ids: [0])
...@@ -675,7 +675,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do ...@@ -675,7 +675,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
levels.each do |level| levels.each do |level|
it "does not update with unauthorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do it "does not update with unauthorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do
assignee = create(:user) assignee = create(:user)
project.update(visibility_level: level) project.update!(visibility_level: level)
feature_visibility_attr = :"#{merge_request.model_name.plural}_access_level" feature_visibility_attr = :"#{merge_request.model_name.plural}_access_level"
project.project_feature.update_attribute(feature_visibility_attr, ProjectFeature::PRIVATE) project.project_feature.update_attribute(feature_visibility_attr, ProjectFeature::PRIVATE)
......
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