Sha256: 652139d0fa7b057ab4f973f66d41f94c3291cb1f63fbd949c32be4d22b6cd25a

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

# encoding: UTF-8
require 'acceptance/spec_helper'

describe 'Searching within a model', :live => true do
  it "returns results" do
    article = Article.create! :title => 'Pancakes'
    index

    Article.search.first.should == article
  end

  it "returns results matching the given query" do
    pancakes = Article.create! :title => 'Pancakes'
    waffles  = Article.create! :title => 'Waffles'
    index

    articles = Article.search 'pancakes'
    articles.should include(pancakes)
    articles.should_not include(waffles)
  end

  it "handles unicode characters" do
    istanbul = City.create! :name => 'İstanbul'
    index

    City.search('İstanbul').to_a.should == [istanbul]
  end

  it "will star provided queries on request" do
    article = Article.create! :title => 'Pancakes'
    index

    Article.search('cake', :star => true).first.should == article
  end

  it "allows for searching on specific indices" do
    article = Article.create :title => 'Pancakes'
    index

    articles = Article.search('pancake', :indices => ['stemmed_article_core'])
    articles.to_a.should == [article]
  end

  it "can search on namespaced models" do
    person = Admin::Person.create :name => 'James Bond'
    index

    Admin::Person.search('Bond').to_a.should == [person]
  end

  it "raises an error if searching through an ActiveRecord scope" do
    lambda {
      City.ordered.search
    }.should raise_error(ThinkingSphinx::MixedScopesError)
  end

  it "does not raise an error when searching with a default ActiveRecord scope" do
    lambda {
      User.search
    }.should_not raise_error(ThinkingSphinx::MixedScopesError)
  end

  it "raises an error when searching with default and applied AR scopes" do
    lambda {
      User.recent.search
    }.should raise_error(ThinkingSphinx::MixedScopesError)
  end
end

describe 'Searching within a model with a realtime index', :live => true do
  it "returns results" do
    product = Product.create! :name => 'Widget'

    Product.search.first.should == product
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.5 spec/acceptance/searching_within_a_model_spec.rb
thinking-sphinx-3.0.4 spec/acceptance/searching_within_a_model_spec.rb
thinking-sphinx-3.0.3 spec/acceptance/searching_within_a_model_spec.rb