Commit fd566881d6bebc06ea8a3846c4f1192f1860be67
1 parent
4eef506d
Exists in
master
and in
21 other branches
Added tests for Active Job
Showing
5 changed files
with
43 additions
and
4 deletions
Show diff stats
Gemfile
gemfiles/mongoid4.gemfile
lib/searchkick/model.rb
... | ... | @@ -34,9 +34,9 @@ module Searchkick |
34 | 34 | |
35 | 35 | def reindex_async |
36 | 36 | if defined?(Searchkick::ReindexV2Job) |
37 | - Searchkick::ReindexV2Job.perform_later(self.class.name, id) | |
37 | + Searchkick::ReindexV2Job.perform_later(self.class.name, id.to_s) | |
38 | 38 | else |
39 | - Delayed::Job.enqueue Searchkick::ReindexJob.new(self.class.name, id) | |
39 | + Delayed::Job.enqueue Searchkick::ReindexJob.new(self.class.name, id.to_s) | |
40 | 40 | end |
41 | 41 | end |
42 | 42 | ... | ... |
test/reindex_job_test.rb
... | ... | @@ -15,7 +15,7 @@ class TestReindexJob < Minitest::Test |
15 | 15 | product = Product.create!(name: "Boom") |
16 | 16 | Product.searchkick_index.refresh |
17 | 17 | assert_search "*", [] |
18 | - Searchkick::ReindexJob.new("Product", product.id).perform | |
18 | + Searchkick::ReindexJob.new("Product", product.id.to_s).perform | |
19 | 19 | Product.searchkick_index.refresh |
20 | 20 | assert_search "*", ["Boom"] |
21 | 21 | end |
... | ... | @@ -25,7 +25,7 @@ class TestReindexJob < Minitest::Test |
25 | 25 | Product.reindex |
26 | 26 | assert_search "*", ["Boom"] |
27 | 27 | product.destroy |
28 | - Searchkick::ReindexJob.new("Product", product.id).perform | |
28 | + Searchkick::ReindexJob.new("Product", product.id.to_s).perform | |
29 | 29 | Product.searchkick_index.refresh |
30 | 30 | assert_search "*", [] |
31 | 31 | end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +require_relative "test_helper" | |
2 | + | |
3 | +class TestReindexV2Job < Minitest::Test | |
4 | + | |
5 | + def setup | |
6 | + super | |
7 | + Searchkick.disable_callbacks | |
8 | + end | |
9 | + | |
10 | + def teardown | |
11 | + Searchkick.enable_callbacks | |
12 | + end | |
13 | + | |
14 | + def test_create | |
15 | + skip if !defined?(ActiveJob) | |
16 | + | |
17 | + product = Product.create!(name: "Boom") | |
18 | + Product.searchkick_index.refresh | |
19 | + assert_search "*", [] | |
20 | + Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s) | |
21 | + Product.searchkick_index.refresh | |
22 | + assert_search "*", ["Boom"] | |
23 | + end | |
24 | + | |
25 | + def test_destroy | |
26 | + skip if !defined?(ActiveJob) | |
27 | + | |
28 | + product = Product.create!(name: "Boom") | |
29 | + Product.reindex | |
30 | + assert_search "*", ["Boom"] | |
31 | + product.destroy | |
32 | + Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s) | |
33 | + Product.searchkick_index.refresh | |
34 | + assert_search "*", [] | |
35 | + end | |
36 | + | |
37 | +end | ... | ... |