Skip to content

Commit

Permalink
fix dashboard/my/collections when default admin set table doesn’t exist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elrayle committed Jan 20, 2022
1 parent 740840a commit dd6501a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/services/hyrax/admin_set_create_service.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/services/hyrax/admin_set_create_service_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit dd6501a

Please sign in to comment.