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

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

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

0.0
/app/models/requests/selected_items_validator.rb
1
# frozen_string_literal: true
2

3
module Requests
×
4
  class SelectedItemsValidator < ActiveModel::Validator
×
5
    def mail_services
×
6
      ["paging", "pres", "annex", "on_order", "in_process", "ppl", "lewis", "on_shelf", "annex_in_library"]
×
7
    end
×
8

9
    def validate(record)
×
10
      record.errors.add(:items, { "empty_set" => { 'text' => 'Please Select an Item to Request!', 'type' => 'options' } }) unless record.items.size >= 1 && !record.items.any? { |item| defined? item.selected }
×
11
      record.items.each do |selected|
×
12
        validate_selected(record, selected)
×
13
      end
×
14
    end
×
15

16
    private
×
17

18
      def validate_selected(record, selected)
×
19
        return unless selected['selected'] == 'true'
×
20
        case selected["type"]
×
21
        when 'digitize', 'digitize_fill_in', 'annex_edd', 'marquand_edd', 'clancy_edd', "clancy_unavailable_edd"
×
22
          validate_delivery_mode(record:, selected:)
×
23
        when 'ill'
×
24
          validate_ill_on_shelf(record, selected, pick_up_phrase: 'delivery of your borrow direct item', action_phrase: 'requested via Borrow Direct')
×
25
        when 'recap_no_items'
×
26
          validate_recap_no_items(record, selected)
×
27
        when 'recap', 'recap_edd', 'recap_in_library', 'clancy_in_library', 'marquand_in_library', 'recap_marquand_edd', 'recap_marquand_in_library'
×
28
          validate_offsite(record, selected)
×
29
        when 'on_shelf'
×
30
          validate_ill_on_shelf(record, selected)
×
31
        when *mail_services
×
32
          validate_pick_up_location(record, selected, selected["type"])
×
33
        else
×
34
          record.errors.add(:items, { selected['mfhd'] => { 'text' => 'Please choose a Request Method for your selected item.', 'type' => 'pick_up' } })
×
35
        end
×
36
      end
×
37

38
      def validate_ill_on_shelf(record, selected, pick_up_phrase: 'your selected item', action_phrase: 'Requested')
×
39
        return unless validate_item_id?(record:, selected:, action_phrase:)
×
40
        item_id = selected['item_id']
×
41
        return if selected['pick_up'].present?
×
42

43
        record.errors.add(:items, { item_id => { 'text' => "Please select a pick-up location for #{pick_up_phrase}", 'type' => 'pick_up' } })
×
44
      end
×
45

46
      def validate_pick_up_location(record, selected, type)
×
47
        return if selected['pick_up'].present?
×
48
        id = selected['item_id']
×
49
        id = selected['mfhd'] if id.blank?
×
50

51
        record.errors.add(:items, { id => { 'text' => "Please select a pick-up location for your selected #{type} item", 'type' => 'pick_up' } })
×
52
      end
×
53

54
      def validate_recap_no_items(record, selected)
×
55
        return if selected['pick_up'].present? || selected['edd_art_title'].present?
×
56

57
        record.errors.add(:items, { selected['mfhd'] => { 'text' => 'Please select a pick-up location for your selected ReCAP item', 'type' => 'pick_up' } })
×
58
      end
×
59

60
      def validate_offsite(record, selected)
×
61
        return unless validate_item_id?(record:, selected:, action_phrase: 'Requested from Off-site Facility')
×
62
        validate_delivery_mode(record:, selected:)
×
63
      end
×
64

65
      def validate_delivery_mode(record:, selected:)
×
66
        item_id = selected['item_id']
×
67
        if selected["delivery_mode_#{item_id}"].nil?
×
68
          record.errors.add(:items, { item_id => { 'text' => 'Please select a delivery type for your selected recap item', 'type' => 'options' } })
×
69
        else
×
70
          delivery_type = selected["delivery_mode_#{item_id}"]
×
71
          record.errors.add(:items, { item_id => { 'text' => 'Please select a pick-up location for your selected recap item', 'type' => 'pick_up' } }) if delivery_type == 'print' && selected['pick_up'].blank?
×
72
          if delivery_type == 'edd'
×
73
            record.errors.add(:items, { item_id => { 'text' => 'Please specify title for the selection you want digitized.', 'type' => 'options' } }) if selected['edd_art_title'].empty?
×
74
          end
×
75
        end
×
76
      end
×
77

78
      def validate_item_id?(record:, selected:, action_phrase:)
×
79
        return true if selected['item_id'].present?
×
80

81
        record.errors.add(:items, { selected['mfhd'] => { 'text' => "Item Cannot be #{action_phrase}, see circulation desk.", 'type' => 'options' } })
×
82
        false
×
83
      end
×
84
  end
×
85
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