Commit 0e3ddf8b9a9c74a860f963cb148cd449d22df9dc

Authored by Andrew Kane
2 parents 4227974d e0f93b22
Exists in reindex_refactor

Merge branch 'master' into reindex_refactor

README.md
... ... @@ -1977,13 +1977,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
1977 1977 - Write, clarify, or fix documentation
1978 1978 - Suggest or add new features
1979 1979  
1980   -If you’re looking for ideas, [try here](https://github.com/ankane/searchkick/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22).
1981   -
1982   -To get started with development and testing:
  1980 +To get started with development:
1983 1981  
1984 1982 ```sh
1985 1983 git clone https://github.com/ankane/searchkick.git
1986 1984 cd searchkick
1987 1985 bundle install
1988   -rake test
  1986 +bundle exec rake test
1989 1987 ```
... ...
lib/searchkick/index.rb
... ... @@ -187,11 +187,17 @@ module Searchkick
187 187 options.delete(:refresh)
188 188  
189 189 if method_name
  190 + # TODO throw ArgumentError
  191 + Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any?
  192 +
190 193 # update
191 194 import_scope(relation, method_name: method_name, scope: scope)
192 195 self.refresh if refresh
193 196 true
194 197 elsif scoped && !full
  198 + # TODO throw ArgumentError
  199 + Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any?
  200 +
195 201 # reindex association
196 202 import_scope(relation, scope: scope)
197 203 self.refresh if refresh
... ...
lib/searchkick/model.rb
... ... @@ -41,6 +41,8 @@ module Searchkick
41 41  
42 42 class << self
43 43 def searchkick_search(term = "*", **options, &block)
  44 + # TODO same for Mongoid
  45 + Searchkick.warn("calling search on a relation is deprecated") if respond_to?(:current_scope) && !current_scope.nil?
44 46 Searchkick.search(term, model: self, **options, &block)
45 47 end
46 48 alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name
... ...
test/match_test.rb
... ... @@ -301,4 +301,17 @@ class MatchTest &lt; Minitest::Test
301 301 store_names ["Ice Cream Cake"]
302 302 assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true
303 303 end
  304 +
  305 + # TODO find better place
  306 +
  307 + def test_search_relation
  308 + skip unless defined?(ActiveRecord)
  309 +
  310 + assert_nil Product.current_scope
  311 + _, stderr = capture_io { Product.search("*") }
  312 + assert_equal "", stderr
  313 + assert Product.where(name: nil).current_scope
  314 + _, stderr = capture_io { Product.where(name: nil).search("*") }
  315 + assert_match "WARNING", stderr
  316 + end
304 317 end
... ...
test/reindex_test.rb
... ... @@ -92,4 +92,10 @@ class ReindexTest &lt; Minitest::Test
92 92 def test_refresh_full_reindex
93 93 Product.reindex(refresh: true)
94 94 end
  95 +
  96 + def test_partial_async
  97 + store_names ["Product A"]
  98 + # warn for now
  99 + Product.reindex(:search_name, async: true)
  100 + end
95 101 end
... ...