Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ransack/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(object, params = {}, options = {})
if params.is_a? Hash
params = params.dup
params = params.transform_values { |v| v.is_a?(String) && strip_whitespace ? v.strip : v }
params.delete_if { |k, v| [*v].all?{ |i| i.blank? && i != false } }
params.delete_if { |k, v| [*v].all?{ |i| i.blank? && i != false && !i.nil? } }
else
params = {}
end
Expand Down
6 changes: 6 additions & 0 deletions spec/ransack/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ module Ransack
Search.new(Person, name_eq_any: ['foobar'])
end

it 'keeps conditions with a nil value in an array before building' do
expect_any_instance_of(Search).to receive(:build)
.with({ 'name_in' => [nil] })
Search.new(Person, name_in: [nil])
end

it 'does not raise exception for string :params argument' do
expect { Search.new(Person, '') }.not_to raise_error
end
Expand Down
Loading