Skip to content

Commit

Permalink
add specs for hyrax:embargo:deactivate_expired
Browse files Browse the repository at this point in the history
there has been some question about whether this rake task actually releases
expired embargoes. this tests that it does, and ensures that it integrates with
the UI correctly by checking against `Hyrax::EmbargoHelper` (which lists
enforced embargoes for use by views).
  • Loading branch information
tamsin johnson committed Aug 29, 2023
1 parent 87eadbc commit 08ebfe0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/factories/hyrax_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
factory :hyrax_work, class: 'Hyrax::Test::SimpleWork' do
trait :under_embargo do
association :embargo, factory: :hyrax_embargo

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

trait :with_expired_enforced_embargo do
Expand Down
55 changes: 55 additions & 0 deletions spec/tasks/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@
require 'rake'

RSpec.describe "Rake tasks" do
describe "hyrax:embargo:deactivate_expired", :clean_repo do
let!(:active) do
[FactoryBot.valkyrie_create(:hyrax_work, :under_embargo),
FactoryBot.valkyrie_create(:hyrax_work, :under_embargo)]
end

let!(:expired) do
[FactoryBot.valkyrie_create(:hyrax_work, :with_expired_enforced_embargo),
FactoryBot.valkyrie_create(:hyrax_work, :with_expired_enforced_embargo)]
end

before do
load_rake_environment [File.expand_path("../../../lib/tasks/embargo_lease.rake", __FILE__)]
end

it "updates the persisted work ACLs for expired embargoes" do
expect { run_task 'hyrax:embargo:deactivate_expired' }
.to change {
Hyrax.query_service.find_many_by_ids(ids: expired.map(&:id))
.map { |work| work.permission_manager.read_groups.to_a }
}
.from([contain_exactly('registered'), contain_exactly('registered')])
.to([include('public'), include('public')])
end

it "updates the persisted work visibility for expired embargoes" do
expect { run_task 'hyrax:embargo:deactivate_expired' }
.to change {
Hyrax.query_service.find_many_by_ids(ids: expired.map(&:id))
.map(&:visibility)
}
.from(['authenticated', 'authenticated'])
.to(['open', 'open'])
end

it "does not update visibility for works with active embargoes" do
expect { run_task 'hyrax:embargo:deactivate_expired' }
.not_to change {
Hyrax.query_service.find_many_by_ids(ids: active.map(&:id))
.map(&:visibility)
}
.from(['authenticated', 'authenticated'])
end

it "removes the work from Hyrax::EmbargoHelper.assets_under_embargo" do
helper = Class.new { include Hyrax::EmbargoHelper }

# this helper is the source of truth for listing currently enforced embargoes for the UI
expect { run_task 'hyrax:embargo:deactivate_expired' }
.to change { helper.new.assets_under_embargo }
.from(contain_exactly(*(active + expired).map { |work| have_attributes(id: work.id) }))
.to(contain_exactly(*active.map { |work| have_attributes(id: work.id) }))
end
end

describe "hyrax:user:list_emails" do
let!(:user1) { create(:user) }
let!(:user2) { create(:user) }
Expand Down

0 comments on commit 08ebfe0

Please sign in to comment.