Skip to content

Commit

Permalink
Convert DorHarvester#resources into an enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 19, 2016
1 parent c2951d3 commit 4c399a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/models/dor_harvester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def instance(current_exhibit)
end

def resources
@resources ||= druids.map { |d| Spotlight::Dor::Resources.indexer.resource(d) }
return to_enum(:resources) { druids.size } unless block_given?

druids.each { |d| yield Spotlight::Dor::Resources.indexer.resource(d) }
end

def druids
Expand Down
12 changes: 8 additions & 4 deletions spec/services/dor_solr_document_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
require 'rails_helper'

describe DorSolrDocumentBuilder do
subject { described_class.new harvester }

let(:exhibit) { FactoryGirl.create(:exhibit) }
let(:harvester) { DorHarvester.new druid_list: 'xf680rd3068', exhibit: exhibit }
let(:resource) { harvester.resources.first }
let(:druid) { 'xf680rd3068' }
let(:harvester) { DorHarvester.new druid_list: druid, exhibit: exhibit }
let(:resources) { [resource].to_enum }
let(:resource) { Harvestdor::Indexer::Resource.new(indexer, druid) }
let(:indexer) { Spotlight::Dor::Resources.indexer }

subject { described_class.new harvester }

before do
allow(resource).to receive(:exists?).and_return(true)
allow(harvester).to receive(:resources).and_return(resources)
allow(harvester).to receive(:blacklight_solr).and_return(double)
allow(harvester).to receive(:to_global_id).and_return('x')
allow(indexer).to receive(:solr_document)
Expand Down

0 comments on commit 4c399a7

Please sign in to comment.