Sha256: 534396a54c68b96558939e5d9cba8852bcdfedb40b630df16a1e43f7a15fbcbd

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

describe Hyrax::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, search_field: 'all_fields' } }
  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

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-1.1.1 spec/search_builder/hyrax/catalog_search_builder_spec.rb
hyrax-1.1.0 spec/search_builder/hyrax/catalog_search_builder_spec.rb
hyrax-1.0.5 spec/search_builder/hyrax/catalog_search_builder_spec.rb
hyrax-1.0.4 spec/search_builder/hyrax/catalog_search_builder_spec.rb
hyrax-1.0.3 spec/search_builder/hyrax/catalog_search_builder_spec.rb
hyrax-1.0.2 spec/search_builder/hyrax/catalog_search_builder_spec.rb