Skip to content

Commit 41b12ba

Browse files
authored
Merge pull request #904 from projectblacklight/895-idless-nesting
Bugfixes for ID-less components: prepend al_ to IDs & correctly set a…
2 parents a1036a5 + 1e2b7c6 commit 41b12ba

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

lib/arclight/hash_absolute_xpath.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(node)
2424
end
2525

2626
def to_hexdigest
27-
self.class.hash_algorithm.hexdigest(absolute_xpath)
27+
self.class.hash_algorithm.hexdigest(absolute_xpath).prepend('al_')
2828
end
2929

3030
def absolute_xpath

lib/arclight/traject/ead2_config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
"The ID of this document will be #{parent_id}#{hexdigest}."
256256
].join(' ')
257257
end
258+
record['id'] = hexdigest
258259
hexdigest
259260
else
260261
record.attribute('id')&.value&.strip&.gsub('.', '-')

spec/features/traject/ead2_indexing_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,18 +659,24 @@
659659
let(:fixture_path) do
660660
Arclight::Engine.root.join('spec', 'fixtures', 'ead', 'sample', 'no-ids-recordgrp-level.xml')
661661
end
662+
let(:first_component) { result['components'].first }
663+
let(:second_component) { result['components'].second }
662664

663665
it 'mints component ids by hashing absolute paths' do
664666
expect(result).to include 'components'
665667
expect(result['components']).not_to be_empty
666-
first_component = result['components'].first
667-
second_component = result['components'].second
668668

669-
expect(first_component['ref_ssi']).to contain_exactly('4bf70b448ac8351a147acff1dd8b1c0b9a791980')
670-
expect(first_component['id']).to contain_exactly('ehllHemingwayErnest-sample4bf70b448ac8351a147acff1dd8b1c0b9a791980')
669+
expect(first_component['ref_ssi']).to contain_exactly('al_4bf70b448ac8351a147acff1dd8b1c0b9a791980')
670+
expect(first_component['id']).to contain_exactly('ehllHemingwayErnest-sampleal_4bf70b448ac8351a147acff1dd8b1c0b9a791980')
671+
672+
expect(second_component['ref_ssi']).to contain_exactly('al_54b06e5ad77cab05ec7f6beeaca50022c47d9c7b')
673+
expect(second_component['id']).to contain_exactly('ehllHemingwayErnest-sampleal_54b06e5ad77cab05ec7f6beeaca50022c47d9c7b')
674+
end
671675

672-
expect(second_component['ref_ssi']).to contain_exactly('54b06e5ad77cab05ec7f6beeaca50022c47d9c7b')
673-
expect(second_component['id']).to contain_exactly('ehllHemingwayErnest-sample54b06e5ad77cab05ec7f6beeaca50022c47d9c7b')
676+
it 'indexes trail of ancestor ids' do
677+
expect(second_component['parent_ssm']).to equal_array_ignoring_whitespace(
678+
%w[ehllHemingwayErnest-sample al_4bf70b448ac8351a147acff1dd8b1c0b9a791980]
679+
)
674680
end
675681
end
676682

spec/lib/arclight/hash_absolute_xpath_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@
4747
expect(described_class.new(components[4]).absolute_xpath).to eq 'document/ead/archdesc/dsc/c1/c1'
4848
end
4949

50-
it 'hashes the absolute_xpath' do
51-
expect(described_class.new(components[0]).to_hexdigest).to eq '9c4e84c284385184b7e3548ebe2a81a9df522a67'
52-
expect(described_class.new(components[1]).to_hexdigest).to eq '73760c5f85d3691b9f537a5ca3d887825e6e0ee9'
53-
expect(described_class.new(components[2]).to_hexdigest).to eq '44c3b0a0ba891df68aa056f9d3e3fcf23f64ad4e'
54-
expect(described_class.new(components[3]).to_hexdigest).to eq '75fdc26f3f0a5fd30e157dbd523885a4eda7ecb3'
55-
expect(described_class.new(components[4]).to_hexdigest).to eq '72636263da05d832fb4a05c90c2b2c79480af70e'
50+
it 'hashes the absolute_xpath & prepends al_' do
51+
expect(described_class.new(components[0]).to_hexdigest).to eq 'al_9c4e84c284385184b7e3548ebe2a81a9df522a67'
52+
expect(described_class.new(components[1]).to_hexdigest).to eq 'al_73760c5f85d3691b9f537a5ca3d887825e6e0ee9'
53+
expect(described_class.new(components[2]).to_hexdigest).to eq 'al_44c3b0a0ba891df68aa056f9d3e3fcf23f64ad4e'
54+
expect(described_class.new(components[3]).to_hexdigest).to eq 'al_75fdc26f3f0a5fd30e157dbd523885a4eda7ecb3'
55+
expect(described_class.new(components[4]).to_hexdigest).to eq 'al_72636263da05d832fb4a05c90c2b2c79480af70e'
5656
end
5757

5858
it 'allows the hashing algorithm to be configured' do
5959
hash_algorithm = described_class.hash_algorithm
6060
described_class.hash_algorithm = Digest::SHA256
61-
expect(described_class.new(components[0]).to_hexdigest).to eq '4b884bc407a22e7e6a41867ef4987b7c49f81c641fe0c4d1f92009a5e4b963a9'
61+
expect(described_class.new(components[0]).to_hexdigest).to eq 'al_4b884bc407a22e7e6a41867ef4987b7c49f81c641fe0c4d1f92009a5e4b963a9'
6262
described_class.hash_algorithm = hash_algorithm
6363
end
6464
end

0 commit comments

Comments
 (0)