Sha256: 69e2da30078b6ee36a4ea5d33b7952d80d0aeb8770d051bf004c9b20b5a6c19c

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

require 'acceptance/spec_helper'

describe 'SQL delta indexing', :live => true do
  it "automatically indexes new records" do
    guards = Book.create(
      :title => 'Guards! Guards!', :author => 'Terry Pratchett'
    )
    index

    expect(Book.search('Terry Pratchett').to_a).to eq([guards])

    men = Book.create(
      :title => 'Men At Arms', :author => 'Terry Pratchett'
    )
    sleep 0.25

    expect(Book.search('Terry Pratchett').to_a).to eq([guards, men])
  end

  it "automatically indexes updated records" do
    book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
    index

    expect(Book.search('Harry').to_a).to eq([book])

    book.reload.update_attributes(:author => 'Terry Pratchett')
    sleep 0.25

    expect(Book.search('Terry').to_a).to eq([book])
  end

  it "does not match on old values" do
    book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
    index

    expect(Book.search('Harry').to_a).to eq([book])

    book.reload.update_attributes(:author => 'Terry Pratchett')
    sleep 0.25

    expect(Book.search('Harry')).to be_empty
  end

  it "does not match on old values with alternative ids" do
    album = Album.create :name => 'Eternal Nightcap', :artist => 'The Whitloms'
    index

    expect(Album.search('Whitloms').to_a).to eq([album])

    album.reload.update_attributes(:artist => 'The Whitlams')
    sleep 0.25

    expect(Book.search('Whitloms')).to be_empty
  end

  it "automatically indexes new records of subclasses" do
    book = Hardcover.create(
      :title => 'American Gods', :author => 'Neil Gaiman'
    )
    sleep 0.25

    expect(Book.search('Gaiman').to_a).to eq([book])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 spec/acceptance/sql_deltas_spec.rb
thinking-sphinx-3.4.1 spec/acceptance/sql_deltas_spec.rb
thinking-sphinx-3.4.0 spec/acceptance/sql_deltas_spec.rb