spec/unit/indexer_spec.rb in gdor-indexer-0.5.0 vs spec/unit/indexer_spec.rb in gdor-indexer-0.6.0

- old
+ new

@@ -1,11 +1,10 @@ -require 'spec_helper' +require 'yaml' describe GDor::Indexer do before(:all) do @config_yml_path = File.join(File.dirname(__FILE__), '..', 'config', 'walters_integration_spec.yml') - require 'yaml' @yaml = YAML.load_file(@config_yml_path) @ns_decl = "xmlns='#{Mods::MODS_NS}'" @fake_druid = 'oo000oo0000' @coll_druid_from_test_config = 'ww121ss5000' @mods_xml = "<mods #{@ns_decl}><note>Indexer test</note></mods>" @@ -80,11 +79,11 @@ expect(@indexer).to receive(:log_results) expect(@indexer).to receive(:email_results) @indexer.harvest_and_index end - it 'indexs each resource' do + it 'indexes each resource' do allow(@indexer).to receive(:harvestdor).and_return(Class.new do def initialize(*items) @items = items end @@ -107,17 +106,17 @@ it 'sends a solr commit' do expect(@indexer.solr_client).to receive(:commit!) @indexer.harvest_and_index end it 'does not commit if nocommit is set' do - expect(@indexer.solr_client).to_not receive(:commit!) + expect(@indexer.solr_client).not_to receive(:commit!) @indexer.harvest_and_index(true) end end describe '#index' do - it 'indexs collections as collections' do + it 'indexes collections as collections' do expect(@indexer).to receive(:collection_solr_document).with(collection) @indexer.index collection end it 'indexes other resources as items' do @@ -194,21 +193,20 @@ expect(doc_hash).to include id: @fake_druid, building_facet: 'Stanford Digital Repository' end end # item_solr_document context '#collection_solr_document' do + let(:doc_hash) { GDor::Indexer::SolrDocHash.new } it 'calls validate_collection' do - doc_hash = GDor::Indexer::SolrDocHash.new allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(doc_hash) # speed up the test expect(doc_hash).to receive(:validate_collection).and_return([]) - doc_hash = @indexer.collection_solr_document collection + @indexer.collection_solr_document collection end it 'calls GDor::Indexer::SolrDocBuilder.validate_mods' do - doc_hash = GDor::Indexer::SolrDocHash.new allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(doc_hash) # speed up the test expect(doc_hash).to receive(:validate_mods).and_return([]) - doc_hash = @indexer.collection_solr_document collection + @indexer.collection_solr_document collection end it 'populates druid and access_facet fields' do doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include druid: @coll_druid_from_test_config, access_facet: 'Online' end @@ -220,52 +218,50 @@ allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(GDor::Indexer::SolrDocHash.new) # speed up the test doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include collection_type: 'Digital Collection' end + context 'add format_main_ssim Archive/Manuscript' do it 'no other values' do allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(GDor::Indexer::SolrDocHash.new) - doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include format_main_ssim: 'Archive/Manuscript' end it 'other values present' do allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(GDor::Indexer::SolrDocHash.new({ format_main_ssim: %w(Image Video) })) - doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include format_main_ssim: ['Image', 'Video', 'Archive/Manuscript'] end it 'already has values Archive/Manuscript' do allow_any_instance_of(GDor::Indexer::SolrDocBuilder).to receive(:doc_hash).and_return(GDor::Indexer::SolrDocHash.new({ format_main_ssim: 'Archive/Manuscript' })) - doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include format_main_ssim: ['Archive/Manuscript'] end end + it 'populates building_facet field with Stanford Digital Repository' do doc_hash = @indexer.collection_solr_document collection expect(doc_hash).to include building_facet: 'Stanford Digital Repository' end end # index_coll_obj_per_config context '#add_coll_info and supporting methods' do before(:each) do @coll_druids_array = [collection] end + let(:doc_hash) { GDor::Indexer::SolrDocHash.new({}) } it 'adds no collection field values to doc_hash if there are none' do - doc_hash = GDor::Indexer::SolrDocHash.new({}) @indexer.add_coll_info(doc_hash, nil) expect(doc_hash[:collection]).to be_nil expect(doc_hash[:collection_with_title]).to be_nil expect(doc_hash[:display_type]).to be_nil end context 'collection field' do it 'is added field to doc hash' do - doc_hash = GDor::Indexer::SolrDocHash.new({}) @indexer.add_coll_info(doc_hash, @coll_druids_array) expect(doc_hash[:collection]).to match_array [@coll_druid_from_test_config] end it 'adds two values to doc_hash when object belongs to two collections' do coll_druid1 = 'oo111oo2222' @@ -284,11 +280,10 @@ expect(doc_hash[:collection_with_title]).to match_array ["#{coll_druid}-|-zzz"] end it 'adds two values to doc_hash when object belongs to two collections' do coll_druid1 = 'oo111oo2222' coll_druid2 = 'oo333oo4444' - doc_hash = GDor::Indexer::SolrDocHash.new({}) @indexer.add_coll_info(doc_hash, [double(druid: coll_druid1, bare_druid: coll_druid1, public_xml: @ng_pub_xml, identity_md_obj_label: 'foo'), double(druid: coll_druid2, bare_druid: coll_druid2, public_xml: @ng_pub_xml, identity_md_obj_label: 'bar')]) expect(doc_hash[:collection_with_title]).to match_array ["#{coll_druid1}-|-foo", "#{coll_druid2}-|-bar"] end end @@ -345,29 +340,29 @@ subject do @indexer.email_report_body end it 'email body includes coll id' do - expect(subject).to match /testcoll indexed coll record is: ww121ss5000/ + expect(subject).to match(/testcoll indexed coll record is: ww121ss5000/) end it 'email body includes coll title' do - expect(subject).to match /coll title: testcoll title/ + expect(subject).to match(/coll title: testcoll title/) end it 'email body includes failed to index druids' do @indexer.instance_variable_set(:@druids_failed_to_ix, %w(a b)) - expect(subject).to match /records that may have failed to index: \na\nb\n\n/ + expect(subject).to match(/records that may have failed to index: \na\nb\n\n/) end it 'email body include validation messages' do @indexer.instance_variable_set(:@validation_messages, ['this is a validation message']) - expect(subject).to match /this is a validation message/ + expect(subject).to match(/this is a validation message/) end it 'email includes reference to full log' do - expect(subject).to match /full log is at gdor_indexer\/shared\/spec\/test_logs\/testcoll\.log/ + expect(subject).to match(/full log is at gdor_indexer\/shared\/spec\/test_logs\/testcoll\.log/) end end describe '#email_results' do before :each do @@ -376,10 +371,10 @@ allow(@indexer).to receive(:email_report_body).and_return('Report Body') end it 'has an appropriate subject' do expect(@indexer).to receive(:send_email) do |_to, opts| - expect(opts[:subject]).to match /is finished/ + expect(opts[:subject]).to match(/is finished/) end @indexer.email_results end