Commit 0255fb8086822de769bbbcc78a8040323b41ae80
1 parent
c347c1e4
Exists in
master
and in
8 other branches
Fixed relation check for Mongoid
Showing
2 changed files
with
4 additions
and
8 deletions
Show diff stats
lib/searchkick/model.rb
... | ... | @@ -42,8 +42,7 @@ module Searchkick |
42 | 42 | class << self |
43 | 43 | def searchkick_search(term = "*", **options, &block) |
44 | 44 | # TODO throw error in next major version |
45 | - # TODO add Mongoid condition | |
46 | - relation = respond_to?(:current_scope) ? !current_scope.nil? : false | |
45 | + relation = respond_to?(:current_scope) ? !current_scope.nil? : !Mongoid::Threaded.current_scope(self).nil? | |
47 | 46 | Searchkick.warn("calling search on a relation is deprecated") if relation |
48 | 47 | |
49 | 48 | Searchkick.search(term, model: self, **options, &block) |
... | ... | @@ -59,10 +58,11 @@ module Searchkick |
59 | 58 | alias_method :search_index, :searchkick_index unless method_defined?(:search_index) |
60 | 59 | |
61 | 60 | def searchkick_reindex(method_name = nil, **options) |
62 | - scoped = (respond_to?(:current_scope) && respond_to?(:default_scoped) && current_scope && current_scope.to_sql != default_scoped.to_sql) || | |
61 | + # TODO properly check relation like in searchkick_search method | |
62 | + relation = (respond_to?(:current_scope) && respond_to?(:default_scoped) && current_scope && current_scope.to_sql != default_scoped.to_sql) || | |
63 | 63 | (respond_to?(:queryable) && queryable != unscoped.with_default_scope) |
64 | 64 | |
65 | - searchkick_index.reindex(searchkick_klass, method_name, scoped: scoped, **options) | |
65 | + searchkick_index.reindex(searchkick_klass, method_name, scoped: relation, **options) | |
66 | 66 | end |
67 | 67 | alias_method :reindex, :searchkick_reindex unless method_defined?(:reindex) |
68 | 68 | ... | ... |
test/match_test.rb
... | ... | @@ -305,8 +305,6 @@ class MatchTest < Minitest::Test |
305 | 305 | # TODO find better place |
306 | 306 | |
307 | 307 | def test_search_relation |
308 | - skip if defined?(Mongoid) # for now | |
309 | - | |
310 | 308 | _, stderr = capture_io { Product.search("*") } |
311 | 309 | assert_equal "", stderr |
312 | 310 | _, stderr = capture_io { Product.all.search("*") } |
... | ... | @@ -314,8 +312,6 @@ class MatchTest < Minitest::Test |
314 | 312 | end |
315 | 313 | |
316 | 314 | def test_search_relation_default_scope |
317 | - skip if defined?(Mongoid) # for now | |
318 | - | |
319 | 315 | Band.reindex |
320 | 316 | |
321 | 317 | _, stderr = capture_io { Band.search("*") } | ... | ... |