Sha256: f88eaad4bcc8f5085ba59143252228e2603a5f0f5872c5eb0ee55d5762ed1aff

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 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

  it 'finds root objects when type is blank' do
    animal = Animal.create :name => 'Animal', type: ''
    index

    Animal.search.to_a.should == [animal]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.2 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.1.1 spec/acceptance/searching_with_sti_spec.rb
thinking-sphinx-3.1.0 spec/acceptance/searching_with_sti_spec.rb