Commit 73269b58 authored by Rémy Coutable's avatar Rémy Coutable

MergeRequest#environments now returns an empty array when diff_head_commit is nil

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 1038ef54
......@@ -652,7 +652,7 @@ class MergeRequest < ActiveRecord::Base
end
def environments
return unless diff_head_commit
return [] unless diff_head_commit
target_project.environments.select do |environment|
environment.includes_commit?(diff_head_commit)
......
......@@ -703,16 +703,24 @@ describe MergeRequest, models: true do
describe "#environments" do
let(:project) { create(:project) }
let!(:environment) { create(:environment, project: project) }
let!(:environment1) { create(:environment, project: project) }
let!(:environment2) { create(:environment, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
it 'selects deployed environments' do
create(:deployment, environment: environment, sha: project.commit('master').id)
create(:deployment, environment: environment1, sha: project.commit('feature').id)
environments = create_list(:environment, 3, project: project)
create(:deployment, environment: environments.first, sha: project.commit('master').id)
create(:deployment, environment: environments.second, sha: project.commit('feature').id)
expect(merge_request.environments).to eq [environment]
expect(merge_request.environments).to eq [environments.first]
end
context 'without a diff_head_commit' do
before do
expect(merge_request).to receive(:diff_head_commit).and_return(nil)
end
it 'returns an empty array' do
expect(merge_request.environments).to be_empty
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