Sha256: 99b375b6467ccefd8b9b6fe9ccbc2e5413e85b831e380675db32354db2d9a5fc

Contents?: true

Size: 1.22 KB

Versions: 34

Compression:

Stored size: 1.22 KB

Contents

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

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

34 entries across 34 versions & 8 rubygems

Version Path
benjaminkrause-sunspot-0.9.7 spec/api/indexer/batch_spec.rb
benjaminkrause-sunspot-0.9.8 spec/api/indexer/batch_spec.rb
erichummel-sunspot-1.2.1g spec/api/indexer/batch_spec.rb
erichummel-sunspot-1.2.1f spec/api/indexer/batch_spec.rb
erichummel-sunspot-1.2.1b spec/api/indexer/batch_spec.rb
erichummel-sunspot-1.2.1a spec/api/indexer/batch_spec.rb
lisausa-sunspot-1.2.1.1 spec/api/indexer/batch_spec.rb
ruben-sunspot-1.1.4 spec/api/indexer/batch_spec.rb
ruben-sunspot-1.1.3 spec/api/indexer/batch_spec.rb
ruben-sunspot-1.1.2 spec/api/indexer/batch_spec.rb
sunspot-1.2.1 spec/api/indexer/batch_spec.rb
sunspot-1.2.0 spec/api/indexer/batch_spec.rb
ruben-sunspot-1.1.1 spec/api/indexer/batch_spec.rb
ruben-sunspot-1.1.0 spec/api/indexer/batch_spec.rb
nuatt_sunspot-1.1.0.3 spec/api/indexer/batch_spec.rb
sunspot-1.1.0 spec/api/indexer/batch_spec.rb
sunspot-1.0.5 spec/api/indexer/batch_spec.rb
sunspot-1.0.4 spec/api/indexer/batch_spec.rb
sunspot-1.0.3 spec/api/indexer/batch_spec.rb
sunspot-1.0.2 spec/api/indexer/batch_spec.rb