diff options
author | Rémy Coutable <remy@rymai.me> | 2016-03-18 20:16:04 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-03-18 21:01:20 +0300 |
commit | bc92de8f038012b284ea1cbfbb2f0950943ebd88 (patch) | |
tree | c3601cd3a142e68ee5ca8ca5eff6fe85965d0bbf /spec/models/merge_request_spec.rb | |
parent | 4a8a8282d93fa8a486fdd3adc67a40fee737861d (diff) |
Add a safeguard in MergeRequest#compute_diverged_commits_count
We have to ensure source_sha and target_sha are not nil before calling
Gitlab::Git::Commit.between.
Diffstat (limited to 'spec/models/merge_request_spec.rb')
-rw-r--r-- | spec/models/merge_request_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 654c71b6825..2165cfb7a32 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -86,6 +86,16 @@ describe MergeRequest, models: true do end end + describe '#target_sha' do + context 'when the target branch does not exist anymore' do + subject { create(:merge_request).tap { |mr| mr.update_attribute(:target_branch, 'deleted') } } + + it 'returns nil' do + expect(subject.target_sha).to be_nil + end + end + end + describe '#source_sha' do let(:last_branch_commit) { subject.source_project.repository.commit(subject.source_branch) } @@ -310,6 +320,18 @@ describe MergeRequest, models: true do let(:project) { create(:project) } let(:fork_project) { create(:project, forked_from_project: project) } + context 'when the target branch does not exist anymore' do + subject { create(:merge_request).tap { |mr| mr.update_attribute(:target_branch, 'deleted') } } + + it 'does not crash' do + expect{ subject.diverged_commits_count }.not_to raise_error + end + + it 'returns 0' do + expect(subject.diverged_commits_count).to eq(0) + end + end + context 'diverged on same repository' do subject(:merge_request_with_divergence) { create(:merge_request, :diverged, source_project: project, target_project: project) } |