diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 12:09:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 12:09:13 +0000 |
commit | 211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7 (patch) | |
tree | 0ad37172721a39b0d57240bb1b4e70f200a0d93e /spec/services/merge_requests | |
parent | 456a7247f9e88fc2518b69a1a00e905c6db6d775 (diff) | |
download | gitlab-ce-211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/merge_requests')
3 files changed, 119 insertions, 0 deletions
diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 3db1471bf3c..8490127058c 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -483,6 +483,14 @@ describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do expect(merge_request).to be_persisted end + it 'calls MergeRequests::LinkLfsObjectsService#execute', :sidekiq_might_not_need_inline do + expect_next_instance_of(MergeRequests::LinkLfsObjectsService) do |service| + expect(service).to receive(:execute).with(instance_of(MergeRequest)) + end + + described_class.new(project, user, opts).execute + end + it 'does not create the merge request when the target project is archived' do target_project.update!(archived: true) diff --git a/spec/services/merge_requests/link_lfs_objects_service_spec.rb b/spec/services/merge_requests/link_lfs_objects_service_spec.rb new file mode 100644 index 00000000000..f07cf13e4f2 --- /dev/null +++ b/spec/services/merge_requests/link_lfs_objects_service_spec.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MergeRequests::LinkLfsObjectsService, :sidekiq_inline do + include ProjectForksHelper + include RepoHelpers + + let(:target_project) { create(:project, :public, :repository) } + + let(:merge_request) do + create( + :merge_request, + target_project: target_project, + target_branch: 'lfs', + source_project: source_project, + source_branch: 'link-lfs-objects' + ) + end + + subject { described_class.new(target_project) } + + shared_examples_for 'linking LFS objects' do + context 'when source project is the same as target project' do + let(:source_project) { target_project } + + it 'does not call Projects::LfsPointers::LfsLinkService#execute' do + expect(Projects::LfsPointers::LfsLinkService).not_to receive(:new) + + execute + end + end + + context 'when source project is different from target project' do + let(:user) { create(:user) } + let(:source_project) { fork_project(target_project, user, namespace: user.namespace, repository: true) } + + before do + create_branch(source_project, 'link-lfs-objects', 'lfs') + end + + context 'and there are changes' do + before do + allow(source_project).to receive(:lfs_enabled?).and_return(true) + end + + context 'and there are LFS objects added' do + before do + create_file_in_repo(source_project, 'link-lfs-objects', 'link-lfs-objects', 'one.lfs', 'One') + create_file_in_repo(source_project, 'link-lfs-objects', 'link-lfs-objects', 'two.lfs', 'Two') + end + + it 'calls Projects::LfsPointers::LfsLinkService#execute with OIDs of LFS objects in merge request' do + expect_next_instance_of(Projects::LfsPointers::LfsLinkService) do |service| + expect(service).to receive(:execute).with(%w[ + 8b12507783d5becacbf2ebe5b01a60024d8728a8f86dcc818bce699e8b3320bc + 94a72c074cfe574742c9e99e863322f73feff82981d065ff65a0308f44f19f62 + ]) + end + + execute + end + end + + context 'but there are no LFS objects added' do + before do + create_file_in_repo(source_project, 'link-lfs-objects', 'link-lfs-objects', 'one.txt', 'One') + end + + it 'does not call Projects::LfsPointers::LfsLinkService#execute' do + expect(Projects::LfsPointers::LfsLinkService).not_to receive(:new) + + execute + end + end + end + + context 'and there are no changes' do + it 'does not call Projects::LfsPointers::LfsLinkService#execute' do + expect(Projects::LfsPointers::LfsLinkService).not_to receive(:new) + + execute + end + end + end + end + + context 'when no oldrev and newrev passed' do + let(:execute) { subject.execute(merge_request) } + + it_behaves_like 'linking LFS objects' + end + + context 'when oldrev and newrev are passed' do + let(:execute) { subject.execute(merge_request, oldrev: merge_request.diff_base_sha, newrev: merge_request.diff_head_sha) } + + it_behaves_like 'linking LFS objects' + end + + def create_branch(project, new_name, branch_name) + ::Branches::CreateService.new(project, user).execute(new_name, branch_name) + end +end diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 1ba216e8ff1..b67779a912d 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -384,6 +384,14 @@ describe MergeRequests::RefreshService do end context 'open fork merge request' do + it 'calls MergeRequests::LinkLfsObjectsService#execute' do + expect_next_instance_of(MergeRequests::LinkLfsObjectsService) do |svc| + expect(svc).to receive(:execute).with(@fork_merge_request, oldrev: @oldrev, newrev: @newrev) + end + + refresh + end + it 'executes hooks with update action' do refresh |