From 43db098d2bc17dc80ed274b1b908aa39bcce1b63 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 4 Oct 2022 21:06:04 -0700 Subject: [PATCH] Added model method to Searchkick::Relation and don't load relation when klass method is called --- CHANGELOG.md | 1 + lib/searchkick/relation.rb | 3 +++ test/relation_test.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 0 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 929d1d7..ba8e51a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 5.0.5 (unreleased) +- Added `model` method to `Searchkick::Relation` - Fixed deprecation warning with `redis` gem ## 5.0.4 (2022-06-16) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 4bd2798..48b4f24 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -8,6 +8,9 @@ module Searchkick delegate :body, :params, to: :query delegate_missing_to :private_execute + attr_reader :model + alias_method :klass, :model + def initialize(model, term = "*", **options) @model = model @term = term diff --git a/test/relation_test.rb b/test/relation_test.rb index 246d2af..345fae5 100644 --- a/test/relation_test.rb +++ b/test/relation_test.rb @@ -34,6 +34,16 @@ class RelationTest < Minitest::Test assert_equal ["Product A", "Product B"], Product.search("product").pluck(:name).sort end + def test_model + assert_equal Product, Product.search("product").model + assert_nil Searchkick.search("product").model + end + + def test_klass + assert_equal Product, Product.search("product").klass + assert_nil Searchkick.search("product").klass + end + # TODO uncomment in 6.0 # def test_to_yaml # store_names ["Product A", "Product B"] -- libgit2 0.21.0