@@ -10,22 +10,25 @@ class SearchState
10
10
# @param [ActionController::Parameters] params
11
11
# @param [Blacklight::Config] blacklight_config
12
12
def initialize ( params , blacklight_config )
13
- if params . instance_of? Hash
14
- # This is an ActionView::TestCase workaround. Will be resolved by
15
- # https://github.com/rails/rails/pull/22913 (Rails > 4.2.5)
16
- @params = params . with_indifferent_access
17
- else
13
+ if params . respond_to? ( :to_unsafe_h )
18
14
# This is the typical (not-ActionView::TestCase) code path.
19
15
@params = params . to_unsafe_h
20
16
# In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
21
17
@params = @params . with_indifferent_access if @params . instance_of? Hash
18
+ elsif params . is_a? Hash
19
+ # This is an ActionView::TestCase workaround for Rails 4.2.
20
+ @params = params . dup . with_indifferent_access
21
+ else
22
+ @params = params . dup . to_h . with_indifferent_access
22
23
end
24
+
23
25
@blacklight_config = blacklight_config
24
26
end
25
27
26
- def to_h
28
+ def to_hash
27
29
@params
28
30
end
31
+ alias to_h to_hash
29
32
30
33
def reset
31
34
Blacklight ::SearchState . new ( ActionController ::Parameters . new , blacklight_config )
@@ -112,7 +115,7 @@ def remove_facet_params(field, item)
112
115
# @yield [params] The merged parameters hash before being sanitized
113
116
def params_for_search ( params_to_merge = { } , &block )
114
117
# params hash we'll return
115
- my_params = params . dup . merge ( params_to_merge . dup )
118
+ my_params = params . dup . merge ( Blacklight :: SearchState . new ( params_to_merge , blacklight_config ) )
116
119
117
120
if block_given?
118
121
yield my_params
0 commit comments