Handle null/not null properly. Fixes #8

This commit is contained in:
Ernie Miller 2011-07-15 07:16:38 -04:00
parent ce0318cc78
commit 59dd9ae754
2 changed files with 5 additions and 3 deletions

View File

@ -41,7 +41,7 @@ module Ransack
end
def valid_arity?
values.size <= 1 || predicate.compound || %w(in not_in).include?(predicate.name)
values.size <= 1 || predicate.wants_array
end
def attributes
@ -188,11 +188,12 @@ module Ransack
end
def formatted_values_for_attribute(attr)
casted_values_for_attribute(attr).map do |val|
formatted = casted_values_for_attribute(attr).map do |val|
val = attr.ransacker.formatter.call(val) if attr.ransacker && attr.ransacker.formatter
val = predicate.format(val)
val
end
predicate.wants_array ? formatted : formatted.first
end
def default_type

View File

@ -1,6 +1,6 @@
module Ransack
class Predicate
attr_reader :name, :arel_predicate, :type, :formatter, :validator, :compound
attr_reader :name, :arel_predicate, :type, :formatter, :validator, :compound, :wants_array
class << self
@ -41,6 +41,7 @@ module Ransack
@formatter = opts[:formatter]
@validator = opts[:validator] || lambda { |v| v.present? }
@compound = opts[:compound]
@wants_array = @compound || ['in', 'not_in'].include?(@arel_predicate)
end
def eql?(other)