spec/unit/embargoable_spec.rb in hydra-access-controls-7.1.0.rc1 vs spec/unit/embargoable_spec.rb in hydra-access-controls-7.1.0.rc2

- old
+ new

@@ -46,21 +46,43 @@ expect(subject.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE expect(subject.embargo_release_date).to eq future_date.to_time.utc expect(subject.visibility_after_embargo).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED end end + context 'deactivate_embargo!' do - it "should remove the associated embargo information and record it in the object's embargo history" do - subject.embargo_release_date = past_date.to_s + before do subject.visibility_during_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE subject.visibility_after_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC - subject.deactivate_embargo! - expect(subject.embargo_release_date).to be_nil - expect(subject.visibility_during_embargo).to be_nil - expect(subject.visibility_after_embargo).to be_nil - expect(subject.embargo_history.last).to include("An expired embargo was deactivated on #{Date.today}.") + subject.embargo_release_date = release_date end + + context "when the embargo is expired" do + let(:release_date) { past_date.to_s } + + it "should remove the associated embargo information and record it in the object's embargo history" do + subject.deactivate_embargo! + expect(subject.embargo_release_date).to be_nil + expect(subject.visibility_during_embargo).to be_nil + expect(subject.visibility_after_embargo).to be_nil + expect(subject.embargo_history.last).to include("An expired embargo was deactivated on #{Date.today}.") + end + end + + context "when the embargo is active" do + let(:release_date) { future_date.to_s } + + it "should remove the associated embargo information and record it in the object's embargo history" do + expect { + subject.deactivate_embargo! + }.to change { subject.under_embargo? }.from(true).to(false) + expect(subject.embargo_release_date).to be_nil + expect(subject.visibility_during_embargo).to be_nil + expect(subject.visibility_after_embargo).to be_nil + expect(subject.embargo_history.last).to include("An active embargo was deactivated on #{Date.today}.") + end + end end context 'apply_lease' do it "applies appropriate embargo_visibility settings" do subject.apply_lease(future_date.to_s, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE) @@ -76,18 +98,38 @@ expect(subject.visibility_after_lease).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE end end context 'deactivate_lease!' do - it "should remove the associated embargo information and record it in the object's embargo history" do - subject.lease_expiration_date = past_date.to_s + before do + subject.lease_expiration_date = expiration_date subject.visibility_during_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC subject.visibility_after_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE - subject.deactivate_lease! - expect(subject.lease_expiration_date).to be_nil - expect(subject.visibility_during_lease).to be_nil - expect(subject.visibility_after_lease).to be_nil - expect(subject.lease_history.last).to include("An expired lease was deactivated on #{Date.today}.") + end + + context "when the lease is expired" do + let(:expiration_date) { past_date.to_s } + + it "should remove the associated lease information and record it in the object's lease history" do + subject.deactivate_lease! + expect(subject.lease_expiration_date).to be_nil + expect(subject.visibility_during_lease).to be_nil + expect(subject.visibility_after_lease).to be_nil + expect(subject.lease_history.last).to include("An expired lease was deactivated on #{Date.today}.") + end + end + context "when the lease is active" do + let(:expiration_date) { future_date.to_s } + + it "should remove the associated lease information and record it in the object's lease history" do + expect { + subject.deactivate_lease! + }.to change { subject.active_lease? }.from(true).to(false) + expect(subject.lease_expiration_date).to be_nil + expect(subject.visibility_during_lease).to be_nil + expect(subject.visibility_after_lease).to be_nil + expect(subject.lease_history.last).to include("An active lease was deactivated on #{Date.today}.") + end end end context 'under_embargo?' do context "when embargo date is past" do