searchlogic 2.4.18 → 2.4.19

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
  :build:
4
4
  :minor: 4
5
- :patch: 18
5
+ :patch: 19
@@ -35,11 +35,6 @@ module Searchlogic
35
35
  :not_blank => [:present]
36
36
  }
37
37
 
38
- GROUP_CONDITIONS = {
39
- :in => [],
40
- :not_in => []
41
- }
42
-
43
38
  CONDITIONS = {}
44
39
 
45
40
  # Add any / all variations to every comparison and wildcard condition
@@ -50,12 +45,10 @@ module Searchlogic
50
45
  end
51
46
 
52
47
  CONDITIONS[:equals_any] = CONDITIONS[:equals_any] + [:in]
53
- CONDITIONS[:does_not_equal_any] = CONDITIONS[:does_not_equal_any] + [:not_in]
48
+ CONDITIONS[:does_not_equal_all] = CONDITIONS[:does_not_equal_all] + [:not_in]
54
49
 
55
50
  BOOLEAN_CONDITIONS.each { |condition, aliases| CONDITIONS[condition] = aliases }
56
51
 
57
- GROUP_CONDITIONS.each { |condition, aliases| CONDITIONS[condition] = aliases }
58
-
59
52
  PRIMARY_CONDITIONS = CONDITIONS.keys
60
53
  ALIAS_CONDITIONS = CONDITIONS.values.flatten
61
54
 
@@ -158,35 +151,28 @@ module Searchlogic
158
151
  def scope_options(condition, column_type, sql, options = {})
159
152
  case condition.to_s
160
153
  when /_(any|all)$/
161
- any_or_all_scope_options(column_type, sql, options)
154
+ searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
155
+ return {} if values.empty?
156
+ values.flatten!
157
+ values.collect! { |value| value_with_modifier(value, options[:value_modifier]) }
158
+
159
+ join = $1 == "any" ? " OR " : " AND "
160
+
161
+ scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
162
+
163
+ {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
164
+ }
162
165
  else
163
- general_scope_options(column_type, sql, options)
166
+ searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
167
+ values.collect! { |value| value_with_modifier(value, options[:value_modifier]) }
168
+
169
+ scope_sql = sql.is_a?(Proc) ? sql.call(*values) : sql
170
+
171
+ {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
172
+ }
164
173
  end
165
174
  end
166
175
 
167
- def any_or_all_scope_options(column_type, sql, options)
168
- searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
169
- return {} if values.empty?
170
- values.flatten!
171
- values.collect! { |value| value_with_modifier(value, options[:value_modifier]) }
172
-
173
- join = $1 == "any" ? " OR " : " AND "
174
- scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
175
-
176
- {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
177
- }
178
- end
179
-
180
- def general_scope_options(column_type, sql, options)
181
- searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
182
- values.collect! { |value| value_with_modifier(value, options[:value_modifier]) }
183
-
184
- scope_sql = sql.is_a?(Proc) ? sql.call(*values) : sql
185
-
186
- {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
187
- }
188
- end
189
-
190
176
  def value_with_modifier(value, modifier)
191
177
  case modifier
192
178
  when :like
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.18"
8
+ s.version = "2.4.19"
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-04-15}
12
+ s.date = %q{2010-04-16}
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 = [
@@ -185,4 +185,14 @@ describe Searchlogic::NamedScopes::AssociationConditions do
185
185
  :joins => ["INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'", " INNER JOIN \"companies\" ON \"companies\".id = \"users\".company_id "]
186
186
  }
187
187
  end
188
+
189
+ it "should allow any on a has_many relationship" do
190
+ company1 = Company.create
191
+ user1 = company1.users.create
192
+ company2 = Company.create
193
+ user2 = company2.users.create
194
+ user3 = company2.users.create
195
+
196
+ Company.users_id_equals_any([user2.id, user3.id]).all(:select => "DISTINCT companies.*").should == [company2]
197
+ end
188
198
  end
@@ -123,93 +123,93 @@ describe Searchlogic::NamedScopes::Conditions do
123
123
 
124
124
  it "should have equals any" do
125
125
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
126
- User.username_equals_any("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
126
+ User.username_equals_any("bjohnson", "thunt").all.should == User.find_all_by_username(["bjohnson", "thunt"])
127
127
  end
128
128
 
129
129
  it "should have equals all" do
130
130
  %w(bjohnson thunt dainor).each { |username| User.create(:username => username) }
131
- User.username_equals_all("bjohnson", "thunt").all == []
131
+ User.username_equals_all("bjohnson", "thunt").all.should == []
132
132
  end
133
133
 
134
134
  it "should have does not equal any" do
135
135
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
136
- User.username_does_not_equal_any("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
136
+ User.username_does_not_equal_any("bjohnson", "thunt").all.should == User.find_all_by_username(["bjohnson", "thunt", "dgainor"])
137
137
  end
138
138
 
139
139
  it "should have does not equal all" do
140
140
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
141
- User.username_does_not_equal_all("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
141
+ User.username_does_not_equal_all("bjohnson", "thunt").all.should == User.find_all_by_username("dgainor")
142
142
  end
143
143
 
144
144
  it "should have less than any" do
145
145
  (5..7).each { |age| User.create(:age => age) }
146
- User.age_less_than_any(7,6).all == User.find_all_by_age([5, 6])
146
+ User.age_less_than_any(7,6).all.should == User.find_all_by_age([5, 6])
147
147
  end
148
148
 
149
149
  it "should have less than all" do
150
150
  (5..7).each { |age| User.create(:age => age) }
151
- User.age_less_than_all(7,6).all == User.find_all_by_age(5)
151
+ User.age_less_than_all(7,6).all.should == User.find_all_by_age(5)
152
152
  end
153
153
 
154
154
  it "should have less than or equal to any" do
155
155
  (5..7).each { |age| User.create(:age => age) }
156
- User.age_less_than_or_equal_to_any(7,6).all == User.find_all_by_age([5, 6, 7])
156
+ User.age_less_than_or_equal_to_any(7,6).all.should == User.find_all_by_age([5, 6, 7])
157
157
  end
158
158
 
159
159
  it "should have less than or equal to all" do
160
160
  (5..7).each { |age| User.create(:age => age) }
161
- User.age_less_than_or_equal_to_all(7,6).all == User.find_all_by_age([5, 6])
161
+ User.age_less_than_or_equal_to_all(7,6).all.should == User.find_all_by_age([5, 6])
162
162
  end
163
163
 
164
164
  it "should have less than any" do
165
165
  (5..7).each { |age| User.create(:age => age) }
166
- User.age_greater_than_any(5,6).all == User.find_all_by_age([6, 7])
166
+ User.age_greater_than_any(5,6).all.should == User.find_all_by_age([6, 7])
167
167
  end
168
168
 
169
169
  it "should have greater than all" do
170
170
  (5..7).each { |age| User.create(:age => age) }
171
- User.age_greater_than_all(5,6).all == User.find_all_by_age(7)
171
+ User.age_greater_than_all(5,6).all.should == User.find_all_by_age(7)
172
172
  end
173
173
 
174
174
  it "should have greater than or equal to any" do
175
175
  (5..7).each { |age| User.create(:age => age) }
176
- User.age_greater_than_or_equal_to_any(5,6).all == User.find_all_by_age([5, 6, 7])
176
+ User.age_greater_than_or_equal_to_any(5,6).all.should == User.find_all_by_age([5, 6, 7])
177
177
  end
178
178
 
179
179
  it "should have greater than or equal to all" do
180
180
  (5..7).each { |age| User.create(:age => age) }
181
- User.age_greater_than_or_equal_to_all(5,6).all == User.find_all_by_age([6, 7])
181
+ User.age_greater_than_or_equal_to_all(5,6).all.should == User.find_all_by_age([6, 7])
182
182
  end
183
183
 
184
184
  it "should have like all" do
185
185
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
186
- User.username_like_all("bjohnson", "thunt").all == []
187
- User.username_like_all("n", "o").all == User.find_all_by_username(["bjohnson", "thunt"])
186
+ User.username_like_all("bjohnson", "thunt").all.should == []
187
+ User.username_like_all("n", "o").all.should == User.find_all_by_username(["bjohnson", "dgainor"])
188
188
  end
189
189
 
190
190
  it "should have like any" do
191
191
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
192
- User.username_like_all("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
192
+ User.username_like_any("bjohnson", "thunt").all.should == User.find_all_by_username(["bjohnson", "thunt"])
193
193
  end
194
194
 
195
195
  it "should have begins with all" do
196
196
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
197
- User.username_begins_with_all("bjohnson", "thunt").all == []
197
+ User.username_begins_with_all("bjohnson", "thunt").all.should == []
198
198
  end
199
199
 
200
200
  it "should have begins with any" do
201
201
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
202
- User.username_begins_with_any("bj", "th").all == User.find_all_by_username(["bjohnson", "thunt"])
202
+ User.username_begins_with_any("bj", "th").all.should == User.find_all_by_username(["bjohnson", "thunt"])
203
203
  end
204
204
 
205
205
  it "should have ends with all" do
206
206
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
207
- User.username_ends_with_all("n", "r").all == []
207
+ User.username_ends_with_all("n", "r").all.should == []
208
208
  end
209
209
 
210
210
  it "should have ends with any" do
211
211
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
212
- User.username_ends_with_any("n", "r").all == User.find_all_by_username(["bjohnson", "dgainor"])
212
+ User.username_ends_with_any("n", "r").all.should == User.find_all_by_username(["bjohnson", "dgainor"])
213
213
  end
214
214
  end
215
215
 
@@ -278,12 +278,12 @@ describe Searchlogic::NamedScopes::Conditions do
278
278
  context "group conditions" do
279
279
  it "should have in" do
280
280
  (5..7).each { |age| User.create(:age => age) }
281
- User.age_in([5,6]).all == User.find(:all, :conditions => ["users.age IN (?)", [5, 6]])
281
+ User.age_in([5,6]).all.should == User.find(:all, :conditions => ["users.age IN (?)", [5, 6]])
282
282
  end
283
283
 
284
284
  it "should have not_in" do
285
285
  (5..7).each { |age| User.create(:age => age) }
286
- User.age_not_in([5,6]).all == User.find(:all, :conditions => ["users.age NOT IN (?)", [5, 6]])
286
+ User.age_not_in([5,6]).all.should == User.find(:all, :conditions => ["users.age NOT IN (?)", [5, 6]])
287
287
  end
288
288
  end
289
289
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 4
8
- - 18
9
- version: 2.4.18
8
+ - 19
9
+ version: 2.4.19
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Johnson of Binary Logic
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-15 00:00:00 -04:00
17
+ date: 2010-04-16 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency