Skip to content

Commit

Permalink
adjust implementation of can_resolve? and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Dec 2, 2019
1 parent d8fffdd commit 2b00e9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/services/metadata_service.rb
Expand Up @@ -12,14 +12,13 @@ def known_prefixes
end

def can_resolve?(identifier)
(prefix, _identifier) = identifier.split(/:/, 2)
handlers.key?(prefix.to_sym)
known_prefixes.any? { |prefix| identifier.start_with?(prefix.to_s) }
end

# return the identifiers found in the same order of the known prefixes we specified
def resolvable(identifiers)
res_ids = identifiers.select { |identifier| can_resolve?(identifier) }
MetadataService.known_prefixes.map { |prefix| res_ids.find { |res_id| res_id.start_with?(prefix.to_s) } }.compact
known_prefixes.map { |prefix| res_ids.find { |res_id| res_id.start_with?(prefix.to_s) } }.compact
end

def fetch(identifier)
Expand Down
14 changes: 14 additions & 0 deletions spec/services/metadata_service_spec.rb
Expand Up @@ -21,6 +21,20 @@
end
end

describe 'can_resolve?' do
it 'returns false for an unknown prefix' do
expect(described_class).not_to be_can_resolve('bogus:1234')
end

it 'returns true for barcodes' do
expect(described_class).to be_can_resolve('barcode:1234')
end

it 'returns true for catkeys' do
expect(described_class).to be_can_resolve('catkey:1234')
end
end

describe 'Symphony handler' do
let(:resource) { instance_double(MarcxmlResource, mods: mods) }
let(:mods) { File.read(File.join(fixture_dir, 'mods_record.xml')) }
Expand Down

0 comments on commit 2b00e9b

Please sign in to comment.