Skip to content

Commit

Permalink
Display creators in alphabetical order in JSON view
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-dce committed Oct 11, 2024
1 parent 6e8ba46 commit 5a8f06e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/views/hyrax/base/show.json.jbuilder
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)
42 changes: 42 additions & 0 deletions spec/views/hyrax/base/show.json.jbuilder_spec.rb
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

0 comments on commit 5a8f06e

Please sign in to comment.