diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8e51a6..4079e918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `model` method to `Searchkick::Relation` - Fixed deprecation warning with `redis` gem +- Fixed `respond_to?` method on relation loading relation ## 5.0.4 (2022-06-16) diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index 48b4f24d..adcfc89c 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -202,6 +202,10 @@ def loaded? !@execute.nil? end + def respond_to_missing?(method_name, include_all) + Results.new(nil, nil, nil).respond_to?(method_name, include_all) || super + end + # TODO uncomment in 6.0 # def to_yaml # private_execute.to_a.to_yaml diff --git a/test/relation_test.rb b/test/relation_test.rb index 345fae5b..7fa5d7bb 100644 --- a/test/relation_test.rb +++ b/test/relation_test.rb @@ -44,6 +44,15 @@ def test_klass assert_nil Searchkick.search("product").klass end + def test_respond_to + relation = Product.search("product") + assert relation.respond_to?(:page) + assert relation.respond_to?(:response) + assert relation.respond_to?(:size) + refute relation.respond_to?(:hello) + refute relation.loaded? + end + # TODO uncomment in 6.0 # def test_to_yaml # store_names ["Product A", "Product B"]