summaryrefslogtreecommitdiff
path: root/spec/services/merge_requests
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/services/merge_requests
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/merge_requests')
-rw-r--r--spec/services/merge_requests/conflicts/resolve_service_spec.rb1
-rw-r--r--spec/services/merge_requests/create_service_spec.rb1
-rw-r--r--spec/services/merge_requests/ff_merge_service_spec.rb10
-rw-r--r--spec/services/merge_requests/push_options_handler_service_spec.rb33
-rw-r--r--spec/services/merge_requests/pushed_branches_service_spec.rb17
-rw-r--r--spec/services/merge_requests/rebase_service_spec.rb1
-rw-r--r--spec/services/merge_requests/refresh_service_spec.rb3
-rw-r--r--spec/services/merge_requests/squash_service_spec.rb1
8 files changed, 35 insertions, 32 deletions
diff --git a/spec/services/merge_requests/conflicts/resolve_service_spec.rb b/spec/services/merge_requests/conflicts/resolve_service_spec.rb
index c4d50124ca9..0abc70f71b0 100644
--- a/spec/services/merge_requests/conflicts/resolve_service_spec.rb
+++ b/spec/services/merge_requests/conflicts/resolve_service_spec.rb
@@ -205,6 +205,7 @@ RSpec.describe MergeRequests::Conflicts::ResolveService do
let(:resolver) do
MergeRequests::Conflicts::ListService.new(merge_request).conflicts.resolver
end
+
let(:regex_conflict) do
resolver.conflict_for_path(resolver.conflicts, 'files/ruby/regex.rb', 'files/ruby/regex.rb')
end
diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb
index a8661f027e8..bb62e594e7a 100644
--- a/spec/services/merge_requests/create_service_spec.rb
+++ b/spec/services/merge_requests/create_service_spec.rb
@@ -347,6 +347,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do
target_branch: 'master'
}
end
+
let(:issuable) { described_class.new(project, user, params).execute }
end
diff --git a/spec/services/merge_requests/ff_merge_service_spec.rb b/spec/services/merge_requests/ff_merge_service_spec.rb
index c3da02273a4..55856deeaca 100644
--- a/spec/services/merge_requests/ff_merge_service_spec.rb
+++ b/spec/services/merge_requests/ff_merge_service_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe MergeRequests::FfMergeService do
assignees: [user2],
author: create(:user))
end
+
let(:project) { merge_request.project }
let(:valid_merge_params) { { sha: merge_request.diff_head_sha } }
@@ -113,9 +114,16 @@ RSpec.describe MergeRequests::FfMergeService do
it 'logs and saves error if there is an PreReceiveError exception' do
error_message = 'error message'
+ raw_message = 'The truth is out there'
- allow(service).to receive(:repository).and_raise(Gitlab::Git::PreReceiveError, "GitLab: #{error_message}")
+ pre_receive_error = Gitlab::Git::PreReceiveError.new(raw_message, "GitLab: #{error_message}")
+ allow(service).to receive(:repository).and_raise(pre_receive_error)
allow(service).to receive(:execute_hooks)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
+ pre_receive_error,
+ pre_receive_message: raw_message,
+ merge_request_id: merge_request.id
+ )
service.execute(merge_request)
diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb
index 55f92d6bd0a..85bcf4562b1 100644
--- a/spec/services/merge_requests/push_options_handler_service_spec.rb
+++ b/spec/services/merge_requests/push_options_handler_service_spec.rb
@@ -5,9 +5,10 @@ require 'spec_helper'
RSpec.describe MergeRequests::PushOptionsHandlerService do
include ProjectForksHelper
- let(:user) { create(:user) }
- let(:project) { create(:project, :public, :repository) }
- let(:forked_project) { fork_project(project, user, repository: true) }
+ let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:user) { create(:user, developer_projects: [project]) }
+ let_it_be(:forked_project) { fork_project(project, user, repository: true) }
+
let(:service) { described_class.new(project, user, changes, push_options) }
let(:source_branch) { 'fix' }
let(:target_branch) { 'feature' }
@@ -21,28 +22,14 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" }
let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{project.default_branch}" }
- before do
- project.add_developer(user)
- end
-
shared_examples_for 'a service that can create a merge request' do
subject(:last_mr) { MergeRequest.last }
- it 'creates a merge request' do
- expect { service.execute }.to change { MergeRequest.count }.by(1)
- end
-
- it 'sets the correct target branch' do
+ it 'creates a merge request with the correct target branch and assigned user' do
branch = push_options[:target] || project.default_branch
- service.execute
-
+ expect { service.execute }.to change { MergeRequest.count }.by(1)
expect(last_mr.target_branch).to eq(branch)
- end
-
- it 'assigns the MR to the user' do
- service.execute
-
expect(last_mr.assignees).to contain_exactly(user)
end
@@ -54,15 +41,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
allow(forked_project).to receive(:empty_repo?).and_return(false)
end
- it 'sets the correct source project' do
+ it 'sets the correct source and target project' do
service.execute
expect(last_mr.source_project).to eq(forked_project)
- end
-
- it 'sets the correct target project' do
- service.execute
-
expect(last_mr.target_project).to eq(project)
end
end
@@ -746,6 +728,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end
describe 'when MRs are not enabled' do
+ let(:project) { create(:project, :public, :repository).tap { |pr| pr.add_developer(user) } }
let(:push_options) { { create: true } }
let(:changes) { new_branch_changes }
diff --git a/spec/services/merge_requests/pushed_branches_service_spec.rb b/spec/services/merge_requests/pushed_branches_service_spec.rb
index 6e9c77bd3b6..cd6af4c275e 100644
--- a/spec/services/merge_requests/pushed_branches_service_spec.rb
+++ b/spec/services/merge_requests/pushed_branches_service_spec.rb
@@ -8,19 +8,24 @@ RSpec.describe MergeRequests::PushedBranchesService do
context 'when branches pushed' do
let(:pushed_branches) do
- %w(branch1 branch2 extra1 extra2 extra3).map do |branch|
+ %w(branch1 branch2 closed-branch1 closed-branch2 extra1 extra2).map do |branch|
{ ref: "refs/heads/#{branch}" }
end
end
- it 'returns only branches which have a merge request' do
+ it 'returns only branches which have a open and closed merge request' do
create(:merge_request, source_branch: 'branch1', source_project: project)
create(:merge_request, source_branch: 'branch2', source_project: project)
create(:merge_request, target_branch: 'branch2', source_project: project)
- create(:merge_request, :closed, target_branch: 'extra1', source_project: project)
- create(:merge_request, source_branch: 'extra2')
-
- expect(service.execute).to contain_exactly('branch1', 'branch2')
+ create(:merge_request, :closed, target_branch: 'closed-branch1', source_project: project)
+ create(:merge_request, :closed, source_branch: 'closed-branch2', source_project: project)
+ create(:merge_request, source_branch: 'extra1')
+
+ expect(service.execute).to contain_exactly(
+ 'branch1',
+ 'branch2',
+ 'closed-branch2'
+ )
end
end
diff --git a/spec/services/merge_requests/rebase_service_spec.rb b/spec/services/merge_requests/rebase_service_spec.rb
index 2e525f2ed01..653fcf12a76 100644
--- a/spec/services/merge_requests/rebase_service_spec.rb
+++ b/spec/services/merge_requests/rebase_service_spec.rb
@@ -13,6 +13,7 @@ RSpec.describe MergeRequests::RebaseService do
target_branch: 'master',
rebase_jid: rebase_jid
end
+
let(:project) { merge_request.project }
let(:repository) { project.repository.raw }
let(:skip_ci) { false }
diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb
index 18c4cef7087..0696e8a247f 100644
--- a/spec/services/merge_requests/refresh_service_spec.rb
+++ b/spec/services/merge_requests/refresh_service_spec.rb
@@ -555,11 +555,13 @@ RSpec.describe MergeRequests::RefreshService do
message: 'Test commit',
branch_name: 'master')
end
+
let!(:second_commit) do
@fork_project.repository.create_file(@user, 'test2.txt', 'More test data',
message: 'Second test commit',
branch_name: 'master')
end
+
let!(:forked_master_mr) do
create(:merge_request,
source_project: @fork_project,
@@ -567,6 +569,7 @@ RSpec.describe MergeRequests::RefreshService do
target_branch: 'master',
target_project: @project)
end
+
let(:force_push_commit) { @project.commit('feature').id }
it 'reloads a new diff for a push to the forked project' do
diff --git a/spec/services/merge_requests/squash_service_spec.rb b/spec/services/merge_requests/squash_service_spec.rb
index 1ec1dc0f6eb..acbd0a42fcd 100644
--- a/spec/services/merge_requests/squash_service_spec.rb
+++ b/spec/services/merge_requests/squash_service_spec.rb
@@ -13,6 +13,7 @@ RSpec.describe MergeRequests::SquashService do
let(:squash_dir_path) do
File.join(Gitlab.config.shared.path, 'tmp/squash', repository.gl_repository, merge_request.id.to_s)
end
+
let(:merge_request_with_one_commit) do
create(:merge_request,
source_branch: 'feature', source_project: project,