diff --git a/app/search_builders/hyrax/expired_embargo_search_builder.rb b/app/search_builders/hyrax/expired_embargo_search_builder.rb index 7cf1281f78..b21a895047 100644 --- a/app/search_builders/hyrax/expired_embargo_search_builder.rb +++ b/app/search_builders/hyrax/expired_embargo_search_builder.rb @@ -6,7 +6,13 @@ class ExpiredEmbargoSearchBuilder < EmbargoSearchBuilder def only_expired_embargoes(solr_params) solr_params[:fq] ||= [] - solr_params[:fq] = 'embargo_release_date_dtsi:[* TO NOW]' + solr_params[:fq] = "embargo_release_date_dtsi:[* TO #{now}]" + end + + private + + def now + Hyrax::TimeService.time_in_utc.utc.xmlschema end end end diff --git a/app/search_builders/hyrax/expired_lease_search_builder.rb b/app/search_builders/hyrax/expired_lease_search_builder.rb index 5932855e52..ee416b80e4 100644 --- a/app/search_builders/hyrax/expired_lease_search_builder.rb +++ b/app/search_builders/hyrax/expired_lease_search_builder.rb @@ -6,7 +6,13 @@ class ExpiredLeaseSearchBuilder < LeaseSearchBuilder def only_expired_leases(solr_params) solr_params[:fq] ||= [] - solr_params[:fq] = 'lease_expiration_date_dtsi:[* TO NOW]' + solr_params[:fq] = "lease_expiration_date_dtsi:[* TO #{now}]" + end + + private + + def now + Hyrax::TimeService.time_in_utc.utc.xmlschema end end end diff --git a/app/services/hyrax/access_control_list.rb b/app/services/hyrax/access_control_list.rb index cd200d202e..35ca3e504c 100644 --- a/app/services/hyrax/access_control_list.rb +++ b/app/services/hyrax/access_control_list.rb @@ -136,7 +136,7 @@ def grant(mode) # # @return [Boolean] def pending_changes? - change_set.changed? + !change_set.resource.persisted? || change_set.changed? end ## diff --git a/app/services/hyrax/custom_queries/find_access_control.rb b/app/services/hyrax/custom_queries/find_access_control.rb index 9512e68c0c..68d3a60883 100644 --- a/app/services/hyrax/custom_queries/find_access_control.rb +++ b/app/services/hyrax/custom_queries/find_access_control.rb @@ -20,7 +20,7 @@ def find_access_control_for(resource:) .find_inverse_references_by(resource: resource, property: :access_to) .find { |r| r.is_a?(Hyrax::AccessControl) } || raise(Valkyrie::Persistence::ObjectNotFoundError) - rescue ArgumentError # some adapters raise ArgumentError for missing resources + rescue ArgumentError, Ldp::Gone # some adapters raise ArgumentError for missing resources raise(Valkyrie::Persistence::ObjectNotFoundError) end end diff --git a/spec/services/hyrax/access_control_list_spec.rb b/spec/services/hyrax/access_control_list_spec.rb index 62e2ff6259..6afcf0e5e6 100644 --- a/spec/services/hyrax/access_control_list_spec.rb +++ b/spec/services/hyrax/access_control_list_spec.rb @@ -119,10 +119,21 @@ .from be_empty end - it 'does not publish when permissions are unchanged' do - expect { acl.save } - .not_to change { listener.object_acl_updated } - .from nil + context 'when not persisted' do + it 'publishes when permissions are unchanged' do + expect { acl.save } + .to change { listener.object_acl_updated } + .from nil + end + end + + context 'when persisted' do + before { acl.save } + + it 'does not publish when permissions are unchanged' do + expect { acl.save } + .not_to change { listener.object_acl_updated } + end end context 'with additions' do diff --git a/spec/services/hyrax/custom_queries/find_access_control_spec.rb b/spec/services/hyrax/custom_queries/find_access_control_spec.rb index a703d41c51..7358a12152 100644 --- a/spec/services/hyrax/custom_queries/find_access_control_spec.rb +++ b/spec/services/hyrax/custom_queries/find_access_control_spec.rb @@ -1,17 +1,28 @@ # frozen_string_literal: true -RSpec.describe Hyrax::CustomQueries::FindAccessControl do +RSpec.describe Hyrax::CustomQueries::FindAccessControl, skip: !Hyrax.config.disable_wings do subject(:query_handler) { described_class.new(query_service: query_service) } - let(:adapter) { Valkyrie::MetadataAdapter.find(:test_adapter) } + let(:adapter) { Hyrax.metadata_adapter } let(:persister) { adapter.persister } let(:query_service) { adapter.query_service } describe '#find_access_control' do context 'for missing object' do - let(:resource) { Valkyrie::Resource.new } + let(:resource) { Hyrax::Resource.new } it 'raises ObjectNotFoundError' do expect { query_handler.find_access_control_for(resource: resource) } - .to raise_error { Valkyrie::Persistence::ObjectNotFoundError } + .to raise_error Valkyrie::Persistence::ObjectNotFoundError + end + end + + context 'for deleted object' do + let(:resource) { persister.save(resource: Hyrax::Resource.new) } + + before { persister.delete(resource: resource) } + + it 'raises ObjectNotFoundError' do + expect { query_handler.find_access_control_for(resource: resource) } + .to raise_error Valkyrie::Persistence::ObjectNotFoundError end end @@ -22,8 +33,8 @@ before { acl } # ensure the acl gets saved it 'returns the acl' do - expect(query_handler.find_access_control_for(resource: resource)) - .to eq acl + expect(query_handler.find_access_control_for(resource: resource).id) + .to eq acl.id end end @@ -39,7 +50,7 @@ it 'raises ObjectNotFoundError' do expect { query_handler.find_access_control_for(resource: resource) } - .to raise_error { Valkyrie::Persistence::ObjectNotFoundError } + .to raise_error Valkyrie::Persistence::ObjectNotFoundError end end end diff --git a/spec/services/hyrax/listeners/file_metadata_listener_spec.rb b/spec/services/hyrax/listeners/file_metadata_listener_spec.rb index 3c978f2471..0ffbf90a0f 100644 --- a/spec/services/hyrax/listeners/file_metadata_listener_spec.rb +++ b/spec/services/hyrax/listeners/file_metadata_listener_spec.rb @@ -20,8 +20,8 @@ it 'indexes the file_set' do expect { listener.on_file_metadata_updated(event) } .to change { fake_adapter.saved_resources } - .from(be_empty) - .to contain_exactly(file_set) + .from(contain_exactly(file_set)) # Saving the ACL triggers an index + .to(contain_exactly(file_set, file_set)) end context 'when the file is not in a file set' do @@ -53,7 +53,7 @@ it 'does not index the file_set' do expect { listener.on_file_metadata_updated(event) } .not_to change { fake_adapter.saved_resources } - .from(be_empty) + .from(contain_exactly(file_set)) # Saving the ACL triggers an index end end end diff --git a/spec/wings/services/custom_queries/find_access_control_spec.rb b/spec/wings/services/custom_queries/find_access_control_spec.rb index 5e52f5ab41..26dc178318 100644 --- a/spec/wings/services/custom_queries/find_access_control_spec.rb +++ b/spec/wings/services/custom_queries/find_access_control_spec.rb @@ -13,11 +13,11 @@ describe '#find_access_control' do context 'for missing object' do - let(:resource) { Valkyrie::Resource.new } + let(:resource) { Hyrax::Resource.new } it 'raises ObjectNotFoundError' do expect { query_handler.find_access_control_for(resource: resource) } - .to raise_error { Valkyrie::Persistence::ObjectNotFoundError } + .to raise_error Valkyrie::Persistence::ObjectNotFoundError end end