Sha256: 001f940dcd66a38c799a0bac1ead91c6bdbb23025065dd050be07ae17dc27443

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

describe Sufia::CatalogSearchBuilder do
  let(:context) { double }
  let(:builder) { described_class.new(context).with(blacklight_params) }
  let(:solr_params) { Blacklight::Solr::Request.new }
  let(:blacklight_params) { { q: user_query } }
  let(:user_query) { "find me" }

  describe "#show_works_or_works_that_contain_files" do
    subject { builder.show_works_or_works_that_contain_files(solr_params) }

    context "with a user query" do
      it "creates a valid solr join for works and files" do
        subject
        expect(solr_params[:user_query]).to eq user_query
        expect(solr_params[:q]).to eq "{!lucene}_query_:\"{!dismax v=$user_query}\" _query_:\"{!join from=id to=file_set_ids_ssim}{!dismax v=$user_query}\""
      end
    end

    context "without a user query" do
      let(:blacklight_params) { {} }
      it "does not modify the query" do
        subject
        expect(solr_params[:user_query]).to be_nil
        expect(solr_params[:q]).to be_nil
      end
    end

    context "when doing a fielded search" do
      let(:blacklight_params) { { q: user_query, search_field: 'depositor' } }
      # Blacklight sets up these values when we've done a fielded search.
      # Here we're ensuring they aren't wiped out
      let(:solr_params) { Blacklight::Solr::Request.new("q" => "{!qf=depositor_ssim pf=depositor_ssim}\"#{user_query}\"") }
      it "does not modify the query" do
        subject
        expect(solr_params[:user_query]).to be_nil
        expect(solr_params[:q]).to eq '{!qf=depositor_ssim pf=depositor_ssim}"find me"'
      end
    end
  end

  describe "#show_only_active_records" do
    subject { builder.show_only_active_records(solr_params) }
    it "includes suppressed switch" do
      subject
      expect(solr_params[:fq]).to eq ["-suppressed_bsi:true"]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sufia-7.4.1 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.4.0 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.3.1 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.3.0 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.3.0.rc3 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.3.0.rc2 spec/search_builder/sufia/catalog_search_builder_spec.rb
sufia-7.3.0.rc1 spec/search_builder/sufia/catalog_search_builder_spec.rb