From 186c4dd7b4f6d4edc68c6fd65703665d14877e3e Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Wed, 30 Nov 2016 11:57:38 +0000 Subject: Fix broken link for latest deployment Updates changelog with MR ID --- app/helpers/environment_helper.rb | 6 ++++++ app/views/projects/builds/show.html.haml | 3 +-- .../unreleased/25136-last-deployment-link.yml | 4 ++++ spec/features/projects/builds_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/25136-last-deployment-link.yml diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 27975b7ddb7..5fde912ab2c 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -20,6 +20,12 @@ module EnvironmentHelper link_to "##{deployment.iid}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] end + def last_deployment_link(deployment, link_text) + return unless deployment + + link_to link_text, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + end + def last_deployment_link_for_environment_build(project, build) environment = environment_for_build(project, build) return unless environment diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index 108674dbba6..46a1969b348 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -46,8 +46,7 @@ - else This build is creating a deployment to #{environment_link_for_build(@build.project, @build)} - if environment.try(:last_deployment) - and will overwrite the - = link_to 'latest deployment', deployment_link(environment.last_deployment) + and will overwrite the #{last_deployment_link(environment.last_deployment, 'latest deployment')} .prepend-top-default - if @build.erased? diff --git a/changelogs/unreleased/25136-last-deployment-link.yml b/changelogs/unreleased/25136-last-deployment-link.yml new file mode 100644 index 00000000000..eab1534aa66 --- /dev/null +++ b/changelogs/unreleased/25136-last-deployment-link.yml @@ -0,0 +1,4 @@ +--- +title: Fix Latest deployment link is broken +merge_request: 7839 +author: diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb index a0ccc472d11..f25a0abb33d 100644 --- a/spec/features/projects/builds_spec.rb +++ b/spec/features/projects/builds_spec.rb @@ -227,6 +227,28 @@ feature 'Builds', :feature do expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1') end end + + context "Build starts environment" do + context "Build is successfull and has deployment" do + it "shows a link for the build" do + -# link to environment.name + expect(page).to have_link() + end + end + + context "Build is complete and not successfull" do + it "shows a link for the build" do + -# link to environment.name + expect(page).to have_link() + end + end + + context "Build creates a new deployment" do + it "shows a link to lastest deployment" do + expect(page).to have_link("latest deployment") + end + end + end end describe "POST /:project/builds/:id/cancel" do -- cgit v1.2.1 From 19e1b3246dfe085ef604c820e3bc8263e5bffd43 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 2 Dec 2016 17:10:37 +0000 Subject: Updates tests Fix tests Fix rubocop error Fix broken test --- spec/features/projects/builds_spec.rb | 42 +++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb index f25a0abb33d..2b6ad5e3420 100644 --- a/spec/features/projects/builds_spec.rb +++ b/spec/features/projects/builds_spec.rb @@ -228,24 +228,42 @@ feature 'Builds', :feature do end end - context "Build starts environment" do - context "Build is successfull and has deployment" do - it "shows a link for the build" do - -# link to environment.name - expect(page).to have_link() + context 'When build starts environment' do + context 'Build is successfull and has deployment' do + it 'shows a link for the build' do + environment = create(:environment, project: project) + pipeline = create(:ci_pipeline, project: project) + deployment = create(:deployment) + build1 = create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) + + visit namespace_project_build_path(project.namespace, project, build1) + + expect(page).to have_link environment.name end end - context "Build is complete and not successfull" do - it "shows a link for the build" do - -# link to environment.name - expect(page).to have_link() + context 'Build is complete and not successfull' do + it 'shows a link for the build' do + environment = create(:environment, project: project) + pipeline = create(:ci_pipeline, project: project) + build1 = create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) + + visit namespace_project_build_path(project.namespace, project, build1) + + expect(page).to have_link environment.name end end - context "Build creates a new deployment" do - it "shows a link to lastest deployment" do - expect(page).to have_link("latest deployment") + context 'Build creates a new deployment' do + it 'shows a link to lastest deployment' do + environment = create(:environment, project: project) + create(:deployment, environment: environment, sha: project.commit.id) + pipeline = create(:ci_pipeline, project: project) + build1 = create(:ci_build, :success, environment: environment.name, pipeline: pipeline) + + visit namespace_project_build_path(project.namespace, project, build1) + + expect(page).to have_link('latest deployment') end end end -- cgit v1.2.1 From 2dc907bc1761499e27c0a75eeccbbd350b38f80e Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Wed, 7 Dec 2016 10:34:00 +0000 Subject: Changes after review Fix error --- app/helpers/environment_helper.rb | 14 ++++++-------- app/views/projects/builds/show.html.haml | 2 +- spec/features/projects/builds_spec.rb | 8 ++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 5fde912ab2c..96d6f64eb8e 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -14,16 +14,14 @@ module EnvironmentHelper end end - def deployment_link(deployment) + def deployment_link(deployment, text) return unless deployment - link_to "##{deployment.iid}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] - end - - def last_deployment_link(deployment, link_text) - return unless deployment - - link_to link_text, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + if text + link_to text, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + else + link_to "##{deployment.iid}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] + end end def last_deployment_link_for_environment_build(project, build) diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index 46a1969b348..3ef46872199 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -46,7 +46,7 @@ - else This build is creating a deployment to #{environment_link_for_build(@build.project, @build)} - if environment.try(:last_deployment) - and will overwrite the #{last_deployment_link(environment.last_deployment, 'latest deployment')} + and will overwrite the #{deployment_link(environment.last_deployment, 'latest deployment')} .prepend-top-default - if @build.erased? diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb index 2b6ad5e3420..ea99239d5fc 100644 --- a/spec/features/projects/builds_spec.rb +++ b/spec/features/projects/builds_spec.rb @@ -228,8 +228,8 @@ feature 'Builds', :feature do end end - context 'When build starts environment' do - context 'Build is successfull and has deployment' do + context 'when build starts environment' do + context 'build is successfull and has deployment' do it 'shows a link for the build' do environment = create(:environment, project: project) pipeline = create(:ci_pipeline, project: project) @@ -242,7 +242,7 @@ feature 'Builds', :feature do end end - context 'Build is complete and not successfull' do + context 'build is complete and not successfull' do it 'shows a link for the build' do environment = create(:environment, project: project) pipeline = create(:ci_pipeline, project: project) @@ -254,7 +254,7 @@ feature 'Builds', :feature do end end - context 'Build creates a new deployment' do + context 'build creates a new deployment' do it 'shows a link to lastest deployment' do environment = create(:environment, project: project) create(:deployment, environment: environment, sha: project.commit.id) -- cgit v1.2.1 From 4eb53036c7469d027d2a75aff9e70950557195d2 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Wed, 7 Dec 2016 15:27:22 +0000 Subject: Changes after review --- app/helpers/environment_helper.rb | 10 ++++------ app/views/projects/builds/show.html.haml | 2 +- spec/features/projects/builds_spec.rb | 31 ++++++++++++++----------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 96d6f64eb8e..ff8550439d0 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -14,14 +14,12 @@ module EnvironmentHelper end end - def deployment_link(deployment, text) + def deployment_link(deployment, text: nil) return unless deployment - if text - link_to text, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] - else - link_to "##{deployment.iid}", [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] - end + link_label = text ? text : "##{deployment.iid}" + + link_to link_label, [deployment.project.namespace.becomes(Namespace), deployment.project, deployment.deployable] end def last_deployment_link_for_environment_build(project, build) diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index 3ef46872199..cdeb81372ee 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -46,7 +46,7 @@ - else This build is creating a deployment to #{environment_link_for_build(@build.project, @build)} - if environment.try(:last_deployment) - and will overwrite the #{deployment_link(environment.last_deployment, 'latest deployment')} + and will overwrite the #{deployment_link(environment.last_deployment, text: 'latest deployment')} .prepend-top-default - if @build.erased? diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb index ea99239d5fc..8c4d4320dc5 100644 --- a/spec/features/projects/builds_spec.rb +++ b/spec/features/projects/builds_spec.rb @@ -229,39 +229,36 @@ feature 'Builds', :feature do end context 'when build starts environment' do + let(:environment) { create(:environment, project: project) } + let(:pipeline) { create(:ci_pipeline, project: project) } + context 'build is successfull and has deployment' do - it 'shows a link for the build' do - environment = create(:environment, project: project) - pipeline = create(:ci_pipeline, project: project) - deployment = create(:deployment) - build1 = create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) + let(:deployment) { create(:deployment) } + let(:build) { create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) } - visit namespace_project_build_path(project.namespace, project, build1) + it 'shows a link for the build' do + visit namespace_project_build_path(project.namespace, project, build) expect(page).to have_link environment.name end end context 'build is complete and not successfull' do - it 'shows a link for the build' do - environment = create(:environment, project: project) - pipeline = create(:ci_pipeline, project: project) - build1 = create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) + let(:build) { create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) } - visit namespace_project_build_path(project.namespace, project, build1) + it 'shows a link for the build' do + visit namespace_project_build_path(project.namespace, project, build) expect(page).to have_link environment.name end end context 'build creates a new deployment' do - it 'shows a link to lastest deployment' do - environment = create(:environment, project: project) - create(:deployment, environment: environment, sha: project.commit.id) - pipeline = create(:ci_pipeline, project: project) - build1 = create(:ci_build, :success, environment: environment.name, pipeline: pipeline) + let!(:deployment) { create(:deployment, environment: environment, sha: project.commit.id) } + let(:build) { create(:ci_build, :success, environment: environment.name, pipeline: pipeline) } - visit namespace_project_build_path(project.namespace, project, build1) + it 'shows a link to lastest deployment' do + visit namespace_project_build_path(project.namespace, project, build) expect(page).to have_link('latest deployment') end -- cgit v1.2.1