Project

General

Profile

Actions

Bug #18157

closed

Actions::Foreman::Report::Import.cleanup_after parses ActiveSupport::Duration#parts incorrectly

Added by Dominic Cleal almost 8 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Under Rails 5.0.1, the Actions::Foreman::Report::Import.cleanup_after method fails to return the correct number of days and fails the existing unit test:

cleanup#test_0001_derive the number of dates based on Report::DEFAULT_EXPIRATION [test/unit/actions/report/import_test.rb:39]:
Expected: "7d"
Actual: "d"

The code attempts to do Hash[1.week.parts][:days], but the ActiveSupport::Duration#parts method isn't a very reliable API to determine days from a duration, as it depends on how the duration was constructed. Under Rails 4.2.7.1 it returns [[:days, 7]] but under Rails 5.0.1 it returns [[:weeks, 1]].

It should use division of durations or .to_i to be more reliable.

Actions

Also available in: Atom PDF