Skip to content

Commit

Permalink
Add a WorkRelation to query against all works
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jun 1, 2016
1 parent 7d093cc commit ad5e708
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
40 changes: 40 additions & 0 deletions app/search_builders/curation_concerns/work_relation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module CurationConcerns
class WorkRelation < ActiveFedora::Relation
def initialize(opts = {})
super(DummyModel, opts)
end

def equivalent_class?(klass)
CurationConcerns.config.curation_concerns.include?(klass)
end

def search_model_clause
clauses = CurationConcerns.config.curation_concerns.map do |k|
ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: k.to_s)
end
clauses.size == 1 ? clauses.first : "(#{clauses.join(' OR ')})"
end

class DummyModel
def self.primary_concern
CurationConcerns.config.curation_concerns.first
end

def self.delegated_attributes
primary_concern.delegated_attributes
end

def self.solr_query_handler
primary_concern.solr_query_handler
end

def self.default_sort_params
primary_concern.default_sort_params
end

def self.id_to_uri(*args)
primary_concern.id_to_uri(*args)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/search_builders/curation_concerns/work_relation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

RSpec.describe CurationConcerns::WorkRelation do
let!(:work) { create(:generic_work) }
let!(:file_set) { create(:file_set) }
let!(:collection) { create(:collection) }
it 'has works and not collections or file sets' do
expect(subject).to eq [work]
end
end

0 comments on commit ad5e708

Please sign in to comment.