-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display creators in alphabetical order in JSON view
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
fields = ((@curation_concern.class.fields & @presenter.methods)).sort # alphabedized list of field names to include | ||
fields = fields.reject{|field| field.match?(/id/)} # exclude internal ID fields | ||
|
||
json.extract! @curation_concern, :id, :title # ensure id and title appear first | ||
json.extract! @curation_concern, *fields # add the other fields | ||
json.creator @presenter.alpha_creator # replace the creator node with the alphabetized creator list | ||
json.version @curation_concern.try(:etag) |
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,42 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'hyrax/base/show.json.jbuilder', type: :view do | ||
let(:curation_concern) { | ||
FactoryBot.build(:populated_publication, | ||
creator: ["Delahaye, Jacquotte", "Back From The Dead Red", "anon. 17th Century"]) | ||
} | ||
let(:solr_document) { SolrDocument.new( | ||
:id=>'dummy_id', | ||
"system_create_dtsi"=>"2024-10-11T21:18:28Z", | ||
"system_modified_dtsi"=>"2024-10-11T21:18:28Z", | ||
"has_model_ssim"=>["Publication"], | ||
"series_tesim"=>["Staff Report (Federal Reserve Bank of Minneapolis. Research Department)"], | ||
"series_sim"=>["Staff Report (Federal Reserve Bank of Minneapolis. Research Department)"], | ||
"abstract_tesim"=>["This is my abstract"], | ||
"description_tesim"=>["This is my description"], "identifier_tesim"=>["https://doi.org/10.21034/sr.600"], | ||
"title_tesim"=>["The 1929 Stock Market: Irving Fisher Was Right: Additional Files"], | ||
"title_sim"=>["The 1929 Stock Market: Irving Fisher Was Right: Additional Files"], | ||
"title_ssi"=>"The 1929 Stock Market: Irving Fisher Was Right: Additional Files", | ||
"resource_type_tesim"=>["Dataset"], | ||
"resource_type_sim"=>["Dataset"], | ||
"creator_tesim"=>["Delahaye, Jacquotte", "Back From The Dead Red", "anon. 17th Century"], | ||
"creator_sim"=>["Delahaye, Jacquotte", "Back From The Dead Red", "anon. 17th Century"], | ||
"alpha_creator_tesim"=>["anon. 17th Century", "Back From The Dead Red", "Delahaye, Jacquotte"] | ||
) } | ||
let(:presenter) { CypripediumWorkPresenter.new(solr_document, nil) } | ||
let(:json) do | ||
rendered = ApplicationController.render template: subject, | ||
format: :json, | ||
assigns: { curation_concern: curation_concern, presenter: presenter } | ||
JSON.parse(rendered) | ||
end | ||
|
||
before do | ||
allow(curation_concern).to receive(:etag).and_return('not persisted') | ||
end | ||
|
||
it 'alphabetizes creator names' do | ||
expect(json['creator']).to eq ["anon. 17th Century", "Back From The Dead Red", "Delahaye, Jacquotte"] | ||
end | ||
end |