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 1 commit
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ GIT

GIT
remote: https://github.com/samvera/hyrax.git
revision: 74703481e1a9cd07831c439e788338fc6bd74c17
revision: db11f7fe3fe00b841bf0034bb0afe56c9806fadb
branch: double_combo
specs:
hyrax (5.0.0.rc2)
Expand Down
18 changes: 18 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,18 @@
# 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 human_readable_type&.downcase&.strip&.ends_with?('resource')
human_readable_type.titleize.delete(' ')&.safe_constantize ||
model_classifier(classifier).classifier(self).best_model
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', 'human_readable_type_tesim' => 'Generic work resource' } }

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', 'human_readable_type_tesim' => 'Generic work resource' } }

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