From e2969b4e953df4d2b59a82f68c65850e248d889d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 7 Oct 2022 11:36:52 -0700 Subject: [PATCH] Added load method to relation --- lib/searchkick/relation.rb | 5 +++++ test/relation_test.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 2fec0fc..6cf5b43 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -202,6 +202,11 @@ module Searchkick !@execute.nil? end + def load + private_execute + self + end + def respond_to_missing?(method_name, include_all) Results.new(nil, nil, nil).respond_to?(method_name, include_all) || super end diff --git a/test/relation_test.rb b/test/relation_test.rb index 3970bf3..8065e6f 100644 --- a/test/relation_test.rb +++ b/test/relation_test.rb @@ -23,6 +23,14 @@ class RelationTest < Minitest::Test assert_equal ["Product A"], products.map(&:name) end + def test_load + Product.search_index.refresh + products = Product.search("*") + refute products.loaded? + assert products.load.loaded? + assert products.load.load.loaded? + end + def test_clone products = Product.search("*") assert_equal 10, products.limit(10).limit_value -- libgit2 0.21.0