Merge pull request #7533 from opf/fix/30743/reporting-rounding-float-values

[30743] Round displayed float values to precision correctly
pull/7539/head
Markus Kahl 5 years ago committed by GitHub
commit 543b0f33b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      lib/redmine/i18n.rb
  2. 4
      modules/costs/spec/features/time_entries_spec.rb
  3. 8
      modules/reporting/spec/features/custom_fields_spec.rb
  4. 6
      modules/reporting/spec/features/me_value_spec.rb
  5. 20
      modules/reporting/spec/features/permissions_spec.rb
  6. 29
      spec/features/time_entry/time_entry_report_spec.rb

@ -76,7 +76,7 @@ module Redmine
end
def localized_float(number, locale: ::I18n.locale, precision: 2)
number_with_delimiter(number, locale: locale, precision: precision)
number_with_precision(number, locale: locale, precision: precision)
rescue StandardError => e
Rails.logger.error("Failed to localize float number #{number}: #{e}")
('%.2f' % hours.to_f)

@ -76,7 +76,7 @@ describe 'Work Package table cost entries', type: :feature, js: true do
find('#show_cost_objects').set true
click_on 'Apply'
expect(page).to have_selector('.time-entry a', text: '10.0 h')
expect(page).to have_selector('.time-entry a', text: '2.5 h')
expect(page).to have_selector('.time-entry a', text: '10.00 h')
expect(page).to have_selector('.time-entry a', text: '2.50 h')
end
end

@ -88,7 +88,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
# Expect row of work package
within('#result-table') do
expect(page).to have_selector('.top.result', text: '12.5 hours')
expect(page).to have_selector('.top.result', text: '12.50 hours')
end
# Update filter to other value
@ -98,7 +98,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
# Expect empty result table
within('#result-table') do
expect(page).to have_no_selector('.top.result', text: '12.5 hours')
expect(page).to have_no_selector('.top.result', text: '12.50 hours')
end
expect(page).to have_selector('.generic-table--no-results-title')
end
@ -126,7 +126,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
expect(row_elements[1].text).to eq(work_package.to_s)
row_elements = page.all('table.report tr.odd td')
expect(row_elements[0].text).to eq('12.5 hours')
expect(row_elements[0].text).to eq('12.50 hours')
end
end
@ -224,7 +224,7 @@ describe 'Custom fields reporting', type: :feature, js: true do
expect(row_elements[1].text).to eq(work_package.to_s)
row_elements = page.all('table.report tr.odd td')
expect(row_elements[0].text).to eq('12.5 hours')
expect(row_elements[0].text).to eq('12.50 hours')
end
end
end

@ -40,7 +40,7 @@ describe 'Cost report showing my own times', type: :feature, js: true do
check 'query_is_public'
find('#query-icon-save-button').click
expect(page).to have_selector('.report', text: '10.0')
expect(page).to have_selector('.report', text: '10.00')
report = CostQuery.last
user_filter = report.serialized[:filters].detect { |name,_| name == filter_name }
@ -51,8 +51,8 @@ describe 'Cost report showing my own times', type: :feature, js: true do
# Create and save cost report
visit cost_report_path(report.id, project_id: project.identifier)
expect(page).to have_no_selector('.report', text: '10.0')
expect(page).to have_selector('.report', text: '15.0')
expect(page).to have_no_selector('.report', text: '10.00')
expect(page).to have_selector('.report', text: '15.00')
expect(find("##{filter_selector}").value).to eq 'me'
end

@ -64,8 +64,8 @@ describe 'Cost report calculations', type: :feature, js: true do
let(:current_user) { admin }
it 'shows everything' do
expect(page).to have_content '5.0 hours'
expect(page).to have_content '10.0 hours'
expect(page).to have_content '5.00 hours'
expect(page).to have_content '10.00 hours'
report_page.switch_to_type 'Translations'
@ -83,8 +83,8 @@ describe 'Cost report calculations', type: :feature, js: true do
end
it 'shows everything' do
expect(page).to have_content '5.0 hours'
expect(page).to have_content '10.0 hours'
expect(page).to have_content '5.00 hours'
expect(page).to have_content '10.00 hours'
report_page.switch_to_type 'Translations'
expect(page).to have_selector('td.units', text: '3.0 plural_unit', wait: 10)
end
@ -106,8 +106,8 @@ describe 'Cost report calculations', type: :feature, js: true do
end
it 'shows his own costs' do
expect(page).to have_content '5.0 hours'
expect(page).not_to have_content '10.0 hours'
expect(page).to have_content '5.00 hours'
expect(page).not_to have_content '10.00 hours'
report_page.switch_to_type 'Translations'
expect(page).to have_selector('td.units', text: '3.0 plural_unit', wait: 10)
end
@ -120,8 +120,8 @@ describe 'Cost report calculations', type: :feature, js: true do
end
it 'shows his own time only' do
expect(page).to have_content '5.0 hours'
expect(page).not_to have_content '10.0 hours'
expect(page).to have_content '5.00 hours'
expect(page).not_to have_content '10.00 hours'
report_page.switch_to_type 'Translations'
expect(page).to have_selector('.generic-table--no-results-title')
@ -136,8 +136,8 @@ describe 'Cost report calculations', type: :feature, js: true do
it 'shows his own costs' do
expect(page).to have_selector('.generic-table--no-results-title')
expect(page).not_to have_content '5.0 hours'
expect(page).not_to have_content '10.0 hours'
expect(page).not_to have_content '5.00 hours'
expect(page).not_to have_content '10.00 hours'
report_page.switch_to_type 'Translations'
expect(page).to have_no_selector('td.unit', text: '3.0 plural_unit')
end

@ -89,12 +89,37 @@ describe 'time entry report', type: :feature, js: true do
select 'Month', from: 'columns'
find('.timelog-report-selection').click_button('Apply')
expect(page).to have_selector('.total-hours', text: 'Total: 10.0 hours')
expect(page).to have_selector('.total-hours', text: 'Total: 10.00 hours')
expect(page).to have_selector('tr.total .hours', text: '5.00')
select 'Year', from: 'columns'
find('.timelog-report-selection').click_button('Apply')
expect(page).to have_selector('.total-hours', text: 'Total: 10.0 hours')
expect(page).to have_selector('.total-hours', text: 'Total: 10.00 hours')
end
end
describe 'with more precise values' do
let!(:project_time_entry) {
FactoryBot.create_list(:time_entry,
2,
project: project,
work_package: work_package,
hours: 2.249999999)
}
it 'rounds them to two decimals precision (Regression #30743)' do
visit time_entries_report_path
select 'Project', from: 'criterias'
select 'Month', from: 'columns'
find('.timelog-report-selection').click_button('Apply')
expect(page).to have_selector('.total-hours', text: 'Total: 9.50 hours')
expect(page).to have_selector('tr.total .hours', text: '4.50')
select 'Year', from: 'columns'
find('.timelog-report-selection').click_button('Apply')
expect(page).to have_selector('.total-hours', text: 'Total: 9.50 hours')
end
end
end

Loading…
Cancel
Save