Commit 6aa28c22 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'rails-save-bang-project-controllers' into 'master'

Fix Rails/SaveBang offenses for spec/controllers/projects

See merge request gitlab-org/gitlab!57643
parents 1f0a21f6 38b31444
...@@ -189,22 +189,6 @@ Rails/SaveBang: ...@@ -189,22 +189,6 @@ Rails/SaveBang:
- 'spec/controllers/omniauth_callbacks_controller_spec.rb' - 'spec/controllers/omniauth_callbacks_controller_spec.rb'
- 'spec/controllers/profiles/emails_controller_spec.rb' - 'spec/controllers/profiles/emails_controller_spec.rb'
- 'spec/controllers/profiles/notifications_controller_spec.rb' - 'spec/controllers/profiles/notifications_controller_spec.rb'
- 'spec/controllers/projects/artifacts_controller_spec.rb'
- 'spec/controllers/projects/cycle_analytics/events_controller_spec.rb'
- 'spec/controllers/projects/cycle_analytics_controller_spec.rb'
- 'spec/controllers/projects/discussions_controller_spec.rb'
- 'spec/controllers/projects/forks_controller_spec.rb'
- 'spec/controllers/projects/group_links_controller_spec.rb'
- 'spec/controllers/projects/imports_controller_spec.rb'
- 'spec/controllers/projects/issues_controller_spec.rb'
- 'spec/controllers/projects/labels_controller_spec.rb'
- 'spec/controllers/projects/milestones_controller_spec.rb'
- 'spec/controllers/projects/notes_controller_spec.rb'
- 'spec/controllers/projects/pipelines_controller_spec.rb'
- 'spec/controllers/projects/releases/evidences_controller_spec.rb'
- 'spec/controllers/projects/runners_controller_spec.rb'
- 'spec/controllers/projects/starrers_controller_spec.rb'
- 'spec/controllers/projects/uploads_controller_spec.rb'
- 'spec/controllers/projects_controller_spec.rb' - 'spec/controllers/projects_controller_spec.rb'
- 'spec/controllers/sent_notifications_controller_spec.rb' - 'spec/controllers/sent_notifications_controller_spec.rb'
- 'spec/controllers/sessions_controller_spec.rb' - 'spec/controllers/sessions_controller_spec.rb'
......
---
title: Fix Rails/SaveBang rubocop offenses in spec/controllers/projects/*
merge_request: 57643
author: Abdul Wadood @abdulwd
type: fixed
...@@ -448,7 +448,7 @@ RSpec.describe Projects::ArtifactsController do ...@@ -448,7 +448,7 @@ RSpec.describe Projects::ArtifactsController do
context 'with regular branch' do context 'with regular branch' do
before do before do
pipeline.update(ref: 'master', pipeline.update!(ref: 'master',
sha: project.commit('master').sha) sha: project.commit('master').sha)
get :latest_succeeded, params: params_from_ref('master') get :latest_succeeded, params: params_from_ref('master')
...@@ -459,7 +459,7 @@ RSpec.describe Projects::ArtifactsController do ...@@ -459,7 +459,7 @@ RSpec.describe Projects::ArtifactsController do
context 'with branch name containing slash' do context 'with branch name containing slash' do
before do before do
pipeline.update(ref: 'improve/awesome', pipeline.update!(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha) sha: project.commit('improve/awesome').sha)
get :latest_succeeded, params: params_from_ref('improve/awesome') get :latest_succeeded, params: params_from_ref('improve/awesome')
...@@ -470,7 +470,7 @@ RSpec.describe Projects::ArtifactsController do ...@@ -470,7 +470,7 @@ RSpec.describe Projects::ArtifactsController do
context 'with branch name and path containing slashes' do context 'with branch name and path containing slashes' do
before do before do
pipeline.update(ref: 'improve/awesome', pipeline.update!(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha) sha: project.commit('improve/awesome').sha)
get :latest_succeeded, params: params_from_ref('improve/awesome', job.name, 'file/README.md') get :latest_succeeded, params: params_from_ref('improve/awesome', job.name, 'file/README.md')
......
...@@ -26,7 +26,7 @@ RSpec.describe Projects::CycleAnalytics::EventsController do ...@@ -26,7 +26,7 @@ RSpec.describe Projects::CycleAnalytics::EventsController do
let(:issue) { create(:issue, project: project, created_at: 9.days.ago) } let(:issue) { create(:issue, project: project, created_at: 9.days.ago) }
before do before do
issue.update(milestone: milestone) issue.update!(milestone: milestone)
end end
it 'is not empty' do it 'is not empty' do
......
...@@ -85,7 +85,7 @@ RSpec.describe Projects::DiscussionsController do ...@@ -85,7 +85,7 @@ RSpec.describe Projects::DiscussionsController do
context "when the discussion is not resolvable" do context "when the discussion is not resolvable" do
before do before do
note.update(system: true) note.update!(system: true)
end end
it "returns status 404" do it "returns status 404" do
...@@ -168,7 +168,7 @@ RSpec.describe Projects::DiscussionsController do ...@@ -168,7 +168,7 @@ RSpec.describe Projects::DiscussionsController do
context "when the discussion is not resolvable" do context "when the discussion is not resolvable" do
before do before do
note.update(system: true) note.update!(system: true)
end end
it "returns status 404" do it "returns status 404" do
......
...@@ -71,7 +71,7 @@ RSpec.describe Projects::ForksController do ...@@ -71,7 +71,7 @@ RSpec.describe Projects::ForksController do
context 'when fork is internal' do context 'when fork is internal' do
before do before do
forked_project.update(visibility_level: Project::INTERNAL, group: group) forked_project.update!(visibility_level: Project::INTERNAL, group: group)
end end
it 'forks counts are correct' do it 'forks counts are correct' do
...@@ -86,7 +86,7 @@ RSpec.describe Projects::ForksController do ...@@ -86,7 +86,7 @@ RSpec.describe Projects::ForksController do
context 'when fork is private' do context 'when fork is private' do
before do before do
forked_project.update(visibility_level: Project::PRIVATE, group: group) forked_project.update!(visibility_level: Project::PRIVATE, group: group)
end end
shared_examples 'forks counts' do shared_examples 'forks counts' do
......
...@@ -31,7 +31,7 @@ RSpec.describe Projects::GroupLinksController do ...@@ -31,7 +31,7 @@ RSpec.describe Projects::GroupLinksController do
context 'when project is not allowed to be shared with a group' do context 'when project is not allowed to be shared with a group' do
before do before do
group.update(share_with_group_lock: false) group.update!(share_with_group_lock: false)
end end
include_context 'link project to group' include_context 'link project to group'
......
...@@ -47,7 +47,7 @@ RSpec.describe Projects::ImportsController do ...@@ -47,7 +47,7 @@ RSpec.describe Projects::ImportsController do
context 'when import is in progress' do context 'when import is in progress' do
before do before do
import_state.update(status: :started) import_state.update!(status: :started)
end end
it 'renders template' do it 'renders template' do
...@@ -65,7 +65,7 @@ RSpec.describe Projects::ImportsController do ...@@ -65,7 +65,7 @@ RSpec.describe Projects::ImportsController do
context 'when import failed' do context 'when import failed' do
before do before do
import_state.update(status: :failed) import_state.update!(status: :failed)
end end
it 'redirects to new_namespace_project_import_path' do it 'redirects to new_namespace_project_import_path' do
...@@ -77,7 +77,7 @@ RSpec.describe Projects::ImportsController do ...@@ -77,7 +77,7 @@ RSpec.describe Projects::ImportsController do
context 'when import finished' do context 'when import finished' do
before do before do
import_state.update(status: :finished) import_state.update!(status: :finished)
end end
context 'when project is a fork' do context 'when project is a fork' do
...@@ -126,7 +126,7 @@ RSpec.describe Projects::ImportsController do ...@@ -126,7 +126,7 @@ RSpec.describe Projects::ImportsController do
context 'when import never happened' do context 'when import never happened' do
before do before do
import_state.update(status: :none) import_state.update!(status: :none)
end end
it 'redirects to namespace_project_path' do it 'redirects to namespace_project_path' do
......
...@@ -44,7 +44,7 @@ RSpec.describe Projects::IssuesController do ...@@ -44,7 +44,7 @@ RSpec.describe Projects::IssuesController do
let_it_be(:issue) { create(:issue, project: new_project) } let_it_be(:issue) { create(:issue, project: new_project) }
before do before do
project.route.destroy project.route.destroy!
new_project.redirect_routes.create!(path: project.full_path) new_project.redirect_routes.create!(path: project.full_path)
new_project.add_developer(user) new_project.add_developer(user)
end end
...@@ -711,7 +711,7 @@ RSpec.describe Projects::IssuesController do ...@@ -711,7 +711,7 @@ RSpec.describe Projects::IssuesController do
issue.update!(last_edited_by: deleted_user, last_edited_at: Time.current) issue.update!(last_edited_by: deleted_user, last_edited_at: Time.current)
deleted_user.destroy deleted_user.destroy!
sign_in(user) sign_in(user)
end end
...@@ -1064,10 +1064,10 @@ RSpec.describe Projects::IssuesController do ...@@ -1064,10 +1064,10 @@ RSpec.describe Projects::IssuesController do
labels = create_list(:label, 10, project: project).map(&:to_reference) labels = create_list(:label, 10, project: project).map(&:to_reference)
issue = create(:issue, project: project, description: 'Test issue') issue = create(:issue, project: project, description: 'Test issue')
control_count = ActiveRecord::QueryRecorder.new { issue.update(description: [issue.description, label].join(' ')) }.count control_count = ActiveRecord::QueryRecorder.new { issue.update!(description: [issue.description, label].join(' ')) }.count
# Follow-up to get rid of this `2 * label.count` requirement: https://gitlab.com/gitlab-org/gitlab-foss/issues/52230 # Follow-up to get rid of this `2 * label.count` requirement: https://gitlab.com/gitlab-org/gitlab-foss/issues/52230
expect { issue.update(description: [issue.description, labels].join(' ')) } expect { issue.update!(description: [issue.description, labels].join(' ')) }
.not_to exceed_query_limit(control_count + 2 * labels.count) .not_to exceed_query_limit(control_count + 2 * labels.count)
end end
...@@ -1923,7 +1923,7 @@ RSpec.describe Projects::IssuesController do ...@@ -1923,7 +1923,7 @@ RSpec.describe Projects::IssuesController do
before do before do
sign_in(user) sign_in(user)
project.route.destroy project.route.destroy!
new_project.redirect_routes.create!(path: project.full_path) new_project.redirect_routes.create!(path: project.full_path)
new_project.add_developer(user) new_project.add_developer(user)
end end
......
...@@ -65,7 +65,7 @@ RSpec.describe Projects::LabelsController do ...@@ -65,7 +65,7 @@ RSpec.describe Projects::LabelsController do
end end
it 'does not include group labels when project does not belong to a group' do it 'does not include group labels when project does not belong to a group' do
project.update(namespace: create(:namespace)) project.update!(namespace: create(:namespace))
list_labels list_labels
...@@ -221,7 +221,7 @@ RSpec.describe Projects::LabelsController do ...@@ -221,7 +221,7 @@ RSpec.describe Projects::LabelsController do
end end
context 'when requesting a redirected path' do context 'when requesting a redirected path' do
let_it_be(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } let_it_be(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') }
it 'redirects to the canonical path' do it 'redirects to the canonical path' do
get :index, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' } get :index, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' }
...@@ -267,7 +267,7 @@ RSpec.describe Projects::LabelsController do ...@@ -267,7 +267,7 @@ RSpec.describe Projects::LabelsController do
end end
context 'when requesting a redirected path' do context 'when requesting a redirected path' do
let_it_be(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } let_it_be(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') }
it 'returns not found' do it 'returns not found' do
post :generate, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' } post :generate, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' }
......
...@@ -105,7 +105,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -105,7 +105,7 @@ RSpec.describe Projects::MilestonesController do
context 'with a single group ancestor' do context 'with a single group ancestor' do
before do before do
project.update(namespace: group) project.update!(namespace: group)
get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json
end end
...@@ -122,7 +122,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -122,7 +122,7 @@ RSpec.describe Projects::MilestonesController do
let!(:subgroup_milestone) { create(:milestone, group: subgroup) } let!(:subgroup_milestone) { create(:milestone, group: subgroup) }
before do before do
project.update(namespace: subgroup) project.update!(namespace: subgroup)
get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json
end end
...@@ -158,7 +158,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -158,7 +158,7 @@ RSpec.describe Projects::MilestonesController do
let(:group) { create(:group) } let(:group) { create(:group) }
before do before do
project.update(namespace: group) project.update!(namespace: group)
end end
context 'when user does not have permission to promote milestone' do context 'when user does not have permission to promote milestone' do
...@@ -234,7 +234,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -234,7 +234,7 @@ RSpec.describe Projects::MilestonesController do
end end
it 'renders 404' do it 'renders 404' do
project.update(namespace: user.namespace) project.update!(namespace: user.namespace)
post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid } post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid }
...@@ -253,7 +253,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -253,7 +253,7 @@ RSpec.describe Projects::MilestonesController do
before do before do
project.add_guest(guest_user) project.add_guest(guest_user)
sign_in(guest_user) sign_in(guest_user)
issue.update(assignee_ids: issue_assignee.id) issue.update!(assignee_ids: issue_assignee.id)
end end
context "when issue is not confidential" do context "when issue is not confidential" do
...@@ -269,7 +269,7 @@ RSpec.describe Projects::MilestonesController do ...@@ -269,7 +269,7 @@ RSpec.describe Projects::MilestonesController do
context "when issue is confidential" do context "when issue is confidential" do
before do before do
issue.update(confidential: true) issue.update!(confidential: true)
end end
it 'shows no milestone participants' do it 'shows no milestone participants' do
......
...@@ -334,7 +334,7 @@ RSpec.describe Projects::NotesController do ...@@ -334,7 +334,7 @@ RSpec.describe Projects::NotesController do
before do before do
project.update_attribute(:visibility_level, project_visibility) project.update_attribute(:visibility_level, project_visibility)
project.project_feature.update(merge_requests_access_level: merge_requests_access_level) project.project_feature.update!(merge_requests_access_level: merge_requests_access_level)
sign_in(user) sign_in(user)
end end
...@@ -917,7 +917,7 @@ RSpec.describe Projects::NotesController do ...@@ -917,7 +917,7 @@ RSpec.describe Projects::NotesController do
context "when the note is not resolvable" do context "when the note is not resolvable" do
before do before do
note.update(system: true) note.update!(system: true)
end end
it "returns status 404" do it "returns status 404" do
...@@ -980,7 +980,7 @@ RSpec.describe Projects::NotesController do ...@@ -980,7 +980,7 @@ RSpec.describe Projects::NotesController do
context "when the note is not resolvable" do context "when the note is not resolvable" do
before do before do
note.update(system: true) note.update!(system: true)
end end
it "returns status 404" do it "returns status 404" do
......
...@@ -13,7 +13,7 @@ RSpec.describe Projects::PipelinesController do ...@@ -13,7 +13,7 @@ RSpec.describe Projects::PipelinesController do
allow(Sidekiq.logger).to receive(:info) allow(Sidekiq.logger).to receive(:info)
stub_not_protect_default_branch stub_not_protect_default_branch
project.add_developer(user) project.add_developer(user)
project.project_feature.update(builds_access_level: feature) project.project_feature.update!(builds_access_level: feature)
sign_in(user) sign_in(user)
end end
...@@ -702,7 +702,7 @@ RSpec.describe Projects::PipelinesController do ...@@ -702,7 +702,7 @@ RSpec.describe Projects::PipelinesController do
before do before do
project.add_developer(user) project.add_developer(user)
project.project_feature.update(builds_access_level: feature) project.project_feature.update!(builds_access_level: feature)
end end
context 'with a valid .gitlab-ci.yml file' do context 'with a valid .gitlab-ci.yml file' do
...@@ -777,7 +777,7 @@ RSpec.describe Projects::PipelinesController do ...@@ -777,7 +777,7 @@ RSpec.describe Projects::PipelinesController do
before do before do
project.add_developer(user) project.add_developer(user)
project.project_feature.update(builds_access_level: feature) project.project_feature.update!(builds_access_level: feature)
end end
context 'with a valid .gitlab-ci.yml file' do context 'with a valid .gitlab-ci.yml file' do
......
...@@ -62,7 +62,7 @@ RSpec.describe Projects::Releases::EvidencesController do ...@@ -62,7 +62,7 @@ RSpec.describe Projects::Releases::EvidencesController do
context 'when the release was created before evidence existed' do context 'when the release was created before evidence existed' do
before do before do
evidence.destroy evidence.destroy!
end end
it_behaves_like 'not found' it_behaves_like 'not found'
......
...@@ -46,7 +46,7 @@ RSpec.describe Projects::RunnersController do ...@@ -46,7 +46,7 @@ RSpec.describe Projects::RunnersController do
describe '#resume' do describe '#resume' do
it 'marks the runner as active and ticks the queue' do it 'marks the runner as active and ticks the queue' do
runner.update(active: false) runner.update!(active: false)
expect do expect do
post :resume, params: params post :resume, params: params
...@@ -61,7 +61,7 @@ RSpec.describe Projects::RunnersController do ...@@ -61,7 +61,7 @@ RSpec.describe Projects::RunnersController do
describe '#pause' do describe '#pause' do
it 'marks the runner as inactive and ticks the queue' do it 'marks the runner as inactive and ticks the queue' do
runner.update(active: true) runner.update!(active: true)
expect do expect do
post :pause, params: params post :pause, params: params
......
...@@ -170,7 +170,7 @@ RSpec.describe Projects::StarrersController do ...@@ -170,7 +170,7 @@ RSpec.describe Projects::StarrersController do
context 'when project is private' do context 'when project is private' do
before do before do
project.update(visibility_level: Project::PRIVATE) project.update!(visibility_level: Project::PRIVATE)
end end
it 'starrers are not visible for non logged in users' do it 'starrers are not visible for non logged in users' do
......
...@@ -29,7 +29,7 @@ RSpec.describe Projects::UploadsController do ...@@ -29,7 +29,7 @@ RSpec.describe Projects::UploadsController do
let!(:upload) { create(:upload, :issuable_upload, :with_file, model: model) } let!(:upload) { create(:upload, :issuable_upload, :with_file, model: model) }
let(:project) { model } let(:project) { model }
let(:upload_path) { File.basename(upload.path) } let(:upload_path) { File.basename(upload.path) }
let!(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } let!(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') }
it 'redirects to a file with the proper extension' do it 'redirects to a file with the proper extension' do
get :show, params: { namespace_id: project.namespace, project_id: project.to_param + 'old', filename: File.basename(upload.path), secret: upload.secret } get :show, params: { namespace_id: project.namespace, project_id: project.to_param + 'old', filename: File.basename(upload.path), secret: upload.secret }
......
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