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

pulibrary / pdc_discovery / c22943e7-fec0-4630-b91e-844cc844ccdc

08 Nov 2024 02:14PM UTC coverage: 96.253% (-1.0%) from 97.231%
c22943e7-fec0-4630-b91e-844cc844ccdc

Pull #710

circleci

20LM22
xit 302 error
Pull Request #710: Runs tests in random order

7 of 8 new or added lines in 2 files covered. (87.5%)

40 existing lines in 3 files now uncovered.

3545 of 3683 relevant lines covered (96.25%)

292.16 hits per line

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

88.6
/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✔
UNCOV
8
      DspaceIndexer.new(dspace_fixtures)
×
9
    end
10
    before do
1✔
UNCOV
11
      indexer.index
×
12
    end
13

14
    describe "GET /doi/:doi" do
1✔
15
      let(:doi) { "doi:10.1088/0029-5515/57/1/016034" }
1✔
16
      let(:document_id) { "84912" }
1✔
17

18
      xit "retrieves Solr Documents using a given DOI" do
1✔
UNCOV
19
        get "/doi/#{doi}"
×
UNCOV
20
        expect(response).to redirect_to(solr_document_path(id: document_id))
×
21
      end
22

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

26
        xit "retrieves Solr Documents using a given DOI" do
1✔
UNCOV
27
          get "/doi/#{doi}"
×
UNCOV
28
          expect(response).to redirect_to(solr_document_path(id: document_id))
×
29
        end
30
      end
31
    end
32

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

41
      context "when passing only a segment of the ARK" do
1✔
42
        let(:ark) { "88435/dsp01kd17cw34n" }
1✔
43

44
        xit "retrieves Solr Documents using a given ARK" do
1✔
UNCOV
45
          get "/ark/#{ark}"
×
UNCOV
46
          expect(response).to redirect_to(solr_document_path(id: document_id))
×
47
        end
48
      end
49
    end
50
  end
51

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

71
      before do
1✔
72
        Blacklight.default_index.connection.delete_by_query("*:*")
1✔
73
        Blacklight.default_index.connection.commit
1✔
74
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works.rss")
1✔
75
          .to_return(status: 200, body: rss_feed)
76
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/6.json")
1✔
77
          .to_return(status: 200, body: resource1, headers: {})
78
        stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/20.json")
1✔
79
          .to_return(status: 200, body: bitklavier_binaural, headers: {})
80

81
        indexer.index
1✔
82
      end
83

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

93
  context "when a connection error is encountered while trying to access the Solr endpoint" do
1✔
94
    let(:document_id) { "84912" }
4✔
95
    let(:repository) { instance_double(Blacklight::Solr::Repository) }
4✔
96
    let(:repository2) { instance_double(Blacklight::Solr::Repository) }
4✔
97
    let(:search_service) { instance_double(Blacklight::SearchService) }
4✔
98
    let(:search_service2) { instance_double(Blacklight::SearchService) }
4✔
99
    let(:ping) { true }
2✔
100

101
    before do
1✔
102
      allow(search_service2).to receive(:fetch).and_return(nil)
3✔
103
      allow(repository2).to receive(:ping).and_return(ping)
3✔
104
      allow(repository2).to receive(:search).and_return(nil)
3✔
105
      allow(search_service2).to receive(:repository).and_return(repository2)
3✔
106

107
      allow(repository).to receive(:ping).and_return(ping)
3✔
108
      allow(search_service).to receive(:repository).and_return(repository)
3✔
109

110
      allow(Blacklight::SearchService).to receive(:new).and_return(search_service, search_service2)
3✔
111
    end
112

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

116
      before do
1✔
117
        allow(search_service).to receive(:fetch).and_raise(Blacklight::Exceptions::ECONNREFUSED)
1✔
118
        get "/catalog/#{document_id}"
1✔
119
      end
120

121
      it "responds with an error view" do
1✔
122
        expect(response).to redirect_to("/errors/network_error")
1✔
123
      end
124
    end
125

126
    context "when Solr is not at all accessible for the RSolr client" do
1✔
127
      let(:ping) { false }
2✔
128
      let(:uri) { instance_double(URI::HTTP) }
2✔
129
      let(:request) { double(Net::HTTPRequest) }
2✔
130

131
      before do
1✔
132
        allow(uri).to receive(:user)
1✔
133
        allow(uri).to receive(:password)
1✔
134
        allow(uri).to receive(:dup).and_return(uri)
1✔
135
        allow(request).to receive(:[]).with(:uri).and_return(uri)
1✔
136
        allow(request).to receive(:[]=)
1✔
137
        allow(request).to receive(:get?)
1✔
138
        allow(search_service).to receive(:fetch).and_raise(RSolr::Error::ConnectionRefused, request)
1✔
139
        get "/catalog/#{document_id}"
1✔
140
      end
141

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

147
    context "when Solr is accessible" do
1✔
148
      let(:document) { SolrDocument.new(id: document_id) }
2✔
149

150
      before do
1✔
151
        allow(search_service).to receive(:fetch).and_raise(Blacklight::Exceptions::ECONNREFUSED)
1✔
152
        allow(search_service).to receive(:fetch).and_return([nil, document])
1✔
153
        get "/catalog/#{document_id}"
1✔
154
      end
155

156
      it "retrieves Solr Documents using a given DOI" do
1✔
157
        expect(response.status).to eq(200)
1✔
158
      end
159
    end
160
  end
161

162
  describe "#show" do
1✔
163
    xit "shows the catalog" do
1✔
UNCOV
164
      document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
×
UNCOV
165
      get "/catalog/#{document.id}", params: { format: "json" }
×
UNCOV
166
      expect(response.status).to eq(200)
×
167
    end
168
  end
169

170
  describe "#bibtex" do
1✔
171
    it "returns citations" do
1✔
172
      document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
1✔
173
      get "/catalog/#{document.id}/bibtex", params: { id: document.id }
1✔
174
      expect(response.status).to eq(200)
1✔
175
    end
176
  end
177
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