Commit 1af30cd8 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'pl-spec-controller-projects-mr-perf' into 'master'

Speed up projects merge requests controller specs

See merge request gitlab-org/gitlab!46098
parents c915477a 81ad5c9c
...@@ -842,7 +842,6 @@ Rails/SaveBang: ...@@ -842,7 +842,6 @@ Rails/SaveBang:
- 'spec/controllers/projects/imports_controller_spec.rb' - 'spec/controllers/projects/imports_controller_spec.rb'
- 'spec/controllers/projects/issues_controller_spec.rb' - 'spec/controllers/projects/issues_controller_spec.rb'
- 'spec/controllers/projects/labels_controller_spec.rb' - 'spec/controllers/projects/labels_controller_spec.rb'
- 'spec/controllers/projects/merge_requests_controller_spec.rb'
- 'spec/controllers/projects/milestones_controller_spec.rb' - 'spec/controllers/projects/milestones_controller_spec.rb'
- 'spec/controllers/projects/notes_controller_spec.rb' - 'spec/controllers/projects/notes_controller_spec.rb'
- 'spec/controllers/projects/pipelines_controller_spec.rb' - 'spec/controllers/projects/pipelines_controller_spec.rb'
......
...@@ -6,14 +6,10 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -6,14 +6,10 @@ RSpec.describe Projects::MergeRequestsController do
include ProjectForksHelper include ProjectForksHelper
include Gitlab::Routing include Gitlab::Routing
let(:project) { create(:project, :repository) } let_it_be_with_refind(:project) { create(:project, :repository) }
let(:user) { project.owner } let_it_be_with_reload(:project_public_with_private_builds) { create(:project, :repository, :public, :builds_private) }
let(:user) { project.owner }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:merge_request_with_conflicts) do
create(:merge_request, source_branch: 'conflict-resolvable', target_branch: 'conflict-start', source_project: project, merge_status: :unchecked) do |mr|
mr.mark_as_unmergeable
end
end
before do before do
sign_in(user) sign_in(user)
...@@ -107,7 +103,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -107,7 +103,7 @@ RSpec.describe Projects::MergeRequestsController do
render_views render_views
it 'renders merge request page' do it 'renders merge request page' do
merge_request.merge_request_diff.destroy merge_request.merge_request_diff.destroy!
go(format: :html) go(format: :html)
...@@ -147,7 +143,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -147,7 +143,7 @@ RSpec.describe Projects::MergeRequestsController do
let(:new_project) { create(:project) } let(:new_project) { create(: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
...@@ -359,12 +355,11 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -359,12 +355,11 @@ RSpec.describe Projects::MergeRequestsController do
end end
context 'there is no source project' do context 'there is no source project' do
let(:project) { create(:project, :repository) }
let(:forked_project) { fork_project_with_submodules(project) } let(:forked_project) { fork_project_with_submodules(project) }
let!(:merge_request) { create(:merge_request, source_project: forked_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) } let!(:merge_request) { create(:merge_request, source_project: forked_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
before do before do
forked_project.destroy forked_project.destroy!
end end
it 'closes MR without errors' do it 'closes MR without errors' do
...@@ -435,7 +430,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -435,7 +430,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'when the merge request is not mergeable' do context 'when the merge request is not mergeable' do
before do before do
merge_request.update(title: "WIP: #{merge_request.title}") merge_request.update!(title: "WIP: #{merge_request.title}")
post :merge, params: base_params post :merge, params: base_params
end end
...@@ -475,7 +470,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -475,7 +470,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'when squash is passed as 1' do context 'when squash is passed as 1' do
it 'updates the squash attribute on the MR to true' do it 'updates the squash attribute on the MR to true' do
merge_request.update(squash: false) merge_request.update!(squash: false)
merge_with_sha(squash: '1') merge_with_sha(squash: '1')
expect(merge_request.reload.squash_on_merge?).to be_truthy expect(merge_request.reload.squash_on_merge?).to be_truthy
...@@ -484,7 +479,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -484,7 +479,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'when squash is passed as 0' do context 'when squash is passed as 0' do
it 'updates the squash attribute on the MR to false' do it 'updates the squash attribute on the MR to false' do
merge_request.update(squash: true) merge_request.update!(squash: true)
merge_with_sha(squash: '0') merge_with_sha(squash: '0')
expect(merge_request.reload.squash_on_merge?).to be_falsey expect(merge_request.reload.squash_on_merge?).to be_falsey
...@@ -547,7 +542,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -547,7 +542,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'and head pipeline is not the current one' do context 'and head pipeline is not the current one' do
before do before do
head_pipeline.update(sha: 'not_current_sha') head_pipeline.update!(sha: 'not_current_sha')
end end
it 'returns :failed' do it 'returns :failed' do
...@@ -667,9 +662,9 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -667,9 +662,9 @@ RSpec.describe Projects::MergeRequestsController do
end end
context "when the user is owner" do context "when the user is owner" do
let(:owner) { create(:user) } let_it_be(:owner) { create(:user) }
let(:namespace) { create(:namespace, owner: owner) } let_it_be(:namespace) { create(:namespace, owner: owner) }
let(:project) { create(:project, :repository, namespace: namespace) } let_it_be(:project) { create(:project, :repository, namespace: namespace) }
before do before do
sign_in owner sign_in owner
...@@ -765,7 +760,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -765,7 +760,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
context 'with private builds on a public project' do context 'with private builds on a public project' do
let(:project) { create(:project, :repository, :public, :builds_private) } let(:project) { project_public_with_private_builds }
context 'for a project owner' do context 'for a project owner' do
it 'responds with serialized pipelines' do it 'responds with serialized pipelines' do
...@@ -813,7 +808,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -813,7 +808,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'with public builds' do context 'with public builds' do
let(:forked_project) do let(:forked_project) do
fork_project(project, fork_user, repository: true).tap do |new_project| fork_project(project, fork_user, repository: true).tap do |new_project|
new_project.project_feature.update(builds_access_level: ProjectFeature::ENABLED) new_project.project_feature.update!(builds_access_level: ProjectFeature::ENABLED)
end end
end end
...@@ -855,7 +850,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -855,7 +850,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
describe 'GET exposed_artifacts' do describe 'GET exposed_artifacts' do
let(:merge_request) do let_it_be(:merge_request) do
create(:merge_request, create(:merge_request,
:with_merge_request_pipeline, :with_merge_request_pipeline,
target_project: project, target_project: project,
...@@ -993,7 +988,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -993,7 +988,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
describe 'GET coverage_reports' do describe 'GET coverage_reports' do
let(:merge_request) do let_it_be(:merge_request) do
create(:merge_request, create(:merge_request,
:with_merge_request_pipeline, :with_merge_request_pipeline,
target_project: project, target_project: project,
...@@ -1123,7 +1118,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1123,7 +1118,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
describe 'GET terraform_reports' do describe 'GET terraform_reports' do
let(:merge_request) do let_it_be(:merge_request) do
create(:merge_request, create(:merge_request,
:with_merge_request_pipeline, :with_merge_request_pipeline,
target_project: project, target_project: project,
...@@ -1271,7 +1266,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1271,7 +1266,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
describe 'GET test_reports' do describe 'GET test_reports' do
let(:merge_request) do let_it_be(:merge_request) do
create(:merge_request, create(:merge_request,
:with_diffs, :with_diffs,
:with_merge_request_pipeline, :with_merge_request_pipeline,
...@@ -1382,7 +1377,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1382,7 +1377,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
describe 'GET accessibility_reports' do describe 'GET accessibility_reports' do
let(:merge_request) do let_it_be(:merge_request) do
create(:merge_request, create(:merge_request,
:with_diffs, :with_diffs,
:with_merge_request_pipeline, :with_merge_request_pipeline,
...@@ -1419,7 +1414,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1419,7 +1414,7 @@ RSpec.describe Projects::MergeRequestsController do
end end
context 'permissions on a public project with private CI/CD' do context 'permissions on a public project with private CI/CD' do
let(:project) { create(:project, :repository, :public, :builds_private) } let(:project) { project_public_with_private_builds }
let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } } let(:accessibility_comparison) { { status: :parsed, data: { summary: 1 } } }
context 'while signed out' do context 'while signed out' do
...@@ -1505,7 +1500,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1505,7 +1500,7 @@ RSpec.describe Projects::MergeRequestsController do
describe 'POST remove_wip' do describe 'POST remove_wip' do
before do before do
merge_request.title = merge_request.wip_title merge_request.title = merge_request.wip_title
merge_request.save merge_request.save!
post :remove_wip, post :remove_wip,
params: { params: {
...@@ -1626,7 +1621,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1626,7 +1621,7 @@ RSpec.describe Projects::MergeRequestsController do
it 'links to the environment on that project', :sidekiq_might_not_need_inline do it 'links to the environment on that project', :sidekiq_might_not_need_inline do
get_ci_environments_status get_ci_environments_status
expect(json_response.first['url']).to match /#{forked.full_path}/ expect(json_response.first['url']).to match(/#{forked.full_path}/)
end end
context "when environment_target is 'merge_commit'", :sidekiq_might_not_need_inline do context "when environment_target is 'merge_commit'", :sidekiq_might_not_need_inline do
...@@ -1653,7 +1648,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1653,7 +1648,7 @@ RSpec.describe Projects::MergeRequestsController do
get_ci_environments_status(environment_target: 'merge_commit') get_ci_environments_status(environment_target: 'merge_commit')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.first['url']).to match /#{project.full_path}/ expect(json_response.first['url']).to match(/#{project.full_path}/)
end end
end end
end end
...@@ -1773,7 +1768,7 @@ RSpec.describe Projects::MergeRequestsController do ...@@ -1773,7 +1768,7 @@ RSpec.describe Projects::MergeRequestsController do
context 'with project member visibility on a public project' do context 'with project member visibility on a public project' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository, :public, :builds_private) } let(:project) { project_public_with_private_builds }
it 'returns pipeline data to project members' do it 'returns pipeline data to project members' do
project.add_developer(user) project.add_developer(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