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

pulibrary / orangelight / a6d74097-7dd1-408b-8bb7-e85e5c0615d7

23 Oct 2025 02:16PM UTC coverage: 95.355% (+0.04%) from 95.311%
a6d74097-7dd1-408b-8bb7-e85e5c0615d7

push

circleci

web-flow
Merge pull request #5254 from pulibrary/factory

Refactor: move Requestable creation out of Requests::Form

160 of 161 new or added lines in 7 files covered. (99.38%)

6138 of 6437 relevant lines covered (95.35%)

1502.59 hits per line

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

97.06
/app/models/requests/requestables_list.rb
1
# frozen_string_literal: true
2
module Requests
3✔
3
  # This class is a factory that is responsible for creating
4
  # a list of Requestables based on the provided document and
5
  # holdings data
6
  class RequestablesList
3✔
7
    include Bibdata
3✔
8
    include Scsb
3✔
9

10
    def initialize(document:, holdings:, location:, mfhd:, patron:)
3✔
11
      @document = document
291✔
12
      @holdings = holdings
291✔
13
      @location = location
291✔
14
      @mfhd = mfhd
291✔
15
      @patron = patron
291✔
16
    end
17

18
    def to_a
3✔
19
      if document._source.blank?
297✔
20
        []
3✔
21
      elsif too_many_items?
294✔
22
        TooManyItemsFactory.new(document:, holding:, location:, patron:).call
5✔
23
      elsif document.scsb_record?
289✔
24
        ScsbItemsFactory.new(document:, holdings:, location:, patron:).call
31✔
25
      elsif items.present?
258✔
26
        AlmaItemsFactory.new(document:, holdings:, items:, location:, mfhd:, patron:).call
258✔
27
      else
NEW
28
        NoItemsFactory.new(document:, holding:, location:, patron:).call
×
29
      end
30
    end
31

32
    def too_many_items?
3✔
33
      holding.items&.count&.> 500
816✔
34
    end
35

36
    ## Loads item availability through the Request Bibdata service using the items_by_mfhd method
37
    # items_by_mfhd makes the availability call:
38
    # bibdata_conn.get "/bibliographic/#{system_id}/holdings/#{mfhd_id}/availability.json"
39
    # returns nil if there are no attached items
40
    # if mfhd set returns only items associated with that mfhd
41
    # if no mfhd returns items sorted by mfhd
42
    def items
3✔
43
      return nil unless system_id
518✔
44
      return nil if too_many_items?
518✔
45
      @items ||= begin
518✔
46
        mfhd_items = { mfhd => items_by_mfhd(system_id, mfhd) }
255✔
47
        mfhd_items.empty? ? nil : mfhd_items.with_indifferent_access
255✔
48
      end
49
    end
50

51
    private
3✔
52

53
      attr_reader :document, :holdings, :location, :mfhd, :patron
3✔
54

55
      def system_id
3✔
56
        document.id
773✔
57
      end
58

59
      def holding
3✔
60
        Holding.new(mfhd_id: mfhd, holding_data: holdings[mfhd])
821✔
61
      end
62
  end
63
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