From b1b1beaa65b009a359e9da82c2afa5f9230f4c39 Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Thu, 31 Aug 2023 10:27:24 -0700 Subject: [PATCH] make ResourceVisibilityPropagator use Valkyrie for setup these specs already cast an AF object to valkyrie for use, they just predate convenient factories. a pretty light spec refactor here. --- spec/factories/hyrax_work.rb | 4 ++++ .../hyrax/resource_visibility_propagator_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spec/factories/hyrax_work.rb b/spec/factories/hyrax_work.rb index 31e28948f6..597234c20b 100644 --- a/spec/factories/hyrax_work.rb +++ b/spec/factories/hyrax_work.rb @@ -56,6 +56,10 @@ work.permission_manager.edit_users = evaluator.edit_users work.permission_manager.read_users = evaluator.read_users + # these are both no-ops if an active embargo/lease isn't present + Hyrax::EmbargoManager.new(resource: work).apply + Hyrax::LeaseManager.new(resource: work).apply + work.permission_manager.acl.save Hyrax.index_adapter.save(resource: work) if evaluator.with_index diff --git a/spec/services/hyrax/resource_visibility_propagator_spec.rb b/spec/services/hyrax/resource_visibility_propagator_spec.rb index 189858aaa0..dd7b62417c 100644 --- a/spec/services/hyrax/resource_visibility_propagator_spec.rb +++ b/spec/services/hyrax/resource_visibility_propagator_spec.rb @@ -3,7 +3,7 @@ RSpec.describe Hyrax::ResourceVisibilityPropagator do subject(:propagator) { described_class.new(source: work) } let(:queries) { Hyrax.custom_queries } - let(:work) { FactoryBot.create(:work_with_files).valkyrie_resource } + let(:work) { FactoryBot.valkyrie_create(:hyrax_work, :with_member_file_sets) } let(:file_sets) { queries.find_child_file_sets(resource: work) } context 'a public work' do @@ -14,13 +14,13 @@ expect(file_sets.first.visibility).to eq 'restricted' expect { propagator.propagate } - .to change { queries.find_child_file_sets(resource: work).map(&:visibility) } + .to change { queries.find_child_file_sets(resource: work).map(&:visibility).to_a } .to contain_exactly(work.visibility, work.visibility) end end context 'when work is under embargo' do - let(:work) { FactoryBot.create(:embargoed_work_with_files).valkyrie_resource } + let(:work) { FactoryBot.valkyrie_create(:hyrax_work, :under_embargo, :with_member_file_sets) } before do fs = file_sets.first @@ -30,7 +30,7 @@ it 'copies visibility' do expect { propagator.propagate } - .to change { queries.find_child_file_sets(resource: work).map(&:visibility) } + .to change { queries.find_child_file_sets(resource: work).map(&:visibility).to_a } .to contain_exactly(work.visibility, work.visibility) end @@ -45,7 +45,7 @@ end context 'when work is under lease' do - let(:work) { FactoryBot.create(:leased_work_with_files).valkyrie_resource } + let(:work) { FactoryBot.valkyrie_create(:hyrax_work, :under_lease, :with_member_file_sets) } before do fs = file_sets.first @@ -55,7 +55,7 @@ it 'copies visibility' do expect { propagator.propagate } - .to change { queries.find_child_file_sets(resource: work).map(&:visibility) } + .to change { queries.find_child_file_sets(resource: work).map(&:visibility).to_a } .to contain_exactly(work.visibility, work.visibility) end