Commit 7acb7819e0e7944edf259c66d2324e353c5b1a7b
1 parent
64a827a0
Exists in
master
and in
18 other branches
Created pattern for testing index options more easily [skip ci]
Showing
3 changed files
with
24 additions
and
7 deletions
Show diff stats
test/language_test.rb
... | ... | @@ -7,10 +7,12 @@ class LanguageTest < Minitest::Test |
7 | 7 | |
8 | 8 | def test_chinese |
9 | 9 | skip unless ENV["CHINESE"] |
10 | - Song.reindex | |
11 | - store_names ["中华人民共和国国歌"], Song | |
12 | - assert_search "中华人民共和国", ["中华人民共和国国歌"], {}, Song | |
13 | - assert_search "国歌", ["中华人民共和国国歌"], {}, Song | |
14 | - assert_search "人", [], {}, Song | |
10 | + | |
11 | + with_options(Song, language: "chinese") do | |
12 | + store_names ["中华人民共和国国歌"], Song | |
13 | + assert_search "中华人民共和国", ["中华人民共和国国歌"], {}, Song | |
14 | + assert_search "国歌", ["中华人民共和国国歌"], {}, Song | |
15 | + assert_search "人", [], {}, Song | |
16 | + end | |
15 | 17 | end |
16 | 18 | end | ... | ... |
test/reindex_test.rb
test/test_helper.rb
... | ... | @@ -528,7 +528,7 @@ class Sku |
528 | 528 | end |
529 | 529 | |
530 | 530 | class Song |
531 | - searchkick language: "chinese" | |
531 | + searchkick | |
532 | 532 | end |
533 | 533 | |
534 | 534 | Product.searchkick_index.delete if Product.searchkick_index.exists? |
... | ... | @@ -547,7 +547,6 @@ class Minitest::Test |
547 | 547 | Store.destroy_all |
548 | 548 | Animal.destroy_all |
549 | 549 | Speaker.destroy_all |
550 | - Sku.destroy_all | |
551 | 550 | end |
552 | 551 | |
553 | 552 | protected |
... | ... | @@ -579,4 +578,15 @@ class Minitest::Test |
579 | 578 | def assert_first(term, expected, options = {}, klass = Product) |
580 | 579 | assert_equal expected, klass.search(term, options).map(&:name).first |
581 | 580 | end |
581 | + | |
582 | + def with_options(model, options) | |
583 | + previous_options = model.searchkick_options.dup | |
584 | + begin | |
585 | + model.searchkick_options.merge!(options) | |
586 | + model.reindex | |
587 | + ensure | |
588 | + model.searchkick_options.clear | |
589 | + model.searchkick_options.merge!(previous_options) | |
590 | + end | |
591 | + end | |
582 | 592 | end | ... | ... |