Project

General

Profile

Bug #18157

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

Added by Dominic Cleal over 4 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Bugzilla link:
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.

Associated revisions

Revision 3a1cd1db (diff)
Added by Dominic Cleal over 4 years ago

fixes #18157 - use AS::Duration division to get days from expiry

ActiveSupport::Duration#parts was an unreliable API as it contains data
used internally when constructing durations.

History

#1 Updated by The Foreman Bot over 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4209 added

#2 Updated by Dominic Cleal over 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#3 Updated by Dominic Cleal over 4 years ago

  • Legacy Backlogs Release (now unused) set to 209

Also available in: Atom PDF