From dd6501a66873e1e83223209203f95668edda9632 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 20 Jan 2022 12:31:15 -0500 Subject: [PATCH] =?UTF-8?q?fix=20dashboard/my/collections=20when=20default?= =?UTF-8?q?=20admin=20set=20table=20doesn=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bug caused the missing table to be checked even after determining that saving the default admin set id wasn’t supported. Added a failing test and fixed the bug. --- app/services/hyrax/admin_set_create_service.rb | 9 +++++++-- spec/services/hyrax/admin_set_create_service_spec.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/services/hyrax/admin_set_create_service.rb b/app/services/hyrax/admin_set_create_service.rb index ca5b41382a..a798e8dcad 100644 --- a/app/services/hyrax/admin_set_create_service.rb +++ b/app/services/hyrax/admin_set_create_service.rb @@ -118,7 +118,12 @@ def find_default_admin_set return if id.blank? Hyrax.query_service.find_by(id: id) rescue Valkyrie::Persistence::ObjectNotFoundError - # id is saved but doesn't exist + # The default ID is DEFAULT_ID when saving is not supported. It is ok + # for this default id to be known but not found. The admin set will be + # created with DEFAULT_ID by find_or_create_default_admin_set. + return unless save_default? + + # id is saved in the default_admin_set_persister's table but doesn't exist # NOTE: This is a corrupt state and shouldn't happen. Manual intervention # is required to determine the correct value for the default admin # set id. The saved id either needs to be updated to the correct @@ -142,7 +147,7 @@ def find_unsaved_default_admin_set # @return [String | nil] the default admin set id; returns nil if not set # @note For general use, it is better to use `Hyrax.config.default_admin_set_id`. def default_admin_set_id - DEFAULT_ID unless save_default? + return DEFAULT_ID unless save_default? id = default_admin_set_persister.first&.default_admin_set_id id = find_unsaved_default_admin_set&.id&.to_s if id.blank? id diff --git a/spec/services/hyrax/admin_set_create_service_spec.rb b/spec/services/hyrax/admin_set_create_service_spec.rb index f7bb949e5a..d468a991b0 100644 --- a/spec/services/hyrax/admin_set_create_service_spec.rb +++ b/spec/services/hyrax/admin_set_create_service_spec.rb @@ -43,6 +43,14 @@ end end + context "and Hyrax::DefaultAdministrativeSet table does not exist" do + before { allow(Hyrax::DefaultAdministrativeSet).to receive(:save_supported?).and_return(false) } + it "creates a default admin set with the DEFAULT_ID" do + expect(Hyrax::DefaultAdministrativeSet).not_to receive(:first) + expect(described_class.find_or_create_default_admin_set.id).to eq described_class::DEFAULT_ID + end + end + context "when default admin set id is NOT saved in the database" do before { allow(Hyrax::DefaultAdministrativeSet).to receive(:count).and_return(0) } context "but default admin set does exist" do