1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Model.search("") should not raise exception

Consider query like: "users?q=some-string" or "users?q=" and
controller content User.search(params[:q])
This commit is contained in:
Bonias 2014-02-27 10:22:36 +01:00
parent 5bb0fbe522
commit ee3b496654
2 changed files with 8 additions and 1 deletions

View file

@ -14,7 +14,8 @@ module Ransack
:translate, :to => :base :translate, :to => :base
def initialize(object, params = {}, options = {}) def initialize(object, params = {}, options = {})
(params ||= {}).delete_if { |k, v| v.blank? && v != false } params = {} unless params.is_a?(Hash)
params.delete_if { |k, v| v.blank? && v != false }
@context = Context.for(object, options) @context = Context.for(object, options)
@context.auth_object = options[:auth_object] @context.auth_object = options[:auth_object]
@base = Nodes::Grouping.new(@context, 'and') @base = Nodes::Grouping.new(@context, 'and')

View file

@ -3,6 +3,12 @@ require 'spec_helper'
module Ransack module Ransack
describe Search do describe Search do
describe "#initialize" do
it "do not raise exception for string :params argument" do
lambda { Search.new(Person, "") }.should_not raise_error
end
end
describe '#build' do describe '#build' do
it 'creates Conditions for top-level attributes' do it 'creates Conditions for top-level attributes' do
search = Search.new(Person, :name_eq => 'Ernie') search = Search.new(Person, :name_eq => 'Ernie')