Sha256: 2018db5444e501e2ab26db3d3134c35a2b6b3be4c9d1b6018a6c1d98749efb40

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

require 'acceptance/spec_helper'

describe 'Sphinx scopes', :live => true do
  it "allows calling sphinx scopes from models" do
    gods  = Book.create! :title => 'American Gods',      :year => 2001
    boys  = Book.create! :title => 'Anansi Boys',        :year => 2005
    grave = Book.create! :title => 'The Graveyard Book', :year => 2009
    index

    Book.by_year(2009).to_a.should == [grave]
  end

  it "allows scopes to return both query and options" do
    gods  = Book.create! :title => 'American Gods',      :year => 2001
    boys  = Book.create! :title => 'Anansi Boys',        :year => 2005
    grave = Book.create! :title => 'The Graveyard Book', :year => 2009
    index

    Book.by_query_and_year('Graveyard', 2009).to_a.should == [grave]
  end

  it "allows chaining of scopes" do
    gods  = Book.create! :title => 'American Gods',      :year => 2001
    boys  = Book.create! :title => 'Anansi Boys',        :year => 2005
    grave = Book.create! :title => 'The Graveyard Book', :year => 2009
    index

    Book.by_year(2001).by_query_and_year('Graveyard', 2009).to_a.
      should == [grave]
  end

  it "allows further search calls on scopes" do
    gaiman    = Book.create! :title => 'American Gods'
    pratchett = Book.create! :title => 'Small Gods'
    index

    Book.by_query('Gods').search('Small').to_a.should == [pratchett]
  end

  it "allows accessing counts on scopes" do
    Book.create! :title => 'American Gods'
    Book.create! :title => 'Anansi Boys'
    Book.create! :title => 'Small Gods'
    Book.create! :title => 'Night Watch'
    index

    Book.by_query('gods').count.should == 2
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.3 spec/acceptance/sphinx_scopes_spec.rb
thinking-sphinx-3.0.2 spec/acceptance/sphinx_scopes_spec.rb
thinking-sphinx-3.0.1 spec/acceptance/sphinx_scopes_spec.rb
thinking-sphinx-3.0.0 spec/acceptance/sphinx_scopes_spec.rb
thinking-sphinx-3.0.0.rc spec/acceptance/sphinx_scopes_spec.rb
thinking-sphinx-3.0.0.pre spec/acceptance/sphinx_scopes_spec.rb