Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses spec/jobs/lease_expiry_job_spec.rb and associated factories. #6596

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions spec/factories/hyrax_file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@
end
end

trait :under_lease do
association :lease, factory: :hyrax_lease

after(:create) do |fs, _e|
Hyrax::LeaseManager.new(resource: fs).apply
fs.permission_manager.acl.save
end
end

trait :with_expired_enforced_lease do
after(:build) do |fs, _evaluator|
fs.lease = FactoryBot.valkyrie_create(:hyrax_lease, :expired)
end

after(:create) do |fs, _evaluator|
allow(Hyrax::TimeService).to receive(:time_in_utc).and_return(10.days.ago)
Hyrax::LeaseManager.new(resource: fs).apply
fs.permission_manager.acl.save
allow(Hyrax::TimeService).to receive(:time_in_utc).and_call_original
end
end

trait :public do
transient do
visibility_setting { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
Expand Down
3 changes: 1 addition & 2 deletions spec/factories/hyrax_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
after(:create) do |work, _evaluator|
allow(Hyrax::TimeService).to receive(:time_in_utc).and_return(10.days.ago)
Hyrax::LeaseManager.new(resource: work).apply
allow(Hyrax::TimeService).to receive(:time_in_utc).and_call_original

work.permission_manager.acl.save
allow(Hyrax::TimeService).to receive(:time_in_utc).and_call_original
end
end

Expand Down
97 changes: 67 additions & 30 deletions spec/jobs/lease_expiry_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,85 @@
RSpec.describe LeaseExpiryJob, :clean_repo do
subject { described_class }

let(:past_date) { 2.days.ago }
context 'with Valkyrie resources' do
let(:leased_work) { valkyrie_create(:hyrax_work, :under_lease) }
let(:work_with_expired_lease) { valkyrie_create(:hyrax_work, :with_expired_enforced_lease) }
let(:file_set_with_expired_lease) { valkyrie_create(:hyrax_file_set, :with_expired_enforced_lease) }

let(:leased_work) { create(:leased_work) }

let!(:work_with_expired_lease) do
build(:work, lease_expiration_date: past_date.to_s, visibility_during_lease: 'open', visibility_after_lease: 'restricted').tap do |work|
work.save(validate: false)
describe '#records_with_expired_leases' do
it 'returns all records with expired leases' do
records = [work_with_expired_lease.id, file_set_with_expired_lease.id]
expect(described_class.new.records_with_expired_leases.map(&:id)).to eq(records)
end
end
end

let!(:file_set_with_expired_lease) do
build(:file_set, lease_expiration_date: past_date.to_s, visibility_during_lease: 'open', visibility_after_lease: 'restricted').tap do |file_set|
file_set.save(validate: false)
describe '#perform' do
it 'expires leases on works with expired leases' do
expect(work_with_expired_lease.visibility).to eq('open')
described_class.new.perform
reloaded = Hyrax.query_service.find_by(id: work_with_expired_lease.id)
expect(reloaded.visibility).to eq('authenticated')
end

it 'expires leases on filesets with expired leases' do
expect(file_set_with_expired_lease.visibility).to eq('open')
described_class.new.perform
reloaded = Hyrax.query_service.find_by(id: file_set_with_expired_lease.id)
expect(reloaded.visibility).to eq('authenticated')
end

it 'does not expire leases that are still in effect' do
expect(leased_work.visibility).to eq('open')
described_class.new.perform
reloaded = Hyrax.query_service.find_by(id: leased_work.id)
expect(reloaded.visibility).to eq('open')
end
end
end

describe '#records_with_expired_leases' do
it 'returns all records with expired leases' do
records = described_class.new.records_with_expired_leases
expect(records.map(&:id))
.to contain_exactly(work_with_expired_lease.id,
file_set_with_expired_lease.id)
context 'with ActiveFedora objects', :active_fedora do
let(:past_date) { 2.days.ago }
let(:leased_work) { create(:leased_work) }

let!(:work_with_expired_lease) do
build(:work, lease_expiration_date: past_date.to_s, visibility_during_lease: 'open', visibility_after_lease: 'restricted').tap do |work|
work.save(validate: false)
end
end
end

describe '#perform' do
it 'expires leases on works with expired leases' do
described_class.new.perform
work_with_expired_lease.reload
expect(work_with_expired_lease.visibility).to eq('restricted')
let!(:file_set_with_expired_lease) do
build(:file_set, lease_expiration_date: past_date.to_s, visibility_during_lease: 'open', visibility_after_lease: 'restricted').tap do |file_set|
file_set.save(validate: false)
end
end

it 'expires leases on filesets with expired leases' do
described_class.new.perform
file_set_with_expired_lease.reload
expect(file_set_with_expired_lease.visibility).to eq('restricted')
describe '#records_with_expired_leases' do
it 'returns all records with expired leases' do
records = described_class.new.records_with_expired_leases
expect(records.map(&:id))
.to contain_exactly(work_with_expired_lease.id,
file_set_with_expired_lease.id)
end
end

it 'does not expire leases that are still in effect' do
described_class.new.perform
leased_work.reload
expect(leased_work.visibility).to eq('open')
describe '#perform' do
it 'expires leases on works with expired leases' do
described_class.new.perform
work_with_expired_lease.reload
expect(work_with_expired_lease.visibility).to eq('restricted')
end

it 'expires leases on filesets with expired leases' do
described_class.new.perform
file_set_with_expired_lease.reload
expect(file_set_with_expired_lease.visibility).to eq('restricted')
end

it 'does not expire leases that are still in effect' do
described_class.new.perform
leased_work.reload
expect(leased_work.visibility).to eq('open')
end
end
end
end