spec/unit/indexer_spec.rb in gdor-indexer-0.7.1 vs spec/unit/indexer_spec.rb in gdor-indexer-0.8.0

- old
+ new

@@ -226,16 +226,16 @@ 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) })) + 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' })) + 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 @@ -244,13 +244,11 @@ 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 do - @coll_druids_array = [collection] - end + let(:coll_druids_array) { [collection] } let(:doc_hash) { GDor::Indexer::SolrDocHash.new({}) } it 'adds no collection field values to doc_hash if there are none' do @indexer.add_coll_info(doc_hash, nil) expect(doc_hash[:collection]).to be_nil @@ -258,11 +256,11 @@ expect(doc_hash[:display_type]).to be_nil end context 'collection field' do it 'is added field to doc hash' do - @indexer.add_coll_info(doc_hash, @coll_druids_array) + @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' coll_druid2 = 'oo333oo4444' @@ -291,22 +289,22 @@ before do @indexer.coll_display_types_from_items(collection) end it 'gets single item display_type for single collection (and no dups)' do allow(@indexer).to receive(:identity_md_obj_label) - doc_hash = GDor::Indexer::SolrDocHash.new({ display_type: 'image' }) - @indexer.add_coll_info(doc_hash, @coll_druids_array) - doc_hash = GDor::Indexer::SolrDocHash.new({ display_type: 'image' }) - @indexer.add_coll_info(doc_hash, @coll_druids_array) + doc_hash = GDor::Indexer::SolrDocHash.new(display_type: 'image') + @indexer.add_coll_info(doc_hash, coll_druids_array) + doc_hash = GDor::Indexer::SolrDocHash.new(display_type: 'image') + @indexer.add_coll_info(doc_hash, coll_druids_array) expect(@indexer.coll_display_types_from_items(collection)).to match_array ['image'] end it 'gets multiple formats from multiple items for single collection' do allow(@indexer).to receive(:identity_md_obj_label) - doc_hash = GDor::Indexer::SolrDocHash.new({ display_type: 'image' }) - @indexer.add_coll_info(doc_hash, @coll_druids_array) - doc_hash = GDor::Indexer::SolrDocHash.new({ display_type: 'file' }) - @indexer.add_coll_info(doc_hash, @coll_druids_array) + doc_hash = GDor::Indexer::SolrDocHash.new(display_type: 'image') + @indexer.add_coll_info(doc_hash, coll_druids_array) + doc_hash = GDor::Indexer::SolrDocHash.new(display_type: 'file') + @indexer.add_coll_info(doc_hash, coll_druids_array) expect(@indexer.coll_display_types_from_items(collection)).to match_array %w(image file) end end # coll_display_types_from_items end # add_coll_info @@ -358,11 +356,11 @@ @indexer.instance_variable_set(:@validation_messages, instance_double(File, rewind: 0, read: '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(%r{full log is at gdor_indexer/shared/spec/test_logs/testcoll\.log}) end end describe '#email_results' do before do @@ -373,27 +371,24 @@ it 'has an appropriate subject' do expect(@indexer).to receive(:send_email) do |_to, opts| expect(opts[:subject]).to match(/is finished/) end - @indexer.email_results end it 'sends the email to the notification list' do expect(@indexer).to receive(:send_email) do |to, _opts| expect(to).to eq @indexer.config.notification end - @indexer.email_results end it 'has the report body' do expect(@indexer).to receive(:send_email) do |_to, opts| expect(opts[:body]).to eq 'Report Body' end - @indexer.email_results end end describe '#send_email' do @@ -408,11 +403,11 @@ expect_any_instance_of(Mail::Message).to receive(:deliver!) do |mail| expect(mail.subject).to eq 'Subject' expect(mail.from).to match_array ['rspec'] expect(mail.body).to eq 'Body' end - @indexer.send_email 'notification-list@example.com', { from: 'rspec', subject: 'Subject', body: 'Body' } + @indexer.send_email 'notification-list@example.com', from: 'rspec', subject: 'Subject', body: 'Body' end end describe '#solr_client' do it 'defaults to the harvestdor-configured client' do @@ -420,10 +415,9 @@ end it 'can be set as an option' do solr_client = double @indexer = described_class.new(solr_client: solr_client) - expect(@indexer.solr_client).to eq solr_client end end # context "skip heartbeat" do