diff --git a/app/actors/hyrax/actors/collections_membership_actor.rb b/app/actors/hyrax/actors/collections_membership_actor.rb index 68607fe7dc..84a5e289e5 100644 --- a/app/actors/hyrax/actors/collections_membership_actor.rb +++ b/app/actors/hyrax/actors/collections_membership_actor.rb @@ -70,7 +70,6 @@ def assign_nested_attributes_for_collection(env) # along side the FileSets on the show page def add(env, id) collection = Hyrax.config.collection_class.find(id) - collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX return unless env.current_ability.can?(:deposit, collection) env.curation_concern.member_of_collections << collection diff --git a/app/controllers/hyrax/dashboard/collection_members_controller.rb b/app/controllers/hyrax/dashboard/collection_members_controller.rb index 989ab477f0..48e10d1b05 100644 --- a/app/controllers/hyrax/dashboard/collection_members_controller.rb +++ b/app/controllers/hyrax/dashboard/collection_members_controller.rb @@ -30,7 +30,6 @@ def update_members # rubocop:disable Metrics/MethodLength after_update_error(err_msg) if err_msg.present? return if err_msg.present? - @collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX) begin Hyrax::Collections::CollectionMemberService.add_members_by_ids(collection_id: collection_id, new_member_ids: batch_ids, diff --git a/app/controllers/hyrax/dashboard/collections_controller.rb b/app/controllers/hyrax/dashboard/collections_controller.rb index 54e2baddcb..eac9890a7a 100644 --- a/app/controllers/hyrax/dashboard/collections_controller.rb +++ b/app/controllers/hyrax/dashboard/collections_controller.rb @@ -219,8 +219,6 @@ def update_active_fedora_collection process_branding @collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless Hyrax::CollectionType.for(collection: @collection).discoverable? - # we don't have to reindex the full graph when updating collection - @collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX if @collection.update(collection_params.except(:members)) after_update_response else diff --git a/app/forms/hyrax/forms/dashboard/nest_collection_form.rb b/app/forms/hyrax/forms/dashboard/nest_collection_form.rb index 6cd3e61690..c35fb4d059 100644 --- a/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +++ b/app/forms/hyrax/forms/dashboard/nest_collection_form.rb @@ -38,7 +38,6 @@ def initialize(parent: nil, validates :parent, presence: true validates :child, presence: true validate :parent_and_child_can_be_nested - validate :nesting_within_maximum_depth def save return false unless valid? @@ -83,12 +82,11 @@ def available_parent_collections # rerouting to new_dashboard_collection_path to add the new collection as # a child. Since we don't yet have a child collection, the valid? option can't be used here. def validate_add - if nestable?(parent) - nesting_within_maximum_depth - else + unless nestable?(parent) errors.add(:parent, :cannot_have_child_nested) - false + return false end + true end def remove @@ -104,17 +102,6 @@ def remove attr_accessor :query_service, :persistence_service, :context, :collection - # ideally we would love to be able to eliminate collections which exceed the - # maximum nesting depth from the lists of available collections, but the queries - # needed to make the determination are too expensive to do for every possible - # collection, so we only test for this situation prior to saving the new - # relationship. - def nesting_within_maximum_depth - return true if query_service.valid_combined_nesting_depth?(parent: parent, child: child, scope: context) - errors.add(:collection, :exceeds_maximum_nesting_depth) - false - end - def parent_and_child_can_be_nested if nestable?(parent) && nestable?(child) return true if query_service.parent_and_child_can_nest?(parent: parent, child: child, scope: context) diff --git a/app/indexers/hyrax/repository_reindexer.rb b/app/indexers/hyrax/repository_reindexer.rb deleted file mode 100644 index aa4fdfb0d9..0000000000 --- a/app/indexers/hyrax/repository_reindexer.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true -require 'active_fedora/base' -require 'active_fedora/version' - -module Hyrax - module RepositoryReindexer - extend ActiveSupport::Concern - - module ClassMethods - # overrides https://github.com/samvera/active_fedora/blob/master/lib/active_fedora/indexing.rb#L95-L125 - # see implementation details in adapters/nesting_index_adapter.rb#each_perservation_document_id_and_parent_ids - def reindex_everything(*) - Samvera::NestingIndexer.reindex_all!(extent: Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX) - end - end - end -end - -ActiveFedora::Base.module_eval { include Hyrax::RepositoryReindexer } diff --git a/app/models/concerns/hyrax/collection_behavior.rb b/app/models/concerns/hyrax/collection_behavior.rb index db41c7896a..fda814adb8 100644 --- a/app/models/concerns/hyrax/collection_behavior.rb +++ b/app/models/concerns/hyrax/collection_behavior.rb @@ -10,7 +10,6 @@ module CollectionBehavior include Hyrax::HumanReadableType include Hyrax::HasRepresentative include Hyrax::Permissions - include Hyrax::CollectionNesting included do validates_with HasOneTitleValidator diff --git a/app/models/concerns/hyrax/collection_nesting.rb b/app/models/concerns/hyrax/collection_nesting.rb deleted file mode 100644 index f4c72fb0b5..0000000000 --- a/app/models/concerns/hyrax/collection_nesting.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true -module Hyrax - # Responsible for adding the necessary callbacks for updating the nested collection information - # This is part of the after update index because it is a potentially very expensive process. - # - # @todo Consider extracting the update_index callback to ActiveFedora::Base - module CollectionNesting - extend ActiveSupport::Concern - - included do - extend ActiveModel::Callbacks - include ActiveModel::Validations::Callbacks - - define_model_callbacks :update_index, only: :after - after_update_index :update_nested_collection_relationship_indices - after_destroy :update_child_nested_collection_relationship_indices - before_save :before_update_nested_collection_relationship_indices - after_save :after_update_nested_collection_relationship_indices - - def before_update_nested_collection_relationship_indices - @during_save = true - end - - def after_update_nested_collection_relationship_indices - @during_save = false - reindex_nested_relationships_for(id: id, extent: reindex_extent) - end - - def update_nested_collection_relationship_indices - return if @during_save - reindex_nested_relationships_for(id: id, extent: reindex_extent) - end - - def update_child_nested_collection_relationship_indices - children = find_children_of(destroyed_id: id) - children.each do |child| - reindex_nested_relationships_for(id: child.id, extent: Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX) - end - end - end - - def update_index(*args) - _run_update_index_callbacks { super } - end - - def find_children_of(destroyed_id:) - Hyrax::SolrService.query(Hyrax::SolrQueryBuilderService.construct_query(member_of_collection_ids_ssim: destroyed_id)) - end - - # Only models which include Hyrax::CollectionNesting will respond to this method. - # Used to determine whether a model gets reindexed via Samvera::NestingIndexer during full repository reindexing, - def use_nested_reindexing? - true - end - - # The following methods allow an option to reindex an object only if the nesting indexer fields are not - # already in the object's solr document. Added to prevent unnecessary indexing of all ancestors of a parent - # when one child gets added to the parent. By default, we do the full graph indexing. - def reindex_extent - @reindex_extent ||= Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX - end - - def reindex_extent=(val) - @reindex_extent = val - end - - private - - def reindex_nested_relationships_for(id:, extent:) - Hyrax.config.nested_relationship_reindexer.call(id: id, extent: extent) - end - end -end diff --git a/app/models/concerns/hyrax/work_behavior.rb b/app/models/concerns/hyrax/work_behavior.rb index 46602a6509..72da66ed73 100644 --- a/app/models/concerns/hyrax/work_behavior.rb +++ b/app/models/concerns/hyrax/work_behavior.rb @@ -20,7 +20,6 @@ module WorkBehavior include ProxyDeposit include Works::Metadata include WithEvents - include Hyrax::CollectionNesting included do property :owner, predicate: RDF::URI.new('http://opaquenamespace.org/ns/hydra/owner'), multiple: false diff --git a/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb b/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb index 40872da287..71df846163 100644 --- a/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +++ b/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb @@ -6,13 +6,11 @@ class NestedCollectionsSearchBuilder < ::Hyrax::CollectionSearchBuilder # @param access [Symbol] :edit, :read, :discover - With the given :access what all can # @param collection [::Collection] # @param scope [Object] Typically a controller that responds to #current_ability, #blackligh_config - # @param nesting_attributes [NestingAttributes] an object encapsulating nesting attributes of the collection # @param nest_direction [Symbol] (:as_parent or :as_child) the direction we are adding nesting to this collection - def initialize(access:, collection:, scope:, nesting_attributes:, nest_direction:) + def initialize(access:, collection:, scope:, nest_direction:) super(scope) @collection = collection @discovery_permissions = extract_discovery_permissions(access) - @nesting_attributes = nesting_attributes @nest_direction = nest_direction end @@ -24,74 +22,16 @@ def with_pagination(solr_parameters) solr_parameters[:rows] = 1000 end + # Solr can do graph traversal without the need of special indexing with the Graph query parser so + # use this to compute both the parents and children of the current collection then exclude them + # See https://solr.apache.org/guide/solr/latest/query-guide/other-parsers.html#graph-query-parser def show_only_other_collections_of_the_same_collection_type(solr_parameters) solr_parameters[:fq] ||= [] solr_parameters[:fq] += [ - "-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([limit_ids]), - Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid) + Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid), + "-{!graph from=id to=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_parent}}id:#{@collection.id}", + "-{!graph to=id from=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_child}}id:#{@collection.id}" ] - solr_parameters[:fq] += limit_clause if limit_clause # add limits to prevent illegal nesting arrangements - end - - private - - def limit_ids - # exclude current collection from returned list - limit_ids = [@collection.id.to_s] - # cannot add a parent that is already a parent - limit_ids += @nesting_attributes.parents if @nesting_attributes.parents && @nest_direction == :as_parent - limit_ids - end - - # remove collections from list in order to to prevent illegal nesting arrangements - def limit_clause - case @nest_direction - when :as_parent - eligible_to_be_a_parent - when :as_child - eligible_to_be_a_child - end - end - - # To be eligible to be a parent collection of child "Collection G": - # 1) cannot have any pathnames containing Collection G's ID - # 2) cannot already be Collection G's direct parent - # => this is handled through limit_ids method - def eligible_to_be_a_parent - # Using a !lucene query allows us to get items using a wildcard query, a feature not supported via AF query builder. - ["-_query_:\"{!lucene df=#{Samvera::NestingIndexer.configuration.solr_field_name_for_storing_pathnames}}*#{@collection.id}*\""] - end - - # To be eligible to be a child collection of parent "Collection F": - # 1) Cannot have any pathnames containing any of Collection F's pathname or ancestors - # 2) cannot already be Collection F's direct child - def eligible_to_be_a_child - exclude_path = [] - exclude_path << exclude_if_paths_contain_collection - exclude_path << exclude_if_already_parent - end - - def exclude_if_paths_contain_collection - # 1) Exclude any pathnames containing any of Collection F's pathname or ancestors - array_to_exclude = [] + @nesting_attributes.pathnames unless @nesting_attributes.pathnames.nil? - array_to_exclude += @nesting_attributes.ancestors unless @nesting_attributes.ancestors.nil? - # build a unique string containing all of Collection F's pathnames and ancestors - exclude_list = "" - array_to_exclude&.uniq&.each do |element| - exclude_list += ' ' unless exclude_list.empty? - exclude_list += element.to_s - end - # Using a !lucene query allows us to get items which match any individual element - # from the list. Building the query via the AF builder created a !field query which - # only searches the field for an exact string and doesn't allow an "OR" connection - # between the elements. - return "-_query_:\"{!lucene q.op=OR df=#{Samvera::NestingIndexer.configuration.solr_field_name_for_storing_pathnames}}#{exclude_list}\"" unless exclude_list.empty? - "" - end - - def exclude_if_already_parent - # 2) Exclude any of Collection F's direct children - "-" + ActiveFedora::SolrQueryBuilder.construct_query(Samvera::NestingIndexer.configuration.solr_field_name_for_storing_parent_ids => @collection.id.to_s) end end end diff --git a/app/services/hyrax/adapters/nesting_index_adapter.rb b/app/services/hyrax/adapters/nesting_index_adapter.rb deleted file mode 100644 index 5114962f7c..0000000000 --- a/app/services/hyrax/adapters/nesting_index_adapter.rb +++ /dev/null @@ -1,193 +0,0 @@ -# frozen_string_literal: true -module Hyrax - module Adapters - module NestingIndexAdapter - FULL_REINDEX = "full" - LIMITED_REINDEX = "limited" - - # @!group Providing interface for a Samvera::NestingIndexer::Adapter - - ## - # @api public - # - # @param id [String] - # @return Samvera::NestingIndexer::Document::PreservationDocument - def self.find_preservation_document_by(id:) - # Not everything is guaranteed to have library_collection_ids - # If it doesn't have it, what do we do? - parent_ids = find_preservation_parent_ids_for(id: id) - Samvera::NestingIndexer::Documents::PreservationDocument.new(id: id, parent_ids: parent_ids) - end - - ## - # @api public - # - # @param id [String] - # @return Samvera::NestingIndexer::Document::PreservationDocument - def self.find_preservation_parent_ids_for(id:) - # Not everything is guaranteed to have library_collection_ids - # If it doesn't have it, what do we do? - fedora_object = Hyrax::Base.uncached do - fedora_object = ActiveFedora::Base.find(id) - end - - if fedora_object.respond_to?(:member_of_collection_ids) - fedora_object.member_of_collection_ids - else - [] - end - end - - ## - # @api public - # - # @param id [String] - # @return Samvera::NestingIndexer::Documents::IndexDocument - def self.find_index_document_by(id:) - solr_document = find_solr_document_by(id: id) - coerce_solr_document_to_index_document(original_solr_document: solr_document, id: id) - end - - ## - # @api public - # @yieldparam id [String] - # @yieldparam parent_id [Array] - # - # @see Samvera::NestingIndexer.reindex_all!(extent: FULL_REINDEX) - def self.each_perservation_document_id_and_parent_ids(&block) # rubocop:disable Lint/UnusedMethodArgument - ActiveFedora::Base.descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true).each do |uri| - id = Hyrax.config.translate_uri_to_id.call(uri) - object = ActiveFedora::Base.find(id) - parent_ids = object.try(:member_of_collection_ids) || [] - - # NOTE: we do not yield when the object has parents. Calling the nested indexer for the - # top id will reindex all descendants as well. - if object.try(:use_nested_reindexing?) - yield(id, parent_ids) if parent_ids.empty? - else - Hyrax.logger.info "Re-indexing via to_solr ... #{id}" - Hyrax::SolrService.add(object.to_solr, commit: true) - end - end - end - - ## - # @api public - # - # From the nesting_document, we will need to add the nesting attributes to the underlying SOLR document for the object - # - # @param nesting_document [Samvera::NestingIndexer::Documents::IndexDocument] - # @return Hash - the attributes written to the indexing layer - def self.write_nesting_document_to_index_layer(nesting_document:) - solr_doc = Hyrax::Base.uncached do - ActiveFedora::Base.find(nesting_document.id).to_solr # What is the current state of the solr document - end - - # Now add the details from the nesting indexer to the document - add_nesting_attributes( - solr_doc: solr_doc, - ancestors: nesting_document.ancestors, - parent_ids: nesting_document.parent_ids, - pathnames: nesting_document.pathnames, - depth: nesting_document.deepest_nested_depth - ) - end - - ## - # @api public - # - # @param solr_doc [SolrDocument] - # @param ancestors [Array] - # @param parent_ids [Array] - # @param pathnames [Array] - # @param depth [Array] the object's deepest nesting depth - # @return [SolrDocument] - def self.add_nesting_attributes(solr_doc:, ancestors:, parent_ids:, pathnames:, depth:) - solr_doc[solr_field_name_for_storing_ancestors] = ancestors - solr_doc[solr_field_name_for_storing_parent_ids] = parent_ids - solr_doc[solr_field_name_for_storing_pathnames] = pathnames - solr_doc[solr_field_name_for_deepest_nested_depth] = depth - Hyrax::SolrService.add(solr_doc, commit: true) - solr_doc - end - - ## - # @api public - # - # @param document [Samvera::NestingIndexer::Documents::IndexDocument] - # @param extent [String] if not "full" or nil, doesn't yield children for reindexing - # @yield Samvera::NestingIndexer::Documents::IndexDocument - # - # @return [void] - def self.each_child_document_of(document:, extent:, &block) # rubocop:disable Lint/UnusedMethodArgument - raw_child_solr_documents_of(parent_document: document).each do |solr_document| - child_document = coerce_solr_document_to_index_document(original_solr_document: solr_document, id: solr_document.fetch('id')) - # during light reindexing, we want to reindex the child only if fields aren't already there - yield(child_document) if full_reindex?(extent: extent) || child_document.pathnames.empty? - end - end - - # @!endgroup - # @!group Supporting methods for interface implementation - - ## - # @api private - # - # @todo Need to implement retrieving parent_ids, pathnames, and ancestors from the given document - def self.coerce_solr_document_to_index_document(original_solr_document:, id:) - Samvera::NestingIndexer::Documents::IndexDocument.new( - id: id, - parent_ids: original_solr_document.fetch(solr_field_name_for_storing_parent_ids) { [] }, - pathnames: original_solr_document.fetch(solr_field_name_for_storing_pathnames) { [] }, - ancestors: original_solr_document.fetch(solr_field_name_for_storing_ancestors) { [] } - ) - end - private_class_method :coerce_solr_document_to_index_document - - ## - # @api private - def self.find_solr_document_by(id:) - query = Hyrax::SolrQueryService.new.with_ids(ids: [id]).build - document = Hyrax::SolrService.query(query, rows: 1).first - document = ActiveFedora::Base.find(id).to_solr if document.nil? - raise "Unable to find SolrDocument with ID=#{id}" if document.nil? - document - end - private_class_method :find_solr_document_by - - ## - # @api private - def self.nesting_configuration - @nesting_configuration ||= Samvera::NestingIndexer.configuration - end - - class << self - delegate :solr_field_name_for_storing_pathnames, - :solr_field_name_for_storing_ancestors, - :solr_field_name_for_storing_parent_ids, - :solr_field_name_for_deepest_nested_depth, to: :nesting_configuration - end - - ## - # @api private - # @param parent_document [Curate::Indexer::Documents::IndexDocument] - # @return [Hash] A raw response document from SOLR - # - # @todo What is the appropriate suffix to apply to the solr_field_name? - def self.raw_child_solr_documents_of(parent_document:) - # query Solr for all of the documents included as a member_of_collection parent. Or up to 10000 of them. - child_query = Hyrax::SolrQueryBuilderService.construct_query(member_of_collection_ids_ssim: parent_document.id) - Hyrax::SolrService.query(child_query, rows: 10_000.to_i) - end - private_class_method :raw_child_solr_documents_of - - def self.full_reindex?(extent:) - return true if extent == FULL_REINDEX - false - end - private_class_method :full_reindex? - - # @!endgroup - end - end -end diff --git a/app/services/hyrax/collections/nested_collection_query_service.rb b/app/services/hyrax/collections/nested_collection_query_service.rb index 9ba2488fed..2d96bf1b9a 100644 --- a/app/services/hyrax/collections/nested_collection_query_service.rb +++ b/app/services/hyrax/collections/nested_collection_query_service.rb @@ -4,26 +4,6 @@ module Collections ## # A query service handling nested collection queries. module NestedCollectionQueryService - ## - # @api private - # - # an encapsulation of a collection's nesting index attributes - class NestingAttributes - attr_accessor :parents, :pathnames, :ancestors, :depth, :id - - def initialize(id:, scope:) - query_builder = Hyrax::CollectionSearchBuilder.new(scope).where(id: id.to_s) - query = Hyrax::Collections::NestedCollectionQueryService.clean_lucene_error(builder: query_builder) - response = scope.repository.search(query) - collection_doc = response.documents.first - @id = id.to_s - @parents = collection_doc[Samvera::NestingIndexer.configuration.solr_field_name_for_storing_parent_ids] - @pathnames = collection_doc[Samvera::NestingIndexer.configuration.solr_field_name_for_storing_pathnames] - @ancestors = collection_doc[Samvera::NestingIndexer.configuration.solr_field_name_for_storing_ancestors] - @depth = collection_doc[Samvera::NestingIndexer.configuration.solr_field_name_for_deepest_nested_depth] - end - end - ## # @api public # @@ -71,8 +51,7 @@ def self.available_parent_collections(child:, scope:, limit_to_id: nil) def self.parent_collections(child:, scope:, page: 1) return [] unless nestable?(collection: child) query_builder = Hyrax::NestedCollectionsParentSearchBuilder.new(scope: scope, child: child, page: page) - query = clean_lucene_error(builder: query_builder) - scope.repository.search(query) + scope.repository.search(query_builder.query) end ## @@ -86,39 +65,18 @@ def self.parent_collections(child:, scope:, page: 1) # id is in the response. Useful for validation. # @param nest_direction [Symbol] :as_child or :as_parent def self.query_solr(collection:, access:, scope:, limit_to_id:, nest_direction:) - nesting_attributes = NestingAttributes.new(id: collection.id.to_s, scope: scope) query_builder = Hyrax::Dashboard::NestedCollectionsSearchBuilder.new( access: access, collection: collection, scope: scope, - nesting_attributes: nesting_attributes, nest_direction: nest_direction ) query_builder.where(id: limit_to_id.to_s) if limit_to_id - query = clean_lucene_error(builder: query_builder) - scope.repository.search(query) + scope.repository.search(query_builder.query) end private_class_method :query_solr - ## - # @api private - # - # clean query for +{!lucene}+ error - # - # @param builder [SearchBuilder] - # @return [Blacklight::Solr::Request] cleaned and functional query - def self.clean_lucene_error(builder:) - # TODO: Need to investigate further to understand why these particular queries - # using the where cause fail when others in the app apparently work - # - # Perhaps see . - # This can be averted by using #with in at least some cases? - query = builder.query.to_hash - query['q'] = query['q'].gsub('{!lucene}', '') if query.key?('q') - query - end - ## # @api public # @@ -144,73 +102,6 @@ def self.parent_and_child_can_nest?(parent:, child:, scope:) true end - # @api public - # - # Does the nesting depth fall within defined limit? - # - # @param parent [::Collection] - # @param child [nil, ::Collection] will be nil if we are nesting a new - # collection under the parent - # @param scope [Object] Typically a controller object that responds - # to +repository+, +can?+, +blacklight_config+, +current_ability+ - # - # @return [Boolean] true if the parent can nest the child; false otherwise - def self.valid_combined_nesting_depth?(parent:, child: nil, scope:) - # We limit the total depth of collections to the size specified in the samvera-nesting_indexer configuration. - child_depth = child_nesting_depth(child: child, scope: scope) - parent_depth = parent_nesting_depth(parent: parent, scope: scope) - return false if parent_depth + child_depth > Samvera::NestingIndexer.configuration.maximum_nesting_depth - true - end - - # @api private - # - # Get the child collection's nesting depth - # - # @param child [::Collection] - # @return [Fixnum] the largest number of collections in a path nested - # under this collection (including this collection) - def self.child_nesting_depth(child:, scope:) - return 1 unless child - # The nesting depth of a child collection is found by finding the largest nesting depth - # among all collections and works which have the child collection in the paths, and - # subtracting the nesting depth of the child collection itself. - # => 1) First we find all the collections with this child in the path, sort the results in descending order, and take the first result. - # note: We need to include works in this search. They are included in the depth validations in - # the indexer, so we do NOT use collection search builder here. - builder = Hyrax::SearchBuilder.new(scope).with({ - q: "#{Samvera::NestingIndexer.configuration.solr_field_name_for_storing_pathnames}:/.*#{child.id}.*/", - sort: "#{Samvera::NestingIndexer.configuration.solr_field_name_for_deepest_nested_depth} desc" - }) - builder.rows = 1 - query = clean_lucene_error(builder: builder) - response = scope.repository.search(query).documents.first - - # Now we have the largest nesting depth for all paths containing this collection - descendant_depth = response[Samvera::NestingIndexer.configuration.solr_field_name_for_deepest_nested_depth] - - # => 2) Then we get the stored depth of the child collection itself to eliminate the collections above this one from our count, and add 1 to add back in this collection itself - child_depth = NestingAttributes.new(id: child.id.to_s, scope: scope).depth - nesting_depth = descendant_depth - child_depth + 1 - - # this should always be positive, but just being safe - nesting_depth.positive? ? nesting_depth : 1 - end - private_class_method :child_nesting_depth - - # @api private - # - # Get the parent collection's nesting depth - # - # @param parent [::Collection] - # @return [Fixnum] the largest number of collections above - # this collection (includes this collection) - def self.parent_nesting_depth(parent:, scope:) - return 1 if parent.nil? - NestingAttributes.new(id: parent.id.to_s, scope: scope).depth - end - private_class_method :parent_nesting_depth - # @api private # # @param collection [Hyrax::PcdmCollection,::Collection] diff --git a/config/initializers/nesting_indexer_initializer.rb b/config/initializers/nesting_indexer_initializer.rb deleted file mode 100644 index 2d3e73b990..0000000000 --- a/config/initializers/nesting_indexer_initializer.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require 'samvera/nesting_indexer' -require 'hyrax/repository_reindexer' - -Samvera::NestingIndexer.configure do |config| - # How many layers of nesting are allowed for collections - # For maximum_nesting_depth of 3 the following will raise an exception - # C1 <- C2 <- C3 <- W1 - config.maximum_nesting_depth = 5 - config.adapter = Hyrax::Adapters::NestingIndexAdapter - config.solr_field_name_for_storing_parent_ids = "nesting_collection__parent_ids_ssim" - config.solr_field_name_for_storing_ancestors = "nesting_collection__ancestors_ssim" - config.solr_field_name_for_storing_pathnames = "nesting_collection__pathnames_ssim" - config.solr_field_name_for_deepest_nested_depth = 'nesting_collection__deepest_nested_depth_isi' -end diff --git a/lib/hyrax/configuration.rb b/lib/hyrax/configuration.rb index 64fb51ee6e..e2b6c2e624 100644 --- a/lib/hyrax/configuration.rb +++ b/lib/hyrax/configuration.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require 'hyrax/role_registry' -require 'samvera/nesting_indexer' module Hyrax ## @@ -65,7 +64,6 @@ def initialize @registered_concerns = [] @role_registry = Hyrax::RoleRegistry.new @default_active_workflow_name = DEFAULT_ACTIVE_WORKFLOW_NAME - @nested_relationship_reindexer = default_nested_relationship_reindexer end DEFAULT_ACTIVE_WORKFLOW_NAME = 'default' @@ -843,12 +841,6 @@ def uploader @uploader ||= default_uploader_config end - attr_accessor :nested_relationship_reindexer - - def default_nested_relationship_reindexer - ->(id:, extent:) { Samvera::NestingIndexer.reindex_relationships(id: id, extent: extent) } - end - attr_writer :solr_select_path def solr_select_path @solr_select_path ||= ActiveFedora.solr_config.fetch(:select_path, 'select') diff --git a/spec/actors/hyrax/actors/lease_actor_spec.rb b/spec/actors/hyrax/actors/lease_actor_spec.rb index 6d086191b3..e52cc3b6b2 100644 --- a/spec/actors/hyrax/actors/lease_actor_spec.rb +++ b/spec/actors/hyrax/actors/lease_actor_spec.rb @@ -105,7 +105,7 @@ let(:leased_work) { create(:leased_work, with_lease_attributes: lease_attributes) } let(:subject) { described_class.new(leased_work) } - it 'destroys and reindexes the new permission appropriately in solr', with_nested_reindexing: true do + it 'destroys and reindexes the new permission appropriately in solr' do allow(leased_work.lease).to receive(:active?).and_return false subject.destroy expect(::SolrDocument.find(leased_work.id)[:visibility_ssi]).to eq(authenticated_vis) diff --git a/spec/factories/collections.rb b/spec/factories/collections.rb index 2b5cf14eae..f1f2e467d7 100644 --- a/spec/factories/collections.rb +++ b/spec/factories/collections.rb @@ -71,33 +71,6 @@ # ] } # let(:collection_type) { create(:collection_lw_type, settings) } # let(:collection) { build(:collection_lw, collection_type: collection_type) } - # - # @example Build a collection with nesting fields set in the solr document. Light weight. - # NOTE: The property `with_nesting_attributes` is only supported for building collections. The attributes will - # be overwritten by the save process when creating a collection, thus effectively ignoring this property. - # let(:collection) { build(:collection_lw, with_nesting_attributes: { ancestors: ['Parent_1'], - # parent_ids: ['Parent_1'], - # pathnames: ['Parent_1/Collection123'], - # depth: 2 }) } - # - # @example Create a collection with everything. Extreme heavy weight. This is very slow and should be avoided. - # NOTE: Everything gets created. - # NOTE: Build options effect created collections as follows... - # * `with_permission_template` can specify user/group permissions. A permission template is always created. - # * `collection_type_settings` can specify to create a collection type with specific settings - # * `with_solr_document` is ignored. A solr document is always created. - # * `with_nested_attributes` is ignored. - # NOTE: Additional process is required for testing nested collections with Fedora objects. See next example. - # let(:collection) { create(:collection_lw) } - # - # @example Create collections for use with nested collection index testing. - # NOTE: For light weight nested collection testing using solr documents only, see `with_nested_attributes` above - # NOTE: Full indexed nested collections with solr documents and Fedora objects are created by... - # * creating multiple collections (expensive) - # * nesting them and saving - causing reindex of the Fedora objects (expensive) - # For tests of nesting functionality requiring the Fedora object and reindexing, in the test itself - # include `:with_nested_reindexing` - # it "returns the collection and its members", :with_nested_reindexing do factory :collection_lw, class: Collection do transient do @@ -106,7 +79,6 @@ collection_type { nil } collection_type_settings { nil } with_permission_template { false } - with_nesting_attributes { nil } with_solr_document { false } end sequence(:title) { |n| ["Collection Title #{n}"] } @@ -118,7 +90,6 @@ CollectionLwFactoryHelper.process_collection_type_settings(collection, evaluator) CollectionLwFactoryHelper.process_with_permission_template(collection, evaluator) CollectionLwFactoryHelper.process_with_solr_document(collection, evaluator) - CollectionLwFactoryHelper.process_with_nesting_attributes(collection, evaluator) end before(:create) do |collection, evaluator| @@ -273,7 +244,7 @@ def self.process_collection_type_settings(collection, evaluator) # @param [Class] evaluator holding the transient properties for the current build/creation process # @param [Boolean] if true, force the permission template to be created def self.process_with_permission_template(collection, evaluator, force = false) - return unless force || evaluator.with_permission_template || RSpec.current_example.metadata[:with_nested_reindexing] + return unless force || evaluator.with_permission_template collection.id ||= FactoryBot.generate(:object_id) attributes = { source_id: collection.id } attributes[:manage_users] = user_managers(evaluator.with_permission_template, evaluator.user) @@ -281,21 +252,6 @@ def self.process_with_permission_template(collection, evaluator, force = false) FactoryBot.create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id) end - # Process the with_nesting_attributes transient property such that... - # * adds nesting related solr-document fields for ancestors, parent_ids, pathnames, and depth - # @param [Collection] collection object being built/created by the factory - # @param [Class] evaluator holding the transient properties for the current build/creation process - def self.process_with_nesting_attributes(collection, evaluator) - return unless evaluator.with_nesting_attributes.present? && Hyrax::CollectionType.for(collection: collection).nestable? - Hyrax::Adapters::NestingIndexAdapter.add_nesting_attributes( - solr_doc: solr_document_with_permissions(collection, evaluator), - ancestors: evaluator.with_nesting_attributes[:ancestors], - parent_ids: evaluator.with_nesting_attributes[:parent_ids], - pathnames: evaluator.with_nesting_attributes[:pathnames], - depth: evaluator.with_nesting_attributes[:depth] - ) - end - # Process the with_solr_document transient property such that... # * a solr document is created for the collection # * permissions identified by with_permission_template, if any, are added to the solr fields @@ -303,7 +259,6 @@ def self.process_with_nesting_attributes(collection, evaluator) # @param [Class] evaluator holding the transient properties for the current build/creation process def self.process_with_solr_document(collection, evaluator) return unless evaluator.with_solr_document - return if evaluator.with_nesting_attributes.present? && Hyrax::CollectionType.for(collection: collection).nestable? # will create the solr document there instead Hyrax::SolrService.add(solr_document_with_permissions(collection, evaluator), commit: true) end diff --git a/spec/factories/collections_factory.rb b/spec/factories/collections_factory.rb index 9817bfe352..847efaa4ac 100644 --- a/spec/factories/collections_factory.rb +++ b/spec/factories/collections_factory.rb @@ -5,26 +5,15 @@ # light weight collection factory. DO NOT ADD tests using this factory. # # rubocop:disable Layout/LineLength - # @example let(:collection) { build(:collection, collection_type_settings: [:not_nestable, :discoverable, :sharable, :allow_multiple_membership], with_nesting_attributes: {ancestors: [], parent_ids: [], pathnames: [], depth: 1}) } + # @example let(:collection) { build(:collection, collection_type_settings: [:not_nestable, :discoverable, :sharable, :allow_multiple_membership]) } # rubocop:enable Layout/LineLength - # Regarding testing nested collections: - # To get the nested collection solr fields in the solr document for query purposes there are two options: - # => 1) use create(:collection) and add "with_nested_reindexing: true" to the spec will force the collection to be - # created and run through the entire indexing. - # => when you need a permission template AND nesting fields in the solr_document - # => certain ability tests (:discover, for example) require the permission template be created - # => 2) use build(:collection) and add with_nesting_attributes: {ancestors: [], parent_ids: [], pathnames: [], depth: 1} - # to the build the collection and create a solr document using the given nesting attributes - # => this can be used to speed up the specs when a made-up solr document is adequate and no permission template is required - transient do user { create(:user) } # allow defaulting to default user collection collection_type_settings { nil } with_permission_template { false } create_access { false } - with_nesting_attributes { nil } end sequence(:title) { |n| ["Collection Title #{n}"] } @@ -35,29 +24,13 @@ elsif collection.collection_type_gid.nil? collection.collection_type = create(:user_collection_type) end - - # if requested, create a solr document and add the nesting fields into it - # when a nestable collection is built. This reduces the need to use - # create and :with_nested_indexing for nested collection testing - if evaluator.with_nesting_attributes.present? && Hyrax::CollectionType.for(collection: collection).nestable? - Hyrax::Adapters::NestingIndexAdapter.add_nesting_attributes( - solr_doc: evaluator.to_solr, - ancestors: evaluator.with_nesting_attributes[:ancestors], - parent_ids: evaluator.with_nesting_attributes[:parent_ids], - pathnames: evaluator.with_nesting_attributes[:pathnames], - depth: evaluator.with_nesting_attributes[:depth] - ) - end end after(:create) do |collection, evaluator| - # create the permission template if it was requested, OR if nested reindexing is included (so we can apply the user's - # permissions). Nested indexing requires that the user's permissions be saved on the Fedora object... if simply in - # local memory, they are lost when the adapter pulls the object from Fedora to reindex. - if evaluator.with_permission_template || evaluator.create_access || RSpec.current_example.metadata[:with_nested_reindexing] + # create the permission template if it was requested + if evaluator.with_permission_template || evaluator.create_access attributes = { source_id: collection.id } - attributes[:manage_users] = CollectionFactoryHelper.user_managers(evaluator.with_permission_template, evaluator.user, - (evaluator.create_access || RSpec.current_example.metadata[:with_nested_reindexing])) + attributes[:manage_users] = CollectionFactoryHelper.user_managers(evaluator.with_permission_template, evaluator.user, evaluator.create_access) attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge) create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: collection.id) collection.reset_access_controls! diff --git a/spec/factory_tests/collections_factory_spec.rb b/spec/factory_tests/collections_factory_spec.rb index 1f397666b0..ed0c799fa9 100644 --- a/spec/factory_tests/collections_factory_spec.rb +++ b/spec/factory_tests/collections_factory_spec.rb @@ -97,98 +97,12 @@ end end end - - context 'with_nesting_attributes' do - let(:collection_type) { FactoryBot.create(:collection_type) } - let(:current_ability) { instance_double(Ability, admin?: true) } - let(:scope) { FakeSearchBuilderScope.new(current_ability: current_ability) } - let(:solr_doc) { Hyrax::SolrService.get("id:#{col.id}")["response"]["docs"].first } - let(:nesting_attributes) do - Hyrax::Collections::NestedCollectionQueryService::NestingAttributes.new(id: col.id, scope: scope) - end - - context 'without additional permissions' do - let(:col) do - build(:collection_lw, id: 'Collection123', - collection_type_gid: collection_type.to_global_id.to_s, - with_nesting_attributes: { ancestors: ['Parent_1'], - parent_ids: ['Parent_1'], - pathnames: ['Parent_1/Collection123'], - depth: 2 }) - end - - it 'will persist a queryable solr document with the given attributes' do - expect(nesting_attributes.id).to eq('Collection123') - expect(nesting_attributes.parents).to eq(['Parent_1']) - expect(nesting_attributes.pathnames).to eq(['Parent_1/Collection123']) - expect(nesting_attributes.ancestors).to eq(['Parent_1']) - expect(nesting_attributes.depth).to eq(2) - expect(solr_doc["id"]).to eq col.id - expect(solr_doc["has_model_ssim"].first).to eq "Collection" - expect(solr_doc["edit_access_person_ssim"]).to include(col.depositor) - end - end - - context ' and with_permission_template' do - let(:col) do - build(:collection_lw, id: 'Collection123', - collection_type_gid: collection_type.to_global_id.to_s, - with_nesting_attributes: { ancestors: ['Parent_1'], - parent_ids: ['Parent_1'], - pathnames: ['Parent_1/Collection123'], - depth: 2 }, - with_permission_template: { manage_users: [user_mgr], - deposit_users: [user_dep], - view_users: [user_vw] }) - end - - it 'will persist a queryable solr document with the given attributes' do - expect(nesting_attributes.id).to eq('Collection123') - expect(nesting_attributes.parents).to eq(['Parent_1']) - expect(nesting_attributes.pathnames).to eq(['Parent_1/Collection123']) - expect(nesting_attributes.ancestors).to eq(['Parent_1']) - expect(nesting_attributes.depth).to eq(2) - expect(solr_doc["id"]).to eq col.id - expect(solr_doc["has_model_ssim"].first).to eq "Collection" - expect(solr_doc["edit_access_person_ssim"]).to include(col.depositor, user_mgr.user_key) - expect(solr_doc["read_access_person_ssim"]).to include(user_dep.user_key, user_vw.user_key) - end - end - - context 'and with_permission_template and with_solr_document' do - let(:col) do - build(:collection_lw, id: 'Collection123', - collection_type_gid: collection_type.to_global_id.to_s, - with_nesting_attributes: { ancestors: ['Parent_1'], - parent_ids: ['Parent_1'], - pathnames: ['Parent_1/Collection123'], - depth: 2 }, - with_permission_template: { manage_users: [user_mgr], - deposit_users: [user_dep], - view_users: [user_vw] }, - with_solr_document: true) - end - - it 'will persist a queryable solr document with the given attributes' do - expect(nesting_attributes.id).to eq('Collection123') - expect(nesting_attributes.parents).to eq(['Parent_1']) - expect(nesting_attributes.pathnames).to eq(['Parent_1/Collection123']) - expect(nesting_attributes.ancestors).to eq(['Parent_1']) - expect(nesting_attributes.depth).to eq(2) - expect(solr_doc["id"]).to eq col.id - expect(solr_doc["has_model_ssim"].first).to eq "Collection" - expect(solr_doc["edit_access_person_ssim"]).to include(col.depositor, user_mgr.user_key) - expect(solr_doc["read_access_person_ssim"]).to include(user_dep.user_key, user_vw.user_key) - end - end - end end describe 'create' do # collection_type_settings and collection_type_gid are tested by `build` and are the same for `build` and `create` # with_solr_document is tested by build # with_permission_template is tested by build except that the permission template is always created for `create` - # with_nested_attributes not supported for create context 'with_permission_template' do it 'will create a permission template and access even when it is the default value of false' do @@ -196,17 +110,5 @@ expect { create(:collection_lw) }.to change { Hyrax::PermissionTemplateAccess.count }.by(1) end end - - context 'when including nesting indexing', with_nested_reindexing: true do - # Nested indexing requires that the user's permissions be saved - # on the Fedora object... if simply in local memory, they are - # lost when the adapter pulls the object from Fedora to reindex. - let(:user) { create(:user) } - let(:collection) { create(:collection_lw, user: user) } - - it 'will authorize the creating user' do - expect(user.can?(:edit, collection)).to be true - end - end end end diff --git a/spec/features/edit_work_spec.rb b/spec/features/edit_work_spec.rb index ced2331eb9..35a8dc070e 100644 --- a/spec/features/edit_work_spec.rb +++ b/spec/features/edit_work_spec.rb @@ -36,7 +36,7 @@ context 'when the user changes permissions' do let(:work) { create(:private_work, user: user, admin_set: default_admin_set) } - it 'confirms copying permissions to files using Hyrax layout and shows updated value', with_nested_reindexing: true do + it 'confirms copying permissions to files using Hyrax layout and shows updated value' do # e.g. /concern/generic_works/jq085k20z/edit visit edit_hyrax_generic_work_path(work) choose('generic_work_visibility_open') diff --git a/spec/forms/hyrax/forms/dashboard/nest_collection_form_spec.rb b/spec/forms/hyrax/forms/dashboard/nest_collection_form_spec.rb index cf9dd3e6ef..a7b190e394 100644 --- a/spec/forms/hyrax/forms/dashboard/nest_collection_form_spec.rb +++ b/spec/forms/hyrax/forms/dashboard/nest_collection_form_spec.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true RSpec.describe Hyrax::Forms::Dashboard::NestCollectionForm, type: :form do - let(:nesting_depth_result) { true } let(:context) { double('Context', current_user: user) } let(:user) { create(:user) } @@ -10,8 +9,7 @@ end let(:query_service) do - double(Hyrax::Collections::NestedCollectionQueryService, - valid_combined_nesting_depth?: nesting_depth_result) + double(Hyrax::Collections::NestedCollectionQueryService) end describe '.default_query_service' do @@ -20,7 +18,6 @@ it { is_expected.to respond_to(:available_parent_collections) } it { is_expected.to respond_to(:available_child_collections) } it { is_expected.to respond_to(:parent_and_child_can_nest?) } - it { is_expected.to respond_to(:valid_combined_nesting_depth?) } end describe '.default_persistence_service' do @@ -45,16 +42,13 @@ it { is_expected.to validate_presence_of(:child) } context 'parent and child nesting' do - let(:nesting_depth_result) { false } - it 'is invalid if child cannot be nested within the parent' do expect(query_service).to receive(:parent_and_child_can_nest?).with(parent: parent, child: child, scope: context).and_return(false) expect { form.valid? } .to change { form.errors.to_hash } .to include parent: ["cannot have child nested within it"], - child: ["cannot nest within parent"], - collection: ["nesting exceeds the allowed maximum nesting depth."] + child: ["cannot nest within parent"] end end @@ -136,23 +130,10 @@ end context 'when nestable' do - context 'when at maximum nesting level' do - let(:parent) { double(nestable?: true) } - let(:nesting_depth_result) { false } - - it 'validates the parent cannot have additional files nested' do - expect { form.validate_add } - .to change { form.errors.to_hash } - .to include collection: ["nesting exceeds the allowed maximum nesting depth."] - end - end - - context 'when valid' do - let(:parent) { double(nestable?: true) } + let(:parent) { double(nestable?: true) } - it 'validates the parent can contain nested subcollections' do - expect(form.validate_add).to eq true - end + it 'validates the parent can contain nested subcollections' do + expect(form.validate_add).to eq true end end end @@ -220,16 +201,13 @@ it { is_expected.to validate_presence_of(:child) } context 'parent and child nesting' do - let(:nesting_depth_result) { false } - it 'is invalid if child cannot be nested within the parent' do expect(query_service).to receive(:parent_and_child_can_nest?).with(parent: parent, child: child, scope: context).and_return(false) expect { form.valid? } .to change { form.errors.to_hash } .to include parent: ["cannot have child nested within it"], - child: ["cannot nest within parent"], - collection: ["nesting exceeds the allowed maximum nesting depth."] + child: ["cannot nest within parent"] end end @@ -311,23 +289,10 @@ end context 'when nestable' do - context 'when at maximum nesting level' do - let(:parent_nestable) { true } - let(:nesting_depth_result) { false } - - it 'validates the parent cannot have additional files nested' do - expect { form.validate_add } - .to change { form.errors.to_hash } - .to include collection: ["nesting exceeds the allowed maximum nesting depth."] - end - end - - context 'when valid' do - let(:parent_nestable) { true } + let(:parent_nestable) { true } - it 'validates the parent can contain nested subcollections' do - expect(form.validate_add).to eq true - end + it 'validates the parent can contain nested subcollections' do + expect(form.validate_add).to eq true end end end diff --git a/spec/indexers/hyrax/repository_reindexer_spec.rb b/spec/indexers/hyrax/repository_reindexer_spec.rb deleted file mode 100644 index 44eb475b8a..0000000000 --- a/spec/indexers/hyrax/repository_reindexer_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true -RSpec.describe Hyrax::RepositoryReindexer do - let(:subject) { Samvera::NestingIndexer } - - it 'overrides ActiveFedora#reindex_everything' do - expect(subject).to receive(:reindex_all!).with(extent: Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX) - ActiveFedora::Base.reindex_everything - end -end diff --git a/spec/lib/hyrax/configuration_spec.rb b/spec/lib/hyrax/configuration_spec.rb index 7d9638859b..50ef90e2f0 100644 --- a/spec/lib/hyrax/configuration_spec.rb +++ b/spec/lib/hyrax/configuration_spec.rb @@ -41,7 +41,6 @@ it { is_expected.to respond_to(:collection_model=) } it { is_expected.to respond_to(:contact_email) } it { is_expected.to respond_to(:default_admin_set_id) } - it { is_expected.to respond_to(:default_nested_relationship_reindexer) } it { is_expected.to respond_to(:derivative_services) } it { is_expected.to respond_to(:derivative_services=) } it { is_expected.to respond_to(:display_media_download_link=) } @@ -75,7 +74,6 @@ it { is_expected.to respond_to(:max_days_between_fixity_checks) } it { is_expected.to respond_to(:max_days_between_fixity_checks=) } it { is_expected.to respond_to(:max_notifications_for_dashboard) } - it { is_expected.to respond_to(:nested_relationship_reindexer) } it { is_expected.to respond_to(:owner_permission_levels) } it { is_expected.to respond_to(:permission_levels) } it { is_expected.to respond_to(:permission_options) } diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index b33bfa41cd..8814ba2349 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -289,56 +289,5 @@ class Member < ActiveFedora::Base expect { build(:collection_lw) }.not_to change { Hyrax::PermissionTemplateAccess.count } end end - - describe 'when including nesting indexing', with_nested_reindexing: true do - # Nested indexing requires that the user's permissions be saved - # on the Fedora object... if simply in local memory, they are - # lost when the adapter pulls the object from Fedora to reindex. - let(:user) { create(:user) } - let(:collection) { create(:collection, user: user) } - - it 'will authorize the creating user' do - expect(user.can?(:edit, collection)).to be true - end - end - - describe 'when including with_nesting_attributes' do - let(:collection_type) { create(:collection_type) } - let(:blacklight_config) { CatalogController.blacklight_config } - let(:repository) { Blacklight::Solr::Repository.new(blacklight_config) } - let(:current_ability) { instance_double(Ability, admin?: true) } - let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config, search_state_class: nil) } - - context 'when building a collection' do - let(:coll123) do - build(:collection_lw, - id: 'Collection123', - collection_type_gid: collection_type.to_global_id, - with_nesting_attributes: - { ancestors: ['Parent_1'], - parent_ids: ['Parent_1'], - pathnames: ['Parent_1/Collection123'], - depth: 2 }) - end - let(:nesting_attributes) do - Hyrax::Collections::NestedCollectionQueryService::NestingAttributes.new(id: coll123.id, scope: scope) - end - - it 'will persist a queryable solr document with the given attributes' do - expect(nesting_attributes.id).to eq('Collection123') - expect(nesting_attributes.parents).to eq(['Parent_1']) - expect(nesting_attributes.pathnames).to eq(['Parent_1/Collection123']) - expect(nesting_attributes.ancestors).to eq(['Parent_1']) - expect(nesting_attributes.depth).to eq(2) - end - end - end - end - - describe '#update_nested_collection_relationship_indices', :with_nested_reindexing do - it 'will be called once for the Collection resource and once for the nested ACL permission resource' do - expect(Samvera::NestingIndexer).to receive(:reindex_relationships).exactly(2).times.with(id: kind_of(String), extent: kind_of(String)) - collection.save! - end end end diff --git a/spec/models/concerns/hyrax/collection_nesting_spec.rb b/spec/models/concerns/hyrax/collection_nesting_spec.rb deleted file mode 100644 index a99c83a956..0000000000 --- a/spec/models/concerns/hyrax/collection_nesting_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true -RSpec.describe Hyrax::CollectionNesting do - describe 'including this module' do - let(:klass) do - Class.new do - extend ActiveModel::Callbacks - include ActiveModel::Validations::Callbacks - # Because we need these declared before we include the Hyrax::CollectionNesting - define_model_callbacks :destroy, only: :after - define_model_callbacks :save, only: :after - define_model_callbacks :save, only: :before - - def destroy - true - end - - def update_index - true - end - - def before_save - false - end - - def after_save - true - end - include Hyrax::CollectionNesting - - attr_accessor :id - end - end - - let(:user) { create(:user) } - let!(:collection) { create(:collection_lw, collection_type_settings: [:nestable]) } - let!(:child_collection) { create(:collection_lw, collection_type_settings: [:nestable]) } - let(:extent) { Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX } - - before do - Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: collection, child: child_collection) - end - - subject { klass.new.tap { |obj| obj.id = collection.id } } - - it { is_expected.to callback(:update_nested_collection_relationship_indices).after(:update_index) } - it { is_expected.to callback(:update_child_nested_collection_relationship_indices).after(:destroy) } - it { is_expected.to callback(:before_update_nested_collection_relationship_indices).before(:save) } - it { is_expected.to callback(:after_update_nested_collection_relationship_indices).after(:save) } - it { is_expected.to respond_to(:update_nested_collection_relationship_indices) } - it { is_expected.to respond_to(:update_child_nested_collection_relationship_indices) } - it { is_expected.to respond_to(:use_nested_reindexing?) } - it { is_expected.to respond_to(:reindex_extent) } - it { is_expected.to respond_to(:reindex_extent=) } - - context 'after_update_index callback' do - describe '#update_nested_collection_relationship_indices' do - it 'will call Hyrax.config.nested_relationship_reindexer' do - expect(Hyrax.config.nested_relationship_reindexer).to receive(:call).with(id: subject.id, extent: extent).and_call_original - subject.update_nested_collection_relationship_indices - end - - it 'will not call during save' do - allow(klass).to receive(:before_save).and_return(true) - expect(Hyrax.config.nested_relationship_reindexer).not_to receive(:call) - end - end - end - - context 'after_destroy callback', with_nested_reindexing: true do - describe '#update_child_nested_collection_relationship_indices' do - it 'will call Hyrax.config.nested_relationship_reindexer' do - expect(Hyrax.config.nested_relationship_reindexer).to receive(:call).with(id: child_collection.id, extent: extent).and_call_original - subject.update_child_nested_collection_relationship_indices - end - end - - describe '#find_children_of' do - it 'will return an array containing the child collection ids' do - expect(subject.find_children_of(destroyed_id: collection.id).first.id).to eq(child_collection.id) - end - end - end - end -end diff --git a/spec/models/hyrax/work_behavior_spec.rb b/spec/models/hyrax/work_behavior_spec.rb index 65caa68586..2e5ca27791 100644 --- a/spec/models/hyrax/work_behavior_spec.rb +++ b/spec/models/hyrax/work_behavior_spec.rb @@ -17,8 +17,7 @@ class EssentialWork < ActiveFedora::Base Hyrax::Serializers, Hydra::WithDepositor, Hydra::AccessControls::Embargoable, - Hyrax::Suppressible, - Hyrax::CollectionNesting) + Hyrax::Suppressible) end describe '#to_s' do @@ -48,11 +47,4 @@ class EssentialWork < ActiveFedora::Base expect(EssentialWork.indexer).to eq klass end end - - describe '#update_nested_collection_relationship_indices', :with_nested_reindexing do - it 'will be called after save' do - expect(Samvera::NestingIndexer).to receive(:reindex_relationships).with(id: kind_of(String), extent: kind_of(String)) - subject.save! - end - end end diff --git a/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb b/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb index 7af25bbe0c..3021c472d0 100644 --- a/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb +++ b/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb @@ -9,14 +9,7 @@ [false, true].each do |test_valkyrie| context "when test_valkyrie is #{test_valkyrie}" do let(:builder) do - described_class.new(scope: scope, access: access, collection: collection, - nesting_attributes: nesting_attributes, nest_direction: test_nest_direction) - end - let(:nesting_attributes) do - double(parents: ['Parent_1', 'Parent_2'], - pathnames: ["Parent_1/#{collection_id}", "Parent_2/#{collection_id}"], - ancestors: ['Parent_1', 'Parent_2'], - depth: 2) + described_class.new(scope: scope, access: access, collection: collection, nest_direction: test_nest_direction) end let(:collection_id) { collection.id.to_s } @@ -53,14 +46,12 @@ subject { builder.show_only_other_collections_of_the_same_collection_type(solr_params) } context 'when nesting :as_parent' do - let(:test_nest_direction) { :as_parent } - - it 'will exclude the given collection and its parents' do + it 'will exclude the given collection, its parents, and direct children' do subject expect(solr_params.fetch(:fq)).to contain_exactly( - "-{!terms f=id}#{collection_id},#{nesting_attributes.parents.first},#{nesting_attributes.parents.last}", "_query_:\"{!field f=collection_type_gid_ssim}#{collection.collection_type_gid}\"", - "-_query_:\"{!lucene df=nesting_collection__pathnames_ssim}*#{collection_id}*\"" + "-{!graph to=id from=member_of_collection_ids_ssim}id:#{collection.id}", + "-{!graph from=id to=member_of_collection_ids_ssim maxDepth=1}id:#{collection.id}" ) end end @@ -68,16 +59,13 @@ context 'when nesting :as_child' do let(:test_nest_direction) { :as_child } - it 'will build the search for valid children' do + it 'will exclude the given collection, its children, and direct parents' do subject - # rubocop:disable Layout/LineLength expect(solr_params.fetch(:fq)).to contain_exactly( - "-{!terms f=id}#{collection_id}", "_query_:\"{!field f=collection_type_gid_ssim}#{collection.collection_type_gid}\"", - "-_query_:\"{!lucene q.op=OR df=nesting_collection__pathnames_ssim}#{nesting_attributes.pathnames.first} #{nesting_attributes.pathnames.last} #{nesting_attributes.ancestors.first} #{nesting_attributes.ancestors.last}\"", - "-_query_:\"{!field f=nesting_collection__parent_ids_ssim}#{collection_id}\"" + "-{!graph to=id from=member_of_collection_ids_ssim maxDepth=1}id:#{collection.id}", + "-{!graph from=id to=member_of_collection_ids_ssim}id:#{collection.id}" ) - # rubocop:enable Layout/LineLength end end end diff --git a/spec/services/hyrax/adapters/nesting_index_adapter_spec.rb b/spec/services/hyrax/adapters/nesting_index_adapter_spec.rb deleted file mode 100644 index 727820317d..0000000000 --- a/spec/services/hyrax/adapters/nesting_index_adapter_spec.rb +++ /dev/null @@ -1,205 +0,0 @@ -# frozen_string_literal: true -require 'samvera/nesting_indexer/adapters/interface_behavior_spec' - -RSpec.describe Hyrax::Adapters::NestingIndexAdapter do - it_behaves_like 'a Samvera::NestingIndexer::Adapter' - - describe '.find_preservation_document_by' do - let(:id) { '123' } - - subject { described_class.find_preservation_document_by(id: id) } - - context 'with a not found fedora document ' do - let(:id) { 'so-very-missing-no-document-here' } - - it 'raises ActiveFedora::ObjectNotFound' do - expect { subject }.to raise_error(ActiveFedora::ObjectNotFoundError) - end - end - context 'with fedora document that does not have #member_of_collection_ids' do - let(:document) { double("Document", id: id) } - - before do - expect(ActiveFedora::Base).to receive(:find).with(document.id).and_return(document) - end - - it { is_expected.to be_a(Samvera::NestingIndexer::Documents::PreservationDocument) } - end - context 'with fedora document that has #member_of_collection_ids' do - let(:document) { double("Document", id: id, member_of_collection_ids: ['456', '789']) } - - before do - expect(ActiveFedora::Base).to receive(:find).with(document.id).and_return(document) - end - - it { is_expected.to be_a(Samvera::NestingIndexer::Documents::PreservationDocument) } - end - end - - describe '.find_index_document_by' do - subject { described_class.find_index_document_by(id: id) } - - context 'with id not in solr, it builds from Fedora' do - let(:id) { 'so-very-missing-no-document-here' } - let(:document) { double("Document", id: id, fetch: nil) } - let(:object) { double("Object_to_reindex", id: id, to_solr: document) } - - before do - allow(ActiveFedora::Base).to receive(:find).with(id).and_return(object) - end - - it { is_expected.to be_a(Samvera::NestingIndexer::Documents::IndexDocument) } - end - - context 'with a found id' do - let(:id) { "abc-def-ghi" } - let(:document) { { id: id } } - - before do - Hyrax::SolrService.delete(id) - Hyrax::SolrService.add(document, commit: true) - end - - it { is_expected.to be_a(Samvera::NestingIndexer::Documents::IndexDocument) } - end - end - - describe '.each_perservation_document_id_and_parent_ids', clean_repo: true do - let!(:nested_parent) { build(:collection_lw, member_of_collections: []) } - let!(:nested_with_parent) { create(:collection_lw, member_of_collections: [nested_parent]) } - let!(:work) { create(:generic_work) } - let(:count_of_items) { ActiveFedora::Base.descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true).count } - - it 'uses direct add to Solr on non-nested objects but yields the document and parent_ids to allow nesting logic to fire' do - # The two collections and the work are handled via the nesting indexer. - # we expect remaining repository objects to reindex via to_solr. - expect(Hyrax::SolrService).to receive(:add).exactly(count_of_items - 3).times - yielded = [] - described_class.each_perservation_document_id_and_parent_ids do |document_id, parent_ids| - yielded << [document_id, parent_ids] - end - # collections or works with parents do not yield, so parent_ids should always be an empty array, and nested_with_parent is not yielded. - expect(yielded).to contain_exactly([work.id, []], [nested_parent.id, []]) - end - end - - describe '.each_child_document_of', clean_repo: true do - let(:ancestors_key) { described_class.solr_field_name_for_storing_ancestors } - let(:pathnames_key) { described_class.solr_field_name_for_storing_pathnames } - let(:index_document_class) { Samvera::NestingIndexer::Documents::IndexDocument } - let(:parent) { { id: document.id } } - let(:document) { index_document_class.new(id: 'parent-1', pathnames: ['parent-1'], parent_ids: [], ancestors: []) } - let(:children) do - [{ id: 'child-1', - member_of_collection_ids_ssim: [document.id], - ancestors_key => [document.id], - pathnames_key => ['child-1'] }, - { id: 'child-2', - member_of_collection_ids_ssim: [document.id], - ancestors_key => [document.id] }] - end - let(:not_my_children) do - [{ id: 'youre-not-my-dad-1', - member_of_collection_ids_ssim: ['parent-2'], - ancestors_key => ['parent-2'], - pathnames_key => ['youre-not-my-dad-1'] }, - { id: 'i-am-your-grandchild', - member_of_collection_ids_ssim: ['parent-3'], - ancestors_key => ['parent-1/parent-3'], - pathnames_key => ['i-am-your-grandchild'] }] - end - - before do - ([parent] + children + not_my_children).each do |doc| - Hyrax::SolrService.add(doc, commit: true) - end - end - - context 'with full reindexing extent' do - it 'yields all of the child solr-documents of the given document' do - child_index_documents = [] - described_class.each_child_document_of(document: document, extent: Hyrax::Adapters::NestingIndexAdapter::FULL_REINDEX) do |doc| - child_index_documents << doc - end - expect(child_index_documents.count).to eq(2) - child_index_documents.each do |child| - expect(child).to be_a(index_document_class) - expect(child.ancestors).to eq([document.id]) - end - end - end - - context 'with limited reindexing extent' do - it 'yields only child documents without pathnames' do - child_index_documents = [] - described_class.each_child_document_of(document: document, extent: Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX) do |doc| - child_index_documents << doc - end - expect(child_index_documents.count).to eq(1) - child_index_documents.each do |child| - expect(child).to be_a(index_document_class) - expect(child.ancestors).to eq([document.id]) - end - end - end - end - - describe '.write_nesting_document_to_index_layer' do - let(:work) { create(:work) } - let(:query_for_works_solr_document) { ->(id:) { Hyrax::SolrService.query(Hyrax::SolrQueryBuilderService.construct_query_for_ids([id])).first } } - # rubocop:disable RSpec/ExampleLength - it 'will append parent_ids, ancestors, pathnames, and deepest_nested_depth to the SOLR document' do - previous_solr_keys = work.to_solr.keys - expect(previous_solr_keys).not_to include(described_class.solr_field_name_for_storing_ancestors) - expect(previous_solr_keys).not_to include(described_class.solr_field_name_for_storing_parent_ids) - expect(previous_solr_keys).not_to include(described_class.solr_field_name_for_storing_pathnames) - expect(previous_solr_keys).not_to include(described_class.solr_field_name_for_deepest_nested_depth) - - existing_queried_solr_document = query_for_works_solr_document.call(id: work.id) - expect(existing_queried_solr_document).not_to be_key(described_class.solr_field_name_for_storing_ancestors) - expect(existing_queried_solr_document).not_to be_key(described_class.solr_field_name_for_storing_parent_ids) - expect(existing_queried_solr_document).not_to be_key(described_class.solr_field_name_for_storing_pathnames) - expect(existing_queried_solr_document).not_to be_key(described_class.solr_field_name_for_deepest_nested_depth) - - nesting_document = Samvera::NestingIndexer::Documents::IndexDocument.new( - id: work.id, - parent_ids: ['123'], - pathnames: ["123#{Samvera::NestingIndexer::Documents::ANCESTOR_AND_PATHNAME_DELIMITER}#{work.id}"], - ancestors: ['123'] - ) - returned_solr_document = described_class.write_nesting_document_to_index_layer(nesting_document: nesting_document) - - expect(returned_solr_document.fetch(described_class.solr_field_name_for_storing_ancestors)).to eq(nesting_document.ancestors) - expect(returned_solr_document.fetch(described_class.solr_field_name_for_storing_parent_ids)).to eq(nesting_document.parent_ids) - expect(returned_solr_document.fetch(described_class.solr_field_name_for_storing_pathnames)).to eq(nesting_document.pathnames) - expect(returned_solr_document.fetch(described_class.solr_field_name_for_deepest_nested_depth)).to eq(nesting_document.deepest_nested_depth) - - newly_queried_solr_document = query_for_works_solr_document.call(id: work.id) - expect(newly_queried_solr_document.fetch(described_class.solr_field_name_for_storing_ancestors)).to eq(nesting_document.ancestors) - expect(newly_queried_solr_document.fetch(described_class.solr_field_name_for_storing_parent_ids)).to eq(nesting_document.parent_ids) - expect(newly_queried_solr_document.fetch(described_class.solr_field_name_for_storing_pathnames)).to eq(nesting_document.pathnames) - expect(newly_queried_solr_document.fetch(described_class.solr_field_name_for_deepest_nested_depth)).to eq(nesting_document.deepest_nested_depth) - end - # rubocop:enable RSpec/ExampleLength - end - - describe '.solr_field_name_for_storing_ancestors' do - subject { described_class.solr_field_name_for_storing_ancestors } - - it { is_expected.to match(/_ssim$/) } - end - - describe '.solr_field_name_for_deepest_nested_depth' do - subject { described_class.solr_field_name_for_deepest_nested_depth } - - it 'is expected to be a single value integer' do - expect(subject).to match(/_isi$/) - end - end - - describe '.solr_field_name_for_storing_parent_ids' do - subject { described_class.solr_field_name_for_storing_parent_ids } - - it { is_expected.to match(/_ssim$/) } - end -end diff --git a/spec/services/hyrax/collections/nested_collection_persistence_service_spec.rb b/spec/services/hyrax/collections/nested_collection_persistence_service_spec.rb index a740100f7a..8abab8889f 100644 --- a/spec/services/hyrax/collections/nested_collection_persistence_service_spec.rb +++ b/spec/services/hyrax/collections/nested_collection_persistence_service_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -RSpec.describe Hyrax::Collections::NestedCollectionPersistenceService, with_nested_reindexing: true do +RSpec.describe Hyrax::Collections::NestedCollectionPersistenceService do let(:parent) { FactoryBot.valkyrie_create(:hyrax_collection) } let(:child) { FactoryBot.valkyrie_create(:hyrax_collection) } diff --git a/spec/services/hyrax/collections/nested_collection_query_service_spec.rb b/spec/services/hyrax/collections/nested_collection_query_service_spec.rb index 231cbc0120..1c99edf9d2 100644 --- a/spec/services/hyrax/collections/nested_collection_query_service_spec.rb +++ b/spec/services/hyrax/collections/nested_collection_query_service_spec.rb @@ -11,84 +11,43 @@ let(:another_collection_type) { create(:collection_type) } let(:coll_a) do - build(:public_collection, + create(:public_collection, id: 'Collection_A', - collection_type: collection_type, - with_nesting_attributes: - { ancestors: [], - parent_ids: [], - pathnames: ['Collection_A'], - depth: 1 }) + collection_type: collection_type) end let(:coll_b) do - build(:public_collection, + create(:public_collection, id: 'Collection_B', collection_type: collection_type, - member_of_collections: [coll_a], - with_nesting_attributes: - { ancestors: ['Collection_A'], - parent_ids: ['Collection_A'], - pathnames: ['Collection_A/Collection_B'], - depth: 2 }) + member_of_collections: [coll_a]) end let(:coll_c) do - build(:public_collection, + create(:public_collection, id: 'Collection_C', collection_type: collection_type, - member_of_collections: [coll_b], - with_nesting_attributes: - { ancestors: ["Collection_A", - "Collection_A/Collection_B"], - parent_ids: ['Collection_B'], - pathnames: ['Collection_A/Collection_B/Collection_C'], - depth: 3 }) + member_of_collections: [coll_b]) end let(:coll_d) do - build(:public_collection, + create(:public_collection, id: 'Collection_D', collection_type: collection_type, - member_of_collections: [coll_c], - with_nesting_attributes: - { ancestors: ["Collection_A", - "Collection_A/Collection_B", - "Collection_A/Collection_B/Collection_C"], - parent_ids: ['Collection_C'], - pathnames: ["Collection_A/Collection_B/Collection_C/Collection_D"], - depth: 4 }) + member_of_collections: [coll_c]) end let(:coll_e) do - build(:public_collection, + create(:public_collection, id: 'Collection_E', collection_type: collection_type, - member_of_collections: [coll_d], - with_nesting_attributes: - { ancestors: ["Collection_A", - "Collection_A/Collection_B", - "Collection_A/Collection_B/Collection_C", - "Collection_A/Collection_B/Collection_C/Collection_D"], - parent_ids: ['Collection_D'], - pathnames: ['Collection_A/Collection_B/Collection_C/Collection_D/Collection_E'], - depth: 5 }) + member_of_collections: [coll_d]) end let(:another) do - build(:public_collection, + create(:public_collection, id: 'Another_One', - collection_type: collection_type, - with_nesting_attributes: - { ancestors: [], - parent_ids: [], - pathnames: ['Another_One'], - depth: 1 }) + collection_type: collection_type) end let(:wrong) do - build(:public_collection, + create(:public_collection, id: 'Wrong_Type', - collection_type: another_collection_type, - with_nesting_attributes: - { ancestors: [], - parent_ids: [], - pathnames: ['Wrong_Type'], - depth: 1 }) + collection_type: another_collection_type) end describe '.available_child_collections' do @@ -104,7 +63,7 @@ subject { described_class.available_child_collections(parent: coll_c, scope: scope) } before do - coll_e # this will also build coll_a through coll_d + coll_e # this will also create coll_a through coll_d another wrong end @@ -149,19 +108,19 @@ end end - describe 'and can read the child', with_nested_reindexing: true do + describe 'and can read the child' do subject { described_class.available_parent_collections(child: coll_c, scope: scope) } # using create option here because permission template is required for testing :deposit access let(:coll_a) do - build(:public_collection_lw, + create(:public_collection_lw, id: 'Collection_A', collection_type: collection_type, user: user, with_permission_template: true) end let(:coll_b) do - build(:public_collection_lw, + create(:public_collection_lw, id: 'Collection_B', collection_type: collection_type, user: user, @@ -169,7 +128,7 @@ member_of_collections: [coll_a]) end let(:coll_c) do - build(:public_collection_lw, + create(:public_collection_lw, id: 'Collection_C', collection_type: collection_type, user: user, @@ -177,7 +136,7 @@ member_of_collections: [coll_b]) end let(:coll_d) do - build(:public_collection_lw, + create(:public_collection_lw, id: 'Collection_D', collection_type: collection_type, user: user, @@ -200,7 +159,7 @@ with_permission_template: true) end let(:wrong) do - build(:public_collection_lw, + create(:public_collection_lw, id: 'Wrong_Type', collection_type: another_collection_type, user: user, @@ -208,7 +167,7 @@ end before do - coll_e # this will also build coll_a through coll_d + coll_e # this will also create coll_a through coll_d another wrong end @@ -217,7 +176,7 @@ it 'returns an array of collections of the same collection type excluding the given collection' do expect(scope).to receive(:can?).with(:read, coll_c).and_return(true) expect(described_class).to receive(:query_solr).with(collection: coll_c, access: :deposit, scope: scope, limit_to_id: nil, nest_direction: :as_parent).and_call_original - expect(subject.map(&:id)).to contain_exactly(coll_a.id, another.id) + expect(subject.map(&:id)).to contain_exactly(another.id, coll_a.id) end end end @@ -243,7 +202,7 @@ it { is_expected.to eq(false) } end - describe 'and are of the same collection type', with_nested_reindexing: true do + describe 'and are of the same collection type' do # using create option here because permission template is required for testing :deposit access let!(:parent) do create(:public_collection_lw, @@ -301,55 +260,4 @@ it { is_expected.to eq(false) } end end - - describe '.valid_combined_nesting_depth?' do - subject { described_class.valid_combined_nesting_depth?(parent: parent, child: child, scope: scope) } - - context 'when total depth > limit' do - let(:parent) { coll_e } - let(:child) { another } - - it 'returns false' do - expect(subject).to eq false - end - end - - context 'when valid combined depth' do - let(:parent) { coll_c } - let(:child) { coll_e } - - it 'returns true' do - expect(subject).to eq true - end - end - end - - describe 'nesting attributes object', with_nested_reindexing: true do - let(:user) { create(:user) } - let(:parent) { FactoryBot.create(:collection_lw, id: 'Parent_Coll', collection_type: collection_type, user: user) } - let(:child) { FactoryBot.create(:collection_lw, id: 'Child_Coll', collection_type: collection_type, user: user) } - let(:nesting_attributes) { Hyrax::Collections::NestedCollectionQueryService::NestingAttributes.new(id: child.id, scope: scope) } - - before do - Hyrax::Collections::NestedCollectionPersistenceService - .persist_nested_collection_for(parent: parent, child: child) - end - - it 'will respond to expected methods' do - expect(nesting_attributes).to respond_to(:id) - expect(nesting_attributes).to respond_to(:parents) - expect(nesting_attributes).to respond_to(:pathnames) - expect(nesting_attributes).to respond_to(:ancestors) - expect(nesting_attributes).to respond_to(:depth) - end - - it 'will encapsulate the nesting attributes in an object' do - expect(nesting_attributes).to be_a(Hyrax::Collections::NestedCollectionQueryService::NestingAttributes) - expect(nesting_attributes.id).to eq('Child_Coll') - expect(nesting_attributes.parents).to eq(['Parent_Coll']) - expect(nesting_attributes.pathnames).to eq(['Parent_Coll/Child_Coll']) - expect(nesting_attributes.ancestors).to eq(['Parent_Coll']) - expect(nesting_attributes.depth).to eq(2) - end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3be28918f4..c27f33fb21 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -145,8 +145,6 @@ def clean_active_fedora_repository DatabaseCleaner.clean_with(:truncation) # Noid minting causes extra LDP requests which slow the test suite. Hyrax.config.enable_noids = false - # Don't use the nested relationship reindexer. Null is much faster - Hyrax.config.nested_relationship_reindexer = ->(id:, extent:) {} # setup a test group service User.group_service = TestHydraGroupService.new # Set a geonames username; doesn't need to be real. @@ -336,15 +334,4 @@ def clean_active_fedora_repository hide_const("Wings") # disable_wings=true removes the Wings constant end end - - # turn on the default nested reindexer; we use a null implementation for most - # tests because it's (supposedly?) much faster. why is it faster but doesn't - # impact most tests? maybe we should fix this in the implementation instead? - config.around(:example, :with_nested_reindexing) do |example| - original_indexer = Hyrax.config.nested_relationship_reindexer - Hyrax.config.nested_relationship_reindexer = - Hyrax.config.default_nested_relationship_reindexer - example.run - Hyrax.config.nested_relationship_reindexer = original_indexer - end end