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,10 +7,12 @@ class LanguageTest < Minitest::Test | ||
7 | 7 | ||
8 | def test_chinese | 8 | def test_chinese |
9 | skip unless ENV["CHINESE"] | 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 | end | 17 | end |
16 | end | 18 | end |
test/reindex_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class ReindexTest < Minitest::Test | 3 | class ReindexTest < Minitest::Test |
4 | + def setup | ||
5 | + super | ||
6 | + Sku.destroy_all | ||
7 | + end | ||
8 | + | ||
4 | def test_scoped | 9 | def test_scoped |
5 | skip if nobrainer? || cequel? | 10 | skip if nobrainer? || cequel? |
6 | 11 |
test/test_helper.rb
@@ -528,7 +528,7 @@ class Sku | @@ -528,7 +528,7 @@ class Sku | ||
528 | end | 528 | end |
529 | 529 | ||
530 | class Song | 530 | class Song |
531 | - searchkick language: "chinese" | 531 | + searchkick |
532 | end | 532 | end |
533 | 533 | ||
534 | Product.searchkick_index.delete if Product.searchkick_index.exists? | 534 | Product.searchkick_index.delete if Product.searchkick_index.exists? |
@@ -547,7 +547,6 @@ class Minitest::Test | @@ -547,7 +547,6 @@ class Minitest::Test | ||
547 | Store.destroy_all | 547 | Store.destroy_all |
548 | Animal.destroy_all | 548 | Animal.destroy_all |
549 | Speaker.destroy_all | 549 | Speaker.destroy_all |
550 | - Sku.destroy_all | ||
551 | end | 550 | end |
552 | 551 | ||
553 | protected | 552 | protected |
@@ -579,4 +578,15 @@ class Minitest::Test | @@ -579,4 +578,15 @@ class Minitest::Test | ||
579 | def assert_first(term, expected, options = {}, klass = Product) | 578 | def assert_first(term, expected, options = {}, klass = Product) |
580 | assert_equal expected, klass.search(term, options).map(&:name).first | 579 | assert_equal expected, klass.search(term, options).map(&:name).first |
581 | end | 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 | end | 592 | end |