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

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

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

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

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

26.79
/app/models/concerns/scsb.rb
1
module Scsb
1✔
2
  extend ActiveSupport::Concern
1✔
3

4
  # if id comes from 001 source is scsb
5
  # if id comes from 009 source is the owning library
6
  def items_by_id(id, source = 'scsb')
1✔
UNCOV
7
    request_body = scsb_bib_id_request(id, source)
×
UNCOV
8
    request_body_json = request_body.to_json
×
UNCOV
9
    scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/bibAvailabilityStatus', request_body_json))
×
10
  end
11

12
  # Retrieves items from the SCSB endpoint using a barcode
13
  def items_by_barcode(barcodes)
1✔
UNCOV
14
    request_body = scsb_barcode_request(barcodes)
×
UNCOV
15
    request_body_json = request_body.to_json
×
UNCOV
16
    scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/itemAvailabilityStatus', request_body_json))
×
17
  end
18

19
  def scsb_request_response_customize(scsb_request_response:)
1✔
UNCOV
20
    scsb_request_response.each do |r|
×
UNCOV
21
      r['itemAvailabilityStatus'] = 'Unavailable' if r['itemAvailabilityStatus'] == 'Not Available'
×
22
    end
23
  end
24

25
  def scsb_barcode_request(barcodes)
1✔
26
    {
UNCOV
27
      barcodes:
×
28
    }
29
  end
30

31
  def scsb_bib_id_request(id, source)
1✔
32
    {
UNCOV
33
      bibliographicId: id,
×
34
      institutionId: source
35
    }
36
  end
37

38
  def scsb_conn
1✔
UNCOV
39
    Faraday.new(url: scsb_server) do |faraday|
×
UNCOV
40
      faraday.request  :url_encoded # form-encode POST params
×
UNCOV
41
      faraday.response :logger unless Rails.env.test? # log requests to STDOUT
×
UNCOV
42
      faraday.adapter  Faraday.default_adapter # make requests with Net::HTTP
×
43
    end
44
  end
45

46
  def parse_scsb_message(message)
1✔
UNCOV
47
    parsed = JSON.parse(message)
×
48
    parsed.instance_of?(Hash) ? parsed.with_indifferent_access : parsed
×
49
  rescue JSON::ParserError
UNCOV
50
    Rails.logger.error("Failed to parse a message from the SCSB server: #{message}")
×
UNCOV
51
    {}
×
52
  end
53

54
  def scsb_response_json(response)
1✔
UNCOV
55
    if response.status != 200
×
UNCOV
56
      Rails.logger.error("The request to the SCSB server failed: #{response.body}")
×
UNCOV
57
      return {}
×
58
    end
59

UNCOV
60
    JSON.parse(response.body)
×
61
  rescue JSON::ParserError
UNCOV
62
    Rails.logger.error("Failed to parse the response from the SCSB server: #{response.body}")
×
UNCOV
63
    {}
×
64
  end
65

66
  def parse_scsb_response(response)
1✔
UNCOV
67
    parsed = scsb_response_json(response)
×
UNCOV
68
    parsed.instance_of?(Hash) ? parsed.with_indifferent_access : parsed
×
69
  end
70

71
  private
1✔
72

73
    def scsb_auth_key
1✔
UNCOV
74
      if Rails.env.test?
×
UNCOV
75
        'TESTME'
×
76
      else
77
        ENV['SCSB_AUTH_KEY']
×
78
      end
79
    end
80

81
    def scsb_server
1✔
UNCOV
82
      if Rails.env.test?
×
UNCOV
83
        'https://test.api.com/'
×
84
      else
85
        ENV['SCSB_SERVER']
×
86
      end
87
    end
88

89
    def scsb_request(request_path, request_body)
1✔
UNCOV
90
      response = self.scsb_conn.post do |req|
×
UNCOV
91
        req.url request_path
×
UNCOV
92
        req.headers['Content-Type'] = 'application/json'
×
UNCOV
93
        req.headers['Accept'] = 'application/json'
×
UNCOV
94
        req.headers['api_key'] = scsb_auth_key
×
UNCOV
95
        req.body = request_body
×
96
      end
UNCOV
97
      parse_scsb_response(response)
×
98
    rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
UNCOV
99
      Rails.logger.warn("#{self.class}: Connection error for #{scsb_server}")
×
UNCOV
100
      raise e
×
101
    end
102
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