Commit c5f4d739f16d27b657bd7c83cac98dd6ec227ac8
1 parent
d0d42d9d
Exists in
master
and in
2 other branches
Added test for scoping [skip ci]
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
test/models/product.rb
@@ -24,7 +24,13 @@ class Product | @@ -24,7 +24,13 @@ class Product | ||
24 | 24 | ||
25 | attr_accessor :conversions, :user_ids, :aisle, :details | 25 | attr_accessor :conversions, :user_ids, :aisle, :details |
26 | 26 | ||
27 | + class << self | ||
28 | + attr_accessor :dynamic_data | ||
29 | + end | ||
30 | + | ||
27 | def search_data | 31 | def search_data |
32 | + return self.class.dynamic_data.call if self.class.dynamic_data | ||
33 | + | ||
28 | serializable_hash.except("id", "_id").merge( | 34 | serializable_hash.except("id", "_id").merge( |
29 | conversions: conversions, | 35 | conversions: conversions, |
30 | user_ids: user_ids, | 36 | user_ids: user_ids, |
test/reindex_test.rb
@@ -64,6 +64,19 @@ class ReindexTest < Minitest::Test | @@ -64,6 +64,19 @@ class ReindexTest < Minitest::Test | ||
64 | assert_search "product", ["Product A", "Product B"] | 64 | assert_search "product", ["Product A", "Product B"] |
65 | end | 65 | end |
66 | 66 | ||
67 | + def test_relation_scoping | ||
68 | + store_names ["Product A", "Product B"] | ||
69 | + Product.dynamic_data = lambda do | ||
70 | + { | ||
71 | + name: "Count #{Product.count}" | ||
72 | + } | ||
73 | + end | ||
74 | + Product.where(name: "Product A").reindex(refresh: true) | ||
75 | + assert_search "count", ["Count 2"], load: false | ||
76 | + ensure | ||
77 | + Product.dynamic_data = nil | ||
78 | + end | ||
79 | + | ||
67 | def test_relation_should_index | 80 | def test_relation_should_index |
68 | store_names ["Product A", "Product B"] | 81 | store_names ["Product A", "Product B"] |
69 | Searchkick.callbacks(false) do | 82 | Searchkick.callbacks(false) do |