searchlogic 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/searchlogic/search.rb +23 -17
- data/searchlogic.gemspec +1 -1
- data/spec/search_spec.rb +13 -7
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/searchlogic/search.rb
CHANGED
@@ -87,6 +87,7 @@ module Searchlogic
|
|
87
87
|
if setter?(name)
|
88
88
|
if scope?(scope_name)
|
89
89
|
mass_conditions.delete(scope_name.to_sym) if !setting_mass_conditions?
|
90
|
+
|
90
91
|
if args.size == 1
|
91
92
|
conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
|
92
93
|
else
|
@@ -106,8 +107,11 @@ module Searchlogic
|
|
106
107
|
scope = conditions_array.inject(klass.scoped(current_scope) || {}) do |scope, condition|
|
107
108
|
scope_name, value = condition
|
108
109
|
|
109
|
-
value.delete_if { |v| ignore_value?(
|
110
|
-
|
110
|
+
value.delete_if { |v| ignore_value?(v) } if mass_conditions.key?(scope_name.to_sym) && value.is_a?(Array)
|
111
|
+
|
112
|
+
if mass_conditions.key?(scope_name.to_sym) && ignore_value?(value)
|
113
|
+
klass.scoped({})
|
114
|
+
else
|
111
115
|
scope_name = normalize_scope_name(scope_name)
|
112
116
|
klass.send(scope_name, value) if !klass.respond_to?(scope_name)
|
113
117
|
arity = klass.named_scope_arity(scope_name)
|
@@ -123,8 +127,6 @@ module Searchlogic
|
|
123
127
|
else
|
124
128
|
scope.send(scope_name, value)
|
125
129
|
end
|
126
|
-
else
|
127
|
-
klass.scoped({})
|
128
130
|
end
|
129
131
|
end
|
130
132
|
scope.send(name, *args, &block)
|
@@ -187,26 +189,30 @@ module Searchlogic
|
|
187
189
|
when Range
|
188
190
|
Range.new(type_cast(value.first, type), type_cast(value.last, type))
|
189
191
|
else
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
192
|
+
if ignore_value?(value)
|
193
|
+
value
|
194
|
+
else
|
195
|
+
# Let's leverage ActiveRecord's type casting, so that casting is consistent
|
196
|
+
# with the other models.
|
197
|
+
column_for_type_cast = ::ActiveRecord::ConnectionAdapters::Column.new("", nil)
|
198
|
+
column_for_type_cast.instance_variable_set(:@type, type)
|
199
|
+
casted_value = column_for_type_cast.type_cast(value)
|
195
200
|
|
196
|
-
|
197
|
-
|
198
|
-
|
201
|
+
if Time.zone && casted_value.is_a?(Time)
|
202
|
+
if value.is_a?(String)
|
203
|
+
(casted_value + (Time.zone.utc_offset * -1)).in_time_zone
|
204
|
+
else
|
205
|
+
casted_value.in_time_zone
|
206
|
+
end
|
199
207
|
else
|
200
|
-
casted_value
|
208
|
+
casted_value
|
201
209
|
end
|
202
|
-
else
|
203
|
-
casted_value
|
204
210
|
end
|
205
211
|
end
|
206
212
|
end
|
207
213
|
|
208
|
-
def ignore_value?(
|
209
|
-
|
214
|
+
def ignore_value?(value)
|
215
|
+
(value.is_a?(String) && value.blank?) || (value.is_a?(Array) && value.empty?)
|
210
216
|
end
|
211
217
|
end
|
212
218
|
end
|
data/searchlogic.gemspec
CHANGED
data/spec/search_spec.rb
CHANGED
@@ -69,6 +69,15 @@ describe "Search" do
|
|
69
69
|
search.username.should == "bjohnson"
|
70
70
|
end
|
71
71
|
|
72
|
+
it "should use custom scopes before normalizing" do
|
73
|
+
User.create(:username => "bjohnson")
|
74
|
+
User.named_scope :username, lambda { |value| {:conditions => {:username => value.reverse}} }
|
75
|
+
search1 = User.search(:username => "bjohnson")
|
76
|
+
search2 = User.search(:username => "nosnhojb")
|
77
|
+
search1.count.should == 0
|
78
|
+
search2.count.should == 1
|
79
|
+
end
|
80
|
+
|
72
81
|
# We ignore them upon execution. But we still want to accept the condition so that returning the conditions
|
73
82
|
# preserves the values.
|
74
83
|
it "should not ignore blank values" do
|
@@ -77,13 +86,10 @@ describe "Search" do
|
|
77
86
|
search.username.should == ""
|
78
87
|
end
|
79
88
|
|
80
|
-
it "should
|
81
|
-
User.
|
82
|
-
|
83
|
-
|
84
|
-
search2 = User.search(:username => "nosnhojb")
|
85
|
-
search1.count.should == 0
|
86
|
-
search2.count.should == 1
|
89
|
+
it "should not ignore blank values and should not cast them" do
|
90
|
+
search = User.search
|
91
|
+
search.conditions = {"id_equals" => ""}
|
92
|
+
search.id_equals.should == ""
|
87
93
|
end
|
88
94
|
|
89
95
|
it "should ignore blank values in arrays" do
|