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

pulibrary / pdc_discovery / 57ef77d4-cc7e-4881-a755-33d8f6457b3b

20 Jun 2024 03:30PM UTC coverage: 97.013% (-0.03%) from 97.045%
57ef77d4-cc7e-4881-a755-33d8f6457b3b

Pull #629

circleci

jrgriffiniii
wip
Pull Request #629: Upgrading support for Ruby 3.3.2

3020 of 3113 relevant lines covered (97.01%)

292.11 hits per line

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

98.96
/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_path, 'spherical_torus.xml')) }
5✔
7
    let(:indexer) do
1✔
8
      DspaceIndexer.new(dspace_fixtures)
4✔
9
    end
10
    before do
1✔
11
      indexer.index
4✔
12
    end
13

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

18
      it "retrieves Solr Documents using a given DOI" do
1✔
19
        get "/doi/#{doi}"
1✔
20
        expect(response).to redirect_to(solr_document_path(id: document_id))
1✔
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" }
2✔
25

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

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

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

44
        it "retrieves Solr Documents using a given ARK" do
1✔
45
          get "/ark/#{ark}"
1✔
46
          expect(response).to redirect_to(solr_document_path(id: document_id))
1✔
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

129
      before do
1✔
130
        allow(search_service).to receive(:fetch).and_raise(RSolr::Error::ConnectionRefused)
1✔
131
        get "/catalog/#{document_id}"
1✔
132
      end
133

134
      it "responds with an error view" do
1✔
135
        expect(response).to redirect_to("/errors/network_error")
×
136
      end
137
    end
138

139
    context "when Solr is accessible" do
1✔
140
      let(:document) { SolrDocument.new(id: document_id) }
2✔
141

142
      before do
1✔
143
        allow(search_service).to receive(:fetch).and_raise(Blacklight::Exceptions::ECONNREFUSED)
1✔
144
        allow(search_service).to receive(:fetch).and_return([nil, document])
1✔
145
        get "/catalog/#{document_id}"
1✔
146
      end
147

148
      it "retrieves Solr Documents using a given DOI" do
1✔
149
        expect(response.status).to eq(200)
1✔
150
      end
151
    end
152
  end
153
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