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

pulibrary / pdc_discovery / fa8e4699-854f-4a43-adc1-7e92603d9eea

pending completion
fa8e4699-854f-4a43-adc1-7e92603d9eea

Pull #441

circleci

Hector Correa
Rubocop nitpicking
Pull Request #441: Indexing to a new collection

70 of 70 new or added lines in 2 files covered. (100.0%)

2073 of 2216 relevant lines covered (93.55%)

170.04 hits per line

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

74.26
/spec/lib/describe_indexer_spec.rb
1
# frozen_string_literal: true
2

3
# rubocop:disable Metrics/BlockLength
4
RSpec.describe DescribeIndexer do
1✔
5
  describe 'indexing a single record' do
1✔
6
    let(:single_item) { file_fixture("bitklavier_binaural.json").read }
17✔
7
    let(:indexer) do
1✔
8
      described_class.new(rss_url: "file://whatever.rss")
16✔
9
    end
10
    let(:indexed_record) do
1✔
11
      Blacklight.default_index.connection.delete_by_query("*:*")
16✔
12
      Blacklight.default_index.connection.commit
16✔
13
      indexer.index_one(single_item)
16✔
14
      response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
×
15
      response["response"]["docs"].first
×
16
    end
17

18
    context "basic fields" do
1✔
19
      ##
20
      # The id is based on the DOI
21
      # A doi of 10.34770/r75s-9j74 will become doi-10-34770-r75s-9j74
22
      it "id" do
1✔
23
        expect(indexed_record["id"]).to eq "doi-10-34770-r75s-9j74"
1✔
24
      end
25

26
      it "stores a copy of the full JSON in CDATA" do
1✔
27
        stored_json = indexed_record["pdc_describe_json_ss"]
1✔
28
        parsed_json = JSON.parse(stored_json)
×
29
        expect(parsed_json["resource"]["titles"][0]["title"]).to eq "bitKlavier Grand Sample Library—Binaural Mic Image"
×
30
      end
31

32
      it "author" do
1✔
33
        expect(indexed_record["author_tesim"]).to eq ['Trueman, Daniel']
1✔
34
      end
35

36
      it "description" do
1✔
37
        description = "The bitKlavier Grand consists"
1✔
38
        expect(indexed_record["description_tsim"].first.include?(description)).to be true
1✔
39
      end
40

41
      it "contributors" do
1✔
42
        expect(indexed_record["contributor_tsim"].include?("Villalta, Andrés")).to eq true
1✔
43
        expect(indexed_record["contributor_tsim"].include?("Chou, Katie")).to eq true
×
44
        expect(indexed_record["contributor_tsim"].include?("Ayres, Christien")).to eq true
×
45
        expect(indexed_record["contributor_tsim"].include?("Wang, Matthew")).to eq true
×
46
      end
47

48
      it "title" do
1✔
49
        # title includes all titles
50
        main_title = "bitKlavier Grand Sample Library—Binaural Mic Image"
1✔
51
        alt_title = "alter title for bitKlavier"
1✔
52
        expect(indexed_record["title_tesim"].include?(main_title)).to eq true
1✔
53
        expect(indexed_record["title_tesim"].include?(alt_title)).to eq true
×
54
        # alt title does not include the main title
55
        expect(indexed_record["alternative_title_tesim"].include?(main_title)).to eq false
×
56
        expect(indexed_record["alternative_title_tesim"].include?(alt_title)).to eq true
×
57
      end
58

59
      it "rights" do
1✔
60
        expect(indexed_record["rights_name_ssi"]).to eq "GNU General Public License"
1✔
61
        expect(indexed_record["rights_uri_ssi"]).to eq "https://www.gnu.org/licenses/gpl-3.0.en.html"
×
62
      end
63

64
      it "keywords" do
1✔
65
        expect(indexed_record["subject_all_ssim"].include?("keyword1")).to eq true
1✔
66
        expect(indexed_record["subject_all_ssim"].include?("keyword2")).to eq true
×
67
        expect(indexed_record["subject_all_ssim"].include?("keyword3")).to eq true
×
68
      end
69

70
      it "collection tag" do
1✔
71
        expect(indexed_record["collection_tag_ssim"].include?("Humanities")).to eq true
1✔
72
        expect(indexed_record["collection_tag_ssim"].include?("Something else")).to eq true
×
73
      end
74

75
      it "community" do
1✔
76
        expect(indexed_record["community_name_ssi"]).to eq "Research Data"
1✔
77
      end
78

79
      it "genre_ssim" do
1✔
80
        expect(indexed_record["genre_ssim"].first).to eq "Dataset"
1✔
81
      end
82

83
      it "issue_date_ssim" do
1✔
84
        expect(indexed_record["issue_date_ssim"].first).to eq "2021"
1✔
85
      end
86

87
      it "publisher_ssim" do
1✔
88
        expect(indexed_record["publisher_ssim"].first).to eq "Princeton University"
1✔
89
      end
90

91
      xit 'referenced_by' do
1✔
92
        expect(result['referenced_by_ssim'].first).to eq 'https://arxiv.org/abs/1903.06605'
×
93
      end
94
    end
95

96
    context "uris" do
1✔
97
      it "stores full URL for ARK and DOI" do
1✔
98
        expect(indexed_record["uri_ssim"].include?("http://arks.princeton.edu/ark:/88435/dsp015999n653h")).to eq true
1✔
99
        expect(indexed_record["uri_ssim"].include?("https://doi.org/10.34770/r75s-9j74")).to eq true
×
100
      end
101
    end
102

103
    context "files" do
1✔
104
      it "stores file detailed information" do
1✔
105
        files = JSON.parse(indexed_record['files_ss'])
1✔
106
        file1 = files.find { |file| file["name"] == "file1.jpg" }
×
107
        file2 = files.find { |file| file["name"] == "file2.txt" }
×
108
        expect(file1["size"]).to eq "316781"
×
109
        expect(file1["url"]).to eq "https://g-5beea4.90d4e.bd7c.data.globus.org/pdc-describe-staging-postcuration/10.80021/3m1k-6036/122/file1.jpg"
×
110
        expect(file2["size"]).to eq "396003"
×
111
      end
112
    end
113

114
    context "all text catch all field" do
1✔
115
      it "indexes the file name in the all text catch all field" do
1✔
116
        files = JSON.parse(indexed_record['files_ss'])
1✔
117
        file_name = File.basename(files.first["name"])
×
118
        response = Blacklight.default_index.connection.get 'select', params: { q: file_name }
×
119
        expect(response["response"]["numFound"]).to eq 1
×
120

121
        response = Blacklight.default_index.connection.get 'select', params: { q: "non-existing-value" }
×
122
        expect(response["response"]["numFound"]).to eq 0
×
123
      end
124
    end
125
  end
126

127
  describe 'indexing an RSS feed from PDC Describe' do
1✔
128
    let(:rss_feed) { file_fixture("works.rss").read }
2✔
129
    let(:resource1) { file_fixture("bitklavier_binaural.json").read }
2✔
130
    let(:resource2) { file_fixture("sowing_the_seeds.json").read }
2✔
131
    let(:rss_url_string) { "https://pdc-describe-prod.princeton.edu/describe/works.rss" }
3✔
132
    let(:indexer) { described_class.new(rss_url: rss_url_string) }
3✔
133

134
    it "has a traject indexer" do
1✔
135
      expect(indexer.traject_indexer).to be_instance_of Traject::Indexer::NokogiriIndexer
1✔
136
    end
137

138
    context 'indexing to solr' do
1✔
139
      before do
1✔
140
        Blacklight.default_index.connection.delete_by_query("*:*")
1✔
141
        Blacklight.default_index.connection.commit
1✔
142
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works.rss")
1✔
143
          .to_return(status: 200, body: rss_feed, headers: {})
144
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/6.json")
1✔
145
          .to_return(status: 200, body: resource1, headers: {})
146
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/20.json")
1✔
147
          .to_return(status: 200, body: resource2, headers: {})
148
      end
149

150
      it "sends items to solr" do
1✔
151
        response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
1✔
152
        expect(response["response"]["numFound"]).to eq 0
1✔
153

154
        # If index_pdc_describe == false, do not index PDC Describe.
155
        # This is a safety measure so we don't index in production until we're ready
156
        # See config/pdc_discovery.yml to change this setting for real
157
        Rails.configuration.pdc_discovery.index_pdc_describe = false
1✔
158
        indexer.index
1✔
159
        response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
1✔
160
        expect(response["response"]["numFound"]).to eq 0
1✔
161

162
        # If index_pdc_describe == true, DO index PDC Describe.
163
        Rails.configuration.pdc_discovery.index_pdc_describe = true
1✔
164
        indexer.index
1✔
165
        response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
1✔
166
        expect(response["response"]["numFound"]).to eq 2
1✔
167
      end
168
    end
169
  end
170
end
171
# rubocop:enable Metrics/BlockLength
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