Skip to content

Commit

Permalink
Ensure NullItem inherits from Item and SimpleDelegator
Browse files Browse the repository at this point in the history
Co-authored-by: Isha Sinha <ishasinha1@users.noreply.github.com>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
Co-authored-by: Liz Garcia <lizgarciao@users.noreply.github.com>
Co-authored-by: Ryan Laddusaw <rladdusaw@users.noreply.github.com>
  • Loading branch information
5 people committed Jun 20, 2023
1 parent 54e0e45 commit 3c31b5e
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 116 deletions.
1 change: 1 addition & 0 deletions app/controllers/requests/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def aeon?

def redirect_single_aeon_thesis_numistatics
### redirect to Aeon for thesis or coin items or single Aeon requestable
### or over 500 Aeon requestable
if @request.thesis? || @request.numismatics?
redirect_to "#{Requests::Config[:aeon_base]}?#{@request.requestable.first.aeon_mapped_params.to_query}"
elsif @request.single_aeon_requestable?
Expand Down
8 changes: 8 additions & 0 deletions app/models/requests/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ def too_many_items?

### builds a list of possible requestable items
# returns a collection of requestable objects or nil
# @return [Array<Requests::Requestable>] array containing Requests::Requestables
def build_requestable
return [] if doc._source.blank?
if partner_system_id?
build_scsb_requestable
elsif !items.nil?
# for single aeon item, ends up in this statement
build_requestable_with_items
else
# for too many aeon items, ends up in this statement
build_requestable_from_data
end
end
Expand All @@ -218,6 +221,7 @@ def availability_data(id)
@availability_data ||= items_by_id(id, scsb_owning_institution(scsb_location))
end

# @return [Array<Requests::Requestable>] array containing Requests::Requestables
def build_scsb_requestable
requestable_items = []
## scsb processing
Expand All @@ -233,6 +237,7 @@ def build_scsb_requestable
requestable_items
end

# @return [Array<Requests::Requestable>] array containing Requests::Requestables
def build_holding_scsb_items(id:, values:, availability_data:, requestable_items:)
return requestable_items if values['items'].nil?
barcodesort = build_barcode_sort(items: values['items'], availability_data:)
Expand Down Expand Up @@ -270,6 +275,7 @@ def status_label(item:, availability_data:)
end
end

# @return [Array<Requests::Requestable>] array containing Requests::Requestables
def build_requestable_with_items
requestable_items = []
barcodesort = {}
Expand All @@ -281,6 +287,7 @@ def build_requestable_with_items
requestable_items.compact
end

# @return [Array<Requests::Requestable>] array containing Requests::Requestables or empty array
def build_requestable_from_data
return if doc[:holdings_1display].nil?
@mfhd ||= 'thesis' if thesis?
Expand Down Expand Up @@ -330,6 +337,7 @@ def get_current_location(item_loc:)
end
end

# This method will always return a Requestable object where .item is a NullItem, because we don't pass an item in
def build_requestable_from_holding(holding_id, holding)
return if holding.blank?
params = build_requestable_params(holding: { holding_id.to_sym.to_s => holding }, location:)
Expand Down
4 changes: 3 additions & 1 deletion app/models/requests/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Requestable
def initialize(bib:, holding: nil, item: nil, location: nil, patron:)
@bib = bib
@holding = holding
@item = item.present? ? Item.new(item) : Item::NullItem.new
# Item inherits from SimpleDelegator which requires at least one argument
# The argument is the Object that SimpleDelegator will delegate to.
@item = item.present? ? Item.new(item) : NullItem.new({})
@location = location
@services = []
@patron = patron
Expand Down
114 changes: 0 additions & 114 deletions app/models/requests/requestable/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,120 +128,6 @@ def partner_holding?
Requests::Config[:recap_partner_locations].keys.include? self["location_code"]
end

class NullItem
def nil?
true
end

def present?
false
end

def blank?
true
end

def item_data?
false
end

def pick_up_location_id
""
end

def pick_up_location_code
""
end

def item_type
""
end

def enum_value
""
end

def cron_value
""
end

def copy_value
""
end

def temp_loc?
""
end

def in_resource_sharing?
false
end

def on_reserve?
false
end

def inaccessible?
false
end

def hold_request?
false
end

def enumerated?
false
end

def item_type_non_circulate?
false
end

def id
nil
end

def use_statement
''
end

def collection_code
''
end

def missing?
false
end

def charged?
false
end

def status_label
''
end

def status
'Unavailable'
end

def available?
false
end

def barcode?
false
end

def barcode
''
end

def partner_holding?
false
end
end

private

def available_statuses
Expand Down
116 changes: 116 additions & 0 deletions app/models/requests/requestable/null_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# frozen_string_literal: true
class Requests::Requestable
class NullItem < Requests::Requestable::Item
def nil?
true
end

def present?
false
end

def blank?
true
end

def item_data?
false
end

def pick_up_location_id
""
end

def pick_up_location_code
""
end

def item_type
""
end

def enum_value
""
end

def cron_value
""
end

def copy_value
""
end

def temp_loc?
""
end

def in_resource_sharing?
false
end

def on_reserve?
false
end

def inaccessible?
false
end

def hold_request?
false
end

def enumerated?
false
end

def item_type_non_circulate?
false
end

def id
nil
end

def use_statement
''
end

def collection_code
''
end

def missing?
false
end

def charged?
false
end

def status_label
''
end

def status
'Unavailable'
end

def available?
false
end

def barcode?
false
end

def barcode
''
end

def partner_holding?
false
end
end
end
2 changes: 1 addition & 1 deletion spec/controllers/requests/request_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
expect(response.status).to eq(302)
end
xit 'redirects you when an aeon record with over 500 items is requested' do
it 'redirects you when an aeon record with over 500 items is requested' do
stub_holding_locations
stub_single_holding_location('rare$hsve')
stub_catalog_raw(bib_id: '9930682063506421')
Expand Down

0 comments on commit 3c31b5e

Please sign in to comment.