Skip to content

Commit

Permalink
Fixed respond_to? method on relation loading relation - #1395
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 7, 2022
1 parent 9bbbe73 commit 8a0303c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions lib/searchkick/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 8a0303c

Please sign in to comment.