parameters_test.rb
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require_relative "test_helper"
class ParametersTest < Minitest::Test
def setup
require "action_controller"
super
end
def test_options
params = ActionController::Parameters.new({store_id: 1})
assert_raises(ActionController::UnfilteredParameters) do
Product.search("*", **params)
end
end
def test_where
params = ActionController::Parameters.new({store_id: 1})
assert_raises(ActionController::UnfilteredParameters) do
Product.search("*", where: params)
end
end
def test_where_permitted
store [{name: "Product A", store_id: 1}, {name: "Product B", store_id: 2}]
params = ActionController::Parameters.new({store_id: 1})
assert_search "product", ["Product A"], where: params.permit(:store_id)
end
def test_where_value
store [{name: "Product A", store_id: 1}, {name: "Product B", store_id: 2}]
params = ActionController::Parameters.new({store_id: 1})
assert_search "product", ["Product A"], where: {store_id: params[:store_id]}
end
def test_where_hash
params = ActionController::Parameters.new({store_id: {value: 10, boost: 2}})
error = assert_raises(TypeError) do
assert_search "product", [], where: {store_id: params[:store_id]}
end
assert_equal error.message, "can't cast ActionController::Parameters"
end
def test_aggs_where
params = ActionController::Parameters.new({store_id: 1})
assert_raises(ActionController::UnfilteredParameters) do
Product.search("*", aggs: {size: {where: params}})
end
end
def test_aggs_where_smart_aggs_false
params = ActionController::Parameters.new({store_id: 1})
assert_raises(ActionController::UnfilteredParameters) do
Product.search("*", aggs: {size: {where: params}}, smart_aggs: false)
end
end
end