Skip to content

Commit

Permalink
Merge pull request #61 from herval/master
Browse files Browse the repository at this point in the history
quick fix: conditional indexing now removes stales from index too
  • Loading branch information
kidpollo committed Apr 24, 2012
2 parents 93b287e + 75dc066 commit f32c2dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/tanker.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/tanker_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit f32c2dc

Please sign in to comment.