Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-21 12:40:03 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-21 12:40:03 +0300
commit0e0c90843f3eb8e97f0c28a48b513324274a4bd5 (patch)
treeca6351619180df59e7ea72eff81640bf4c9b9bdf
parente920414e6cbb3950456892b3ab7c9d9d7b0d056f (diff)
parentd496a6b919abd32252f54e59d5607956005cfb15 (diff)
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
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--spec/models/merge_request_spec.rb25
2 files changed, 26 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 1e8d9908f0a..1b3d6079d2c 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -476,7 +476,7 @@ class MergeRequest < ActiveRecord::Base
end
def ci_commit
- if last_commit
+ if last_commit and source_project
source_project.ci_commit(last_commit.id)
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 90af75ff0e3..567c911425c 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -193,4 +193,29 @@ describe MergeRequest do
it_behaves_like 'a Taskable' do
subject { create :merge_request, :simple }
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