mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Search.new and the ransack scope no longer modify the params hash
Closes #378.
This commit is contained in:
parent
64827eeffe
commit
11398617a1
4 changed files with 21 additions and 6 deletions
|
@ -12,9 +12,7 @@ module Ransack
|
|||
end
|
||||
|
||||
def ransack(params = {}, options = {})
|
||||
params = params.presence || {}
|
||||
Search.new(self, params ? params.delete_if {
|
||||
|k, v| v.blank? && v != false } : params, options)
|
||||
Search.new(self, params, options)
|
||||
end
|
||||
|
||||
def ransacker(name, opts = {}, &block)
|
||||
|
|
|
@ -14,9 +14,12 @@ module Ransack
|
|||
:translate, :to => :base
|
||||
|
||||
def initialize(object, params = {}, options = {})
|
||||
params = {} unless params.is_a?(Hash)
|
||||
(params ||= {})
|
||||
.delete_if { |k, v| [*v].all? { |i| i.blank? && i != false } }
|
||||
if params.is_a? Hash
|
||||
params = params.dup
|
||||
params.delete_if { |k, v| [*v].all?{|i| i.blank? && i != false } }
|
||||
else
|
||||
params = {}
|
||||
end
|
||||
@context = options[:context] || Context.for(object, options)
|
||||
@context.auth_object = options[:auth_object]
|
||||
@base = Nodes::Grouping.new(@context, options[:grouping] || 'and')
|
||||
|
|
|
@ -50,6 +50,14 @@ module Ransack
|
|||
end
|
||||
end
|
||||
|
||||
it 'does not raise exception for string :params argument' do
|
||||
lambda { Person.search('') }.should_not raise_error
|
||||
end
|
||||
|
||||
it 'does not modify the parameters' do
|
||||
params = { :name_eq => '' }
|
||||
expect { Person.search(params)}.not_to change { params }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ransacker' do
|
||||
|
|
|
@ -183,6 +183,12 @@ module Ransack
|
|||
specify { expect { subject }.not_to raise_error }
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not modify the parameters' do
|
||||
params = { :name_eq => '' }
|
||||
expect { Search.new(Person, params)}.not_to change { params }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#result' do
|
||||
|
|
Loading…
Reference in a new issue