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

pulibrary / pdc_discovery / 79cc0f1f-db9d-4052-80b2-03da9188224f

08 Nov 2024 05:55PM UTC coverage: 96.43% (+0.2%) from 96.253%
79cc0f1f-db9d-4052-80b2-03da9188224f

Pull #714

circleci

jrgriffiniii
Addressing the failing tests for DSpace and DescribeIndexer
Pull Request #714: Improving test consistency for DSpace and DescribeIndexer

53 of 59 new or added lines in 6 files covered. (89.83%)

5 existing lines in 2 files now uncovered.

3593 of 3726 relevant lines covered (96.43%)

289.17 hits per line

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

88.8
/spec/requests/catalog_spec.rb
1
# frozen_string_literal: true
2
require 'rails_helper'
1✔
3

4
RSpec.describe "Catalog", type: :request do
1✔
5
  context "when indexing from DSpace" do
1✔
6
    let(:dspace_fixtures) { File.read(File.join(fixture_paths.first, 'spherical_torus.xml')) }
1✔
7
    let(:indexer) do
1✔
8
      DspaceIndexer.new(dspace_fixtures)
×
9
    end
10

11
    before do
1✔
12
      indexer.index
×
13
    end
14

15
    after do
1✔
NEW
16
      indexer.delete!(query: "*:*")
×
17
    end
18

19
    describe "GET /doi/:doi" do
1✔
20
      let(:doi) { "doi:10.1088/0029-5515/57/1/016034" }
1✔
21
      let(:document_id) { "84912" }
1✔
22

23
      xit "retrieves Solr Documents using a given DOI" do
1✔
24
        get "/doi/#{doi}"
×
25
        expect(response).to redirect_to(solr_document_path(id: document_id))
×
26
      end
27

28
      context "when passing only a segment of the DOI" do
1✔
29
        let(:doi) { "10.1088/0029-5515/57/1/016034" }
1✔
30

31
        xit "retrieves Solr Documents using a given DOI" do
1✔
32
          get "/doi/#{doi}"
×
33
          expect(response).to redirect_to(solr_document_path(id: document_id))
×
34
        end
35
      end
36
    end
37

38
    describe "GET /ark/:ark" do
1✔
39
      let(:ark) { "http://arks.princeton.edu/ark:/88435/dsp01kd17cw34n" }
1✔
40
      let(:document_id) { "84912" }
1✔
41
      xit "retrieves Solr Documents using a given ARK" do
1✔
42
        get "/ark/#{ark}"
×
43
        expect(response).to redirect_to(solr_document_path(id: document_id))
×
44
      end
45

46
      context "when passing only a segment of the ARK" do
1✔
47
        let(:ark) { "88435/dsp01kd17cw34n" }
1✔
48

49
        xit "retrieves Solr Documents using a given ARK" do
1✔
50
          get "/ark/#{ark}"
×
51
          expect(response).to redirect_to(solr_document_path(id: document_id))
×
52
        end
53
      end
54
    end
55
  end
56

57
  context "when indexing from PDC Describe" do
1✔
58
    context "when two DOI values are present" do
1✔
59
      let(:resource1) { file_fixture("sowing_the_seeds.json").read }
4✔
60
      let(:bitklavier_binaural_json) { file_fixture("bitklavier_binaural.json").read }
4✔
61
      let(:bitklavier_binaural) do
1✔
62
        response_body = bitklavier_binaural_json
3✔
63
        json_response = JSON.parse(response_body)
3✔
64
        json_resource = json_response["resource"]
3✔
65
        json_titles = json_resource["titles"]
3✔
66
        json_title = json_titles.first
3✔
67
        json_title["title"] = "test title"
3✔
68
        json_response.to_json
3✔
69
      end
70
      let(:doi) { "10.34770/r75s-9j74" }
2✔
71
      let(:document_id) { "doi-10-34770-r75s-9j74" }
2✔
72
      let(:rss_feed) { file_fixture("works.rss").read }
4✔
73
      let(:rss_url_string) { "https://pdc-describe-prod.princeton.edu/describe/works.rss" }
4✔
74
      let(:indexer) { DescribeIndexer.new(rss_url: rss_url_string) }
4✔
75

76
      before do
1✔
77
        # Blacklight.default_index.connection.delete_by_query("*:*")
78
        # Blacklight.default_index.connection.commit
79
        indexer.delete!(query: "*:*")
3✔
80
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works.rss")
3✔
81
          .to_return(status: 200, body: rss_feed)
82
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/6.json")
3✔
83
          .to_return(status: 200, body: resource1, headers: {})
84
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/20.json")
3✔
85
          .to_return(status: 200, body: bitklavier_binaural, headers: {})
86

87
        indexer.index
3✔
88
      end
89

90
      it "defaults to the Solr Documents with 'pdc_describe' within the 'data_source' field" do
1✔
91
        get "/doi/#{doi}"
1✔
92
        expect(response).to redirect_to(solr_document_path(id: document_id))
1✔
93
        follow_redirect!
1✔
94
        expect(response.body).to include("test title")
1✔
95
      end
96

97
      describe "#show" do
1✔
98
        it "shows the catalog" do
1✔
99
          document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
1✔
100
          get "/catalog/#{document.id}", params: { format: "json" }
1✔
101
          expect(response.status).to eq(200)
1✔
102
        end
103
      end
104

105
      describe "#bibtex" do
1✔
106
        it "returns citations" do
1✔
107
          document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
1✔
108
          get "/catalog/#{document.id}/bibtex", params: { id: document.id }
1✔
109
          expect(response.status).to eq(200)
1✔
110
        end
111
      end
112
    end
113
  end
114

115
  context "when a connection error is encountered while trying to access the Solr endpoint" do
1✔
116
    let(:document_id) { "84912" }
4✔
117
    let(:repository) { instance_double(Blacklight::Solr::Repository) }
4✔
118
    let(:repository2) { instance_double(Blacklight::Solr::Repository) }
4✔
119
    let(:search_service) { instance_double(Blacklight::SearchService) }
4✔
120
    let(:search_service2) { instance_double(Blacklight::SearchService) }
4✔
121
    let(:ping) { true }
2✔
122

123
    before do
1✔
124
      allow(search_service2).to receive(:fetch).and_return(nil)
3✔
125
      allow(repository2).to receive(:ping).and_return(ping)
3✔
126
      allow(repository2).to receive(:search).and_return(nil)
3✔
127
      allow(search_service2).to receive(:repository).and_return(repository2)
3✔
128

129
      allow(repository).to receive(:ping).and_return(ping)
3✔
130
      allow(search_service).to receive(:repository).and_return(repository)
3✔
131

132
      allow(Blacklight::SearchService).to receive(:new).and_return(search_service, search_service2)
3✔
133
    end
134

135
    context "when Solr is not at all accessible for the Blacklight client" do
1✔
136
      let(:ping) { false }
2✔
137

138
      before do
1✔
139
        allow(search_service).to receive(:fetch).and_raise(Blacklight::Exceptions::ECONNREFUSED)
1✔
140
        get "/catalog/#{document_id}"
1✔
141
      end
142

143
      it "responds with an error view" do
1✔
144
        expect(response).to redirect_to("/errors/network_error")
1✔
145
      end
146
    end
147

148
    context "when Solr is not at all accessible for the RSolr client" do
1✔
149
      let(:ping) { false }
2✔
150
      let(:uri) { instance_double(URI::HTTP) }
2✔
151
      let(:request) { double(Net::HTTPRequest) }
2✔
152

153
      before do
1✔
154
        allow(uri).to receive(:user)
1✔
155
        allow(uri).to receive(:password)
1✔
156
        allow(uri).to receive(:dup).and_return(uri)
1✔
157
        allow(request).to receive(:[]).with(:uri).and_return(uri)
1✔
158
        allow(request).to receive(:[]=)
1✔
159
        allow(request).to receive(:get?)
1✔
160
        allow(search_service).to receive(:fetch).and_raise(RSolr::Error::ConnectionRefused, request)
1✔
161
        get "/catalog/#{document_id}"
1✔
162
      end
163

164
      it "responds with an error view" do
1✔
165
        expect(response).to redirect_to("/errors/network_error")
1✔
166
      end
167
    end
168

169
    context "when Solr is accessible" do
1✔
170
      let(:document) { SolrDocument.new(id: document_id) }
2✔
171

172
      before do
1✔
173
        allow(search_service).to receive(:fetch).and_raise(Blacklight::Exceptions::ECONNREFUSED)
1✔
174
        allow(search_service).to receive(:fetch).and_return([nil, document])
1✔
175
        get "/catalog/#{document_id}"
1✔
176
      end
177

178
      it "retrieves Solr Documents using a given DOI" do
1✔
179
        expect(response.status).to eq(200)
1✔
180
      end
181
    end
182
  end
183

184
  describe "#show" do
1✔
185
    xit "shows the catalog" do
1✔
186
      document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
×
UNCOV
187
      get "/catalog/#{document.id}", params: { format: "json" }
×
UNCOV
188
      expect(response.status).to eq(200)
×
189
    end
190
  end
191

192
  describe "#bibtex" do
1✔
193
    it "returns citations" do
1✔
194
      document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
1✔
195
      get "/catalog/#{document.id}/bibtex", params: { id: document.id }
1✔
196
      expect(response.status).to eq(200)
1✔
197
    end
198
  end
199
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