diff --git a/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb b/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb index 252bbccf49..078b8b1ae9 100644 --- a/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb +++ b/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb @@ -30,7 +30,7 @@ it "is successful" do subject - expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([work.id])] + expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryService.new.with_ids(ids: [work.id]).build] end end @@ -38,9 +38,38 @@ subject { builder.show_only_works_not_child(solr_params) } it "is successful" do + subject + ids = Hyrax::SolrService.query("{!field f=id}#{work.id}", fl: "member_ids_ssim").flat_map { |x| x.fetch("member_ids_ssim", []) } + expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryService.new.with_ids(ids: [ids]).build] + end + + it "is successful old way" do subject ids = Hyrax::SolrService.query("{!field f=id}#{work.id}", fl: "member_ids_ssim").flat_map { |x| x.fetch("member_ids_ssim", []) } expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryBuilderService.construct_query_for_ids([ids])] + expect(ids.reject(&:blank?).empty?).to eq(false) + end + + it "is successful new same code way" do + subject + ids = Hyrax::SolrService.query("{!field f=id}#{work.id}", fl: "member_ids_ssim").flat_map { |x| x.fetch("member_ids_ssim", []) } + ids = [ids] + expect(ids.to_s).to eq("false") + + # rubocop:disable Style/IfUnlessModifier + if ids.reject(&:blank?).empty? + expect(ids.to_s).to eq("false") + end + if Hyrax::SolrQueryBuilderService.construct_query_for_ids([ids]) == "id:NEVER_USE_THIS_ID" + # if this is true that means he orininal test is bad. + expect(true).to eq(false) + end + expect(solr_params[:fq]).to eq ["-" + Hyrax::SolrQueryService.new.with_ids(ids: ids).build] + end + it "is successful the real test" do + subject + ids = Hyrax::SolrService.query("{!field f=id}#{work.id}", fl: "member_ids_ssim").flat_map { |x| x.fetch("member_ids_ssim", []) } + expect(solr_params[:fq]).to eq ["-" + "id:NEVER_USE_THIS_ID"] end end