Commit c7bebc27a4af5bbd27ae2c91c8341fb07f10a2b8
1 parent
ffcb4dec
Exists in
master
and in
14 other branches
Raise error for invalid query before it's sent to server
Showing
2 changed files
with
26 additions
and
0 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -1043,6 +1043,14 @@ module Searchkick |
1043 | 1043 | |
1044 | 1044 | {regexp: {field => {value: source, flags: "NONE"}}} |
1045 | 1045 | else |
1046 | + # TODO add this for other values | |
1047 | + if value.as_json.is_a?(Enumerable) | |
1048 | + # query will fail, but this is better | |
1049 | + # same message as Active Record | |
1050 | + # TODO make TypeError | |
1051 | + raise "can't cast #{value.class.name}" | |
1052 | + end | |
1053 | + | |
1046 | 1054 | {term: {field => {value: value}}} |
1047 | 1055 | end |
1048 | 1056 | end | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +require_relative "test_helper" | |
2 | + | |
3 | +class ParametersTest < Minitest::Test | |
4 | + def setup | |
5 | + skip unless defined?(ActiveRecord) | |
6 | + require "action_controller" | |
7 | + super | |
8 | + end | |
9 | + | |
10 | + def test_where_hash | |
11 | + params = ActionController::Parameters.new({store_id: {value: 10, boost: 2}}) | |
12 | + # TODO make TypeError | |
13 | + error = assert_raises RuntimeError do | |
14 | + assert_search "product", [], where: params | |
15 | + end | |
16 | + assert_includes error.message, "can't cast ActionController::Parameters" | |
17 | + end | |
18 | +end | ... | ... |