Commit 7925934f authored by Kerri Miller's avatar Kerri Miller

Merge branch 'issue#220040-fix-rails-savebang-requests-api-module' into 'master'

Fix Rails/SaveBang Rubocop offenses for requests/api module

See merge request gitlab-org/gitlab!57887
parents 430620cd 5ca763bc
...@@ -302,23 +302,6 @@ Rails/SaveBang: ...@@ -302,23 +302,6 @@ Rails/SaveBang:
- 'spec/models/user_status_spec.rb' - 'spec/models/user_status_spec.rb'
- 'spec/models/wiki_page/meta_spec.rb' - 'spec/models/wiki_page/meta_spec.rb'
- 'spec/models/wiki_page_spec.rb' - 'spec/models/wiki_page_spec.rb'
- 'spec/requests/api/ci/runner_spec.rb'
- 'spec/requests/api/commit_statuses_spec.rb'
- 'spec/requests/api/conan_packages_spec.rb'
- 'spec/requests/api/deployments_spec.rb'
- 'spec/requests/api/environments_spec.rb'
- 'spec/requests/api/go_proxy_spec.rb'
- 'spec/requests/api/graphql/mutations/merge_requests/set_labels_spec.rb'
- 'spec/requests/api/graphql/user_query_spec.rb'
- 'spec/requests/api/graphql_spec.rb'
- 'spec/requests/api/group_import_spec.rb'
- 'spec/requests/api/group_milestones_spec.rb'
- 'spec/requests/api/internal/base_spec.rb'
- 'spec/requests/api/issues/get_group_issues_spec.rb'
- 'spec/requests/api/issues/post_projects_issues_spec.rb'
- 'spec/requests/api/jobs_spec.rb'
- 'spec/requests/api/labels_spec.rb'
- 'spec/requests/api/project_import_spec.rb'
Rails/TimeZone: Rails/TimeZone:
Enabled: true Enabled: true
......
---
title: Fix Rails/SaveBang Rubocop offenses for requests/api module
merge_request: 57887
author: Huzaifa Iftikhar @huzaifaiftikhar
type: fixed
...@@ -14,8 +14,8 @@ RSpec.describe API::CommitStatuses do ...@@ -14,8 +14,8 @@ RSpec.describe API::CommitStatuses do
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
context 'ci commit exists' do context 'ci commit exists' do
let!(:master) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', protected: false) } let!(:master) { project.ci_pipelines.create!(source: :push, sha: commit.id, ref: 'master', protected: false) }
let!(:develop) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'develop', protected: false) } let!(:develop) { project.ci_pipelines.create!(source: :push, sha: commit.id, ref: 'develop', protected: false) }
context "reporter user" do context "reporter user" do
let(:statuses_id) { json_response.map { |status| status['id'] } } let(:statuses_id) { json_response.map { |status| status['id'] } }
...@@ -270,8 +270,8 @@ RSpec.describe API::CommitStatuses do ...@@ -270,8 +270,8 @@ RSpec.describe API::CommitStatuses do
end end
context 'when a pipeline id is specified' do context 'when a pipeline id is specified' do
let!(:first_pipeline) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', status: 'created') } let!(:first_pipeline) { project.ci_pipelines.create!(source: :push, sha: commit.id, ref: 'master', status: 'created') }
let!(:other_pipeline) { project.ci_pipelines.create(source: :push, sha: commit.id, ref: 'master', status: 'created') } let!(:other_pipeline) { project.ci_pipelines.create!(source: :push, sha: commit.id, ref: 'master', status: 'created') }
subject do subject do
post api(post_url, developer), params: { post api(post_url, developer), params: {
......
...@@ -345,7 +345,7 @@ RSpec.describe API::Deployments do ...@@ -345,7 +345,7 @@ RSpec.describe API::Deployments do
context 'as a maintainer' do context 'as a maintainer' do
it 'returns a 403 when updating a deployment with a build' do it 'returns a 403 when updating a deployment with a build' do
deploy.update(deployable: build) deploy.update!(deployable: build)
put( put(
api("/projects/#{project.id}/deployments/#{deploy.id}", user), api("/projects/#{project.id}/deployments/#{deploy.id}", user),
...@@ -394,7 +394,7 @@ RSpec.describe API::Deployments do ...@@ -394,7 +394,7 @@ RSpec.describe API::Deployments do
end end
it 'returns a 403 when updating a deployment with a build' do it 'returns a 403 when updating a deployment with a build' do
deploy.update(deployable: build) deploy.update!(deployable: build)
put( put(
api("/projects/#{project.id}/deployments/#{deploy.id}", developer), api("/projects/#{project.id}/deployments/#{deploy.id}", developer),
......
...@@ -214,7 +214,7 @@ RSpec.describe API::Environments do ...@@ -214,7 +214,7 @@ RSpec.describe API::Environments do
context 'as a maintainer' do context 'as a maintainer' do
context 'with a stoppable environment' do context 'with a stoppable environment' do
before do before do
environment.update(state: :available) environment.update!(state: :available)
post api("/projects/#{project.id}/environments/#{environment.id}/stop", user) post api("/projects/#{project.id}/environments/#{environment.id}/stop", user)
end end
......
...@@ -363,7 +363,7 @@ RSpec.describe API::GoProxy do ...@@ -363,7 +363,7 @@ RSpec.describe API::GoProxy do
let(:module_name) { base } let(:module_name) { base }
before do before do
project.update(visibility_level: Gitlab::VisibilityLevel::PRIVATE) project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end end
describe 'GET /projects/:id/packages/go/*module_name/@v/list' do describe 'GET /projects/:id/packages/go/*module_name/@v/list' do
...@@ -412,7 +412,7 @@ RSpec.describe API::GoProxy do ...@@ -412,7 +412,7 @@ RSpec.describe API::GoProxy do
let(:module_name) { base } let(:module_name) { base }
before do before do
project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end end
describe 'GET /projects/:id/packages/go/*module_name/@v/list' do describe 'GET /projects/:id/packages/go/*module_name/@v/list' do
......
...@@ -52,7 +52,7 @@ RSpec.describe 'Setting labels of a merge request' do ...@@ -52,7 +52,7 @@ RSpec.describe 'Setting labels of a merge request' do
end end
it 'sets the merge request labels, removing existing ones' do it 'sets the merge request labels, removing existing ones' do
merge_request.update(labels: [label2]) merge_request.update!(labels: [label2])
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
......
...@@ -218,12 +218,14 @@ RSpec.describe API::GroupImport do ...@@ -218,12 +218,14 @@ RSpec.describe API::GroupImport do
stub_uploads_object_storage(ImportExportUploader, direct_upload: true) stub_uploads_object_storage(ImportExportUploader, direct_upload: true)
end end
# rubocop:disable Rails/SaveBang
let(:tmp_object) do let(:tmp_object) do
fog_connection.directories.new(key: 'uploads').files.create( fog_connection.directories.new(key: 'uploads').files.create(
key: "tmp/uploads/#{file_name}", key: "tmp/uploads/#{file_name}",
body: file_upload body: file_upload
) )
end end
# rubocop:enable Rails/SaveBang
let(:fog_file) { fog_to_uploaded_file(tmp_object) } let(:fog_file) { fog_to_uploaded_file(tmp_object) }
let(:params) do let(:params) do
......
...@@ -20,7 +20,7 @@ RSpec.describe API::GroupMilestones do ...@@ -20,7 +20,7 @@ RSpec.describe API::GroupMilestones do
let_it_be(:params) { { include_parent_milestones: true } } let_it_be(:params) { { include_parent_milestones: true } }
before_all do before_all do
group.update(parent: ancestor_group) group.update!(parent: ancestor_group)
end end
shared_examples 'listing all milestones' do shared_examples 'listing all milestones' do
...@@ -83,9 +83,9 @@ RSpec.describe API::GroupMilestones do ...@@ -83,9 +83,9 @@ RSpec.describe API::GroupMilestones do
end end
def setup_for_group def setup_for_group
context_group.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) context_group.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
context_group.add_developer(user) context_group.add_developer(user)
public_project.update(namespace: context_group) public_project.update!(namespace: context_group)
context_group.reload context_group.reload
end end
end end
...@@ -887,7 +887,7 @@ RSpec.describe API::Internal::Base do ...@@ -887,7 +887,7 @@ RSpec.describe API::Internal::Base do
context 'project does not exist' do context 'project does not exist' do
context 'git pull' do context 'git pull' do
it 'returns a 200 response with status: false' do it 'returns a 200 response with status: false' do
project.destroy project.destroy!
pull(key, project) pull(key, project)
......
...@@ -754,7 +754,7 @@ RSpec.describe API::Issues do ...@@ -754,7 +754,7 @@ RSpec.describe API::Issues do
let(:parent_group) { create(:group) } let(:parent_group) { create(:group) }
before do before do
group.update(parent_id: parent_group.id) group.update!(parent_id: parent_group.id)
group_closed_issue.reload group_closed_issue.reload
end end
......
...@@ -111,7 +111,7 @@ RSpec.describe API::Issues do ...@@ -111,7 +111,7 @@ RSpec.describe API::Issues do
let(:not_member) { create(:user) } let(:not_member) { create(:user) }
before do before do
project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE) project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
end end
it 'renders 403' do it 'renders 403' do
......
...@@ -215,7 +215,7 @@ RSpec.describe API::Jobs do ...@@ -215,7 +215,7 @@ RSpec.describe API::Jobs do
first_build = create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: pipeline) first_build = create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: pipeline)
first_build.runner = create(:ci_runner) first_build.runner = create(:ci_runner)
first_build.user = create(:user) first_build.user = create(:user)
first_build.save first_build.save!
control_count = ActiveRecord::QueryRecorder.new { go }.count control_count = ActiveRecord::QueryRecorder.new { go }.count
...@@ -223,7 +223,7 @@ RSpec.describe API::Jobs do ...@@ -223,7 +223,7 @@ RSpec.describe API::Jobs do
second_build = create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: second_pipeline) second_build = create(:ci_build, :trace_artifact, :artifacts, :test_reports, pipeline: second_pipeline)
second_build.runner = create(:ci_runner) second_build.runner = create(:ci_runner)
second_build.user = create(:user) second_build.user = create(:user)
second_build.save second_build.save!
expect { go }.not_to exceed_query_limit(control_count) expect { go }.not_to exceed_query_limit(control_count)
end end
...@@ -684,7 +684,7 @@ RSpec.describe API::Jobs do ...@@ -684,7 +684,7 @@ RSpec.describe API::Jobs do
context 'with regular branch' do context 'with regular branch' do
before do before do
pipeline.reload pipeline.reload
pipeline.update(ref: 'master', pipeline.update!(ref: 'master',
sha: project.commit('master').sha) sha: project.commit('master').sha)
get_for_ref('master') get_for_ref('master')
...@@ -696,7 +696,7 @@ RSpec.describe API::Jobs do ...@@ -696,7 +696,7 @@ RSpec.describe API::Jobs do
context 'with branch name containing slash' do context 'with branch name containing slash' do
before do before do
pipeline.reload pipeline.reload
pipeline.update(ref: 'improve/awesome', pipeline.update!(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha) sha: project.commit('improve/awesome').sha)
end end
...@@ -732,7 +732,7 @@ RSpec.describe API::Jobs do ...@@ -732,7 +732,7 @@ RSpec.describe API::Jobs do
stub_artifacts_object_storage stub_artifacts_object_storage
job.success job.success
project.update(visibility_level: visibility_level, project.update!(visibility_level: visibility_level,
public_builds: public_builds) public_builds: public_builds)
get_artifact_file(artifact) get_artifact_file(artifact)
...@@ -826,7 +826,7 @@ RSpec.describe API::Jobs do ...@@ -826,7 +826,7 @@ RSpec.describe API::Jobs do
context 'with branch name containing slash' do context 'with branch name containing slash' do
before do before do
pipeline.reload pipeline.reload
pipeline.update(ref: 'improve/awesome', pipeline.update!(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha) sha: project.commit('improve/awesome').sha)
end end
......
...@@ -119,7 +119,7 @@ RSpec.describe API::Labels do ...@@ -119,7 +119,7 @@ RSpec.describe API::Labels do
expect(label).not_to be_nil expect(label).not_to be_nil
label.priorities.create(project: label.project, priority: 1) label.priorities.create!(project: label.project, priority: 1)
label.save! label.save!
request_params = { request_params = {
...@@ -139,7 +139,7 @@ RSpec.describe API::Labels do ...@@ -139,7 +139,7 @@ RSpec.describe API::Labels do
expect(label).not_to be_nil expect(label).not_to be_nil
label_id = spec_params[:name] || spec_params[:label_id] label_id = spec_params[:name] || spec_params[:label_id]
label.priorities.create(project: label.project, priority: 1) label.priorities.create!(project: label.project, priority: 1)
label.save! label.save!
request_params = { request_params = {
...@@ -383,7 +383,7 @@ RSpec.describe API::Labels do ...@@ -383,7 +383,7 @@ RSpec.describe API::Labels do
it 'returns 409 if label already exists in group' do it 'returns 409 if label already exists in group' do
group = create(:group) group = create(:group)
group_label = create(:group_label, group: group) group_label = create(:group_label, group: group)
project.update(group: group) project.update!(group: group)
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
params: { params: {
......
...@@ -235,12 +235,14 @@ RSpec.describe API::ProjectImport do ...@@ -235,12 +235,14 @@ RSpec.describe API::ProjectImport do
stub_uploads_object_storage(ImportExportUploader, direct_upload: true) stub_uploads_object_storage(ImportExportUploader, direct_upload: true)
end end
# rubocop:disable Rails/SaveBang
let(:tmp_object) do let(:tmp_object) do
fog_connection.directories.new(key: 'uploads').files.create( fog_connection.directories.new(key: 'uploads').files.create(
key: "tmp/uploads/#{file_name}", key: "tmp/uploads/#{file_name}",
body: fixture_file_upload(file) body: fixture_file_upload(file)
) )
end end
# rubocop:enable Rails/SaveBang
let(:file_upload) { fog_to_uploaded_file(tmp_object) } let(:file_upload) { fog_to_uploaded_file(tmp_object) }
...@@ -285,7 +287,7 @@ RSpec.describe API::ProjectImport do ...@@ -285,7 +287,7 @@ RSpec.describe API::ProjectImport do
it 'returns the import status and the error if failed' do it 'returns the import status and the error if failed' do
project = create(:project, :import_failed) project = create(:project, :import_failed)
project.add_maintainer(user) project.add_maintainer(user)
project.import_state.update(last_error: 'error') project.import_state.update!(last_error: 'error')
get api("/projects/#{project.id}/import", user) get api("/projects/#{project.id}/import", user)
......
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