Sha256: 79eb0a83733c55e7885f99ddab18357df51a4dc3e8588f63ae676ad22cf5b347

Contents?: true

Size: 1.89 KB

Versions: 28

Compression:

Stored size: 1.89 KB

Contents

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

describe 'batch indexing', :type => :indexer do
  let(:posts) { Array.new(2) { |index| Post.new :title => "Post number #{index}!" } }

  it 'should send all batched adds in a single request' do
    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
    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)
    session.batch do
      session.index(posts[0])
      session.remove(posts[1])
    end
    connection.adds
  end

  describe "nesting of batches" do
    let(:a_nested_batch) do
      session.batch do
        session.index posts[0]

        session.batch do
          session.index posts[1]
        end
      end
    end

    it "behaves like two sets of batches, does the inner first, then outer" do
      session.batch { session.index posts[1] }
      session.batch { session.index posts[0] }

      two_sets_of_batches_adds = connection.adds.dup
      connection.adds.clear

      a_nested_batch
      nested_batches_adds = connection.adds

      nested_batches_adds.first.first.field_by_name(:title_ss).value.should eq(
        two_sets_of_batches_adds.first.first.field_by_name(:title_ss).value
      )
    end
  end
end

Version data entries

28 entries across 28 versions & 6 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/api/indexer/batch_spec.rb
sunspot-2.2.7 spec/api/indexer/batch_spec.rb
sunspot-2.2.6 spec/api/indexer/batch_spec.rb
sunspot-2.2.5 spec/api/indexer/batch_spec.rb
sunspot-2.2.4 spec/api/indexer/batch_spec.rb
sunspot-2.2.3 spec/api/indexer/batch_spec.rb
sunspot-2.2.2 spec/api/indexer/batch_spec.rb
sunspot-2.2.1 spec/api/indexer/batch_spec.rb
sunspot-2.2.0 spec/api/indexer/batch_spec.rb
sunspot-2.1.1 spec/api/indexer/batch_spec.rb
sunspot-2.1.0 spec/api/indexer/batch_spec.rb
sunspot-2.0.0 spec/api/indexer/batch_spec.rb
sunspot-2.0.0.pre.130115 spec/api/indexer/batch_spec.rb
gojee-sunspot-2.0.5 spec/api/indexer/batch_spec.rb
sunspot-2.0.0.pre.120925 spec/api/indexer/batch_spec.rb
sunspot_solr-2.0.0.pre.120924 sunspot/spec/api/indexer/batch_spec.rb
sunspot_rails-2.0.0.pre.120924 sunspot/spec/api/indexer/batch_spec.rb
sunspot-2.0.0.pre.120924 sunspot/spec/api/indexer/batch_spec.rb
gojee-sunspot-2.0.4 spec/api/indexer/batch_spec.rb
gojee-sunspot-2.0.2 spec/api/indexer/batch_spec.rb