Skip to content

Commit

Permalink
Replace arch_repo_table_cell helper by its webui2 version
Browse files Browse the repository at this point in the history
The helper arch_repo_table_cell was used only in Bento.

Old tests for arch_repo_table_cell were adapted for the new helper.
  • Loading branch information
eduardoj authored and dmarcoux committed Sep 5, 2019
1 parent 71f6764 commit 1038605
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 51 deletions.
32 changes: 1 addition & 31 deletions src/api/app/helpers/webui/buildresult_helper.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
module Webui::BuildresultHelper
def arch_repo_table_cell(repo, arch, package_name, status = nil, enable_help = true)
status ||= @statushash[repo][arch][package_name] || { 'package' => package_name }
status_id = valid_xml_id("id-#{package_name}_#{repo}_#{arch}")
link_title = status['details']
if status['code']
code = status['code']
theclass = 'status_' + code.gsub(/[- ]/, '_')
# special case for scheduled jobs with constraints limiting the workers a lot
theclass = 'status_scheduled_warning' if code == 'scheduled' && link_title.present?
else
code = ''
theclass = ' '
end

content_tag(:td, class: [theclass, 'buildstatus', 'nowrap']) do
if code.in?(['-', 'unresolvable', 'blocked', 'excluded', 'scheduled'])
concat(link_to(code, '#', title: link_title, id: status_id, class: code))
else
concat(link_to(code.gsub(/\s/, ' '),
package_live_build_log_path(project: @project.to_s, package: package_name, repository: repo, arch: arch),
title: link_title, rel: 'nofollow'))
end

if enable_help && status['code']
concat(' ')
concat(sprite_tag('help', title: Buildresult.status_description(status['code'])))
end
end
end

# NOTE: There is a JavaScript version of this method in project_monitor.js
def webui2_arch_repo_table_cell(repo, arch, package_name, status = nil, enable_help = true)
def arch_repo_table_cell(repo, arch, package_name, status = nil, enable_help = true)
status ||= @statushash[repo][arch][package_name] || { 'package' => package_name }
status_id = valid_xml_id("id-#{package_name}_#{repo}_#{arch}")
link_title = status['details']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
%span.ml-1
= result.architecture
.col-6.col-sm-5.col-xl-6.ml-2.text-nowrap
= webui2_arch_repo_table_cell(result.repository, result.architecture, package, 'code' => result.code, 'details' => result.details)
= arch_repo_table_cell(result.repository, result.architecture, package, 'code' => result.code, 'details' => result.details)
- previous_repo = result.repository
- else
All the results have state
Expand Down
37 changes: 18 additions & 19 deletions src/api/spec/helpers/webui/buildresult_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
allow(helper).to receive(:valid_xml_id) do |rawid|
rawid
end
allow(helper).to receive(:sprite_tag) do |icon, opts|
sprite_tag(icon, opts)
end

assign(:statushash, statushash)
assign(:project, project)
Expand All @@ -43,13 +40,14 @@
let(:key) { key }
let(:encoded_description) { description.gsub("'", ''') } # ' is encoded as '
let(:result) do
"<td class=\"status_#{key} buildstatus nowrap\"><a title=\"#{encoded_description}\" rel=\"nofollow\" " \
"href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\">#{key}</a> <img title=\"#{encoded_description}\" class=" \
"\"icons-help\" alt=\"#{encoded_description}\" src=\"/images/s.gif\" /></td>"
"<i class=\"fa fa-question-circle text-info mr-1\" data-content=\"#{encoded_description}\" data-placement=\"top\" "\
'data-toggle="popover"></i>'\
"<a data-content=\"#{encoded_description}\" data-placement=\"right\" data-toggle=\"popover\" rel=\"nofollow\" "\
"class=\"build-state-#{key}\" href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\">#{key}</a>"
end
let(:result2) do
"<td class=\"status_#{key} buildstatus nowrap\"><a title=\"#{encoded_description}\" rel=\"nofollow\" " \
"href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\">#{key}</a></td>"
"<a data-content=\"#{encoded_description}\" data-placement=\"right\" data-toggle=\"popover\" rel=\"nofollow\" "\
"class=\"build-state-#{key}\" href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\">#{key}</a>"
end

include_examples 'generic case'
Expand All @@ -60,12 +58,13 @@
context "with #{key}" do
let(:key) { key }
let(:result) do
"<td class=\"status_#{key} buildstatus nowrap\"><a title=\"#{description}\" id=\"id-#{package}_#{repo}_#{arch}\" class=\"#{key}\" " \
"href=\"#\">#{key}</a> <img title=\"#{description}\" class=\"icons-help\" alt=\"#{description}\" src=\"/images/s.gif\" /></td>"
"<i class=\"fa fa-question-circle text-info mr-1\" data-content=\"#{description}\" data-placement=\"top\" data-toggle=\"popover\"></i>"\
"<a id=\"id-#{package}_#{repo}_#{arch}\" class=\"build-state-#{key}\" data-content=\"#{description}\" data-placement=\"right\" "\
"data-toggle=\"popover\" href=\"javascript:void(0);\">#{key}</a>"
end
let(:result2) do
"<td class=\"status_#{key} buildstatus nowrap\"><a title=\"#{description}\" id=\"id-#{package}_#{repo}_#{arch}\" class=\"#{key}\" " \
"href=\"#\">#{key}</a></td>"
"<a id=\"id-#{package}_#{repo}_#{arch}\" class=\"build-state-#{key}\" data-content=\"#{description}\" data-placement=\"right\" "\
"data-toggle=\"popover\" href=\"javascript:void(0);\">#{key}</a>"
end

include_examples 'generic case'
Expand All @@ -75,14 +74,13 @@
context 'with scheduled' do
let(:key) { 'scheduled' }
let(:result) do
"<td class=\"status_scheduled_warning buildstatus nowrap\"><a title=\"#{description}\" id=\"id-#{package}_#{repo}_#{arch}\" class=" \
'"scheduled" href="#">scheduled</a>' \
" <img title=\"#{description}\" class=\"icons-help\" alt=\"#{description}\" src=\"/images/s.gif\" />" \
'</td>'
"<i class=\"fa fa-question-circle text-info mr-1\" data-content=\"#{description}\" data-placement=\"top\" data-toggle=\"popover\"></i>"\
"<a id=\"id-#{package}_#{repo}_#{arch}\" class=\"text-warning\" data-content=\"#{description}\" data-placement=\"right\" "\
"data-toggle=\"popover\" href=\"javascript:void(0);\">#{key}</a>"
end
let(:result2) do
"<td class=\"status_scheduled_warning buildstatus nowrap\"><a title=\"#{description}\" id=\"id-#{package}_#{repo}_#{arch}\" class=" \
'"scheduled" href="#">scheduled</a></td>'
"<a id=\"id-#{package}_#{repo}_#{arch}\" class=\"text-warning\" data-content=\"#{description}\" data-placement=\"right\" "\
"data-toggle=\"popover\" href=\"javascript:void(0);\">#{key}</a>"
end

include_examples 'generic case'
Expand All @@ -91,7 +89,8 @@
context 'without status' do
let(:statushash) { { repo.name => { arch => { package.name => nil } } } }
let(:result) do
"<td class=\" buildstatus nowrap\"><a rel=\"nofollow\" href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\"></a></td>"
'<a data-placement="right" data-toggle="popover" rel="nofollow" class=" " '\
"href=\"/package/live_build_log/#{project}/#{package}/#{repo}/#{arch}\"></a>"
end

it { expect(helper.arch_repo_table_cell(repo.name, arch, package.name)).to eq(result) }
Expand Down

0 comments on commit 1038605

Please sign in to comment.