diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-24 14:31:20 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-24 14:31:20 +0000 |
commit | 8b694ae89174c72a9d7f71b43554965031ffa3fb (patch) | |
tree | 8bef72adcdcafb4f4500d56f46a38b63064a695d | |
parent | 604870a6cf57623a4fa36117ec8fd53544dd4b23 (diff) | |
parent | 2f5637d6e39efa4b1a1cd2acdffa478e903ecd98 (diff) | |
download | gitlab-ce-8b694ae89174c72a9d7f71b43554965031ffa3fb.tar.gz |
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
3 files changed, 48 insertions, 13 deletions
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index d8cbfd7173a..108674dbba6 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -40,13 +40,12 @@ This build is the most recent deployment to #{environment_link_for_build(@build.project, @build)}. - else 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? The deployment of this build to #{environment_link_for_build(@build.project, @build)} did not succeed. - else 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 = link_to 'latest deployment', deployment_link(environment.last_deployment) diff --git a/changelogs/unreleased/24779-last-deployment-call-on-nil-environment-fix.yml b/changelogs/unreleased/24779-last-deployment-call-on-nil-environment-fix.yml new file mode 100644 index 00000000000..5e7580fb8f2 --- /dev/null +++ b/changelogs/unreleased/24779-last-deployment-call-on-nil-environment-fix.yml @@ -0,0 +1,4 @@ +--- +title: fixes last_deployment call environment is nil +merge_request: 7671 +author: diff --git a/spec/views/projects/builds/show.html.haml_spec.rb b/spec/views/projects/builds/show.html.haml_spec.rb index e0c77201116..745d0c745bd 100644 --- a/spec/views/projects/builds/show.html.haml_spec.rb +++ b/spec/views/projects/builds/show.html.haml_spec.rb @@ -88,16 +88,46 @@ describe 'projects/builds/show', :view do create(:ci_build, :running, environment: 'staging', pipeline: pipeline) end - let!(:environment) do - create(:environment, name: 'staging', project: project) - end - - 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) + context 'when environment exists' do + let!(:environment) do + create(:environment, name: 'staging', project: project) + end + + 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) + 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 @@ -134,6 +164,8 @@ describe 'projects/builds/show', :view do expect(rendered).to have_css( '.environment-information', text: expected_text) + expect(rendered).not_to have_css( + '.environment-information', text: 'latest deployment') end end end |