Sha256: 44e8bc88ed8d528fd51d6794de4dbf20b9046df47fe4e793fb4797529cea4f9e

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module ThinkingSphinx
  class Search; end
end

require './lib/thinking_sphinx/search/query'

describe ThinkingSphinx::Search::Query do
  describe '#to_s' do
    it "passes through the keyword as provided" do
      query = ThinkingSphinx::Search::Query.new 'pancakes'

      query.to_s.should == 'pancakes'
    end

    it "pairs fields and keywords for given conditions" do
      query = ThinkingSphinx::Search::Query.new '', :title => 'pancakes'

      query.to_s.should == '@title pancakes'
    end

    it "combines both keywords and conditions" do
      query = ThinkingSphinx::Search::Query.new 'tasty', :title => 'pancakes'

      query.to_s.should == 'tasty @title pancakes'
    end

    it "automatically stars keywords if requested" do
      query = ThinkingSphinx::Search::Query.new 'cake', {}, true

      query.to_s.should == '*cake*'
    end

    it "automatically stars condition keywords if requested" do
      query = ThinkingSphinx::Search::Query.new '', {:title => 'pan'}, true

      query.to_s.should == '@title *pan*'
    end

    it "does not star the sphinx_internal_class field keyword" do
      query = ThinkingSphinx::Search::Query.new '',
        {:sphinx_internal_class => 'article'}, true

      query.to_s.should == '@sphinx_internal_class article'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.1 spec/thinking_sphinx/search/query_spec.rb
thinking-sphinx-3.0.0 spec/thinking_sphinx/search/query_spec.rb
thinking-sphinx-3.0.0.rc spec/thinking_sphinx/search/query_spec.rb
thinking-sphinx-3.0.0.pre spec/thinking_sphinx/search/query_spec.rb