Skip to content

Commit

Permalink
Merge pull request #972 from samvera/align_empty_query
Browse files Browse the repository at this point in the history
Check for nil id to avoid InvalidURIError
  • Loading branch information
tpendragon authored Nov 15, 2024
2 parents 9ade54d + a305ce4 commit 4aeffac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/valkyrie/persistence/fedora/query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def validate_id(id)
# @return [Valkyrie::Resource]
# @raise [Valkyrie::Persistence::ObjectNotFoundError]
def resource_from_uri(uri)
raise ::Valkyrie::Persistence::ObjectNotFoundError if uri.nil?
resource = Ldp::Resource.for(connection, uri, connection.get(uri))
resource_factory.to_resource(object: resource)
rescue ::Ldp::Gone, ::Ldp::NotFound
Expand Down
10 changes: 10 additions & 0 deletions lib/valkyrie/specs/shared_specs/queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ class Valkyrie::Specs::ThirdResource < Valkyrie::Resource
expect { query_service.find_by(id: Valkyrie::ID.new("123123123")) }.to raise_error ::Valkyrie::Persistence::ObjectNotFoundError
end

it 'returns a Valkyrie::Persistence::ObjectNotFoundError for an empty string' do
expect { query_service.find_by(id: '') }.to raise_error ::Valkyrie::Persistence::ObjectNotFoundError
end

it 'raises an error if the id is not a Valkyrie::ID or a string' do
expect { query_service.find_by(id: 123) }.to raise_error ArgumentError
expect { query_service.find_by(id: nil) }.to raise_error ArgumentError
end
end

Expand Down Expand Up @@ -117,8 +122,13 @@ class Valkyrie::Specs::ThirdResource < Valkyrie::Resource
expect { query_service.find_by_alternate_identifier(alternate_identifier: Valkyrie::ID.new("123123123")) }.to raise_error ::Valkyrie::Persistence::ObjectNotFoundError
end

it "raises a Valkyrie::Persistence::ObjectNotFoundError for a non-found alternate identifier" do
expect { query_service.find_by_alternate_identifier(alternate_identifier: '') }.to raise_error ::Valkyrie::Persistence::ObjectNotFoundError
end

it 'raises an error if the alternate identifier is not a Valkyrie::ID or a string' do
expect { query_service.find_by_alternate_identifier(alternate_identifier: 123) }.to raise_error ArgumentError
expect { query_service.find_by_alternate_identifier(alternate_identifier: nil) }.to raise_error ArgumentError
end

it 'can have multiple alternate identifiers' do
Expand Down

0 comments on commit 4aeffac

Please sign in to comment.