Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #486 from sul-dlss/t485-split_nil
Browse files Browse the repository at this point in the history
Handle nil embargo_terms.
  • Loading branch information
jcoyne authored Oct 12, 2020
2 parents 67d03b7 + 4eb692c commit a3820eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/hydrus/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def embargo_date_is_well_formed
# past embargo date, because the nightly job that removes embargoMetadata
# once the date has passed might not have run yet.
def embargo_date_in_range
return unless is_embargoed
return unless is_embargoed && collection.embargo_terms
b = beginning_of_embargo_range.to_datetime
e = end_of_embargo_range.to_datetime
dt = embargo_date.to_datetime
Expand Down
15 changes: 14 additions & 1 deletion spec/models/hydrus/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,23 @@
end

describe 'embargo_date_in_range()' do
it 'should not perform validation unless preconditions are met' do
it 'should not perform validation unless is_embargoed preconditions are met' do
expect(item).not_to receive(:beginning_of_embargo_range)
collection = instance_double(Hydrus::Collection, embargo_terms: '2 years')
allow(item).to receive(:collection).and_return(collection)
allow(item).to receive(:is_embargoed).and_return(false)
item.embargo_date_in_range
end

it 'should not perform validation unless collection.embargo_terms preconditions are met' do
expect(item).not_to receive(:beginning_of_embargo_range)

collection = instance_double(Hydrus::Collection, embargo_terms: nil)
allow(item).to receive(:collection).and_return(collection)
allow(item).to receive(:is_embargoed).and_return(true)
item.embargo_date_in_range
end

it 'should add a validation error when embargo_date falls outside the embargo range' do
# Set up beginning/end of embargo range.
b = '2012-02-01T08:00:00Z'
Expand All @@ -673,6 +684,8 @@
}
# Validate those dates.
allow(item).to receive(:is_embargoed).and_return(true)
collection = instance_double(Hydrus::Collection, embargo_terms: '2 years')
allow(item).to receive(:collection).and_return(collection)
k = :embargo_date
dts.each do |dt, is_ok|
expect(item.errors).not_to have_key(k)
Expand Down

0 comments on commit a3820eb

Please sign in to comment.