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

pulibrary / orangelight / 0e37073d-109c-440c-949f-49d2aa86311b

18 Aug 2025 09:05PM UTC coverage: 0.482% (-94.9%) from 95.343%
0e37073d-109c-440c-949f-49d2aa86311b

push

circleci

web-flow
Replace per_page_options_for_select with custom component to avoid deprecation issue (#5186)

* Start creating new component to address deprecaton warning

* Replace per_page_options_for_select with custom component to avoid deprecation issue

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

---------

Co-authored-by: Ryan Jensen <rj1044@princeton.edu>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

0 of 33 new or added lines in 1 file covered. (0.0%)

9374 existing lines in 213 files now uncovered.

47 of 9753 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/submission.rb
1
# frozen_string_literal: true
UNCOV
2
require 'email_validator'
×
3

UNCOV
4
module Requests
×
UNCOV
5
  class Submission
×
UNCOV
6
    include ActiveModel::Validations
×
7

UNCOV
8
    validates :email, presence: true, email: true, length: { minimum: 5, maximum: 50 }
×
UNCOV
9
    validates :user_name, presence: true, length: { minimum: 1, maximum: 50 }
×
UNCOV
10
    validates :user_barcode, allow_blank: true, presence: true, length: { minimum: 5, maximum: 14 },
×
UNCOV
11
                             format: { with: /(^\d{14}$)/i, message: "Please supply a valid library barcode" }
×
UNCOV
12
    validate :item_validations
×
13

UNCOV
14
    def initialize(params, patron)
×
UNCOV
15
      @patron = patron
×
UNCOV
16
      @items = selected_items(params[:requestable])
×
UNCOV
17
      @bib = params[:bib]
×
UNCOV
18
      @services = []
×
UNCOV
19
      @success_messages = []
×
UNCOV
20
    end
×
21

22
    # :reek:DuplicateMethodCall
UNCOV
23
    def self.new_from_hash(original_hash)
×
UNCOV
24
      requestable = original_hash['items']&.map(&:with_indifferent_access) || []
×
UNCOV
25
      patron = Patron.new(user: User.find_by(uid: original_hash['patron']['netid']), patron_hash: original_hash['patron'].with_indifferent_access)
×
UNCOV
26
      new({ requestable:, bib: original_hash['bib'] }, patron)
×
UNCOV
27
    end
×
28

UNCOV
29
    attr_reader :patron, :success_messages
×
30

UNCOV
31
    def email
×
UNCOV
32
      @patron.active_email
×
UNCOV
33
    end
×
34

UNCOV
35
    delegate :source, to: :@patron
×
36

UNCOV
37
    def user_name
×
UNCOV
38
      @patron.netid
×
UNCOV
39
    end
×
40

UNCOV
41
    attr_reader :items
×
42

UNCOV
43
    def filter_items_by_service(service)
×
UNCOV
44
      @items.select { |item| item["type"] == service }
×
UNCOV
45
    end
×
46

UNCOV
47
    def selected_items(requestable_list)
×
UNCOV
48
      items = requestable_list.select { |r| r unless r[:selected] == 'false' || !r.key?('selected') }
×
UNCOV
49
      items.map { |item| categorize_by_delivery_and_location(item) }
×
UNCOV
50
    end
×
51

UNCOV
52
    def item_validations
×
UNCOV
53
      validates_with Requests::SelectedItemsValidator
×
UNCOV
54
    end
×
55

UNCOV
56
    def user_barcode
×
UNCOV
57
      @patron.barcode
×
UNCOV
58
    end
×
59

UNCOV
60
    attr_reader :bib
×
61

UNCOV
62
    def id
×
UNCOV
63
      @bib[:id]
×
UNCOV
64
    end
×
65

UNCOV
66
    def partner_item?(item)
×
UNCOV
67
      Requests.config[:recap_partner_locations].keys.include? item["location_code"]
×
UNCOV
68
    end
×
69

UNCOV
70
    def service_types
×
UNCOV
71
      @types ||= @items.map { |item| item['type'] }.uniq
×
UNCOV
72
      @types
×
UNCOV
73
    end
×
74

UNCOV
75
    def process_submission
×
UNCOV
76
      @services = service_types.map do |type|
×
UNCOV
77
        service_by_type(type)
×
UNCOV
78
      end
×
UNCOV
79
      @services.each(&:handle)
×
80

UNCOV
81
      @success_messages = generate_success_messages(@success_messages)
×
82

UNCOV
83
      @services
×
UNCOV
84
    end
×
85

UNCOV
86
    def service_errors
×
UNCOV
87
      return [] if @services.blank?
×
UNCOV
88
      @services.map(&:errors).flatten
×
UNCOV
89
    end
×
90

UNCOV
91
    def pick_up_location
×
UNCOV
92
      Requests::BibdataService.delivery_locations.dig(items.first&.dig('pick_up'), "library") || {}
×
UNCOV
93
    end
×
94

UNCOV
95
    def marquand?
×
UNCOV
96
      items.first["holding_library"] == 'marquand'
×
UNCOV
97
    end
×
98

UNCOV
99
    def edd?(item)
×
UNCOV
100
      delivery_mode = delivery_mode(item)
×
UNCOV
101
      delivery_mode.present? && delivery_mode == "edd"
×
UNCOV
102
    end
×
103

104
    # Convert the submission to a hash that is compatible that
105
    # Sidekiq can safely serialize to JSON for redis.  This means:
106
    #   * No application-specific objects (unless they are activerecord db objects)
107
    #   * No ActiveSupport::HashWithIndifferentAccess objects, we can only have Hash objects
108
    #   * The keys of the hash must all be strings, not symbols
109
    # See https://github.com/sidekiq/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
UNCOV
110
    def to_h
×
UNCOV
111
      {
×
UNCOV
112
        bib: bib.to_hash.stringify_keys,
×
UNCOV
113
        email: email,
×
UNCOV
114
        errors: errors.messages.stringify_keys,
×
UNCOV
115
        items: items.map { |hash| hash.to_hash.stringify_keys },
×
UNCOV
116
        patron: patron.to_h.to_hash.stringify_keys,
×
UNCOV
117
        pick_up_location: pick_up_location.to_hash.stringify_keys,
×
UNCOV
118
        user_barcode:,
×
UNCOV
119
        user_name:
×
UNCOV
120
      }.stringify_keys
×
UNCOV
121
    end
×
122

UNCOV
123
    private
×
124

UNCOV
125
      def service_by_type(type)
×
UNCOV
126
        case type
×
UNCOV
127
        when 'on_shelf', 'marquand_in_library', 'annex', 'annex_in_library'
×
UNCOV
128
          Requests::Submissions::HoldItem.new(self, service_type: type)
×
UNCOV
129
        when 'recap', 'recap_edd', 'recap_in_library', 'recap_marquand_in_library', 'recap_marquand_edd'
×
UNCOV
130
          Requests::Submissions::Recap.new(self, service_type: type)
×
UNCOV
131
        when 'clancy_in_library'
×
UNCOV
132
          Requests::Submissions::Clancy.new(self)
×
UNCOV
133
        when 'clancy_edd'
×
UNCOV
134
          Requests::Submissions::ClancyEdd.new(self)
×
UNCOV
135
        when 'digitize', 'annex_edd', 'marquand_edd', 'clancy_unavailable_edd'
×
UNCOV
136
          Requests::Submissions::DigitizeItem.new(self, service_type: type)
×
UNCOV
137
        when *inter_library_services
×
UNCOV
138
          Requests::Submissions::Illiad.new(self, service_type: type)
×
UNCOV
139
        else
×
UNCOV
140
          Requests::Submissions::Generic.new(self, service_type: type)
×
UNCOV
141
        end
×
UNCOV
142
      end
×
143

UNCOV
144
      def categorize_by_delivery_and_location(item)
×
UNCOV
145
        library_code = item["library_code"]
×
UNCOV
146
        if recap_no_items?(item)
×
147
          item["type"] = "recap_no_items"
×
UNCOV
148
        elsif print?(item) && library_code == 'annex'
×
UNCOV
149
          item["type"] = "annex"
×
UNCOV
150
        elsif off_site?(library_code)
×
UNCOV
151
          raise Exception, "#{self.class}: Item does not have a delivery mode" unless delivery_mode(item)
×
UNCOV
152
          item["type"] = library_code
×
UNCOV
153
          item["type"] += "_edd" if edd?(item)
×
UNCOV
154
          item["type"] += "_in_library" if in_library?(item)
×
UNCOV
155
        elsif item["type"] == "paging"
×
UNCOV
156
          item["type"] = "digitize" if edd?(item)
×
UNCOV
157
        elsif edd?(item) && library_code.present?
×
UNCOV
158
          item["type"] = "digitize"
×
UNCOV
159
        elsif print?(item) && library_code.present?
×
UNCOV
160
          item["type"] = "on_shelf"
×
UNCOV
161
        end
×
UNCOV
162
        item
×
UNCOV
163
      end
×
164

UNCOV
165
      def in_library?(item)
×
UNCOV
166
        delivery_mode = delivery_mode(item)
×
UNCOV
167
        delivery_mode.present? && delivery_mode == "in_library"
×
UNCOV
168
      end
×
169

UNCOV
170
      def recap_no_items?(item)
×
UNCOV
171
        item["library_code"] == 'recap' && (item["type"] == "digitize_fill_in" || item["type"] == "recap_no_items")
×
UNCOV
172
      end
×
173

UNCOV
174
      def off_site?(library_code)
×
UNCOV
175
        library_code == 'recap' || library_code == 'marquand' || library_code == 'clancy' || library_code == 'recap_marquand' || library_code == 'clancy_unavailable' || library_code == 'annex'
×
UNCOV
176
      end
×
177

UNCOV
178
      def print?(item)
×
UNCOV
179
        delivery_mode = delivery_mode(item)
×
UNCOV
180
        delivery_mode.present? && delivery_mode == "print"
×
UNCOV
181
      end
×
182

UNCOV
183
      def delivery_mode(item)
×
UNCOV
184
        item["delivery_mode_#{item['item_id']}"]
×
UNCOV
185
      end
×
186

UNCOV
187
      def inter_library_services
×
UNCOV
188
        ['ill']
×
UNCOV
189
      end
×
190

UNCOV
191
      def generate_success_messages(success_messages)
×
UNCOV
192
        @services.each do |service|
×
UNCOV
193
          success_messages << service.success_message
×
UNCOV
194
          service.send_mail
×
UNCOV
195
        end
×
UNCOV
196
        success_messages
×
UNCOV
197
      end
×
UNCOV
198
  end
×
UNCOV
199
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