spec/api/indexer/batch_spec.rb in erichummel-sunspot-1.2.1 vs spec/api/indexer/batch_spec.rb in erichummel-sunspot-2.0.0.pre.111215a
- old
+ new
@@ -1,20 +1,20 @@
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
- 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
@@ -34,13 +34,39 @@
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
+
+ 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