From 72714bbaa3414d3c843b572fce7ede87449ba90b Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Thu, 2 Nov 2023 16:46:43 -0400 Subject: [PATCH 1/2] Use hyrax/base/show jbuilder for collection json Fixes the collection's valkyrie id being output as a hash. --- .../concerns/hyrax/collections_controller_behavior.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/hyrax/collections_controller_behavior.rb b/app/controllers/concerns/hyrax/collections_controller_behavior.rb index b345120a46..454ad7e248 100644 --- a/app/controllers/concerns/hyrax/collections_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/collections_controller_behavior.rb @@ -39,7 +39,7 @@ def show respond_to do |format| format.html - format.json { render json: @curation_concern } + format.json { render 'hyrax/base/show' } end end From 2ea1dd021536d8d079c9cdc248a84ffb2e1d3c26 Mon Sep 17 00:00:00 2001 From: Daniel Pierce Date: Thu, 2 Nov 2023 16:47:41 -0400 Subject: [PATCH 2/2] Convert spec to valkyrie resources, add sorting check --- spec/features/collection_spec.rb | 49 +++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/spec/features/collection_spec.rb b/spec/features/collection_spec.rb index 6239ce7322..cb306dfcec 100644 --- a/spec/features/collection_spec.rb +++ b/spec/features/collection_spec.rb @@ -2,35 +2,49 @@ RSpec.describe 'collection', type: :feature do let(:user) { FactoryBot.create(:user) } - let(:collection1) { FactoryBot.create(:public_collection_lw, user: user) } - let(:collection2) { FactoryBot.create(:public_collection_lw, user: user) } - before { sign_in(user) } + # Ensure CollectionResource is the collection model so it is not excluded by solr search builder filters. + # This can likely be removed alongside Wings. + around(:each) do |example| + current_collection_model = Hyrax.config.collection_model + Hyrax.config.collection_model = 'CollectionResource' + example.run + Hyrax.config.collection_model = current_collection_model + end + shared_context 'with many indexed members' do - let(:collection) { FactoryBot.create(:named_collection_lw, user: user) } + let(:collection) { FactoryBot.valkyrie_create(:collection_resource, user: user, title: ['collection title'], description: ['collection description']) } before do docs = (0..12).map do |n| { "has_model_ssim" => [model_name], :id => "zs25x871q#{n}", + "title_tesim" => ["Test Resource #{n}"], + "system_modified_dtsi" => Time.new(2023, 11, 2, n).utc, "depositor_ssim" => [user.user_key], "suppressed_bsi" => false, - "member_of_collection_ids_ssim" => [collection.id], - "nesting_collection__parent_ids_ssim" => [collection.id], + "member_of_collection_ids_ssim" => [collection.id.to_s], + "nesting_collection__parent_ids_ssim" => [collection.id.to_s], "edit_access_person_ssim" => [user.user_key] } end + docs.shuffle! Hyrax::SolrService.add(docs, commit: true) end end describe 'collection show page' do let(:collection) do - FactoryBot.create(:public_collection_lw, user: user, description: ['collection description'], collection_type_settings: :nestable) + FactoryBot.valkyrie_create(:collection_resource, + user: user, + description: ['collection description'], + collection_type_gid: collection_type.to_global_id.to_s, + members: [work1, work2, col1, col2]) end - let!(:work1) { FactoryBot.create(:work, title: ["King Louie"], member_of_collections: [collection], user: user) } - let!(:work2) { FactoryBot.create(:work, title: ["King Kong"], member_of_collections: [collection], user: user) } - let!(:col1) { FactoryBot.create(:public_collection_lw, title: ["Sub-collection 1"], member_of_collections: [collection], user: user) } - let!(:col2) { FactoryBot.create(:public_collection_lw, title: ["Sub-collection 2"], member_of_collections: [collection], user: user) } + let(:collection_type) { FactoryBot.create(:collection_type, :nestable) } + let(:work1) { FactoryBot.valkyrie_create(:monograph, title: ["King Louie"], read_users: [user]) } + let(:work2) { FactoryBot.valkyrie_create(:monograph, title: ["King Kong"], read_users: [user]) } + let(:col1) { FactoryBot.valkyrie_create(:collection_resource, title: ["Sub-collection 1"], read_users: [user]) } + let(:col2) { FactoryBot.valkyrie_create(:collection_resource, title: ["Sub-collection 2"], read_users: [user]) } it "shows a collection with a listing of Descriptive Metadata and catalog-style search results" do visit "/collections/#{collection.id}" @@ -84,8 +98,12 @@ context "with a non-nestable collection type" do let(:collection) do - FactoryBot.create(:public_collection_lw, user: user, description: ['collection description'], collection_type_settings: :not_nestable, with_solr_document: true, with_permission_template: true) + FactoryBot.valkyrie_create(:collection_resource, + user: user, + description: ['collection description'], + collection_type_gid: collection_type.to_global_id.to_s) end + let(:collection_type) { FactoryBot.create(:collection_type, :not_nestable) } it "displays basic information on its show page" do visit "/collections/#{collection.id}" @@ -105,12 +123,17 @@ visit "/collections/#{collection.id}" expect(page).to have_css(".pagination") + + select('date modified ▲', from: 'Sort') + click_button 'Refresh' + + expect(page).to have_text(/Test Resource 0.+1.+2.+3.+4.+5.+6.+7.+8.+9/m) end end describe 'show subcollection pages of a collection' do include_context 'with many indexed members' do - let(:model_name) { 'Collection' } + let(:model_name) { 'CollectionResource' } end it "shows a collection with a listing of Descriptive Metadata and catalog-style search results" do