diff --git a/test/models/product.rb b/test/models/product.rb index efd8c47..b6179df 100644 --- a/test/models/product.rb +++ b/test/models/product.rb @@ -24,7 +24,13 @@ class Product attr_accessor :conversions, :user_ids, :aisle, :details + class << self + attr_accessor :dynamic_data + end + def search_data + return self.class.dynamic_data.call if self.class.dynamic_data + serializable_hash.except("id", "_id").merge( conversions: conversions, user_ids: user_ids, diff --git a/test/reindex_test.rb b/test/reindex_test.rb index c2df3be..3cd2b77 100644 --- a/test/reindex_test.rb +++ b/test/reindex_test.rb @@ -64,6 +64,19 @@ class ReindexTest < Minitest::Test assert_search "product", ["Product A", "Product B"] end + def test_relation_scoping + store_names ["Product A", "Product B"] + Product.dynamic_data = lambda do + { + name: "Count #{Product.count}" + } + end + Product.where(name: "Product A").reindex(refresh: true) + assert_search "count", ["Count 2"], load: false + ensure + Product.dynamic_data = nil + end + def test_relation_should_index store_names ["Product A", "Product B"] Searchkick.callbacks(false) do -- libgit2 0.21.0