Skip to content

Commit

Permalink
Allow the indexer to be set as a class attribute rather than overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 3, 2016
1 parent a721526 commit f6837a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
9 changes: 4 additions & 5 deletions app/models/concerns/curation_concerns/file_set/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module FileSet
module Indexing
extend ActiveSupport::Concern

module ClassMethods
# override the default indexing service
def indexer
CurationConcerns::FileSetIndexer
end
included do
class_attribute :indexer
# the default indexing service
self.indexer = CurationConcerns::FileSetIndexer
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions app/models/concerns/curation_concerns/work_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ module CurationConcerns::WorkBehavior

included do
property :owner, predicate: RDF::URI.new('http://opaquenamespace.org/ns/hydra/owner'), multiple: false
class_attribute :human_readable_short_description
class_attribute :human_readable_short_description, :indexer
self.indexer = CurationConcerns::WorkIndexer
end

module ClassMethods
def indexer
CurationConcerns::WorkIndexer
end

# This governs which partial to draw when you render this type of object
def _to_partial_path #:nodoc:
@_to_partial_path ||= begin
Expand Down
10 changes: 9 additions & 1 deletion spec/models/curation_concerns/work_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EssentialWork < ActiveFedora::Base

subject { EssentialWork.new }

it 'mixs together all the goodness' do
it 'mixes together all the goodness' do
[::CurationConcerns::WithFileSets, ::CurationConcerns::HumanReadableType, CurationConcerns::Noid, CurationConcerns::Serializers, Hydra::WithDepositor, Hydra::AccessControls::Embargoable, Solrizer::Common].each do |mixin|
expect(subject.class.ancestors).to include(mixin)
end
Expand All @@ -38,4 +38,12 @@ class EssentialWork < ActiveFedora::Base
expect(subject.to_solr.keys).to include(:id)
expect(subject.to_solr.keys).to include('has_model_ssim')
end

describe 'indexer' do
let(:klass) { Class.new }
it 'is settable' do
EssentialWork.indexer = klass
expect(subject.indexer).to eq klass
end
end
end
17 changes: 17 additions & 0 deletions spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@
describe '#indexer' do
subject { described_class.indexer }
it { is_expected.to eq CurationConcerns::FileSetIndexer }

describe "setting" do
before do
class AltFile < ActiveFedora::Base
include CurationConcerns::FileSetBehavior
end
end
after do
Object.send(:remove_const, :AltFile)
end
let(:klass) { Class.new }
subject { AltFile.new }
it 'is settable' do
AltFile.indexer = klass
expect(subject.indexer).to eq klass
end
end
end

it 'supports multi-valued fields in solr' do
Expand Down

0 comments on commit f6837a9

Please sign in to comment.