-
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.
document and test
Hyrax::LeaseManager
`LeaseManager` is substantially similar to `EmbargoManager`, and got in without tests, with the idea that a refactor might quickly take place. it didn't and at this point it needs a test harness if that's ever going to happen. in the meanwhile. there are features we want to add to cover the remainder of the lifecycle.
- Loading branch information
tom johnson
committed
May 7, 2020
1 parent
8a784b3
commit a43faee
Showing
2 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Hyrax::LeaseManager do | ||
subject(:manager) { described_class.new(resource: resource) } | ||
let(:resource) { Hyrax::Resource.new } | ||
|
||
shared_context 'when under lease' do | ||
let(:resource) { FactoryBot.build(:hyrax_resource, :under_lease) } | ||
end | ||
|
||
shared_context 'with expired lease' do | ||
let(:resource) { FactoryBot.build(:hyrax_resource, lease: lease) } | ||
let(:lease) { FactoryBot.build(:hyrax_lease, :expired) } | ||
end | ||
|
||
describe '#apply' do | ||
context 'with no lease' do | ||
it 'is a no-op' do | ||
expect { manager.apply } | ||
.not_to change { resource.visibility } | ||
end | ||
end | ||
|
||
context 'with expired lease' do | ||
include_context 'with expired lease' | ||
|
||
it 'is a no-op' do | ||
expect { manager.apply } | ||
.not_to change { resource.visibility } | ||
end | ||
end | ||
|
||
context 'when under lease' do | ||
include_context 'when under lease' | ||
|
||
before { resource.visibility = 'restricted' } | ||
|
||
it 'applies the active lease visibility' do | ||
expect { manager.apply } | ||
.to change { resource.visibility } | ||
.from('restricted') | ||
.to 'open' | ||
end | ||
end | ||
end | ||
|
||
describe '#lease' do | ||
it 'gives an inactive lease' do | ||
expect(manager.lease).not_to be_active | ||
end | ||
|
||
context 'when under lease' do | ||
include_context 'when under lease' | ||
|
||
it 'gives an active lease' do | ||
expect(manager.lease).to be_active | ||
end | ||
|
||
it 'has lease attributes' do | ||
expect(manager.lease) | ||
.to have_attributes visibility_after_lease: 'authenticated', | ||
visibility_during_lease: 'open', | ||
lease_expiration_date: an_instance_of(Date), | ||
lease_history: be_empty | ||
end | ||
end | ||
end | ||
|
||
describe '#under_lease?' do | ||
it { is_expected.not_to be_under_lease } | ||
|
||
context 'when under lease' do | ||
include_context 'when under lease' | ||
|
||
it { is_expected.to be_under_lease } | ||
end | ||
|
||
context 'with expired lease' do | ||
include_context 'with expired lease' | ||
|
||
it { is_expected.not_to be_under_lease } | ||
end | ||
end | ||
end |