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

pulibrary / orangelight / 68f73718-8b3c-4b64-9464-233d807f755d

23 Oct 2025 12:20AM UTC coverage: 95.275%. Remained the same
68f73718-8b3c-4b64-9464-233d807f755d

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

160 of 164 new or added lines in 7 files covered. (97.56%)

1 existing line in 1 file now uncovered.

6150 of 6455 relevant lines covered (95.27%)

1498.04 hits per line

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

98.28
/app/models/requests/requestables_list/alma_items_factory.rb
1
# frozen_string_literal: true
2
module Requests
3✔
3
  class RequestablesList
3✔
4
    # This factory is responsible for creating an array of Requestables for items from Alma
5
    # (which will have a MFHD).  This includes Princeton-owned titles that are at ReCAP.
6
    class AlmaItemsFactory
3✔
7
      include Bibdata
3✔
8
      # :reek:LongParameterList
9
      # rubocop:disable Metrics/ParameterLists
10
      def initialize(document:, holdings:, items:, location:, mfhd:, patron:)
3✔
11
        @document = document
258✔
12
        @holdings = holdings
258✔
13
        @items = items
258✔
14
        @location = location
258✔
15
        @mfhd = mfhd
258✔
16
        @patron = patron
258✔
17
      end
18

19
      # rubocop:enable Metrics/ParameterLists
20

21
      def call
3✔
22
        add_scsb_availability_data_to_items
258✔
23
        items.reduce([]) do |requestables, (holding_id, mfhd_items)|
258✔
24
          requestables.concat requestable_mfhd_items(mfhd_items:) if mfhd == holding_id
258✔
25
        end
26
      end
27

28
        private
3✔
29

30
          attr_accessor :items
3✔
31

32
          def add_scsb_availability_data_to_items
3✔
33
            items[mfhd] = RecapItemAvailability.new(id: system_id, scsb_location:).items_with_availability(items: items[mfhd]) if recap?
258✔
34
          end
35

36
          def too_many_items?
3✔
NEW
37
            holding.items&.count&.> 500
×
38
          end
39

40
          def location_code
3✔
41
            location['code'] if location
2,170✔
42
          end
43

44
          def scsb_location
3✔
45
            document['location_code_s'].first
73✔
46
          end
47

48
          def requestable_mfhd_items(mfhd_items:)
3✔
49
            if mfhd_items.empty?
258✔
50
              NoItemsFactory.new(document:, holding:, location:, patron:).call
42✔
51
            else
52
              mfhd_items.map { |item| requestable_mfhd_item(item) }
2,393✔
53
            end.compact
54
          end
55

56
          def requestable_mfhd_item(item)
3✔
57
            return if item['on_reserve'] == 'Y'
2,177✔
58
            item_current_location = item_current_location(item)
2,170✔
59

60
            Requests::Requestable.new(
2,170✔
61
              bib: document,
62
              holding: holding_data(item, item_current_location['code']),
63
              item: Item.new(item.with_indifferent_access),
64
              location: item_current_location,
65
              patron:
66
            )
67
          end
68

69
          def holding_data(item, item_location_code)
3✔
70
            holding_data = if item["in_temp_library"] && item["temp_location_code"] != "RES_SHARE$IN_RS_REQ"
2,170✔
71
                             holdings[item_location_code]
6✔
72
                           else
73
                             holdings[mfhd]
2,164✔
74
                           end
75
            Holding.new(mfhd_id: mfhd.to_sym.to_s, holding_data:)
2,170✔
76
          end
77

78
          # Calls Requests::BibdataService to get the delivery_locations
79
          # :reek:TooManyStatements
80
          def item_current_location(item)
3✔
81
            item_location_code = if item['in_temp_library']
2,170✔
82
                                   item['temp_location_code']
7✔
83
                                 else
84
                                   item['location']
2,163✔
85
                                 end
86
            current_location = if item_location_code == location_code
2,170✔
87
                                 location
2,160✔
88
                               else
89
                                 temp_locations.retrieve(item_location_code)
10✔
90
                               end
91
            current_location_object = Location.new current_location
2,170✔
92
            current_location["delivery_locations"] = current_location_object.build_delivery_locations if current_location_object.delivery_locations.present?
2,170✔
93
            current_location
2,170✔
94
          end
95

96
          attr_reader :document, :holdings, :location, :mfhd, :patron
3✔
97

98
          # Is this Princeton title at recap?
99
          def recap?
3✔
100
            return false if location.blank?
258✔
101
            location[:remote_storage] == "recap_rmt"
244✔
102
          end
103

104
          def system_id
3✔
105
            document.id
73✔
106
          end
107

108
          def holding
3✔
109
            Holding.new(mfhd_id: mfhd, holding_data: holdings[mfhd])
42✔
110
          end
111

112
          def temp_locations
3✔
113
            @temp_locations ||= TempLocationCache.new
10✔
114
          end
115
    end
116
  end
117
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