diff --git a/app/indexers/concerns/indexes_rights_statements_and_labels.rb b/app/indexers/concerns/indexes_rights_statements_and_labels.rb index 0e2d60547..32cec885e 100644 --- a/app/indexers/concerns/indexes_rights_statements_and_labels.rb +++ b/app/indexers/concerns/indexes_rights_statements_and_labels.rb @@ -2,16 +2,18 @@ module IndexesRightsStatementsAndLabels def to_solr super.tap do |document| - document['rights_statement_ssim'] ||= [] - document['rights_statement_label_ssim'] ||= [] - document['rights_statement_shortcode_ssim'] ||= [] + document['rights_statement_ssim'] = [] + document['rights_statement_label_ssim'] = [] + document['rights_statement_shortcode_ssim'] = [] - resource.rights_statement.each do |original_uri| - value = original_uri.is_a?(ActiveTriples::Resource) ? original_uri.id : original_uri + Array.wrap(resource.rights_statement).each do |original_uri| + value = original_uri.to_s + label = rights_service.label(value) { value } + shortcode = rights_service.shortcode(value) { nil } document['rights_statement_ssim'] << value - document['rights_statement_label_ssim'] << rights_service.label(value) { value } - document['rights_statement_shortcode_ssim'] << rights_service.shortcode(value) { nil } + document['rights_statement_label_ssim'] << label + document['rights_statement_shortcode_ssim'] << shortcode end end end diff --git a/spec/support/shared_contexts/resource_indexing_context.rb b/spec/support/shared_contexts/resource_indexing_context.rb new file mode 100644 index 000000000..0f24d71ca --- /dev/null +++ b/spec/support/shared_contexts/resource_indexing_context.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +RSpec.shared_context 'resource indexing' do + subject(:indexer) { described_class.for(resource: resource) } + + let(:resource_factory) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym } + let(:resource) { build(resource_factory, **metadata) } + let(:metadata) { {} } + let(:solr_document) { indexer.to_solr } +end diff --git a/spec/support/shared_examples/indexing/base_resource_indexer.rb b/spec/support/shared_examples/indexing/base_resource_indexer.rb index 343c8fb65..01b9235a1 100644 --- a/spec/support/shared_examples/indexing/base_resource_indexer.rb +++ b/spec/support/shared_examples/indexing/base_resource_indexer.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true RSpec.shared_examples 'a BaseResourceIndexer' do + include_context 'resource indexing' + describe 'base_metadata fields' do # base metadata it_behaves_like 'it indexes', :bibliographic_citation, to: ['bibliographic_citation_tesim'] @@ -24,13 +26,6 @@ end describe 'field indexing' do - subject(:indexer) { described_class.for(resource: resource) } - - let(:resource_factory) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym } - let(:resource) { build(resource_factory, **metadata) } - let(:metadata) { {} } - let(:solr_document) { indexer.to_solr } - describe 'permalink_urls' do subject(:permalink_url) { solr_document['permalink_ss'] } diff --git a/spec/support/shared_examples/indexing/indexes_a_field.rb b/spec/support/shared_examples/indexing/indexes_a_field.rb index e143090c6..c2ab34f04 100644 --- a/spec/support/shared_examples/indexing/indexes_a_field.rb +++ b/spec/support/shared_examples/indexing/indexes_a_field.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true RSpec.shared_examples 'it indexes' do |field, opts| + include_context 'resource indexing' + suffixes = opts[:to_suffixes] raise 'Pass a field to the "it indexes" shared_example' unless field @@ -13,11 +15,6 @@ end end - let(:indexer) { described_class.for(resource: resource) } - let(:resource_type) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym } - let(:resource) { build(resource_type) } - let(:solr_document) { indexer.to_solr } - to_fields.each do |solr_field| it "#{field} to #{solr_field}" do if solr_field[-1] == 'm'