Skip to content

Commit

Permalink
Merge pull request #6683 from samvera/ensure-common-logic-path
Browse files Browse the repository at this point in the history
🐛 internal_resource and to_rdf_representation are assumptive
  • Loading branch information
dlpierce authored Feb 8, 2024
2 parents 0f12ce7 + f931d29 commit 424690c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/models/admin_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@ class AdminSet < ActiveFedora::Base
DEFAULT_WORKFLOW_NAME = Hyrax.config.default_active_workflow_name

validates_with Hyrax::HasOneTitleValidator

##
# @!group Class Attributes
#
# @!attribute internal_resource
# @return [String]
class_attribute :internal_resource, default: "AdminSet"

class_attribute :human_readable_short_description
# @!endgroup Class Attributes
##

def self.to_rdf_representation
internal_resource
end

def to_rdf_representation
internal_resource
end

self.indexer = Hyrax::AdminSetIndexer

property :title, predicate: ::RDF::Vocab::DC.title
Expand Down
8 changes: 8 additions & 0 deletions app/models/concerns/hyrax/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ module CollectionBehavior

self.indexer = Hyrax::CollectionIndexer

##
# @!group Class Attributes
#
# @!attribute internal_resource
# @return [String]
class_attribute :internal_resource, default: "Collection"

class_attribute :index_collection_type_gid_as, instance_writer: false
##
self.index_collection_type_gid_as = [:symbol]

property :collection_type_gid, predicate: ::RDF::Vocab::SCHEMA.additionalType, multiple: false do |index|
Expand Down
5 changes: 4 additions & 1 deletion lib/wings/valkyrie/query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(adapter:)
def count_all_of_model(model:)
ActiveFedora::Base
.where(has_model_ssim: [model_class_for(model).to_rdf_representation,
model.new.internal_resource.to_s])
model.to_rdf_representation])
.count
end

Expand Down Expand Up @@ -63,6 +63,9 @@ def find_all
#
# @param model [Class]
# @return [Array<Valkyrie::Resource>]
#
# @note Due to implementation details, .find_all_of_model and .count_all_of_model may not
# return the same number of results. Is that a bug? Probably.
def find_all_of_model(model:)
model_class_for(model).all.map do |obj|
resource_factory.to_resource(object: obj)
Expand Down
3 changes: 3 additions & 0 deletions spec/models/admin_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

subject { described_class.new(title: ['Some title']) }

its(:internal_resource) { is_expected.to eq('AdminSet') }
its(:to_rdf_representation) { is_expected.to eq('AdminSet') }

describe '#active_workflow' do
it 'leverages Sipity::Workflow.find_active_workflow_for' do
admin_set = build(:admin_set, id: 1234)
Expand Down
24 changes: 24 additions & 0 deletions spec/wings/valkyrie/query_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ class Image < ActiveFedora::Base
persister.save(resource: Monograph.new)
expect(query_service.count_all_of_model(model: Monograph)).to eq(2)
end

it "can count AdminSet" do
expect(query_service.count_all_of_model(model: AdminSet)).to eq(0)
end

it "can count Hyrax::AdministrativeSet" do
expect(query_service.count_all_of_model(model: Hyrax::AdministrativeSet)).to eq(0)
end

it "can count the configured Hyrax.config.admin_set_model" do
expect(query_service.count_all_of_model(model: Hyrax.config.admin_set_class)).to eq(0)
end

it "can count Collection" do
expect(query_service.count_all_of_model(model: Collection)).to eq(0)
end

it "can count Hyrax::PcdmCollection" do
expect(query_service.count_all_of_model(model: Hyrax::PcdmCollection)).to eq(0)
end

it "can count the configured Hyrax.config.admin_set_model" do
expect(query_service.count_all_of_model(model: Hyrax.config.collection_class)).to eq(0)
end
end

describe ".find_all", clean_repo: true do
Expand Down

0 comments on commit 424690c

Please sign in to comment.