Commit 381bab0748f8e9be328672eb4589ac0376bc909d

Authored by Andrew Kane
1 parent 7a24684b

Do not wipe index when calling remove on new record - closes #405

Showing 2 changed files with 16 additions and 5 deletions   Show diff stats
lib/searchkick/index.rb
... ... @@ -50,11 +50,14 @@ module Searchkick
50 50 end
51 51  
52 52 def remove(record)
53   - client.delete(
54   - index: name,
55   - type: document_type(record),
56   - id: search_id(record)
57   - )
  53 + id = search_id(record)
  54 + unless id.blank?
  55 + client.delete(
  56 + index: name,
  57 + type: document_type(record),
  58 + id: id
  59 + )
  60 + end
58 61 end
59 62  
60 63 def import(records)
... ...
test/index_test.rb
... ... @@ -80,6 +80,14 @@ class TestIndex < Minitest::Test
80 80 Product.reindex
81 81 end
82 82  
  83 + def test_remove_blank_id
  84 + store_names ["Product A"]
  85 + Product.searchkick_index.remove(Product.new)
  86 + assert_search "product", ["Product A"]
  87 + ensure
  88 + Product.reindex
  89 + end
  90 +
83 91 def test_missing_index
84 92 assert_raises(Searchkick::MissingIndexError) { Product.search "test", index_name: "not_found" }
85 93 end
... ...