Permalink
Browse files

Merge pull request #61 from herval/master

quick fix: conditional indexing now removes stales from index too
  • Loading branch information...
2 parents 93b287e + 75dc066 commit f32c2dcf70163ae565ad7aa894ef7aa5e1ef4153 @kidpollo committed Apr 24, 2012
Showing with 19 additions and 3 deletions.
  1. +8 −3 lib/tanker.rb
  2. +11 −0 spec/tanker_spec.rb
View
@@ -392,10 +392,15 @@ def tanker_conditions
end
# update a create instance from index tank
+ # or remove it if not indexable anymore
def update_tank_indexes
- tanker_config.index.add_document(
- it_doc_id, tanker_index_data, tanker_index_options
- ) if tanker_indexable?
+ if tanker_indexable?
+ tanker_config.index.add_document(
+ it_doc_id, tanker_index_data, tanker_index_options
+ )
+ else
+ delete_tank_indexes
+ end
end
# delete instance from index tank
View
@@ -216,6 +216,17 @@ def index_or_not?
end
end
+ it "should remove object from index if conditions are not met" do
+ @dummy_class.send(:tankit, 'dummy index') do
+ indexes :something
+ conditions { false }
+ end
+ dummy_instance = @dummy_class.new
+ dummy_instance.should_receive(:delete_tank_indexes).once
+
+ dummy_instance.update_tank_indexes
+ end
+
it 'should be indexable when no conditions are given' do
@dummy_class.send(:tankit, 'dummy index') do
indexes :something

0 comments on commit f32c2dc

Please sign in to comment.