Sha256: 2b5e7a4e592ac64604c3e274ca3735f0b0ef52659aa541175a4c5e5e73bf16f3

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

require 'acceptance/spec_helper'

describe 'Searching across STI models', :live => true do
  it "returns super- and sub-class results" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    index

    Animal.search.to_a.should == [platypus, duck]
  end

  it "limits results based on subclasses" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    index

    Bird.search.to_a.should == [duck]
  end

  it "returns results for deeper subclasses when searching on their parents" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    emu      = FlightlessBird.create :name => 'Emu'
    index

    Bird.search.to_a.should == [duck, emu]
  end

  it "returns results for deeper subclasses" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    emu      = FlightlessBird.create :name => 'Emu'
    index

    FlightlessBird.search.to_a.should == [emu]
  end

  it "filters out sibling subclasses" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    otter    = Mammal.create :name => 'Otter'
    index

    Bird.search.to_a.should == [duck]
  end

  it "obeys :classes if supplied" do
    platypus = Animal.create :name => 'Platypus'
    duck     = Bird.create :name => 'Duck'
    emu      = FlightlessBird.create :name => 'Emu'
    index

    Bird.search(nil, :skip_sti => true, :classes=>[Bird, FlightlessBird]).to_a.should == [duck, emu]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.6 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.5 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.4 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.3 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.2 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.1 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.0 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.0.rc spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.0.0.pre spec/acceptance/searching_with_sti_spec.rb