-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add valkyrie specs for EmbargoExpiryJob Marks existing spec as AF only. Duplicates existing EmbargoExpiryJob specs but with Valkyrie resources. Spec setup is simplified by not specifying "restricted" visibility, instead expecting the factory default "authenticated". Additional checks to confirm the initial visibility state are also added. The embargo traits from the hyrax_work factory are copied to the hyrax_file_set factory. Saving of the expired embargo ACL is moved to inside the time machine to 10 days ago. Without this change the solr doc will not contain the embargo related fields, causing `#records_with_expired_embargoes` to not find those resources. --------- Co-authored-by: bwatson78 <brad.watson.orlando@gmail.com>
- Loading branch information
Showing
3 changed files
with
91 additions
and
31 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
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
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,48 +1,87 @@ | ||
# frozen_string_literal: true | ||
RSpec.describe EmbargoExpiryJob, :clean_repo do | ||
subject { described_class } | ||
let(:past_date) { 2.days.ago } | ||
let(:embargoed_work) { create(:embargoed_work) } | ||
|
||
let!(:work_with_expired_embargo) do | ||
build(:work, embargo_release_date: past_date.to_s, visibility_during_embargo: 'restricted', visibility_after_embargo: 'open').tap do |work| | ||
work.save(validate: false) | ||
context "with Valkyrie resources" do | ||
let(:embargoed_work) { valkyrie_create(:hyrax_work, :under_embargo) } | ||
let(:work_with_expired_embargo) { valkyrie_create(:hyrax_work, :with_expired_enforced_embargo) } | ||
let(:file_set_with_expired_embargo) { valkyrie_create(:hyrax_file_set, :with_expired_enforced_embargo) } | ||
|
||
describe '#records_with_expired_embargos' do | ||
it 'returns all records with expired embargos' do | ||
records = [work_with_expired_embargo.id, file_set_with_expired_embargo.id] | ||
expect(described_class.new.records_with_expired_embargos.map(&:id)).to eq(records) | ||
end | ||
end | ||
end | ||
|
||
let!(:file_set_with_expired_embargo) do | ||
build(:file_set, embargo_release_date: past_date.to_s, visibility_during_embargo: 'restricted', visibility_after_embargo: 'open').tap do |file_set| | ||
file_set.save(validate: false) | ||
describe '#perform' do | ||
it 'expires embargos on works with expired embargos' do | ||
expect(work_with_expired_embargo.visibility).to eq('authenticated') | ||
described_class.new.perform | ||
reloaded = Hyrax.query_service.find_by(id: work_with_expired_embargo.id) | ||
expect(reloaded.visibility).to eq('open') | ||
end | ||
|
||
it 'expires embargos on file sets with expired embargos' do | ||
expect(file_set_with_expired_embargo.visibility).to eq('authenticated') | ||
described_class.new.perform | ||
reloaded = Hyrax.query_service.find_by(id: file_set_with_expired_embargo.id) | ||
expect(reloaded.visibility).to eq('open') | ||
end | ||
|
||
it "Doesn't expire embargos that are still in effect" do | ||
expect(embargoed_work.visibility).to eq('authenticated') | ||
described_class.new.perform | ||
reloaded = Hyrax.query_service.find_by(id: embargoed_work.id) | ||
expect(reloaded.visibility).to eq('authenticated') | ||
end | ||
end | ||
end | ||
|
||
describe '#records_with_expired_embargos' do | ||
it 'returns all records with expired embargos' do | ||
records = described_class.new.records_with_expired_embargos | ||
context 'with ActiveFedora objects', :active_fedora do | ||
let(:past_date) { 2.days.ago } | ||
let(:embargoed_work) { create(:embargoed_work) } | ||
|
||
expect(records.map(&:id)) | ||
.to contain_exactly(work_with_expired_embargo.id, | ||
file_set_with_expired_embargo.id) | ||
let!(:work_with_expired_embargo) do | ||
build(:work, embargo_release_date: past_date.to_s, visibility_during_embargo: 'restricted', visibility_after_embargo: 'open').tap do |work| | ||
work.save(validate: false) | ||
end | ||
end | ||
end | ||
|
||
describe '#perform' do | ||
it 'expires embargos on works with expired embargos' do | ||
described_class.new.perform | ||
work_with_expired_embargo.reload | ||
expect(work_with_expired_embargo.visibility).to eq('open') | ||
let!(:file_set_with_expired_embargo) do | ||
build(:file_set, embargo_release_date: past_date.to_s, visibility_during_embargo: 'restricted', visibility_after_embargo: 'open').tap do |file_set| | ||
file_set.save(validate: false) | ||
end | ||
end | ||
|
||
it 'expires embargos on file sets with expired embargos' do | ||
described_class.new.perform | ||
file_set_with_expired_embargo.reload | ||
expect(file_set_with_expired_embargo.visibility).to eq('open') | ||
describe '#records_with_expired_embargos' do | ||
it 'returns all records with expired embargos' do | ||
records = described_class.new.records_with_expired_embargos | ||
|
||
expect(records.map(&:id)) | ||
.to contain_exactly(work_with_expired_embargo.id, | ||
file_set_with_expired_embargo.id) | ||
end | ||
end | ||
|
||
it "Doesn't expire embargos that are still in effect" do | ||
described_class.new.perform | ||
embargoed_work.reload | ||
expect(embargoed_work.visibility).to eq('restricted') | ||
describe '#perform' do | ||
it 'expires embargos on works with expired embargos' do | ||
described_class.new.perform | ||
work_with_expired_embargo.reload | ||
expect(work_with_expired_embargo.visibility).to eq('open') | ||
end | ||
|
||
it 'expires embargos on file sets with expired embargos' do | ||
described_class.new.perform | ||
file_set_with_expired_embargo.reload | ||
expect(file_set_with_expired_embargo.visibility).to eq('open') | ||
end | ||
|
||
it "Doesn't expire embargos that are still in effect" do | ||
described_class.new.perform | ||
embargoed_work.reload | ||
expect(embargoed_work.visibility).to eq('restricted') | ||
end | ||
end | ||
end | ||
end |