Skip to content

Commit

Permalink
make a failing test for #5522
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tamsin johnson committed Aug 30, 2023
1 parent 0fb3829 commit 285a5a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
2 changes: 2 additions & 0 deletions app/controllers/hyrax/my/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
60 changes: 40 additions & 20 deletions spec/controllers/hyrax/my/collections_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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 only user 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
6 changes: 5 additions & 1 deletion spec/factories/hyrax_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 285a5a0

Please sign in to comment.