-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧹 Make the appropriate link generate
This commit will add a decorator to check the `human_readable_type` of the given object is a Valkyrie migration object (which by convention ends with 'resource') and adjust the generated link accordingly. For example, a GenericWorkResource should generate links like `/concern/generic_work_resources/...` instead of `/concern/generic_works/...`. The models were updated to include the Hyrax::NestedWorks so the `Attach Child` button would populate the appropriate work types. Lastly, the `Gemfile.lock` was updated to include the latest version of Hyrax `double_combo` branch.
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/models/concerns/hyrax/solr_document_behavior_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
if human_readable_type&.downcase&.strip&.ends_with?('resource') | ||
human_readable_type.titleize.delete(' ').camelize(:upper)&.safe_constantize || | ||
model_classifier(classifier).classifier(self).best_model | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hyrax::SolrDocumentBehavior.prepend(Hyrax::SolrDocumentBehaviorDecorator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
spec/models/concerns/hyrax/solr_document_behavior_decorator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |