diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-03 14:04:58 +0100 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-10 13:28:10 +0100 |
commit | 42265d445f88408501e89b0a9aa959fd6f8d3bcf (patch) | |
tree | 7e90a6b1ebccfabfee2246747a3b267d8f97f69c /spec/services | |
parent | be623ef3c1a867d23e9625fe372c17fcad3c47ce (diff) | |
download | gitlab-ce-42265d445f88408501e89b0a9aa959fd6f8d3bcf.tar.gz |
Migrate Gitlab::Git::Repository#rebase to Gitalyfeature/migrate-rebase-to-gitaly
Closes gitaly#863
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/merge_requests/rebase_service_spec.rb | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/spec/services/merge_requests/rebase_service_spec.rb b/spec/services/merge_requests/rebase_service_spec.rb index d1b37cdd073..1a8377f6453 100644 --- a/spec/services/merge_requests/rebase_service_spec.rb +++ b/spec/services/merge_requests/rebase_service_spec.rb @@ -36,7 +36,7 @@ describe MergeRequests::RebaseService do end end - context 'when unexpected error occurs' do + context 'when unexpected error occurs', :disable_gitaly do before do allow(repository).to receive(:run_git!).and_raise('Something went wrong') end @@ -53,7 +53,7 @@ describe MergeRequests::RebaseService do end end - context 'with git command failure' do + context 'with git command failure', :disable_gitaly do before do allow(repository).to receive(:run_git!).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong') end @@ -71,31 +71,41 @@ describe MergeRequests::RebaseService do end context 'valid params' do - before do - service.execute(merge_request) - end + shared_examples 'successful rebase' do + before do + service.execute(merge_request) + end - it 'rebases source branch' do - parent_sha = merge_request.source_project.repository.commit(merge_request.source_branch).parents.first.sha - target_branch_sha = merge_request.target_project.repository.commit(merge_request.target_branch).sha - expect(parent_sha).to eq(target_branch_sha) - end + it 'rebases source branch' do + parent_sha = merge_request.source_project.repository.commit(merge_request.source_branch).parents.first.sha + target_branch_sha = merge_request.target_project.repository.commit(merge_request.target_branch).sha + expect(parent_sha).to eq(target_branch_sha) + end - it 'records the new SHA on the merge request' do - head_sha = merge_request.source_project.repository.commit(merge_request.source_branch).sha - expect(merge_request.reload.rebase_commit_sha).to eq(head_sha) + it 'records the new SHA on the merge request' do + head_sha = merge_request.source_project.repository.commit(merge_request.source_branch).sha + expect(merge_request.reload.rebase_commit_sha).to eq(head_sha) + end + + it 'logs correct author and commiter' do + head_commit = merge_request.source_project.repository.commit(merge_request.source_branch) + + expect(head_commit.author_email).to eq('dmitriy.zaporozhets@gmail.com') + expect(head_commit.author_name).to eq('Dmitriy Zaporozhets') + expect(head_commit.committer_email).to eq(user.email) + expect(head_commit.committer_name).to eq(user.name) + end end - it 'logs correct author and commiter' do - head_commit = merge_request.source_project.repository.commit(merge_request.source_branch) + context 'when Gitaly rebase feature is enabled' do + it_behaves_like 'successful rebase' + end - expect(head_commit.author_email).to eq('dmitriy.zaporozhets@gmail.com') - expect(head_commit.author_name).to eq('Dmitriy Zaporozhets') - expect(head_commit.committer_email).to eq(user.email) - expect(head_commit.committer_name).to eq(user.name) + context 'when Gitaly rebase feature is disabled', :disable_gitaly do + it_behaves_like 'successful rebase' end - context 'git commands' do + context 'git commands', :disable_gitaly do it 'sets GL_REPOSITORY env variable when calling git commands' do expect(repository).to receive(:popen).exactly(3) .with(anything, anything, hash_including('GL_REPOSITORY')) @@ -106,27 +116,37 @@ describe MergeRequests::RebaseService do end context 'fork' do - let(:forked_project) do - fork_project(project, user, repository: true) + shared_examples 'successful fork rebase' do + let(:forked_project) do + fork_project(project, user, repository: true) + end + + let(:merge_request_from_fork) do + forked_project.repository.create_file( + user, + 'new-file-to-target', + '', + message: 'Add new file to target', + branch_name: 'master') + + create(:merge_request, + source_branch: 'master', source_project: forked_project, + target_branch: 'master', target_project: project) + end + + it 'rebases source branch' do + parent_sha = forked_project.repository.commit(merge_request_from_fork.source_branch).parents.first.sha + target_branch_sha = project.repository.commit(merge_request_from_fork.target_branch).sha + expect(parent_sha).to eq(target_branch_sha) + end end - let(:merge_request_from_fork) do - forked_project.repository.create_file( - user, - 'new-file-to-target', - '', - message: 'Add new file to target', - branch_name: 'master') - - create(:merge_request, - source_branch: 'master', source_project: forked_project, - target_branch: 'master', target_project: project) + context 'when Gitaly rebase feature is enabled' do + it_behaves_like 'successful fork rebase' end - it 'rebases source branch' do - parent_sha = forked_project.repository.commit(merge_request_from_fork.source_branch).parents.first.sha - target_branch_sha = project.repository.commit(merge_request_from_fork.target_branch).sha - expect(parent_sha).to eq(target_branch_sha) + context 'when Gitaly rebase feature is disabled', :disable_gitaly do + it_behaves_like 'successful fork rebase' end end end |