searchlogic 2.4.2 → 2.4.3

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/Rakefile CHANGED
@@ -14,7 +14,6 @@ begin
14
14
  gem.add_dependency "activerecord", ">= 2.0.0"
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
17
- Jeweler::RubyforgeTasks.new
18
17
  rescue LoadError
19
18
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
19
  end
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 2
3
3
  :minor: 4
4
4
  :build:
5
- :patch: 2
5
+ :patch: 3
@@ -61,11 +61,13 @@ module Searchlogic
61
61
 
62
62
  # Accepts a hash of conditions.
63
63
  def conditions=(values)
64
- values.each do |condition, value|
65
- value.delete_if { |v| ignore_value?(v) } if value.is_a?(Array)
66
- next if ignore_value?(value)
64
+ @setting_mass_conditions = true
65
+ result = values.each do |condition, value|
66
+ mass_conditions[condition.to_sym] = value
67
67
  send("#{condition}=", value)
68
68
  end
69
+ @setting_mass_conditions = false
70
+ result
69
71
  end
70
72
 
71
73
  # Delete a condition from the search. Since conditions map to named scopes,
@@ -84,6 +86,7 @@ module Searchlogic
84
86
 
85
87
  if setter?(name)
86
88
  if scope?(scope_name)
89
+ mass_conditions.delete(scope_name.to_sym) if !setting_mass_conditions?
87
90
  if args.size == 1
88
91
  conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
89
92
  else
@@ -102,20 +105,26 @@ module Searchlogic
102
105
  else
103
106
  scope = conditions_array.inject(klass.scoped(current_scope) || {}) do |scope, condition|
104
107
  scope_name, value = condition
105
- scope_name = normalize_scope_name(scope_name)
106
- klass.send(scope_name, value) if !klass.respond_to?(scope_name)
107
- arity = klass.named_scope_arity(scope_name)
108
108
 
109
- if !arity || arity == 0
110
- if value == true
111
- scope.send(scope_name)
109
+ value.delete_if { |v| ignore_value?(scope_name, v) } if value.is_a?(Array)
110
+ if !ignore_value?(scope_name, value)
111
+ scope_name = normalize_scope_name(scope_name)
112
+ klass.send(scope_name, value) if !klass.respond_to?(scope_name)
113
+ arity = klass.named_scope_arity(scope_name)
114
+
115
+ if !arity || arity == 0
116
+ if value == true
117
+ scope.send(scope_name)
118
+ else
119
+ scope
120
+ end
121
+ elsif arity == -1
122
+ scope.send(scope_name, *(value.is_a?(Array) ? value : [value]))
112
123
  else
113
- scope
124
+ scope.send(scope_name, value)
114
125
  end
115
- elsif arity == -1
116
- scope.send(scope_name, *(value.is_a?(Array) ? value : [value]))
117
126
  else
118
- scope.send(scope_name, value)
127
+ klass.scoped({})
119
128
  end
120
129
  end
121
130
  scope.send(name, *args, &block)
@@ -163,6 +172,14 @@ module Searchlogic
163
172
  end
164
173
  end
165
174
 
175
+ def mass_conditions
176
+ @mass_conditions ||= {}
177
+ end
178
+
179
+ def setting_mass_conditions?
180
+ @setting_mass_conditions == true
181
+ end
182
+
166
183
  def type_cast(value, type)
167
184
  case value
168
185
  when Array
@@ -188,8 +205,8 @@ module Searchlogic
188
205
  end
189
206
  end
190
207
 
191
- def ignore_value?(value)
192
- (value.is_a?(String) && value.blank?) || (value.is_a?(Array) && value.empty?)
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?)
193
210
  end
194
211
  end
195
212
  end
data/searchlogic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{searchlogic}
8
- s.version = "2.4.2"
8
+ s.version = "2.4.3"
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"]
12
- s.date = %q{2010-01-26}
12
+ s.date = %q{2010-02-02}
13
13
  s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
14
14
  s.email = %q{bjohnson@binarylogic.com}
15
15
  s.extra_rdoc_files = [
data/spec/search_spec.rb CHANGED
@@ -69,10 +69,12 @@ describe "Search" do
69
69
  search.username.should == "bjohnson"
70
70
  end
71
71
 
72
- it "should ignore blank values" do
72
+ # We ignore them upon execution. But we still want to accept the condition so that returning the conditions
73
+ # preserves the values.
74
+ it "should not ignore blank values" do
73
75
  search = User.search
74
76
  search.conditions = {"username" => ""}
75
- search.username.should be_nil
77
+ search.username.should == ""
76
78
  end
77
79
 
78
80
  it "should use custom scopes before normalizing" do
@@ -87,7 +89,7 @@ describe "Search" do
87
89
  it "should ignore blank values in arrays" do
88
90
  search = User.search
89
91
  search.conditions = {"username_equals_any" => [""]}
90
- search.username_equals_any.should be_blank
92
+ search.username_equals_any.first.should be_blank
91
93
  end
92
94
  end
93
95
 
@@ -361,6 +363,24 @@ describe "Search" do
361
363
  s.created_at_after = Time.now
362
364
  lambda { s.count }.should_not raise_error
363
365
  end
366
+
367
+ it "should ignore blank values" do
368
+ search = User.search
369
+ search.conditions = {"username_equals" => ""}
370
+ search.proxy_options.should == {}
371
+ end
372
+
373
+ it "should not ignore blank values when explicitly set" do
374
+ search = User.search
375
+ search.username_equals = ""
376
+ search.proxy_options.should == {:conditions => ["users.username = ?", ""]}
377
+ end
378
+
379
+ it "should ignore blank values in arrays" do
380
+ search = User.search
381
+ search.conditions = {"username_equals_any" => [""]}
382
+ search.proxy_options.should == {}
383
+ end
364
384
  end
365
385
 
366
386
  context "method delegation" 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.2
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-26 00:00:00 -05:00
12
+ date: 2010-02-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency