Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dashboard/my/collections when default admin set table doesn’t exist #5328

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/services/hyrax/admin_set_create_service.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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