searchlogic 2.4.3 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 2
3
3
  :minor: 4
4
4
  :build:
5
- :patch: 3
5
+ :patch: 4
@@ -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?(scope_name, v) } if value.is_a?(Array)
110
- if !ignore_value?(scope_name, value)
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
- # Let's leverage ActiveRecord's type casting, so that casting is consistent
191
- # with the other models.
192
- column_for_type_cast = ::ActiveRecord::ConnectionAdapters::Column.new("", nil)
193
- column_for_type_cast.instance_variable_set(:@type, type)
194
- casted_value = column_for_type_cast.type_cast(value)
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
- if Time.zone && casted_value.is_a?(Time)
197
- if value.is_a?(String)
198
- (casted_value + (Time.zone.utc_offset * -1)).in_time_zone
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.in_time_zone
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?(scope_name, value)
209
- mass_conditions.key?(scope_name.to_sym) && (value.is_a?(String) && value.blank?) || (value.is_a?(Array) && value.empty?)
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{searchlogic}
8
- s.version = "2.4.3"
8
+ s.version = "2.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
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 use custom scopes before normalizing" do
81
- User.create(:username => "bjohnson")
82
- User.named_scope :username, lambda { |value| {:conditions => {:username => value.reverse}} }
83
- search1 = User.search(:username => "bjohnson")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic