Commit 8b694ae8 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '24779-last-deployment-call-on-nil-environment-fix' into 'master'

changes environment.last_deployment to a try expression so it does not fail if e…

## What does this MR do?

Fixes the call on `environment.last_deployment` to not break when `environment`is not yet set.

## Does this MR meet the acceptance criteria?

- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] API support added
- 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)
- [x] 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 it does - 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 #24779

See merge request !7671
parents 604870a6 2f5637d6
...@@ -40,13 +40,12 @@ ...@@ -40,13 +40,12 @@
This build is the most recent deployment to #{environment_link_for_build(@build.project, @build)}. This build is the most recent deployment to #{environment_link_for_build(@build.project, @build)}.
- else - else
This build is an out-of-date deployment to #{environment_link_for_build(@build.project, @build)}. This build is an out-of-date deployment to #{environment_link_for_build(@build.project, @build)}.
- if environment.last_deployment
View the most recent deployment #{deployment_link(environment.last_deployment)}. View the most recent deployment #{deployment_link(environment.last_deployment)}.
- elsif @build.complete? && !@build.success? - elsif @build.complete? && !@build.success?
The deployment of this build to #{environment_link_for_build(@build.project, @build)} did not succeed. The deployment of this build to #{environment_link_for_build(@build.project, @build)} did not succeed.
- else - else
This build is creating a deployment to #{environment_link_for_build(@build.project, @build)} This build is creating a deployment to #{environment_link_for_build(@build.project, @build)}
- if environment.last_deployment - if environment.try(:last_deployment)
and will overwrite the and will overwrite the
= link_to 'latest deployment', deployment_link(environment.last_deployment) = link_to 'latest deployment', deployment_link(environment.last_deployment)
......
---
title: fixes last_deployment call environment is nil
merge_request: 7671
author:
...@@ -88,6 +88,7 @@ describe 'projects/builds/show', :view do ...@@ -88,6 +88,7 @@ describe 'projects/builds/show', :view do
create(:ci_build, :running, environment: 'staging', pipeline: pipeline) create(:ci_build, :running, environment: 'staging', pipeline: pipeline)
end end
context 'when environment exists' do
let!(:environment) do let!(:environment) do
create(:environment, name: 'staging', project: project) create(:environment, name: 'staging', project: project)
end end
...@@ -99,6 +100,35 @@ describe 'projects/builds/show', :view do ...@@ -99,6 +100,35 @@ describe 'projects/builds/show', :view do
expect(rendered).to have_css( expect(rendered).to have_css(
'.environment-information', text: expected_text) '.environment-information', text: expected_text)
end end
context 'when it has deployment' do
let!(:deployment) do
create(:deployment, environment: environment)
end
it 'shows that deployment will be overwritten' do
expected_text = 'This build is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
expect(rendered).to have_css(
'.environment-information', text: 'latest deployment')
end
end
end
context 'when environment does not exist' do
it 'shows deployment message' do
expected_text = 'This build is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
expect(rendered).not_to have_css(
'.environment-information', text: 'latest deployment')
end
end
end end
context 'build that failed to deploy and environment has not been created' do context 'build that failed to deploy and environment has not been created' do
...@@ -134,6 +164,8 @@ describe 'projects/builds/show', :view do ...@@ -134,6 +164,8 @@ describe 'projects/builds/show', :view do
expect(rendered).to have_css( expect(rendered).to have_css(
'.environment-information', text: expected_text) '.environment-information', text: expected_text)
expect(rendered).not_to have_css(
'.environment-information', text: 'latest deployment')
end 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