Skip to content

Commit

Permalink
Support #find_all_by_model query in Wings
Browse files Browse the repository at this point in the history
This query used to only support specialized Wings generated models, not native
models. This fixes it to support native Valkyrie models when registered.
  • Loading branch information
Tom Johnson committed Jan 11, 2020
1 parent 02618f6 commit ec7d792
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/wings/valkyrie/query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def find_all
end

# Find all work/collection records of a given model, and map to Valkyrie Resources
# @param [Valkyrie::ResourceClass]
# @param model [Class]
# @return [Array<Valkyrie::Resource>]
def find_all_of_model(model:)
model_class_for(model).all.map do |obj|
Expand Down Expand Up @@ -84,8 +84,8 @@ def find_by_alternate_identifier(alternate_identifier:, use_valkyrie: true)
end

# Find all members of a given resource, and map to Valkyrie Resources
# @param [Valkyrie::Resource]
# @param [Valkyrie::ResourceClass]
# @param resource [Valkyrie::Resource]
# @param model [Class]
# @return [Array<Valkyrie::Resource>]
def find_members(resource:, model: nil)
return [] unless resource.respond_to?(:member_ids) && resource.member_ids.present?
Expand All @@ -96,8 +96,8 @@ def find_members(resource:, model: nil)
end

# Find the Valkyrie Resources referenced by another Valkyrie Resource
# @param [<Valkyrie::Resource>]
# @param [Symbol] the property holding the references to another resource
# @param resource [<Valkyrie::Resource>]
# @param property [Symbol] the property holding the references to another resource
# @return [Array<Valkyrie::Resource>]
def find_references_by(resource:, property:)
object = resource_factory.from_resource(resource: resource)
Expand Down Expand Up @@ -167,7 +167,7 @@ def find_id_for(reference)
end

def model_class_for(model)
model.internal_resource.constantize
ModelRegistry.lookup(model) || model.internal_resource.constantize
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/wings/valkyrie/query_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ class Image < ActiveFedora::Base

expect(query_service.find_all_of_model(model: image_resource_class).to_a).to eq []
end

context 'with a native resource class' do
it 'returns all of the model' do
persister.save(resource: resource_class.new)
saved = persister.save(resource: Hyrax::Test::SimpleWork.new)

expect(query_service.find_all_of_model(model: Hyrax::Test::SimpleWork).map(&:id))
.to contain_exactly saved.id
end
end
end

describe ".find_by_alternate_identifier" do
Expand Down

0 comments on commit ec7d792

Please sign in to comment.