From c5f4d739f16d27b657bd7c83cac98dd6ec227ac8 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 21 Feb 2022 13:09:43 -0800 Subject: [PATCH] Added test for scoping [skip ci] --- test/models/product.rb | 6 ++++++ test/reindex_test.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) 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