Skip to content

Commit

Permalink
Merge pull request #518 from samvera/backport_517
Browse files Browse the repository at this point in the history
Ensuring embargo/lease changes are persisted
  • Loading branch information
jeremyf authored Oct 9, 2020
2 parents cc03893 + 0dfbdcf commit 83c0d6f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Embargoable
validates :lease_expiration_date, :'hydra/future_date' => true, if: :enforce_future_date_for_lease?
validates :embargo_release_date, :'hydra/future_date' => true, if: :enforce_future_date_for_embargo?

belongs_to :embargo, predicate: Hydra::ACL.hasEmbargo, class_name: 'Hydra::AccessControls::Embargo'
belongs_to :lease, predicate: Hydra::ACL.hasLease, class_name: 'Hydra::AccessControls::Lease'
belongs_to :embargo, predicate: Hydra::ACL.hasEmbargo, class_name: 'Hydra::AccessControls::Embargo', autosave: true
belongs_to :lease, predicate: Hydra::ACL.hasLease, class_name: 'Hydra::AccessControls::Lease', autosave: true

delegate :visibility_during_embargo, :visibility_during_embargo=, :visibility_after_embargo, :visibility_after_embargo=, :embargo_release_date, :embargo_release_date=, :embargo_history, :embargo_history=, to: :existing_or_new_embargo
delegate :visibility_during_lease, :visibility_during_lease=, :visibility_after_lease, :visibility_after_lease=, :lease_expiration_date, :lease_expiration_date=, :lease_history, :lease_history=, to: :existing_or_new_lease
Expand Down
53 changes: 53 additions & 0 deletions hydra-access-controls/spec/unit/embargoable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,59 @@ def save(returning_value = true)
let(:model) { TestModel.new }
subject { model }

describe 'an object under embargo/lease' do
before do
class ModelWithPersistence < ActiveFedora::Base
include Hydra::AccessControls::Embargoable
end
end
after { Object.send(:remove_const, :ModelWithPersistence) }
let(:original_date) { 7.days.from_now }
let(:updated_date) { 14.days.from_now }
subject { ModelWithPersistence.new }
context 'saved with a new embargo release date' do
it 'will persist the new date' do
subject.visibility_during_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
subject.visibility_after_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
subject.embargo_release_date = original_date
subject.save

# These next three lines are to verify the round-trip for saves.
persisted_object = subject.class.find(subject.id)
expect(persisted_object).to be_under_embargo
expect(persisted_object.embargo_release_date).to eq(original_date)

expect do
persisted_object.embargo_release_date = updated_date
persisted_object.save
end.to change { persisted_object.class.find(persisted_object.id).embargo_release_date }
.from(original_date)
.to(updated_date)
end
end

context 'saved with a new lease expiration date' do
it 'will persist the new date' do
subject.visibility_during_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
subject.visibility_after_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
subject.lease_expiration_date = original_date
subject.save

# These next three lines are to verify the round-trip for saves.
persisted_object = subject.class.find(subject.id)
expect(persisted_object).to be_active_lease
expect(persisted_object.lease_expiration_date).to eq(original_date)

expect do
persisted_object.lease_expiration_date = updated_date
persisted_object.save
end.to change { persisted_object.class.find(persisted_object.id).lease_expiration_date }
.from(original_date)
.to(updated_date)
end
end
end

describe '#embargo_indexer_class' do
subject { model.embargo_indexer_class }
it { is_expected.to eq Hydra::AccessControls::EmbargoIndexer }
Expand Down

0 comments on commit 83c0d6f

Please sign in to comment.