Commit 0e0c9084 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-merge-requests-without-source-projects' into 'master'

Handle removed source projects in MR CI commits

Fixes #3599 

@dzaporozhets assigning this to you since you wrote the original code. Perhaps checking for the source project isn't the right way, but I'm not sure if there's a better way (e.g. somewhere earlier in the process) that we can detect this.

See merge request !1859
parents e920414e d496a6b9
...@@ -476,7 +476,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -476,7 +476,7 @@ class MergeRequest < ActiveRecord::Base
end end
def ci_commit def ci_commit
if last_commit if last_commit and source_project
source_project.ci_commit(last_commit.id) source_project.ci_commit(last_commit.id)
end end
end end
......
...@@ -193,4 +193,29 @@ describe MergeRequest do ...@@ -193,4 +193,29 @@ describe MergeRequest do
it_behaves_like 'a Taskable' do it_behaves_like 'a Taskable' do
subject { create :merge_request, :simple } subject { create :merge_request, :simple }
end end
describe '#ci_commit' do
describe 'when the source project exists' do
it 'returns the latest commit' do
commit = double(:commit, id: '123abc')
ci_commit = double(:ci_commit)
allow(subject).to receive(:last_commit).and_return(commit)
expect(subject.source_project).to receive(:ci_commit).
with('123abc').
and_return(ci_commit)
expect(subject.ci_commit).to eq(ci_commit)
end
end
describe 'when the source project does not exist' do
it 'returns nil' do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.ci_commit).to be_nil
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment