Permalink
Browse files

Fix broken reindex; remove reindex tasks that use mocking

Because it's behavior that matters, folks.
  • Loading branch information...
1 parent ff4be00 commit 3bdd9cc004425f858c7103a9c497ad8e8bb3442c @outoftime outoftime committed Dec 29, 2010
@@ -231,11 +231,13 @@ def solr_index(opts={})
}.merge(opts)
if options[:batch_size]
+ counter = 0
find_in_batches(:include => options[:include], :batch_size => options[:batch_size]) do |records|
solr_benchmark options[:batch_size], counter do
Sunspot.index(records)
end
Sunspot.commit if options[:batch_commit]
+ counter += 1
end
Sunspot.commit unless options[:batch_commit]
else
@@ -301,56 +301,6 @@
end
describe "when using batches" do
-
- it "should use the default options" do
- Post.should_receive(:all).with do |params|
- params[:limit].should == 500
- params[:include].should == []
- params[:conditions].should == ['posts.id > ?', 0]
- params[:order].should == 'posts.id'
- end.and_return(@posts)
- Post.reindex
- end
-
- it "should set the conditions using the overridden table attributes" do
- @posts = Array.new(2) { Author.create }
- Author.should_receive(:all).with do |params|
- params[:conditions].should == ['writers.writer_id > ?', 0]
- params[:order].should == 'writers.writer_id'
- end.and_return(@posts)
- Author.reindex
- end
-
- it "should count the number of records to index" do
- Post.should_receive(:count).and_return(10)
- Post.reindex
- end
-
- it "should override the batch_size" do
- Post.should_receive(:all).with do |params|
- params[:limit].should == 20
- @posts
- end.and_return(@posts)
- Post.reindex(:batch_size => 20)
- end
-
- it "should set the include option" do
- Post.should_receive(:all).with do |params|
- params[:include].should == [{:author => :address}]
- @posts
- end.and_return(@posts)
- Post.reindex(:include => [{:author => :address}])
- end
-
- it "should set the include option from the searchable options" do
- @blogs = Array.new(2) { Blog.create }
- Blog.should_receive(:all).with do |params|
- params[:include].should == [{ :posts => :author }, :comments]
- @blogs
- end.and_return(@blogs)
- Blog.reindex
- end
-
it "should commit after indexing each batch" do
Sunspot.should_receive(:commit).twice
Post.reindex(:batch_size => 1)
@@ -360,7 +310,6 @@
Sunspot.should_receive(:commit).once
Post.reindex(:batch_commit => false)
end
-
end
end
@@ -1,6 +1,7 @@
class Post < ActiveRecord::Base
belongs_to :location
belongs_to :author
+ has_many :comments
searchable :auto_index => false, :auto_remove => false do
string :title
@@ -1,6 +1,7 @@
class Post < ActiveRecord::Base
belongs_to :location
belongs_to :author
+ has_many :comments
searchable :auto_index => false, :auto_remove => false do
string :title

0 comments on commit 3bdd9cc

Please sign in to comment.