Skip to content

Commit

Permalink
Merge branch 'valkyrie_migration_assistance' of https://github.com/sa…
Browse files Browse the repository at this point in the history
…mvera/hyrax into valkyrie_migration_assistance
  • Loading branch information
orangewolf committed Nov 11, 2024
2 parents acf82ea + b4684ef commit 0f84611
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
8 changes: 7 additions & 1 deletion app/search_builders/hyrax/expired_embargo_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion app/search_builders/hyrax/expired_lease_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/services/hyrax/access_control_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def grant(mode)
#
# @return [Boolean]
def pending_changes?
change_set.changed?
!change_set.resource.persisted? || change_set.changed?
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/custom_queries/find_access_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions spec/services/hyrax/access_control_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions spec/services/hyrax/custom_queries/find_access_control_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/services/hyrax/listeners/file_metadata_listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0f84611

Please sign in to comment.