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

pulibrary / orangelight / f87eb836-0f85-451e-aa5b-76b75f782b4f

23 Oct 2025 12:32PM UTC coverage: 95.332% (+0.04%) from 95.29%
f87eb836-0f85-451e-aa5b-76b75f782b4f

Pull #5254

circleci

sandbergja
Refactor: move Requestable creation out of Requests::Form

Prior to this commit, one of the Form class' many
responsibilities was to create many of the
Requestable instances needed by the Requests system.
It created four different kinds of Requestable, and
it was hard to trace the logic throughout the Form
class for each one of those four paths.

This commit takes a different approach: introducing
a factory class named RequestablesList, which
determines what type of Requestable to create,
then delegates the creation to one of four smaller
factories: AlmaItemsFactory, ScsbItemsFactory,
NoItemsFactory, and TooManyItemsFactory.
Pull Request #5254: Refactor: move Requestable creation out of Requests::Form

158 of 159 new or added lines in 7 files covered. (99.37%)

6147 of 6448 relevant lines covered (95.33%)

1499.66 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