diff --git a/lib/ransack/nodes/attribute.rb b/lib/ransack/nodes/attribute.rb index 839180ae7..3e6792e2d 100644 --- a/lib/ransack/nodes/attribute.rb +++ b/lib/ransack/nodes/attribute.rb @@ -44,6 +44,10 @@ def persisted? false end + def inspect + "Attribute <#{name}>" + end + end end end \ No newline at end of file diff --git a/lib/ransack/nodes/condition.rb b/lib/ransack/nodes/condition.rb index 66d8b2edb..07feaf235 100644 --- a/lib/ransack/nodes/condition.rb +++ b/lib/ransack/nodes/condition.rb @@ -200,6 +200,13 @@ def default_type predicate.type || (attributes.first && attributes.first.type) end + def inspect + data =[['attributes', a.try(:map, &:name)], ['predicate', p], ['combinator', m], ['values', v.try(:map, &:value)]].reject { |e| + e[1].blank? + }.map { |v| "#{v[0]}: #{v[1]}" }.join(', ') + "Condition <#{data}>" + end + private def valid_combinator? diff --git a/lib/ransack/nodes/grouping.rb b/lib/ransack/nodes/grouping.rb index 6d15aa087..3e38a8c41 100644 --- a/lib/ransack/nodes/grouping.rb +++ b/lib/ransack/nodes/grouping.rb @@ -154,6 +154,13 @@ def build(params) self end + def inspect + data =[['conditions', conditions], ['combinator', combinator]].reject { |e| + e[1].blank? + }.map { |v| "#{v[0]}: #{v[1]}" }.join(', ') + "Grouping <#{data}>" + end + private def write_attribute(name, val) diff --git a/lib/ransack/nodes/value.rb b/lib/ransack/nodes/value.rb index 0df391058..30951f9cc 100644 --- a/lib/ransack/nodes/value.rb +++ b/lib/ransack/nodes/value.rb @@ -98,6 +98,10 @@ def cast_to_decimal(val) end end + def inspect + "Value <#{value}>" + end + def array_of_arrays?(val) Array === val && Array === val.first end diff --git a/lib/ransack/search.rb b/lib/ransack/search.rb index c94024357..3d8862409 100644 --- a/lib/ransack/search.rb +++ b/lib/ransack/search.rb @@ -90,6 +90,10 @@ def method_missing(method_id, *args) end end + def inspect + "Ransack::Search" + end + private def collapse_multiparameter_attributes!(attrs) diff --git a/spec/ransack/search_spec.rb b/spec/ransack/search_spec.rb index 1e41a6055..7a939fd81 100644 --- a/spec/ransack/search_spec.rb +++ b/spec/ransack/search_spec.rb @@ -104,6 +104,11 @@ module Ransack condition.attributes.first.name.should eq 'name' condition.value.should eq ['Ernie', 'Bert'] end + + it 'does not evaluate the query on #inspect' do + search = Search.new(Person, :children_id_in => [1, 2, 3]) + search.inspect.should_not match /ActiveRecord/ + end end describe '#result' do