Skip to content

Commit

Permalink
Check if a control attribute exists before attempting to read its val…
Browse files Browse the repository at this point in the history
…ue. Resolves an exception encountered when loading the holdings of records without an originalsourceid or another control attribute.
  • Loading branch information
jaronkk committed Jul 8, 2014
1 parent ab72a1e commit 93ee39e
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/exlibris/primo/pnx/dedup_mgr.rb
Expand Up @@ -59,8 +59,10 @@ def method_missing(method, *args, &block)
if !instance_variable_defined?(variable_name)
if dedupmgr?
value = map_values_to_origins(control_attribute)
else
elsif respond_to?(control_attribute)
value = {recordid => send(control_attribute)}
else
value = {recordid => nil}
end
instance_variable_set(variable_name, value)
end
Expand Down
16 changes: 15 additions & 1 deletion test/pnx/holdings_test.rb
@@ -1,6 +1,20 @@
module Pnx
require 'test_helper'
class HoldingsTest < Test::Unit::TestCase
def test_load_other_holdings
reset_primo_configuration
record = Exlibris::Primo::Record.new(:raw_xml => record_other_source_xml)
holdings = record.holdings.collect { | h | }
assert record.respond_to? :display_title
assert record.respond_to? :recordid
assert_not_nil record.holdings
holding = record.holdings.first
assert_equal("nduspec_eadRBSC-MSNEA0506", holding.record_id)
assert_nil(holding.original_source_id)
assert_equal("RBSC-MSNEA0506", holding.source_record_id)
assert_nil(holding.ils_api_id)
end

def test_holdings
reset_primo_configuration
record = Exlibris::Primo::Record.new(:raw_xml => record_xml)
Expand Down Expand Up @@ -50,4 +64,4 @@ def test_holdings
assert_equal("unavailable", holding.availability_status)
end
end
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Expand Up @@ -561,6 +561,10 @@ def record_xml
"</record>"
end

def record_other_source_xml
File.read(File.expand_path("../xml/record_other_sourcesystem.xml", __FILE__))
end

def record_invalid_frbr_xml
"<record>"+
"<control>"+
Expand Down

0 comments on commit 93ee39e

Please sign in to comment.