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

pulibrary / orangelight / 033f0565-37fb-4350-bd4a-68e11c1bcc99

pending completion
033f0565-37fb-4350-bd4a-68e11c1bcc99

Pull #3431

circleci

Jane Sandberg
Remove borrowdirect from requests and orangelight
Pull Request #3431: Remove borrowdirect from requests and orangelight

12 of 12 new or added lines in 5 files covered. (100.0%)

7 existing lines in 3 files now uncovered.

5266 of 5554 relevant lines covered (94.81%)

1516.18 hits per line

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

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

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

9
    def validate(record)
2✔
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 }
207✔
11
      record.items.each do |selected|
88✔
12
        validate_selected(record, selected)
119✔
13
      end
14
    end
15

16
    private
2✔
17

18
      # rubocop:disable Metrics/MethodLength
19
      def validate_selected(record, selected)
2✔
20
        return unless selected['selected'] == 'true'
119✔
21
        case selected["type"]
85✔
22
        when 'digitize', 'digitize_fill_in', 'annex_edd', 'marquand_edd', 'clancy_edd', "clancy_unavailable_edd"
23
          validate_delivery_mode(record:, selected:)
8✔
24
        when 'ill'
25
          validate_ill_on_shelf(record, selected, pick_up_phrase: 'delivery of your borrow direct item', action_phrase: 'requested via Borrow Direct')
4✔
26
        when 'recap_no_items'
27
          validate_recap_no_items(record, selected)
5✔
28
        when 'recap', 'recap_edd', 'recap_in_library', 'clancy_in_library', 'marquand_in_library', 'recap_marquand_edd', 'recap_marquand_in_library'
29
          validate_offsite(record, selected)
39✔
30
        when 'on_shelf'
31
          validate_ill_on_shelf(record, selected)
6✔
32
        when "help_me"
33
          true # nothing to validate
×
34
        when *mail_services
35
          validate_pick_up_location(record, selected, selected["type"])
22✔
36
        else
37
          record.errors.add(:items, { selected['mfhd'] => { 'text' => 'Please choose a Request Method for your selected item.', 'type' => 'pick_up' } })
1✔
38
        end
39
      end
40
      # rubocop:enable Metrics/MethodLength
41

42
      def validate_ill_on_shelf(record, selected, pick_up_phrase: 'your selected item', action_phrase: 'Requested')
2✔
43
        return unless validate_item_id(record:, selected:, action_phrase:)
10✔
44
        item_id = selected['item_id']
10✔
45
        return if selected['pick_up'].present?
10✔
46

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

50
      def validate_pick_up_location(record, selected, type)
2✔
51
        return if selected['pick_up'].present?
22✔
52
        id = selected['item_id']
8✔
53
        id = selected['mfhd'] if id.blank?
8✔
54

55
        record.errors.add(:items, { id => { 'text' => "Please select a pick-up location for your selected #{type} item", 'type' => 'pick_up' } })
8✔
56
      end
57

58
      def validate_recap_no_items(record, selected)
2✔
59
        return if selected['pick_up'].present? || selected['edd_art_title'].present?
5✔
60

61
        record.errors.add(:items, { selected['mfhd'] => { 'text' => 'Please select a pick-up location for your selected ReCAP item', 'type' => 'pick_up' } })
4✔
62
      end
63

64
      def validate_offsite(record, selected)
2✔
65
        return unless validate_item_id(record:, selected:, action_phrase: 'Requested from Off-site Facility')
39✔
66
        validate_delivery_mode(record:, selected:)
39✔
67
      end
68

69
      def validate_delivery_mode(record:, selected:)
2✔
70
        item_id = selected['item_id']
47✔
71
        if selected["delivery_mode_#{item_id}"].nil?
47✔
72
          record.errors.add(:items, { item_id => { 'text' => 'Please select a delivery type for your selected recap item', 'type' => 'options' } })
9✔
73
        else
74
          delivery_type = selected["delivery_mode_#{item_id}"]
38✔
75
          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?
38✔
76
          if delivery_type == 'edd'
38✔
77
            record.errors.add(:items, { item_id => { 'text' => 'Please specify title for the selection you want digitized.', 'type' => 'options' } }) if selected['edd_art_title'].empty?
21✔
78
          end
79
        end
80
      end
81

82
      def validate_item_id(record:, selected:, action_phrase:)
2✔
83
        return true if selected['item_id'].present?
49✔
84

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