searchlogic 2.5.14 → 2.5.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGE2MTk1ZjAzYWQ0ODVkNjg1M2Y3MzYzZmEwMjcxN2E2ZGMwMTNjMg==
5
+ data.tar.gz: !binary |-
6
+ M2ExYTk4MjkxNzhlZjk4ZWM4NGE3MDhkMmI1NDViODBhY2VhOWZlNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODJmNDkzYTAyZTZkZTc1NGE3MTAxMDMzZGFlZTM0MmI1MTQ0ODdiMzI1YzI5
10
+ MDJmMTgwZDM3OTAwODg3NmMxOGRkZjVmNTgxOTI2OWUxOGJjMTZjNDQ0MjNk
11
+ ZmRkZjI2YjZlYTE2NjdiZGEwYTY5MmMzODQ1NzNkYTY2OGU5MzY=
12
+ data.tar.gz: !binary |-
13
+ NGRkZTJmYWRjMTlhYzgyNTdlYzQ5NjU5YmZiNjM4ZGJiMTIxMDRjZGNjMGE5
14
+ ZmFlYjRjNWQ4MDAxYzQ2YTEzZmFiMjEyYTNmYzJiOGM1NzZkNGI5NzE3NTJm
15
+ YTBhZDQwMjJkMTQ0Njc1NTJiZjMyZWMxMDNjYTFjZjdlMWRmZTQ=
@@ -0,0 +1 @@
1
+ 1.9.3-p448
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchlogic (2.5.13)
4
+ searchlogic (2.5.12)
5
5
  activerecord (~> 2.3.12)
6
6
  activesupport (~> 2.3.12)
7
7
 
@@ -14,15 +14,23 @@ GEM
14
14
  appraisal (0.4.1)
15
15
  bundler
16
16
  rake
17
- rake (10.0.4)
17
+ coderay (1.1.0)
18
+ method_source (0.8.2)
19
+ pry (0.9.12.3)
20
+ coderay (~> 1.0)
21
+ method_source (~> 0.8)
22
+ slop (~> 3.4)
23
+ rake (10.1.0)
18
24
  rspec (1.3.2)
19
- sqlite3 (1.3.7)
25
+ slop (3.4.7)
26
+ sqlite3 (1.3.8)
20
27
 
21
28
  PLATFORMS
22
29
  ruby
23
30
 
24
31
  DEPENDENCIES
25
32
  appraisal (= 0.4.1)
33
+ pry
26
34
  rspec (~> 1.3.1)
27
35
  searchlogic!
28
36
  sqlite3
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_record'
2
3
  require "searchlogic/version"
3
4
  require "searchlogic/core_ext/proc"
@@ -62,7 +62,7 @@ module Searchlogic
62
62
  raise ArgumentError.new("The #{klass} class does not respond to the #{association_condition} scope") if !klass.respond_to?(association_condition)
63
63
  arity = klass.named_scope_arity(association_condition)
64
64
 
65
- if !arity
65
+ if !arity || arity == 0
66
66
  # The underlying condition doesn't require any parameters, so let's just create a simple
67
67
  # named scope that is based on a hash.
68
68
  options = {}
@@ -128,13 +128,41 @@ module Searchlogic
128
128
  end
129
129
 
130
130
  def merge_scopes_with_or(scopes)
131
- scopes_options = scopes.collect { |scope| scope.scope(:find) }
132
- conditions = scopes_options.reject { |o| o[:conditions].nil? }.collect { |o| sanitize_sql(o[:conditions]) }
133
- scope = scopes_options.inject(scoped({})) { |current_scope, options| current_scope.scoped(options) }
134
- options = {}
135
- in_searchlogic_delegation { options = scope.scope(:find) }
136
- options.delete(:readonly) unless scopes.any? { |scope| scope.proxy_options.key?(:readonly) }
137
- options.merge(:conditions => "(" + conditions.join(") OR (") + ")")
131
+ options = scopes_options(scopes)
132
+ merged_options = merge_options(options)
133
+ merged_options.delete(:readonly)
134
+ if !merged_options[:joins].blank?
135
+ merged_options[:joins] = convert_joins_to_optional(merged_options[:joins])
136
+ else
137
+ merged_options.delete(:joins)
138
+ end
139
+ conditions = normalized_conditions(options)
140
+ if conditions.any?
141
+ merged_options[:conditions] = "(" + conditions.join(") OR (") + ")"
142
+ end
143
+ merged_options
144
+ end
145
+
146
+ def scopes_options(scopes)
147
+ scopes.collect { |scope| with_exclusive_scope { scope.scope(:find) } }
148
+ end
149
+
150
+ def convert_joins_to_optional(joins)
151
+ joins ||= []
152
+
153
+ (joins || []).collect { |join| join.gsub(/INNER JOIN/, 'LEFT OUTER JOIN') }
154
+ end
155
+
156
+ def merge_options(options)
157
+ with_exclusive_scope do
158
+ options.inject(scoped({:joins => "", :conditions => ""})) do |current_scope, option|
159
+ current_scope.scoped(option)
160
+ end.scope(:find)
161
+ end
162
+ end
163
+
164
+ def normalized_conditions(options)
165
+ options.collect { |option| option[:conditions] && sanitize_sql(option[:conditions]) }.compact
138
166
  end
139
167
  end
140
168
  end
@@ -15,15 +15,12 @@ module Searchlogic
15
15
  if setter?(name)
16
16
  if scope?(scope_name)
17
17
  if args.size == 1
18
- options = scope_options(scope_name).respond_to?(:searchlogic_options) ? scope_options(scope_name).searchlogic_options : {}
19
- options[:cast_single_val_to_array] = cast_single_val_to_array?(condition_name)
20
-
21
18
  write_condition(
22
19
  condition_name,
23
20
  type_cast(
24
21
  args.first,
25
22
  cast_type(scope_name),
26
- options
23
+ scope_options(scope_name).respond_to?(:searchlogic_options) ? scope_options(scope_name).searchlogic_options : {}
27
24
  )
28
25
  )
29
26
  else
@@ -103,7 +100,7 @@ module Searchlogic
103
100
  casted_value = column_for_type_cast.type_cast(value)
104
101
 
105
102
  if Time.zone && casted_value.is_a?(Time)
106
- casted_value = if value.is_a?(String)
103
+ if value.is_a?(String)
107
104
  # if its a string, we should assume the user means the local time
108
105
  # we need to update the object to include the proper time zone without changing
109
106
  # the time
@@ -111,16 +108,11 @@ module Searchlogic
111
108
  else
112
109
  casted_value.in_time_zone
113
110
  end
111
+ else
112
+ casted_value
114
113
  end
115
-
116
- options[:cast_single_val_to_array] ? [casted_value] : casted_value
117
114
  end
118
115
  end
119
-
120
- # For *_equals_any conditions, cast single values to an array, ex: 5 to [5] or 'ben' to ['ben']
121
- def cast_single_val_to_array?(condition_name)
122
- condition_name =~ /^\w+_equals_any/
123
- end
124
116
  end
125
117
  end
126
118
  end
@@ -1,3 +1,3 @@
1
1
  module Searchlogic
2
- VERSION = "2.5.14"
2
+ VERSION = "2.5.15"
3
3
  end
Binary file
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_development_dependency 'rspec', '~> 1.3.1'
18
18
  s.add_development_dependency 'sqlite3'
19
19
  s.add_development_dependency 'appraisal', '0.4.1'
20
+ s.add_development_dependency 'pry'
20
21
 
21
22
 
22
23
  s.files = `git ls-files`.split("\n")
@@ -5,58 +5,58 @@ describe Searchlogic::NamedScopes::OrConditions do
5
5
  User.name_or_username_like('Test')
6
6
  User.respond_to?(:name_or_username_like).should be_true
7
7
  end
8
-
8
+
9
9
  it "should match username or name" do
10
10
  User.username_or_name_like("ben").proxy_options.should == {:conditions => "(users.username LIKE '%ben%') OR (users.name LIKE '%ben%')"}
11
11
  end
12
-
12
+
13
13
  it "should use the specified condition" do
14
14
  User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(users.username LIKE 'ben%') OR (users.name LIKE '%ben%')"}
15
15
  end
16
-
16
+
17
17
  it "should use the last specified condition" do
18
18
  User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(users.username LIKE '%10%') OR (users.name LIKE '%10%') OR (users.id < 10) OR (users.age < 10)"}
19
19
  end
20
-
20
+
21
21
  it "should raise an error on unknown conditions" do
22
22
  lambda { User.usernme_begins_with_or_name_like("ben") }.should raise_error(Searchlogic::NamedScopes::OrConditions::UnknownConditionError)
23
23
  end
24
-
24
+
25
25
  it "should work well with _or_equal_to" do
26
26
  User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
27
27
  end
28
-
28
+
29
29
  it "should work well with _or_equal_to_any" do
30
30
  User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
31
31
  end
32
-
32
+
33
33
  it "should work well with _or_equal_to_all" do
34
34
  User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
35
35
  end
36
-
36
+
37
37
  it "should play nice with other scopes" do
38
38
  User.username_begins_with("ben").id_gt(10).age_not_nil.username_or_name_ends_with("ben").scope(:find).should ==
39
39
  {:conditions => "((users.username LIKE '%ben') OR (users.name LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
40
40
  end
41
-
41
+
42
42
  it "should work with boolean conditions" do
43
43
  User.male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 't') OR (users.name = 'susan')}}
44
44
  User.not_male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 'f') OR (users.name = 'susan')}}
45
45
  lambda { User.male_or_name_eq("susan").all }.should_not raise_error
46
46
  end
47
-
47
+
48
48
  it "should play nice with scopes on associations" do
49
49
  lambda { User.name_or_company_name_like("ben") }.should_not raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
50
- User.name_or_company_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(users.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
51
- User.company_name_or_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(companies.name LIKE '%ben%') OR (users.name LIKE '%ben%')"}
52
- User.company_name_or_company_description_like("ben").proxy_options.should == {:joins =>[:company], :conditions => "(companies.name LIKE '%ben%') OR (companies.description LIKE '%ben%')"}
53
- Cart.user_company_name_or_user_company_name_like("ben").proxy_options.should == {:joins => {:user=>:company}, :conditions => "(companies.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
50
+ User.name_or_company_name_like("ben").proxy_options.should == {:joins => ["LEFT OUTER JOIN \"companies\" ON \"companies\".id = \"users\".company_id"], :conditions => "(users.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
51
+ User.company_name_or_name_like("ben").proxy_options.should == {:joins => ["LEFT OUTER JOIN \"companies\" ON \"companies\".id = \"users\".company_id"], :conditions => "(companies.name LIKE '%ben%') OR (users.name LIKE '%ben%')"}
52
+ User.company_name_or_company_description_like("ben").proxy_options.should == {:joins => ["LEFT OUTER JOIN \"companies\" ON \"companies\".id = \"users\".company_id"], :conditions => "(companies.name LIKE '%ben%') OR (companies.description LIKE '%ben%')"}
53
+ Cart.user_company_name_or_user_company_name_like("ben").proxy_options.should == {:joins => ["LEFT OUTER JOIN \"users\" ON \"carts\".user_id = \"users\".id", "LEFT OUTER JOIN \"companies\" ON \"companies\".id = \"users\".company_id"], :conditions => "(companies.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
54
54
  end
55
-
55
+
56
56
  it "should raise an error on missing condition" do
57
57
  lambda { User.id_or_age(123) }.should raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
58
58
  end
59
-
59
+
60
60
  it "should not get confused by the 'or' in find_or_create_by_* methods" do
61
61
  User.create(:name => "Fred")
62
62
  User.find_or_create_by_name("Fred").should be_a_kind_of User
@@ -66,7 +66,7 @@ describe Searchlogic::NamedScopes::OrConditions do
66
66
  User.create(:name => "Fred", :username => "fredb")
67
67
  User.find_or_create_by_name_and_username("Fred", "fredb").should be_a_kind_of User
68
68
  end
69
-
69
+
70
70
  it "should work with User.search(conditions) method" do
71
71
  User.search(:username_or_name_like => 'ben').proxy_options.should == {:conditions => "(users.username LIKE '%ben%') OR (users.name LIKE '%ben%')"}
72
72
  end
@@ -74,4 +74,11 @@ describe Searchlogic::NamedScopes::OrConditions do
74
74
  it "should convert types properly when used with User.search(conditions) method" do
75
75
  User.search(:id_or_age_lte => '10').proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age <= 10)"}
76
76
  end
77
+
78
+ it "should converts inner joins to left out joins" do
79
+ scopes = []
80
+ scopes << User.orders_id_equals(1)
81
+ scopes << User.carts_id_equals(1)
82
+ User.send(:merge_scopes_with_or, scopes).should == {:conditions=>"(orders.id = 1) OR (carts.id = 1)", :joins=>["LEFT OUTER JOIN \"carts\" ON carts.user_id = users.id", "LEFT OUTER JOIN \"orders\" ON orders.user_id = users.id"]}
83
+ end
77
84
  end
@@ -321,18 +321,6 @@ describe Searchlogic::Search do
321
321
  search.id_equals_any.should == [1, 2, 3]
322
322
  end
323
323
 
324
- it "should be an Array given a single value for *_equals_any" do
325
- search = Order.search
326
- search.id_equals_any = 5
327
- search.id_equals_any.should == [5]
328
- end
329
-
330
- it "shouldn't change to an Array given a single value for *_equals" do
331
- search = Order.search
332
- search.id_equals = 5
333
- search.id_equals.should_not == [5]
334
- end
335
-
336
324
  it "should type cast association conditions" do
337
325
  search = User.search
338
326
  search.orders_total_gt = "10"
@@ -1,5 +1,6 @@
1
1
  Bundler.setup
2
2
  require 'searchlogic'
3
+ require "pry"
3
4
 
4
5
  ENV['TZ'] = 'UTC'
5
6
  Time.zone = 'Eastern Time (US & Canada)'
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.14
5
- prerelease:
4
+ version: 2.5.15
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ben Johnson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-14 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sqlite3
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: appraisal
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - '='
84
74
  - !ruby/object:Gem::Version
@@ -86,11 +76,24 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - '='
92
81
  - !ruby/object:Gem::Version
93
82
  version: 0.4.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
94
97
  description: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
95
98
  email:
96
99
  - bjohnson@binarylogic.com
@@ -99,6 +102,7 @@ extensions: []
99
102
  extra_rdoc_files: []
100
103
  files:
101
104
  - .gitignore
105
+ - .ruby-version
102
106
  - Appraisals
103
107
  - Gemfile
104
108
  - Gemfile.lock
@@ -142,6 +146,7 @@ files:
142
146
  - lib/searchlogic/search/unknown_condition_error.rb
143
147
  - lib/searchlogic/version.rb
144
148
  - rails/init.rb
149
+ - searchlogic-2.5.13.gem
145
150
  - searchlogic.gemspec
146
151
  - spec/searchlogic/active_record/association_proxy_spec.rb
147
152
  - spec/searchlogic/active_record/consistency_spec.rb
@@ -157,27 +162,26 @@ files:
157
162
  - spec/spec_helper.rb
158
163
  homepage: http://github.com/binarylogic/searchlogic
159
164
  licenses: []
165
+ metadata: {}
160
166
  post_install_message:
161
167
  rdoc_options: []
162
168
  require_paths:
163
169
  - lib
164
170
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
171
  requirements:
167
172
  - - ! '>='
168
173
  - !ruby/object:Gem::Version
169
174
  version: '0'
170
175
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
176
  requirements:
173
177
  - - ! '>='
174
178
  - !ruby/object:Gem::Version
175
179
  version: '0'
176
180
  requirements: []
177
181
  rubyforge_project:
178
- rubygems_version: 1.8.25
182
+ rubygems_version: 2.1.10
179
183
  signing_key:
180
- specification_version: 3
184
+ specification_version: 4
181
185
  summary: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
182
186
  test_files:
183
187
  - spec/searchlogic/active_record/association_proxy_spec.rb