Sha256: 5ac35ce3b2384f995c42bdd0dbeca911c132a3344d5697474fe4ff92ca860e58

Contents?: true

Size: 1.16 KB

Versions: 17

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

RSpec.describe RSolr do
  
  it "has a version that can be read via #version or VERSION" do
    expect(RSolr.version).to eq(RSolr::VERSION)
  end

  context "connect" do
    it "should return a RSolr::Client instance" do
      expect(RSolr.connect).to be_a(RSolr::Client)
    end
  end
  
  context '.solr_escape' do
    it "adds backslash to Solr query syntax chars" do
      # per http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Escaping_Special_Characters
      special_chars = [ "+", "-", "&", "|", "!", "(", ")", "{", "}", "[", "]", "^", '"', "~", "*", "?", ":", "\\", "/" ]
      escaped_str = RSolr.solr_escape("aa#{special_chars.join('aa')}aa")
      special_chars.each { |c|
        # note that the ruby code sending the query to Solr will un-escape the backslashes
        # so the result sent to Solr is ultimately a single backslash in front of the particular character 
        expect(escaped_str).to match "\\#{c}"
      }
    end
    it "leaves other chars alone" do
      str = "nothing to see here; let's move along people."
      expect(RSolr.solr_escape(str)).to eq str
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rsolr-2.6.0/spec/api/rsolr_spec.rb
rsolr-2.6.0 spec/api/rsolr_spec.rb
rsolr-2.5.0 spec/api/rsolr_spec.rb
rsolr-2.4.0 spec/api/rsolr_spec.rb
rsolr-2.3.0 spec/api/rsolr_spec.rb
telvue-rsolr-2.2.2 spec/api/rsolr_spec.rb
rsolr-2.2.1 spec/api/rsolr_spec.rb
rsolr-2.2.0 spec/api/rsolr_spec.rb
rsolr-2.1.0 spec/api/rsolr_spec.rb
rsolr-2.0.2 spec/api/rsolr_spec.rb
rsolr-2.0.1 spec/api/rsolr_spec.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rsolr-2.0.0/spec/api/rsolr_spec.rb
rsolr-2.0.0 spec/api/rsolr_spec.rb
rsolr-2.0.0.rc1 spec/api/rsolr_spec.rb
rsolr-2.0.0.pre3 spec/api/rsolr_spec.rb
rsolr-2.0.0.pre2 spec/api/rsolr_spec.rb
rsolr-2.0.0.pre1 spec/api/rsolr_spec.rb