Skip to content

Commit

Permalink
fix failing feature tests that expected results to be an array
Browse files Browse the repository at this point in the history
Results were expected to be an array, but before this commit, an enumeration was returned when using Valkyrie.  This ensures that an array is returned whether working wtih AF or Valkyrie.
  • Loading branch information
elrayle committed May 5, 2021
1 parent 2b485b0 commit 7af0aa6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/services/hyrax/find_objects_via_solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class FindObjectsViaSolrService

class << self
# Find objects matching search criteria.
# @param model [Class]
# @param model [Class] if not using Valkyrie, this is expected to be an ActiveFedora::Base object that supports #where
# @param field_pairs [Hash] a list of pairs of property name and values
# @param join_with [String] the value we're joining the clauses with (default: ' OR ' for backward compatibility with ActiveFedora where)
# @param type [String] The type of query to run. Either 'raw' or 'field' (default: 'field')
# @param use_valkyrie [Boolean] if true, return Valkyrie resource(s); otherwise, return ActiveFedora object(s)
# @return [ActiveFedora | Valkyrie::Resource] objects matching the query
# @return [Array<ActiveFedora|Valkyrie::Resource>] objects matching the query
def find_for_model_by_field_pairs(model:, field_pairs:, join_with: ' OR ', type: 'field', use_valkyrie: Hyrax.config.use_valkyrie?)
model.where(field_pairs) unless use_valkyrie
query = solr_query_builder.construct_query_for_model(model, field_pairs, join_with, type)
results = solr_service.query(query)
ids = results.map(&:id)
return query_service.find_many_by_ids(ids: ids) if use_valkyrie
ids.map { |id| query_service.find_by_alternate_identifier(alternate_identifier: id.to_str, use_valkyrie: false) }
query_service.find_many_by_ids(ids: ids).to_a
end
end
end
Expand Down
18 changes: 14 additions & 4 deletions spec/services/hyrax/find_objects_via_solr_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
let(:field_pairs) do
{ id: collection_ids.map(&:to_s) }
end
subject(:results) { described_class.find_for_model_by_field_pairs(model: ::Collection, field_pairs: field_pairs, use_valkyrie: use_valkyrie) }

it "returns ActiveFedora objects matching the query" do
expect(described_class.find_for_model_by_field_pairs(model: ::Collection, field_pairs: field_pairs, use_valkyrie: false).map(&:title)).to match_array [['Foo'], ['Too']]
context "when use_valkyrie is false" do
let(:use_valkrie) { false }
it "returns ActiveFedora objects matching the query" do
expect(results).to be_kind_of Array
expect(results.map(&:title)).to match_array [['Foo'], ['Too']]
end
end
it "returns Valkyrie::Resources matching the query" do
expect(described_class.find_for_model_by_field_pairs(model: ::Collection, field_pairs: field_pairs, use_valkyrie: true).map(&:title)).to match_array [['Foo'], ['Too']]

context "when use_valkyrie is true" do
let(:use_valkrie) { false }
it "returns Valkyrie::Resources matching the query" do
expect(results).to be_kind_of Array
expect(results.map(&:title)).to match_array [['Foo'], ['Too']]
end
end
end
end

0 comments on commit 7af0aa6

Please sign in to comment.