• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_discovery / 2ac48f63-1531-4c4d-b0c7-21f5447613b7

12 Sep 2024 05:36PM UTC coverage: 97.189% (+0.1%) from 97.054%
2ac48f63-1531-4c4d-b0c7-21f5447613b7

push

circleci

web-flow
Fix coverage reporting by using coveralls circleci orb (#680)

3457 of 3557 relevant lines covered (97.19%)

286.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.59
/spec/system/pppl_indexing_spec.rb
1
# frozen_string_literal: true
2
require 'rails_helper'
1✔
3

4
describe 'PPPL research data indexing', type: :system do
1✔
5
  let(:processed) do
1✔
6
    indexer.process(dspace_xml_io)
6✔
7
    indexer.complete
6✔
8
  end
9
  let(:query_sort) { 'internal_id_lsi desc' }
7✔
10
  let(:blacklight_index) { Blacklight.default_index }
7✔
11
  let(:blacklight_connection) { blacklight_index.connection }
7✔
12
  let(:documents) do
1✔
13
    processed
6✔
14
    http_response = blacklight_connection.select(q: '*:*', params: { rows: 100, sort: query_sort })
6✔
15
    solr_response = http_response['response']
6✔
16
    solr_response['docs']
6✔
17
  end
18
  let(:output) { TrajectOutput.new }
1✔
19
  let(:indexer) do
1✔
20
    Traject::Indexer::NokogiriIndexer.new.tap do |i|
6✔
21
      i.load_config_file(Rails.root.join('lib', 'traject', 'dataspace_research_data_config.rb'))
6✔
22
    end
23
  end
24
  let(:dspace_xml) do
1✔
25
    File.join(fixture_path, 'astrophysical_sciences.xml')
6✔
26
  end
27
  let(:dspace_xml_io) { File.read(dspace_xml) }
7✔
28
  let(:nokogiri_reader) do
1✔
29
    Traject::NokogiriReader.new(dspace_xml_io, indexer.settings)
×
30
  end
31
  let(:records) do
1✔
32
    nokogiri_reader.to_a
×
33
  end
34

35
  before do
1✔
36
    class TrajectOutput < Array
6✔
37
      def put(context)
6✔
38
        push(context.output_hash)
×
39
      end
40
    end
41

42
    blacklight_connection.delete_by_query('*:*')
6✔
43
    blacklight_connection.commit
6✔
44
  end
45

46
  after do
1✔
47
    Object.send(:remove_const, :TrajectOutput)
6✔
48
    blacklight_connection.delete_by_query('*:*')
6✔
49
    blacklight_connection.commit
6✔
50
  end
51

52
  context "when the XML documents has been indexed" do
1✔
53
    let(:first_document) { documents.first }
4✔
54
    let(:last_document) { documents.last }
4✔
55

56
    before do
1✔
57
      documents
6✔
58
    end
59

60
    it 'indexes all XML documents' do
1✔
61
      expect(documents).not_to be_empty
1✔
62
      expect(documents.length).to eq(39)
1✔
63
    end
64

65
    it 'indexes the IDs' do
1✔
66
      expect(first_document).to include('id')
1✔
67
      expect(first_document['id']).to eq('104131')
1✔
68
      expect(last_document).to include('id')
1✔
69
      expect(last_document['id']).to eq('777')
1✔
70
    end
71

72
    context "when indexing XML documents in a different initial order" do
1✔
73
      let(:records) do
1✔
74
        values = nokogiri_reader.to_a
×
75
        values.shuffle
×
76
      end
77

78
      it 'orders the document IDs consistently' do
1✔
79
        expect(first_document).to include('id')
1✔
80
        expect(first_document['id']).to eq('104131')
1✔
81
        expect(last_document).to include('id')
1✔
82
        expect(last_document['id']).to eq('777')
1✔
83
      end
84
    end
85

86
    it 'indexes the titles' do
1✔
87
      expect(first_document).to include('title_tesim')
1✔
88
      titles = first_document['title_tesim']
1✔
89
      expect(titles).not_to be_empty
1✔
90
      expect(titles.length).to eq(1)
1✔
91
      first_title = titles.first
1✔
92
      expect(first_title).to eq('The Dark Side of the Gravitational Force: Lessons from Astrophysics on Gravity, Black Holes, and Dark Matter')
1✔
93
    end
94

95
    it 'indexes the DOI into the `referenced_by` field' do
1✔
96
      expect(documents.length).to eq(39)
1✔
97
      third_document = documents[-3]
1✔
98
      expect(third_document).to include('referenced_by_ssim')
1✔
99
      references = third_document['referenced_by_ssim']
1✔
100
      expect(references).not_to be_empty
1✔
101
      reference = references.first
1✔
102
      expect(reference).to eq('https://arxiv.org/abs/1903.06605')
1✔
103
    end
104

105
    it 'indexes the file metadata' do
1✔
106
      expect(last_document).to include('files_ss')
1✔
107
      files_values = last_document['files_ss']
1✔
108
      files = JSON.parse(files_values)
1✔
109

110
      expect(files.count).to eq(1)
1✔
111
      first_file = files.first
1✔
112
      expect(first_file["name"]).to eq('Sironi_princeton_0181D_10002.pdf')
1✔
113
    end
114
  end
115
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc