Skip to content

Commit

Permalink
Add member methods on AdminSetResource
Browse files Browse the repository at this point in the history
This commit will introduce two instance methods on the AdminSetResource:
- #member_of
- #member_collection_ids

These methods will make it possible for users to query for resources are
on the given AdminSetResource.  This is particularly useful for the
WillowSword gem.

Ref:
- notch8/palni-palci#1071
  • Loading branch information
kirkkwang committed Jan 31, 2025
1 parent e35ce71 commit 007e376
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/admin_set_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ class AdminSetResource < Hyrax::AdministrativeSet
Hyrax::ValkyrieLazyMigration.migrating(self, from: ::AdminSet)

include WithPermissionTemplateShim

def member_of
Hyrax.query_service.find_inverse_references_by(resource: self, property: :admin_set_id)
end

def member_collection_ids
member_of.map(&:id)
end
end
15 changes: 14 additions & 1 deletion spec/models/admin_set_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'spec_helper'

RSpec.describe AdminSetResource do
subject(:admin_set) { described_class.new }
subject(:admin_set) { FactoryBot.valkyrie_create(:hyku_admin_set) }
let!(:resource) { FactoryBot.valkyrie_create(:generic_work_resource, admin_set_id: admin_set.id) }

it_behaves_like 'a Hyrax::AdministrativeSet'

Expand All @@ -19,4 +20,16 @@
subject { described_class }
its(:to_rdf_representation) { is_expected.to eq('AdminSet') }
end

describe '#member_of' do
it 'returns the resources in the admin set' do
expect(subject.member_of).to eq [resource]
end
end

describe '#member_collection_ids' do
it 'returns the collection ids of the resources in the admin set' do
expect(subject.member_collection_ids).to eq [resource.id]
end
end
end

0 comments on commit 007e376

Please sign in to comment.