From 33beab6a2376e6f0309a3a3eb07378e059299bcf Mon Sep 17 00:00:00 2001 From: Seiei Miyagi Date: Thu, 23 Jul 2020 16:27:58 +0900 Subject: [PATCH] Fix timespan format of PDF download --- lib/redmine/export/pdf/issues_pdf_helper.rb | 4 ++++ test/unit/lib/redmine/export/pdf/issues_pdf_test.rb | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb index b49691695..8dcd52245 100644 --- a/lib/redmine/export/pdf/issues_pdf_helper.rb +++ b/lib/redmine/export/pdf/issues_pdf_helper.rb @@ -21,6 +21,8 @@ module Redmine module Export module PDF module IssuesPdfHelper + include Redmine::I18n + # Returns a PDF string of a single issue def issue_to_pdf(issue, assoc={}) pdf = ITCPDF.new(current_language) @@ -385,6 +387,8 @@ def fetch_row_values(issue, query, level) value = " " * level + value when :attachments value = value.to_a.map {|a| a.filename}.join("\n") + when :hours, :estimated_hours, :total_estimated_hours, :spent_hours, :total_spent_hours + value = format_hours(value) end if value.is_a?(Date) format_date(value) diff --git a/test/unit/lib/redmine/export/pdf/issues_pdf_test.rb b/test/unit/lib/redmine/export/pdf/issues_pdf_test.rb index 07b246424..c09e49ded 100644 --- a/test/unit/lib/redmine/export/pdf/issues_pdf_test.rb +++ b/test/unit/lib/redmine/export/pdf/issues_pdf_test.rb @@ -25,7 +25,7 @@ class IssuesPdfHelperTest < ActiveSupport::TestCase include Redmine::Export::PDF::IssuesPdfHelper - def test_fetch_row_values_should_round_float_values + def test_fetch_row_values_should_follow_timestamp_format_setting query = IssueQuery.new(:project => Project.find(1), :name => '_') query.column_names = [:subject, :spent_hours] issue = Issue.find(2) @@ -33,8 +33,15 @@ def test_fetch_row_values_should_round_float_values time_entry = TimeEntry.create!(:spent_on => Date.today, :hours => 4.3432, :user => user, :author => user, :project_id => 1, :issue => issue, :activity => TimeEntryActivity.first) - results = fetch_row_values(issue, query, 0) - assert_equal ["2", "Add ingredients categories", "4.34"], results + with_settings timespan_format: 'decimal' do + results = fetch_row_values(issue, query, 0) + assert_equal ["2", "Add ingredients categories", "4.34"], results + end + + with_settings timespan_format: 'minutes' do + results = fetch_row_values(issue, query, 0) + assert_equal ["2", "Add ingredients categories", "4:21"], results + end end def test_fetch_row_values_should_be_able_to_handle_parent_issue_subject -- 2.27.0