Sha256: b7cb0697c0ac4c9474114eb3f35e5f4fc559ad4fc99223c9e3c35dc616f3cb17

Contents?: true

Size: 1.82 KB

Versions: 12

Compression:

Stored size: 1.82 KB

Contents

require 'acceptance/spec_helper'

describe 'Searching on fields', :live => true do
  it "limits results by field" do
    pancakes = Article.create! :title => 'Pancakes'
    waffles  = Article.create! :title => 'Waffles',
      :content => 'Different to pancakes - and not quite as tasty.'
    index

    articles = Article.search :conditions => {:title => 'pancakes'}
    articles.should include(pancakes)
    articles.should_not include(waffles)
  end

  it "limits results for a field from an association" do
    user     = User.create! :name => 'Pat'
    pancakes = Article.create! :title => 'Pancakes', :user => user
    index

    Article.search(:conditions => {:user => 'pat'}).first.should == pancakes
  end

  it "returns results with matches from grouped fields" do
    user     = User.create! :name => 'Pat'
    pancakes = Article.create! :title => 'Pancakes', :user => user
    waffles  = Article.create! :title => 'Waffles',  :user => user
    index

    Article.search('waffles', :conditions => {:title => 'pancakes'}).to_a.
      should == [pancakes]
  end

  it "returns results with matches from concatenated columns in a field" do
    book = Book.create! :title => 'Night Watch', :author => 'Terry Pratchett'
    index

    Book.search(:conditions => {:info => 'Night Pratchett'}).to_a.
      should == [book]
  end

  it "handles NULLs in concatenated fields" do
    book = Book.create! :title => 'Night Watch'
    index

    Book.search(:conditions => {:info => 'Night Watch'}).to_a.should == [book]
  end

  it "returns results with matches from file fields" do
    file_path = Rails.root.join('tmp', 'caption.txt')
    File.open(file_path, 'w') { |file| file.print 'Cyberpunk at its best' }

    book = Book.create! :title => 'Accelerando', :blurb_file => file_path.to_s
    index

    Book.search('cyberpunk').to_a.should == [book]
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
thinking-sphinx-3.2.0 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.1.4 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.1.3 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.1.2 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.1.1 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.1.0 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.6 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.5 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.4 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.3 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.2 spec/acceptance/searching_on_fields_spec.rb
thinking-sphinx-3.0.1 spec/acceptance/searching_on_fields_spec.rb