Commit 7afee665 authored by Stan Hu's avatar Stan Hu

Merge branch '22246-actionview-template-error-undefined-method-each-for-nil-nilclass' into 'master'

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

## Does this MR meet the acceptance criteria?

- [x] No CHANGELOG needed for a bug introduced in an RC.
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Closes #22246

See merge request !6379
parents ebf541e5 73269b58
...@@ -652,7 +652,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -652,7 +652,7 @@ class MergeRequest < ActiveRecord::Base
end end
def environments def environments
return unless diff_head_commit return [] unless diff_head_commit
target_project.environments.select do |environment| target_project.environments.select do |environment|
environment.includes_commit?(diff_head_commit) environment.includes_commit?(diff_head_commit)
......
...@@ -703,16 +703,24 @@ describe MergeRequest, models: true do ...@@ -703,16 +703,24 @@ describe MergeRequest, models: true do
describe "#environments" do describe "#environments" do
let(:project) { create(:project) } 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) } let(:merge_request) { create(:merge_request, source_project: project) }
it 'selects deployed environments' do it 'selects deployed environments' do
create(:deployment, environment: environment, sha: project.commit('master').id) environments = create_list(:environment, 3, project: project)
create(:deployment, environment: environment1, sha: project.commit('feature').id) 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
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