spec/model_spec.rb in outoftime-sunspot_rails-0.9.9 vs spec/model_spec.rb in outoftime-sunspot_rails-0.9.10

- old
+ new

@@ -161,21 +161,45 @@ Post.reindex Sunspot.commit Post.search.results.to_set.should == @posts.to_set end - it 'should index with a batch size' do - Post.reindex(1) - Sunspot.commit - Post.search.results.to_set.should == @posts.to_set - end - it 'should remove all currently indexed instances' do old_post = Post.create! old_post.index! old_post.destroy Post.reindex Sunspot.commit Post.search.results.to_set.should == @posts.to_set + end + + describe "using batch sizes" do + + it 'should index with a batch size' do + Post.reindex(1) + Sunspot.commit + Post.search.results.to_set.should == @posts.to_set + end + + it "should look for find_in_batches" do + pending "Have to figure out how to remove stubs for Class Methods so this will work" + Post.stub!(:respond_to?).with(:to_ary).and_return(false) + Post.should_receive(:respond_to?).with(:find_in_batches).and_return(true) + Post.reindex(100) + end + + it "should use find_in_batches" do + pending "Have to figure out how to remove stubs for Class Methods so this will work" + Post.should_receive(:find_in_batches).with(:batch_size => 100).and_return([]) + Post.reindex(100) + end + + it "should find all with the batch size and offset if it can't use find_by_batches" do + pending "Have to figure out how to remove stubs for Class Methods so this will work" + Post.stub!(:respond_to?).with(:to_ary).and_return(false) + Post.stub!(:respond_to?).with(:find_in_batches).and_return(false) + Post.should_receive(:all).with(:offset => 0, :limit => 100).and_return([]) + Post.reindex(100) + end end end end