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

pulibrary / orangelight / 7b4a0004-2bb4-48c0-af34-cba3fa475cc3

13 Oct 2025 05:28PM UTC coverage: 95.378% (-0.03%) from 95.409%
7b4a0004-2bb4-48c0-af34-cba3fa475cc3

Pull #5222

circleci

christinach
rename it_recap_annex_pickup? to valid_recap_annex_pickup?
Pull Request #5222: Allow standard circulating location materials to be picked up at multiple branches

58 of 61 new or added lines in 3 files covered. (95.08%)

2 existing lines in 1 file now uncovered.

6232 of 6534 relevant lines covered (95.38%)

1493.44 hits per line

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

87.89
/app/helpers/requests/application_helper.rb
1
# frozen_string_literal: true
2
# rubocop:disable Metrics/ModuleLength
3
module Requests
3✔
4
  module ApplicationHelper
3✔
5
    def format_email(email)
3✔
6
      email&.downcase
160✔
7
    end
8

9
    def format_label(key)
3✔
10
      label = key.to_s
×
11
      human_label = label.tr('_', ' ')
×
12
      formatted = human_label.split.map(&:capitalize).join(' ')
×
13
      formatted
×
14
    end
15

16
    def error_key_format(key)
3✔
17
      keys_to_ignore = ['items']
×
18
      format_label(key) unless keys_to_ignore.include? key.to_s
×
19
    end
20

21
    # array of error_keys
22
    def guest_user_error?(error_keys)
3✔
23
      user_errors = [:email, :user_name, :barcode]
×
24
      error_keys.any? { |item| user_errors.include? item }
×
25
    end
26

27
    def show_pick_up_service_options(requestable, mfhd_id)
3✔
28
      if requestable.on_shelf?
142✔
29
        display_on_shelf(requestable, mfhd_id)
70✔
30
      else
31
        display_requestable_list(requestable)
71✔
32
      end
33
    end
34

35
    def show_service_options(requestable, _mfhd_id)
3✔
36
      if requestable.no_services?
2✔
UNCOV
37
        content_tag(:div, "#{requestable.title} #{enum_copy_display(requestable.item)} #{sanitize(I18n.t('requests.no_services.brief_msg'))}", class: 'visually-hidden') +
×
38
          content_tag(:div, sanitize(I18n.t("requests.no_services.brief_msg")), class: 'service-item', aria: { hidden: true })
39
      elsif requestable.charged? && !requestable.aeon? && !requestable.ask_me?
2✔
40
        render partial: 'checked_out_options', locals: { requestable: }
1✔
41
      else
42
        display_requestable_list(requestable)
1✔
43
      end
44
    end
45

46
    def hidden_service_options(requestable, fill_in: false)
3✔
47
      return hidden_service_options_fill_in(requestable) if fill_in
131✔
48
      hidden = output_request_input(requestable)
120✔
49
      return hidden if hidden.present?
120✔
50

51
      if requestable.services.include? 'recap'
49✔
52
        recap_print_only_input requestable
40✔
53
      else
54
        request_input(requestable.services.first)
9✔
55
      end
56
    end
57

58
    def output_request_input(requestable)
3✔
59
      output = ""
120✔
60
      ['annex', 'pres', 'ppl', 'lewis', 'paging', 'on_order', 'on_shelf'].each do |type|
120✔
61
        next unless requestable.services.include?(type)
786✔
62
        output = request_input(type)
71✔
63
        break
71✔
64
      end
65
      output
120✔
66
    end
67

68
    # only requestable services that support "user-supplied volume info"
69
    def hidden_service_options_fill_in(requestable)
3✔
70
      if requestable.annex?
11✔
71
        request_input('annex')
2✔
72
      elsif requestable.services.include? 'recap_no_items'
9✔
73
        request_input('recap_no_items')
1✔
74
      else
75
        request_input('paging')
8✔
76
      end
77
    end
78

79
    def recap_print_only_input(requestable)
3✔
80
      content_tag(:fieldset, class: 'recap--print', id: "recap_group_#{requestable.preferred_request_id}") do
40✔
81
        concat hidden_field_tag "requestable[][type]", "", value: 'recap'
40✔
82
      end
83
    end
84

85
    # rubocop:disable Style/NumericPredicate
86
    def enum_copy_display(item)
3✔
87
      return "" if item.blank?
529✔
88
      [item.description, item.copy_value].join(" ").strip
527✔
89
    end
90
    # rubocop:enable Style/NumericPredicate
91

92
    def request_input(type)
3✔
93
      hidden_field_tag "requestable[][type]", "", value: type
97✔
94
    end
95

96
    def gfa_lookup(lib_code)
3✔
97
      if lib_code == "firestone"
6✔
98
        "PA"
×
99
      else
100
        lib = Requests::BibdataService.delivery_locations.select { |_key, hash| hash["library"]["code"] == lib_code }
144✔
101
        lib.keys.first.to_s
6✔
102
      end
103
    end
104

105
    def pick_up_classlist(requestable, collapse)
3✔
106
      class_list = "collapse request--print"
152✔
107
      class_list += " show" if !requestable.digitize? && !collapse
152✔
108
      class_list
152✔
109
    end
110

111
    # move this to requestable object
112
    # Default pick-ups should be available
113
    def pick_up_choices(requestable, default_pick_ups, collapse = false)
3✔
114
      content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}", class: pick_up_classlist(requestable, collapse)) do
139✔
115
        preferred_request_content_tag(requestable, requestable.pick_up_locations || default_pick_ups)
139✔
116
      end
117
    end
118

119
    def preferred_request_content_tag(requestable, default_pick_ups)
3✔
120
      (show_pick_up_service_options(requestable, nil) || "".html_safe) +
140✔
121
        content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}_card", class: "card card-body bg-light") do
122
          locs = pick_up_locations(requestable, default_pick_ups)
139✔
123
          # temporary changes issue 438
124
          name = 'requestable[][pick_up]'
139✔
125
          id = "requestable__pick_up_#{requestable.preferred_request_id}"
139✔
126
          if locs.size > 1
139✔
127
            select_tag name.to_s, options_for_select(locs.map { |loc| [loc[:label], { 'pick_up' => loc[:gfa_pickup], 'pick_up_location_code' => loc[:pick_up_location_code] }.to_json] }), prompt: I18n.t("requests.default.pick_up_placeholder"), id: id
543✔
128
          else
129
            single_pickup(requestable.charged?, name, id, locs[0])
80✔
130
          end
131
        end
132
    end
133

134
    # rubocop:disable Rails/OutputSafety
135
    def hidden_fields_mfhd(mfhd)
3✔
136
      hidden = ""
78✔
137
      return hidden if mfhd.nil?
78✔
138
      hidden += hidden_field_tag "mfhd[][call_number]", "", value: (mfhd['call_number']).to_s unless mfhd["call_number"].nil?
77✔
139
      hidden += hidden_field_tag "mfhd[][location]", "", value: (mfhd['location']).to_s unless mfhd["location"].nil?
77✔
140
      hidden += hidden_field_tag "mfhd[][library]", "", value: (mfhd['library']).to_s
77✔
141
      hidden.html_safe
77✔
142
    end
143
    # rubocop:enable Rails/OutputSafety
144

145
    def hidden_fields_item(requestable)
3✔
146
      request_id = requestable.preferred_request_id
534✔
147
      hidden = hidden_field_tag "requestable[][bibid]", "", value: requestable.bib[:id].to_s, id: "requestable_bibid_#{request_id}"
534✔
148
      hidden += hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.mfhd_id, id: "requestable_mfhd_#{request_id}"
534✔
149
      hidden += hidden_field_tag "requestable[][call_number]", "", value: requestable.holding.holding_data['call_number'].to_s, id: "requestable_call_number_#{request_id}" unless requestable.holding.holding_data["call_number"].nil?
534✔
150
      hidden += hidden_field_tag "requestable[][location_code]", "", value: requestable.item_location_code.to_s, id: "requestable_location_#{request_id}"
534✔
151
      hidden += if requestable.item?
534✔
152
                  hidden_fields_for_item(item: requestable.item, preferred_request_id: requestable.preferred_request_id)
521✔
153
                else
154
                  hidden_field_tag("requestable[][item_id]", "", value: requestable.preferred_request_id, id: "requestable_item_id_#{requestable.preferred_request_id}")
13✔
155
                end
156
      hidden += hidden_fields_for_scsb(item: requestable.item) if requestable.partner_holding?
534✔
157
      hidden
534✔
158
    end
159

160
    def isbn_string(array_of_isbns)
3✔
161
      array_of_isbns.join(',')
1✔
162
    end
163

164
    def suppress_login?(request)
3✔
165
      request.only_aeon?
82✔
166
    end
167

168
    def item_checkbox(requestable, single_item_form)
3✔
169
      disabled = !requestable.will_submit_via_form?
515✔
170
      check_box_tag "requestable[][selected]", true, check_box_selected?(disabled, single_item_form), class: 'request--select', disabled:, aria: { labelledby: "title enum_#{requestable.preferred_request_id}" }, id: "requestable_selected_#{requestable.preferred_request_id}"
515✔
171
    end
172

173
    ## If any requestable items have a temp location assume everything at the holding is in a temp loc?
174
    def current_location_label(holding_location_label, requestable_list)
3✔
175
      first_location = requestable_list.first.location
153✔
176
      location_label = first_location.short_label.blank? ? "" : "- #{first_location.short_label}"
153✔
177
      label = if requestable_list.first.temp_loc_other_than_resource_sharing?
153✔
178
                "#{first_location.library_label}#{location_label}"
4✔
179
              else
180
                holding_location_label
149✔
181
              end
182
      "#{label} #{requestable_list.first.call_number}"
153✔
183
    end
184

185
    def check_box_selected?(disabled, single_item_form)
3✔
186
      if single_item_form
515✔
187
        !disabled
43✔
188
      else
189
        false
472✔
190
      end
191
    end
192

193
    def submit_button_disabled?(requestable_list)
3✔
194
      # temporary chane issue 438 guest can no longer check out materials
195
      return true if @user.blank? || @user.guest
57✔
196
      return unsubmittable? requestable_list unless requestable_list.size == 1
55✔
197
      # temporary changes issue 438 do not disable the button for circulating items
198
      # requestable_list.first.services.empty? || requestable_list.first.on_reserve? || (requestable_list.first.services.include? 'on_shelf') || requestable_list.first.ask_me?
199
      requestable_list.first.services.empty? || requestable_list.first.on_reserve?
46✔
200
    end
201

202
    def unsubmittable?(requestable_list)
3✔
203
      !requestable_list.any? { |requestable| (requestable.services | submitable_services).present? }
18✔
204
    end
205

206
    def submitable_services
3✔
207
      ['on_shelf', 'in_process', 'on_order', 'annex', 'recap', 'recap_edd', 'paging', 'recap_no_items', 'ppl', 'lewis']
9✔
208
    end
209

210
    def submit_message(requestable_list)
3✔
211
      single_item = "Request this Item"
53✔
212
      multi_item = "Request Selected Items"
53✔
213
      no_item = "No Items Available"
53✔
214
      return multi_item unless requestable_list.size == 1
53✔
215
      if requestable_list.first.services.empty?
44✔
216
        no_item
×
217
      elsif requestable_list.first.annex?
44✔
218
        # Annex items have the potential to display the
219
        # use the fill-in form, where a user could potentially
220
        # request multiple volumes.  For that reason, we show
221
        # the plural form "Request Selected Items" in this case
222
        multi_item
3✔
223
      else
224
        single_item
41✔
225
      end
226
    end
227

228
    # only show the table sort if there are enough items
229
    # to make it worthwhile
230
    def show_tablesorter(requestable_list)
3✔
231
      return "tablesorter" if table_sorter_present?(requestable_list)
77✔
232
      ""
68✔
233
    end
234

235
    def table_sorter_present?(requestable_list)
3✔
236
      requestable_list.size > 5
110✔
237
    end
238

239
    def display_label
3✔
240
      {
×
241
        author: "Author/Artist",
242
        title: "Title",
243
        date: "Published/Created",
244
        id: "Bibliographic ID",
245
        mfhd: "Holding ID (mfhd)"
246
      }.with_indifferent_access
247
    end
248

249
    def display_status(requestable)
3✔
250
      content_tag(:span, requestable.item['status']) unless requestable.item.nil?
×
251
    end
252

253
    def system_status_label(requestable)
3✔
254
      return "" if requestable.item.blank?
×
255
      content_tag(:div, requestable.item[:status], class: 'system-status')
×
256
    end
257

258
    def display_urls(requestable)
3✔
259
      content_tag :ol do
×
260
        requestable.urls.each do |key, value|
×
261
          unless key == 'iiif_manifest_paths'
×
262
            value.reverse!
×
263
            concat content_tag(:li, link_to(value.join(": "), key), class: 'link')
×
264
          end
265
        end
266
      end
267
    end
268

269
    def self.recap_annex_available_pick_ups(requestable, default_pick_ups)
3✔
270
      locations = requestable.pick_up_locations || default_pick_ups
60✔
271
      pick_ups = locations.select { |loc| Requests::Location.valid_recap_annex_pickup?(loc) }
746✔
272
      pick_ups << default_pick_ups[0] if pick_ups.empty?
60✔
273
      pick_ups
60✔
274
    end
275

276
    private
3✔
277

278
      def display_requestable_list(requestable)
3✔
279
        return if requestable.no_services?
142✔
280
        content_tag(:ul, class: "service-list") do
140✔
281
          if requestable.ill_eligible?
140✔
282
            concat content_tag(:li, sanitize(I18n.t("requests.ill.brief_msg")), class: "service-item")
1✔
283
          else
284
            # there are no instances where more than one actual service is available to an item, so we are going to take the first service that is not edd
285
            filtered_services = if requestable.services.size == 1 && requestable.services.first.include?("edd")
139✔
NEW
286
                                  requestable.services
×
287
                                else
288
                                  requestable.services.reject { |service_name| service_name.include?("edd") }
402✔
289
                                end
290
            brief_msg = I18n.t("requests.#{filtered_services.first}.brief_msg")
139✔
291
            concat content_tag(:li, sanitize(brief_msg), class: "service-item")
139✔
292
          end
293
        end
294
      end
295

296
      def display_on_shelf(requestable, _mfhd_id)
3✔
297
        content_tag(:div) do
70✔
298
          display_requestable_list(requestable)
70✔
299
        end
300
      end
301

302
      def pick_up_locations(requestable, default_pick_ups)
3✔
303
        # we don't want to change the ill_eligible rules
304
        return [default_pick_ups[0]] if requestable.ill_eligible?
139✔
305
        return Requests::ApplicationHelper.recap_annex_available_pick_ups(requestable, default_pick_ups) if requestable.recap? || requestable.annex?
138✔
306
        return default_pick_ups if requestable.location&.standard_circ_location?
78✔
307
        if requestable.delivery_location_label.present?
77✔
308
          [{ label: requestable.delivery_location_label, gfa_pickup: requestable.delivery_location_code, pick_up_location_code: requestable.pick_up_location_code, staff_only: false }]
71✔
309
        else
310
          [{ label: requestable.location.library_label, gfa_pickup: gfa_lookup(requestable.location.library_code), staff_only: false }]
6✔
311
        end
312
      end
313

314
      def hidden_fields_for_item(item:, preferred_request_id:)
3✔
315
        hidden = hidden_field_tag("requestable[][item_id]", "", value: preferred_request_id.to_s, id: "requestable_item_id_#{preferred_request_id}")
521✔
316
        hidden += hidden_field_tag("requestable[][barcode]", "", value: item['barcode'].to_s, id: "requestable_barcode_#{preferred_request_id}") unless item["barcode"].nil?
521✔
317
        hidden += hidden_field_tag("requestable[][enum]", "", value: item.enum_value.to_s, id: "requestable_enum_#{preferred_request_id}") if item.enum_value.present?
521✔
318
        hidden += hidden_field_tag("requestable[][copy_number]", "", value: item.copy_number.to_s, id: "requestable_copy_number_#{preferred_request_id}")
521✔
319
        hidden + hidden_field_tag("requestable[][status]", "", value: item['status'].to_s, id: "requestable_status_#{preferred_request_id}")
521✔
320
      end
321

322
      def hidden_fields_for_scsb(item:)
3✔
323
        hidden = hidden_field_tag("requestable[][cgd]", "", value: item['cgd'].to_s, id: "requestable_cgd_#{item['id']}")
6✔
324
        hidden += hidden_field_tag("requestable[][cc]", "", value: item['collection_code'].to_s, id: "requestable_collection_code_#{item['id']}")
6✔
325
        hidden + hidden_field_tag("requestable[][use_statement]", "", value: item['use_statement'].to_s, id: "requestable_use_statement_#{item['id']}")
6✔
326
      end
327

328
      def single_pickup(is_charged, name, id, location)
3✔
329
        style = if is_charged
80✔
NEW
UNCOV
330
                  'margin-top:10px;'
×
331
                else
332
                  ''
80✔
333
                end
334
        hidden = hidden_field_tag name.to_s, "", value: { 'pick_up' => location[:gfa_pickup], 'pick_up_location_code' => location[:pick_up_location_code] }.to_json, class: 'single-pick-up-hidden', id: id
80✔
335
        label = label_tag id, "Pick-up location: #{location[:label]}", class: 'single-pick-up', style: style.to_s
80✔
336
        hidden + label
80✔
337
      end
338

339
      def aeon_base
3✔
NEW
340
        Requests.config[:aeon_base]
×
341
      end
342
  end
343
end
344
# rubocop:enable Metrics/ModuleLength
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