Sha256: 6ec7e83561c0478b5810f403d229c92e13301c2aa6fe7343aa9418fb49f80cb4

Contents?: true

Size: 1.22 KB

Versions: 14

Compression:

Stored size: 1.22 KB

Contents

require File.expand_path('spec_helper', File.dirname(__FILE__))

describe 'batch indexing', :type => :indexer do
  it 'should send all batched adds in a single request' do
    posts = Array.new(2) { Post.new }
    session.batch do
      for post in posts
        session.index(post)
      end
    end
    connection.adds.length.should == 1
  end

  it 'should add all batched adds' do
    posts = Array.new(2) { Post.new }
    session.batch do
      for post in posts
        session.index(post)
      end
    end
    add = connection.adds.last
    connection.adds.first.map { |add| add.field_by_name(:id).value }.should ==
      posts.map { |post| "Post #{post.id}" }
  end

  it 'should not index changes to models that happen after index call' do
    post = Post.new
    session.batch do
      session.index(post)
      post.title = 'Title'
    end
    connection.adds.first.first.field_by_name(:title_ss).should be_nil
  end

  it 'should batch an add and a delete' do
    pending 'batching all operations'
    connection.should_not_receive(:add)
    connection.should_not_receive(:remove)
    posts = Array.new(2) { Post.new }
    session.batch do
      session.index(posts[0])
      session.remove(posts[1])
    end
    connection.adds
  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
sunspot-1.3.3 spec/api/indexer/batch_spec.rb
sunspot-1.3.2 spec/api/indexer/batch_spec.rb
sunspot-1.3.1 spec/api/indexer/batch_spec.rb
sunspot-2.0.0.pre.111215 spec/api/indexer/batch_spec.rb
cb_sunspot-2.0.0.pre.5 spec/api/indexer/batch_spec.rb
cb_sunspot-2.0.0.pre.3 spec/api/indexer/batch_spec.rb
cb_sunspot-2.0.0.pre3 spec/api/indexer/batch_spec.rb
sunspot-1.3.0 spec/api/indexer/batch_spec.rb
pduey-sunspot-1.2.1.1 spec/api/indexer/batch_spec.rb
sunspot-1.3.0.rc6 spec/api/indexer/batch_spec.rb
erichummel-sunspot-1.2.1 spec/api/indexer/batch_spec.rb
lisausa-sunspot-1.2.1 spec/api/indexer/batch_spec.rb
sunspot_rbg-1.3.1 spec/api/indexer/batch_spec.rb
sunspot_rbg-1.3.0 spec/api/indexer/batch_spec.rb