diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-09-07 09:58:15 +0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-12-05 12:54:10 -0200 |
commit | fe673b492769dc888268a1b2ac25342faa18a817 (patch) | |
tree | 11c2e4b9126feb999b21c54bdd8343b59bab2172 /spec/models/merge_request_spec.rb | |
parent | 003a816afa885d56aa1eb4aadbad2b13b1baa25b (diff) | |
download | gitlab-ce-fe673b492769dc888268a1b2ac25342faa18a817.tar.gz |
Ensure pippeline corresponds with the sha of an MR
Diffstat (limited to 'spec/models/merge_request_spec.rb')
-rw-r--r-- | spec/models/merge_request_spec.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 728028746d8..e10f375d42b 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -828,20 +828,28 @@ describe MergeRequest do end describe '#head_pipeline' do - describe 'when the source project exists' do - it 'returns the latest pipeline' do - pipeline = create(:ci_empty_pipeline, project: subject.source_project, ref: 'master', status: 'running', sha: "123abc", head_pipeline_of: subject) + before do + allow(subject).to receive(:diff_head_sha).and_return('lastsha') + end - expect(subject.head_pipeline).to eq(pipeline) - end + it 'returns nil for MR without head_pipeline_id' do + subject.update_attribute(:head_pipeline_id, nil) + + expect(subject.head_pipeline).to be_nil end - describe 'when the source project does not exist' do - it 'returns nil' do - allow(subject).to receive(:source_project).and_return(nil) + it 'returns nil for MR with old pipeline' do + pipeline = create(:ci_empty_pipeline, sha: 'notlatestsha') + subject.update_attribute(:head_pipeline_id, pipeline.id) - expect(subject.head_pipeline).to be_nil - end + expect(subject.head_pipeline).to be_nil + end + + it 'returns the pipeline for MR with recent pipeline' do + pipeline = create(:ci_empty_pipeline, sha: 'lastsha') + subject.update_attribute(:head_pipeline_id, pipeline.id) + + expect(subject.head_pipeline).to eq(pipeline) end end |