Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Make the appropriate link generate #2159

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/indexers/concerns/hyku_indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ module HykuIndexing
define_method method_name do |*args, **kwargs, &block|
super(*args, **kwargs, &block).tap do |solr_doc|
# rubocop:disable Style/ClassCheck
object = resource if object.kind_of?(Valkyrie::Resource)
object ||= resource

solr_doc['account_cname_tesim'] = Site.instance&.account&.cname
solr_doc['account_institution_name_ssim'] = Site.instance.institution_label
solr_doc['valkyrie_bsi'] = object.kind_of?(Valkyrie::Resource)
# TODO: Reinstate once valkyrie fileset work is complete - https://github.com/scientist-softserv/hykuup_knapsack/issues/34
solr_doc['all_text_tsimv'] = full_text(object.file_sets.first&.id) if object.kind_of?(ActiveFedora::Base)
# rubocop:enable Style/ClassCheck
Expand Down
19 changes: 19 additions & 0 deletions app/models/concerns/hyrax/solr_document_behavior_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 5.0.0rc2 to account for Valkyrie migration object that end in "Resource"

module Hyrax
module SolrDocumentBehaviorDecorator
def hydra_model(classifier: nil)
kirkkwang marked this conversation as resolved.
Show resolved Hide resolved
if valkyrie?
# In the future when we don't have Valkyrie migration objects,
# we wouldn't have the SomethingResource naming convention, so we use super
(first('has_model_ssim') + 'Resource')&.safe_constantize || super
else
super
end
end
end
end

Hyrax::SolrDocumentBehavior.prepend(Hyrax::SolrDocumentBehaviorDecorator)
1 change: 1 addition & 0 deletions app/models/generic_work_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class GenericWorkResource < Hyrax::Work
include Hyrax::Schema(:with_pdf_viewer)
include Hyrax::Schema(:with_video_embed)
include Hyrax::ArResource
include Hyrax::NestedWorks

Hyrax::ValkyrieLazyMigration.migrating(self, from: GenericWork)

Expand Down
1 change: 1 addition & 0 deletions app/models/image_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ImageResource < Hyrax::Work
include Hyrax::Schema(:with_pdf_viewer)
include Hyrax::Schema(:with_video_embed)
include Hyrax::ArResource
include Hyrax::NestedWorks

Hyrax::ValkyrieLazyMigration.migrating(self, from: Image)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

RSpec.describe Hyrax::SolrDocumentBehavior, type: :decorator do
subject(:solr_document) { solr_document_class.new(solr_hash) }
let(:solr_hash) { {} }

let(:solr_document_class) do
Class.new do
include Blacklight::Solr::Document
include Hyrax::SolrDocumentBehavior
end
end

describe '#to_partial_path' do
context 'with an ActiveFedora model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWork' } }

it 'resolves the correct model name' do
expect(solr_document.to_model.to_partial_path).to eq 'hyrax/generic_works/generic_work'
end
end

context 'with a Valkyrie model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWorkResource' } }

it 'resolves the correct model name' do
expect(solr_document.to_model.to_partial_path).to eq 'hyrax/generic_work_resources/generic_work_resource'
end
end

context 'with a Valkyrie migration model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWork', 'valkyrie_bsi' => true } }

it 'resolves the correct model name' do
expect(solr_document.to_model.to_partial_path).to eq 'hyrax/generic_work_resources/generic_work_resource'
end
end
end

describe '#hydra_model' do
it 'gives ActiveFedora::Base by default' do
expect(solr_document.hydra_model).to eq ActiveFedora::Base
end

context 'with an ActiveFedora model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWork' } }

it 'resolves the correct model name' do
expect(solr_document.hydra_model).to eq GenericWork
end
end

context 'with a Valkyrie model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWorkResource' } }

it 'resolves the correct model name' do
expect(solr_document.hydra_model).to eq GenericWorkResource
end
end

context 'with a Valkyrie migration model name' do
let(:solr_hash) { { 'has_model_ssim' => 'GenericWork', 'valkyrie_bsi' => true } }

it 'resolves the correct model name' do
expect(solr_document.hydra_model).to eq GenericWorkResource
end
end
end
end
Loading