Skip to content

Commit

Permalink
Implement search_state_class used by upstream blacklight
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jul 23, 2022
1 parent 6cd2ca8 commit 35cc0a0
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/services/hyrax/collection_member_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ def list_collections
def collection_search_builder
@collection_search_builder ||= ParentCollectionSearchBuilder.new([:include_item_ids, :add_paging_to_solr, :add_access_controls_to_solr_params], self)
end

def search_state_class; end
end
end
4 changes: 4 additions & 0 deletions app/services/hyrax/embargo_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def assets_with_deactivated_embargoes
presenters(builder)
end

def search_state_class
nil
end

private

def presenter_class
Expand Down
4 changes: 4 additions & 0 deletions app/services/hyrax/lease_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def assets_with_deactivated_leases
presenters(builder)
end

def search_state_class
nil
end

private

def presenter_class
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/statistics/depositors/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def depositors

private

delegate :blacklight_config, to: CatalogController
delegate :blacklight_config, :search_state_class, to: CatalogController
delegate :depositor_field, to: DepositSearchBuilder

# results come from Solr in an array where the first item is the user and
Expand Down
1 change: 1 addition & 0 deletions spec/helpers/hyrax/collections_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
allow(controller).to receive(:blacklight_config).and_return(bl_config)
allow(controller).to receive(:repository).and_return(repository)
allow(controller).to receive(:current_ability).and_return(ability)
allow(controller).to receive(:search_state_class).and_return(nil)
end

it 'gives an empty set for a missing collection' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Member < ActiveFedora::Base
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) }
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
Expand Down
3 changes: 2 additions & 1 deletion spec/search_builders/hyrax/admin_set_search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
RSpec.describe Hyrax::AdminSetSearchBuilder do
let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability)
current_ability: ability,
search_state_class: nil)
end
let(:ability) do
::Ability.new(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Hyrax::CollectionMemberSearchBuilder do
subject(:builder) { described_class.new(scope: context, collection: collection, search_includes_models: include_models) }
let(:context) { double("context", blacklight_config: CatalogController.blacklight_config) }
let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, search_state_class: nil) }
let(:solr_params) { { fq: [] } }
let(:include_models) { :both }
let(:collection) { build(:collection_lw, id: '12345') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability,
current_user: user)
current_user: user,
search_state_class: nil)
end
let(:ability) do
::Ability.new(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
RSpec.describe Hyrax::Dashboard::NestedCollectionsSearchBuilder do
let(:scope) { double(current_ability: ability, blacklight_config: CatalogController.blacklight_config) }
let(:scope) { double(current_ability: ability, blacklight_config: CatalogController.blacklight_config, search_state_class: nil) }
let(:access) { :read }
let(:user) { create(:user) }
let(:ability) { ::Ability.new(user) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability,
current_user: user)
current_user: user,
search_state_class: nil)
end
let(:ability) do
::Ability.new(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability,
current_user: user)
current_user: user,
search_state_class: nil)
end
let(:ability) do
::Ability.new(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:solr_params) { { fq: [] } }
let(:item) { double(id: '12345', member_of_collection_ids: ['col1']) }
let(:builder) { described_class.new(solr_params, context) }
let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, item: item) }
let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, item: item, search_state_class: nil) }

describe '#include_item_ids' do
let(:subject) { builder.include_item_ids(solr_params) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let(:ability) { instance_double(Ability, admin?: true) }
let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability)
current_ability: ability,
search_state_class: nil)
end
let(:builder) { described_class.new(context) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

let(:context) do
double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability)
current_ability: ability,
search_state_class: nil)
end

let(:ability) do
Expand Down
3 changes: 2 additions & 1 deletion spec/services/hyrax/admin_set_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
let(:context) do
double(current_ability: Ability.new(user),
repository: controller.repository,
blacklight_config: controller.blacklight_config)
blacklight_config: controller.blacklight_config,
search_state_class: nil)
end
let(:service) { described_class.new(context) }
let(:user) { create(:user) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:user) { create(:user) }
let(:ability) { ::Ability.new(user) }
let(:current_ability) { ability }
let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config) }
let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config, search_state_class: nil) }

let(:collection_type) { create(:collection_type) }
let(:another_collection_type) { create(:collection_type) }
Expand Down
8 changes: 6 additions & 2 deletions spec/support/fakes/fake_search_builder_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# - +#current_user+
# - +#params+
# - +#repository+
# - +#search_state_class+
#
# This provides a fake scope with more control than a generic RSpec double.
class FakeSearchBuilderScope
Expand All @@ -24,17 +25,20 @@ class FakeSearchBuilderScope
# @return [Hash]
# @!attribute [r] repository
# @return [Blacklight::AbstractRepository]
attr_reader :blacklight_config, :current_ability, :current_user, :params, :repository
# @!attribute [r] search_state_class
# @return [Blacklight::SearchState, nil]
attr_reader :blacklight_config, :current_ability, :current_user, :params, :repository, :search_state_class

##
# @param [Blacklight::Configuration] blacklight_config
# @param [::Ability, nil] current_ability
# @param [::User, nil] current_user
def initialize(blacklight_config: CatalogController.blacklight_config, current_ability: nil, current_user: nil, params: {})
def initialize(blacklight_config: CatalogController.blacklight_config, current_ability: nil, current_user: nil, params: {}, search_state_class: nil)
@blacklight_config = blacklight_config
@current_user = current_user
@current_ability = current_ability || ::Ability.new(current_user)
@params = params
@repository = Blacklight::Solr::Repository.new(blacklight_config)
@search_state_class = search_state_class
end
end

0 comments on commit 35cc0a0

Please sign in to comment.