From fe246f33281e01cd93d910a2e628a2e6bbbef7bb Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Wed, 30 Aug 2023 13:45:23 -0700 Subject: [PATCH] make a failing test for #5522 the issue in #5522 is that search filters for collections aren't working correctly on `.koppie` (when collections have `model_name` other than `Collection`). the relevant controller specs were completely stubbed on all the related behavior. this unstubs them so there's a narrow test that fails related to the issue. --- .../hyrax/my/collections_controller.rb | 2 + .../hyrax/my/collections_controller_spec.rb | 60 ++++++++++++------- spec/factories/hyrax_collection.rb | 6 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/controllers/hyrax/my/collections_controller.rb b/app/controllers/hyrax/my/collections_controller.rb index 7c314b3fca..1c8a28e0cc 100644 --- a/app/controllers/hyrax/my/collections_controller.rb +++ b/app/controllers/hyrax/my/collections_controller.rb @@ -37,6 +37,8 @@ def search_action_url(*args) hyrax.my_collections_url(*args) end + # @api public + # # The url of the "more" link for additional facet values def search_facet_path(args = {}) hyrax.my_dashboard_collections_facet_path(args[:id]) diff --git a/spec/controllers/hyrax/my/collections_controller_spec.rb b/spec/controllers/hyrax/my/collections_controller_spec.rb index b55de45645..0a8d4a9db2 100644 --- a/spec/controllers/hyrax/my/collections_controller_spec.rb +++ b/spec/controllers/hyrax/my/collections_controller_spec.rb @@ -1,37 +1,57 @@ # frozen_string_literal: true -RSpec.describe Hyrax::My::CollectionsController, type: :controller do - describe "logged in user" do - describe "#index" do - let(:user) { create(:user) } - let(:response) { instance_double(Blacklight::Solr::Response, response: { 'numFound' => 3 }) } - let(:doc_list) { [double(id: 123), double(id: 456)] } - - before do - sign_in user - end +RSpec.describe Hyrax::My::CollectionsController, :clean_repo, type: :controller do + context "with a logged in user" do + let(:user) { FactoryBot.create(:user) } - it "shows the search results and sets breadcrumbs" do - allow_any_instance_of(Hyrax::SearchService).to receive(:search_results).and_return([response, doc_list]) + before { sign_in(user) } + describe "#index" do + it "sets breadcrumbs" do expect(controller).to receive(:add_breadcrumb).with('Home', root_path(locale: 'en')) expect(controller).to receive(:add_breadcrumb).with('Dashboard', dashboard_path(locale: 'en')) expect(controller).to receive(:add_breadcrumb).with('Collections', my_collections_path(locale: 'en')) + get :index, params: { per_page: 1 } + end + + it "shows empty results with no collections" do + get :index, params: { per_page: 1 } - get :index, params: { per_page: 2 } - expect(assigns[:document_list].length).to eq 2 + expect(assigns[:document_list]).to be_empty + end + + context "with collections deposited by user" do + let!(:user_collections) do + [FactoryBot.valkyrie_create(:hyrax_collection, user: user), + FactoryBot.valkyrie_create(:hyrax_collection, user: user)] + end + + let!(:other_collections) do + [FactoryBot.valkyrie_create(:hyrax_collection), + FactoryBot.valkyrie_create(:hyrax_collection)] + end + + it "shows empty results with no collections" do + get :index, params: { per_page: 10 } + + expect(assigns[:document_list]) + .to contain_exactly(have_attributes(id: user_collections.first.id), + have_attributes(id: user_collections.last.id)) + end end end end describe "#search_facet_path" do - subject { controller.send(:search_facet_path, id: 'keyword_sim') } - - it { is_expected.to eq "/dashboard/my/collections/facet/keyword_sim?locale=en" } + it do + expect(controller.send(:search_facet_path, id: 'keyword_sim')) + .to eq "/dashboard/my/collections/facet/keyword_sim?locale=en" + end end describe "#search_builder_class" do - subject { controller.blacklight_config.search_builder_class } - - it { is_expected.to eq Hyrax::My::CollectionsSearchBuilder } + it 'has a default search builder class'do + expect(controller.blacklight_config.search_builder_class) + .to eq Hyrax::My::CollectionsSearchBuilder + end end end diff --git a/spec/factories/hyrax_collection.rb b/spec/factories/hyrax_collection.rb index 2d1c745525..775289a0e0 100644 --- a/spec/factories/hyrax_collection.rb +++ b/spec/factories/hyrax_collection.rb @@ -19,10 +19,14 @@ access_grants { [] } end + after(:build) do |collection, evaluator| + collection.depositor ||= evaluator.user.user_key + end + after(:create) do |collection, evaluator| if evaluator.members.present? evaluator.members.map do |member| - member.member_of_collection_ids += [collection.id] + member.membner_of_collection_ids += [collection.id] member = Hyrax.persister.save(resource: member) Hyrax.index_adapter.save(resource: member) if evaluator.with_index end