-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle additional GraduationHelper edge cases
Analysing production data showed variants for the requested embargo duration and graduation date that were not covered by the test suite and had unclear behaviors in the code. This PR adds tests to cover the newly identified edge cases and updates the GraduationHelper to match.
- Loading branch information
Showing
2 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
module GraduationHelper | ||
# Given a graduation date and an embargo length, calculate the embargo_release_date. | ||
# This assumes embargo_length values like "6 months", "2 months", "6 years" | ||
def self.embargo_length_to_embargo_release_date(graduation_date, embargo_length) | ||
if embargo_length == InProgressEtd::NO_EMBARGO | ||
def self.embargo_length_to_embargo_release_date(graduation_date, requested_embargo) | ||
if requested_embargo == InProgressEtd::NO_EMBARGO || requested_embargo.blank? | ||
# No post-graduation embargo to apply | ||
Rails.logger.warn "Treating empty requested_embargo as 'None'" if requested_embargo.blank? | ||
graduation_date | ||
else | ||
number, units = embargo_length.split(" ") | ||
# Calculate embargo expiration date | ||
number, units = requested_embargo.split(" ") | ||
raise ArgumentError, "Unexpected embargo length '#{requested_embargo}'" unless valid_length(number, units) | ||
graduation_date = Date.parse(graduation_date) if graduation_date.class == String | ||
graduation_date + Integer(number).send(units.to_sym) | ||
end | ||
end | ||
|
||
# Ensure valid values like "6 months", "2 months", "6 years" | ||
def self.valid_length(number, units) | ||
valid_quantity = number.to_i > 0 | ||
valid_units = ['months', 'year', 'years'].include?(units) | ||
valid_quantity && valid_units | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters