From ea652f20df582c54e8e0f67f666f0136902c7694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Tue, 30 May 2017 08:14:15 +0200 Subject: [PATCH 1/3] [ci] Add tests Webui::PatchinfoHelper#patchinfo_bread_crumb The generation of the package link was failing calling patchinfo_bread_crumb in the helper spec. Thus I changed this in the helper. ==== ActionController::UrlGenerationError: No route matches {:action=>"show", :package=>"package_1", :project=>"project_1"} --- src/api/app/helpers/webui/patchinfo_helper.rb | 6 ++--- .../helpers/webui/patchinfo_helper_spec.rb | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/api/spec/helpers/webui/patchinfo_helper_spec.rb diff --git a/src/api/app/helpers/webui/patchinfo_helper.rb b/src/api/app/helpers/webui/patchinfo_helper.rb index 971b8f95fd0..df7dc713bdb 100644 --- a/src/api/app/helpers/webui/patchinfo_helper.rb +++ b/src/api/app/helpers/webui/patchinfo_helper.rb @@ -1,8 +1,8 @@ module Webui::PatchinfoHelper include Webui::ProjectHelper - def patchinfo_bread_crumb( *args ) - args.insert(0, link_to( @package, action: :show, project: @project, package: @package )) - project_bread_crumb( *args ) + def patchinfo_bread_crumb(*args) + args.insert(0, link_to(@package, package_show_path(project: @project, package: @package))) + project_bread_crumb(*args) end def issue_link( issue ) diff --git a/src/api/spec/helpers/webui/patchinfo_helper_spec.rb b/src/api/spec/helpers/webui/patchinfo_helper_spec.rb new file mode 100644 index 00000000000..51e7970ae80 --- /dev/null +++ b/src/api/spec/helpers/webui/patchinfo_helper_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe Webui::PatchinfoHelper, type: :helper do + describe '#patchinfo_bread_crumb' do + let(:project) { create(:project_with_package) } + + before do + @project = project.name + @package = project.packages.first.name + end + + it "creates a list of project_bread_crumb links, link to the patchinfo package" do + expect(patchinfo_bread_crumb).to eq([ + project_bread_crumb, + link_to(@package, package_show_path(project: @project, package: @package)) + ].flatten) + end + + it "the parameter content to the list" do + expect(patchinfo_bread_crumb('Text')).to eq([ + project_bread_crumb, + link_to(@package, package_show_path(project: @project, package: @package)), + 'Text' + ].flatten) + end + end +end From 2ea15b5a291c39a65d861386006ee69a02bb181f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Tue, 30 May 2017 08:48:56 +0200 Subject: [PATCH 2/3] [ci] Add tests for project_bread_crumbs --- .../spec/helpers/webui/project_helper_spec.rb | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/api/spec/helpers/webui/project_helper_spec.rb b/src/api/spec/helpers/webui/project_helper_spec.rb index b244399ebc2..8bfd4e334d4 100644 --- a/src/api/spec/helpers/webui/project_helper_spec.rb +++ b/src/api/spec/helpers/webui/project_helper_spec.rb @@ -6,7 +6,51 @@ end describe '#project_bread_crumb' do - skip + let(:project) { create(:project_with_package) } + + before do + @project = project.name + end + + it 'creates a list with a link to projects list' do + expect(project_bread_crumb).to eq([link_to('Projects', project_list_public_path)]) + end + + context "when it's called with a parameter" do + it 'adds the content of the parameter to the list' do + expect(project_bread_crumb('my label')).to eq([link_to('Projects', project_list_public_path), 'my label']) + end + end + + context 'when the project has parent projects' do + let(:child_project) { create(:project_with_package, name: "#{project}:child") } + + before do + @project = child_project + @package = project.packages.first.name + end + + it 'adds a link to the parent projects to the list' do + expect(project_bread_crumb('Text')).to eq( + [ + link_to('Projects', project_list_public_path), + [ + link_to(project, project_show_path(project: project)), + link_to('child', project_show_path(project: child_project)) + ], + 'Text' + ] + ) + end + end + + context 'when @spider_bot is true' do + before do + @spider_bot = true + end + + it { expect(project_bread_crumb).to be nil } + end end describe '#format_seconds' do From 7aa9674830a2bfe35c8b6c9e37cc7d29808f0b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Tue, 30 May 2017 08:57:13 +0200 Subject: [PATCH 3/3] [webui] Move patchinfo issue handling from helper to view The code is only used once and not very complex. No need to have it in a helper. --- src/api/app/helpers/webui/patchinfo_helper.rb | 14 -------------- src/api/app/views/webui/patchinfo/show.html.haml | 7 ++++++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/api/app/helpers/webui/patchinfo_helper.rb b/src/api/app/helpers/webui/patchinfo_helper.rb index df7dc713bdb..c7e50384214 100644 --- a/src/api/app/helpers/webui/patchinfo_helper.rb +++ b/src/api/app/helpers/webui/patchinfo_helper.rb @@ -4,18 +4,4 @@ def patchinfo_bread_crumb(*args) args.insert(0, link_to(@package, package_show_path(project: @project, package: @package))) project_bread_crumb(*args) end - - def issue_link( issue ) - # list issue-names with urls and summary from the patchinfo-file - # issue[0] = tracker-name - # issue[1] = issueid - # issue[2] = issue-url - # issue[3] = issue-summary - - if issue[0] == "CVE" - content_tag(:li, link_to((issue[1]).to_s, issue[2]) + ": #{issue[3]}") - else - content_tag(:li, link_to("#{issue[0]}##{issue[1]}", issue[2]) + ": #{issue[3]}") - end - end end diff --git a/src/api/app/views/webui/patchinfo/show.html.haml b/src/api/app/views/webui/patchinfo/show.html.haml index 2d4e85e6c84..b34140ed03b 100644 --- a/src/api/app/views/webui/patchinfo/show.html.haml +++ b/src/api/app/views/webui/patchinfo/show.html.haml @@ -41,7 +41,12 @@ - if @issues.present? %ul - @issues.each do |issue| - = issue_link(issue) + - if issue[0] == "CVE" + %li + = link_to((issue[1]).to_s, issue[2]) + ": #{issue[3]}" + - else + %li + = link_to("#{issue[0]}##{issue[1]}", issue[2]) + ": #{issue[3]}" .box.show_left.show_right %b Required actions: %br/