thinking-sphinx 3.0.6 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -6
- data/Appraisals +5 -5
- data/Gemfile +3 -3
- data/HISTORY +32 -0
- data/README.textile +16 -5
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +3 -2
- data/gemfiles/{rails_3_1.gemfile → rails_4_1.gemfile} +3 -2
- data/lib/thinking_sphinx.rb +5 -0
- data/lib/thinking_sphinx/active_record.rb +2 -1
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +1 -1
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +6 -7
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +2 -2
- data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +1 -1
- data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +34 -0
- data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +4 -0
- data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +4 -0
- data/lib/thinking_sphinx/active_record/index.rb +2 -1
- data/lib/thinking_sphinx/active_record/interpreter.rb +7 -0
- data/lib/thinking_sphinx/active_record/property.rb +1 -1
- data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +10 -16
- data/lib/thinking_sphinx/active_record/sql_builder.rb +7 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +0 -7
- data/lib/thinking_sphinx/active_record/sql_source.rb +20 -20
- data/lib/thinking_sphinx/active_record/sql_source/template.rb +1 -1
- data/lib/thinking_sphinx/capistrano.rb +6 -65
- data/lib/thinking_sphinx/capistrano/v2.rb +58 -0
- data/lib/thinking_sphinx/capistrano/v3.rb +101 -0
- data/lib/thinking_sphinx/configuration.rb +8 -3
- data/lib/thinking_sphinx/configuration/distributed_indices.rb +29 -0
- data/lib/thinking_sphinx/connection.rb +90 -34
- data/lib/thinking_sphinx/controller.rb +20 -0
- data/lib/thinking_sphinx/core/index.rb +4 -0
- data/lib/thinking_sphinx/deletion.rb +15 -11
- data/lib/thinking_sphinx/deltas.rb +9 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +2 -0
- data/lib/thinking_sphinx/distributed.rb +5 -0
- data/lib/thinking_sphinx/distributed/index.rb +24 -0
- data/lib/thinking_sphinx/excerpter.rb +7 -3
- data/lib/thinking_sphinx/facet_search.rb +1 -1
- data/lib/thinking_sphinx/index.rb +2 -6
- data/lib/thinking_sphinx/index_set.rb +10 -8
- data/lib/thinking_sphinx/middlewares.rb +0 -2
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +1 -0
- data/lib/thinking_sphinx/middlewares/geographer.rb +1 -1
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +8 -6
- data/lib/thinking_sphinx/middlewares/utf8.rb +6 -1
- data/lib/thinking_sphinx/query.rb +9 -0
- data/lib/thinking_sphinx/railtie.rb +0 -13
- data/lib/thinking_sphinx/search/query.rb +3 -21
- data/lib/thinking_sphinx/sphinxql.rb +1 -1
- data/lib/thinking_sphinx/wildcard.rb +34 -0
- data/spec/acceptance/geosearching_spec.rb +13 -0
- data/spec/acceptance/indexing_spec.rb +27 -0
- data/spec/acceptance/remove_deleted_records_spec.rb +8 -0
- data/spec/acceptance/searching_with_sti_spec.rb +7 -0
- data/spec/acceptance/searching_within_a_model_spec.rb +8 -0
- data/spec/acceptance/sorting_search_results_spec.rb +1 -1
- data/spec/acceptance/spec_helper.rb +13 -0
- data/spec/acceptance/specifying_sql_spec.rb +2 -2
- data/spec/acceptance/support/sphinx_controller.rb +5 -5
- data/spec/acceptance/support/sphinx_helpers.rb +3 -0
- data/spec/acceptance/suspended_deltas_spec.rb +34 -0
- data/spec/internal/config/database.yml +1 -0
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +13 -6
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -2
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +7 -0
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +6 -0
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +27 -0
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +18 -7
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +17 -7
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +84 -82
- data/spec/thinking_sphinx/configuration_spec.rb +5 -4
- data/spec/thinking_sphinx/connection_spec.rb +1 -1
- data/spec/thinking_sphinx/deletion_spec.rb +10 -28
- data/spec/thinking_sphinx/excerpter_spec.rb +3 -3
- data/spec/thinking_sphinx/facet_search_spec.rb +13 -4
- data/spec/thinking_sphinx/index_set_spec.rb +9 -4
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +8 -0
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +17 -1
- data/spec/thinking_sphinx/search/query_spec.rb +10 -53
- data/spec/thinking_sphinx/wildcard_spec.rb +41 -0
- data/thinking-sphinx.gemspec +6 -5
- metadata +38 -14
- data/lib/thinking_sphinx/active_record/associations.rb +0 -98
- data/spec/thinking_sphinx/active_record/associations_spec.rb +0 -230
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.1.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: joiner
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: middleware
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +86,28 @@ dependencies:
|
|
72
86
|
requirements:
|
73
87
|
- - '>='
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.5.
|
89
|
+
version: 1.5.10
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.5.
|
96
|
+
version: 1.5.10
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: appraisal
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ~>
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
103
|
+
version: 0.5.2
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - ~>
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: 0.5.2
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: combustion
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +128,14 @@ dependencies:
|
|
114
128
|
requirements:
|
115
129
|
- - ~>
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: 1.2.0
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 1.2.0
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rspec
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,9 +167,9 @@ files:
|
|
153
167
|
- README.textile
|
154
168
|
- Rakefile
|
155
169
|
- gemfiles/.gitignore
|
156
|
-
- gemfiles/rails_3_1.gemfile
|
157
170
|
- gemfiles/rails_3_2.gemfile
|
158
171
|
- gemfiles/rails_4_0.gemfile
|
172
|
+
- gemfiles/rails_4_1.gemfile
|
159
173
|
- lib/thinking-sphinx.rb
|
160
174
|
- lib/thinking/sphinx.rb
|
161
175
|
- lib/thinking_sphinx.rb
|
@@ -163,7 +177,6 @@ files:
|
|
163
177
|
- lib/thinking_sphinx/active_record/association.rb
|
164
178
|
- lib/thinking_sphinx/active_record/association_proxy.rb
|
165
179
|
- lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
|
166
|
-
- lib/thinking_sphinx/active_record/associations.rb
|
167
180
|
- lib/thinking_sphinx/active_record/attribute.rb
|
168
181
|
- lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
|
169
182
|
- lib/thinking_sphinx/active_record/attribute/type.rb
|
@@ -173,6 +186,7 @@ files:
|
|
173
186
|
- lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
|
174
187
|
- lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb
|
175
188
|
- lib/thinking_sphinx/active_record/column.rb
|
189
|
+
- lib/thinking_sphinx/active_record/column_sql_presenter.rb
|
176
190
|
- lib/thinking_sphinx/active_record/database_adapters.rb
|
177
191
|
- lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb
|
178
192
|
- lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb
|
@@ -195,11 +209,15 @@ files:
|
|
195
209
|
- lib/thinking_sphinx/batched_search.rb
|
196
210
|
- lib/thinking_sphinx/callbacks.rb
|
197
211
|
- lib/thinking_sphinx/capistrano.rb
|
212
|
+
- lib/thinking_sphinx/capistrano/v2.rb
|
213
|
+
- lib/thinking_sphinx/capistrano/v3.rb
|
198
214
|
- lib/thinking_sphinx/configuration.rb
|
199
215
|
- lib/thinking_sphinx/configuration/consistent_ids.rb
|
200
216
|
- lib/thinking_sphinx/configuration/defaults.rb
|
217
|
+
- lib/thinking_sphinx/configuration/distributed_indices.rb
|
201
218
|
- lib/thinking_sphinx/configuration/minimum_fields.rb
|
202
219
|
- lib/thinking_sphinx/connection.rb
|
220
|
+
- lib/thinking_sphinx/controller.rb
|
203
221
|
- lib/thinking_sphinx/core.rb
|
204
222
|
- lib/thinking_sphinx/core/field.rb
|
205
223
|
- lib/thinking_sphinx/core/index.rb
|
@@ -211,6 +229,8 @@ files:
|
|
211
229
|
- lib/thinking_sphinx/deltas/default_delta.rb
|
212
230
|
- lib/thinking_sphinx/deltas/delete_job.rb
|
213
231
|
- lib/thinking_sphinx/deltas/index_job.rb
|
232
|
+
- lib/thinking_sphinx/distributed.rb
|
233
|
+
- lib/thinking_sphinx/distributed/index.rb
|
214
234
|
- lib/thinking_sphinx/errors.rb
|
215
235
|
- lib/thinking_sphinx/excerpter.rb
|
216
236
|
- lib/thinking_sphinx/facet.rb
|
@@ -242,6 +262,7 @@ files:
|
|
242
262
|
- lib/thinking_sphinx/panes/distance_pane.rb
|
243
263
|
- lib/thinking_sphinx/panes/excerpts_pane.rb
|
244
264
|
- lib/thinking_sphinx/panes/weight_pane.rb
|
265
|
+
- lib/thinking_sphinx/query.rb
|
245
266
|
- lib/thinking_sphinx/railtie.rb
|
246
267
|
- lib/thinking_sphinx/rake_interface.rb
|
247
268
|
- lib/thinking_sphinx/real_time.rb
|
@@ -268,6 +289,7 @@ files:
|
|
268
289
|
- lib/thinking_sphinx/tasks.rb
|
269
290
|
- lib/thinking_sphinx/test.rb
|
270
291
|
- lib/thinking_sphinx/utf8.rb
|
292
|
+
- lib/thinking_sphinx/wildcard.rb
|
271
293
|
- sketchpad.rb
|
272
294
|
- spec/acceptance/association_scoping_spec.rb
|
273
295
|
- spec/acceptance/attribute_access_spec.rb
|
@@ -279,6 +301,7 @@ files:
|
|
279
301
|
- spec/acceptance/geosearching_spec.rb
|
280
302
|
- spec/acceptance/grouping_by_attributes_spec.rb
|
281
303
|
- spec/acceptance/index_options_spec.rb
|
304
|
+
- spec/acceptance/indexing_spec.rb
|
282
305
|
- spec/acceptance/paginating_search_results_spec.rb
|
283
306
|
- spec/acceptance/remove_deleted_records_spec.rb
|
284
307
|
- spec/acceptance/search_counts_spec.rb
|
@@ -333,7 +356,6 @@ files:
|
|
333
356
|
- spec/spec_helper.rb
|
334
357
|
- spec/support/sphinx_yaml_helpers.rb
|
335
358
|
- spec/thinking_sphinx/active_record/association_spec.rb
|
336
|
-
- spec/thinking_sphinx/active_record/associations_spec.rb
|
337
359
|
- spec/thinking_sphinx/active_record/attribute/type_spec.rb
|
338
360
|
- spec/thinking_sphinx/active_record/base_spec.rb
|
339
361
|
- spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb
|
@@ -385,9 +407,10 @@ files:
|
|
385
407
|
- spec/thinking_sphinx/search/glaze_spec.rb
|
386
408
|
- spec/thinking_sphinx/search/query_spec.rb
|
387
409
|
- spec/thinking_sphinx/search_spec.rb
|
410
|
+
- spec/thinking_sphinx/wildcard_spec.rb
|
388
411
|
- spec/thinking_sphinx_spec.rb
|
389
412
|
- thinking-sphinx.gemspec
|
390
|
-
homepage: http://pat.github.
|
413
|
+
homepage: http://pat.github.io/thinking-sphinx/
|
391
414
|
licenses:
|
392
415
|
- MIT
|
393
416
|
metadata: {}
|
@@ -407,7 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
407
430
|
version: '0'
|
408
431
|
requirements: []
|
409
432
|
rubyforge_project: thinking-sphinx
|
410
|
-
rubygems_version: 2.1.
|
433
|
+
rubygems_version: 2.1.11
|
411
434
|
signing_key:
|
412
435
|
specification_version: 4
|
413
436
|
summary: A smart wrapper over Sphinx for ActiveRecord
|
@@ -422,6 +445,7 @@ test_files:
|
|
422
445
|
- spec/acceptance/geosearching_spec.rb
|
423
446
|
- spec/acceptance/grouping_by_attributes_spec.rb
|
424
447
|
- spec/acceptance/index_options_spec.rb
|
448
|
+
- spec/acceptance/indexing_spec.rb
|
425
449
|
- spec/acceptance/paginating_search_results_spec.rb
|
426
450
|
- spec/acceptance/remove_deleted_records_spec.rb
|
427
451
|
- spec/acceptance/search_counts_spec.rb
|
@@ -476,7 +500,6 @@ test_files:
|
|
476
500
|
- spec/spec_helper.rb
|
477
501
|
- spec/support/sphinx_yaml_helpers.rb
|
478
502
|
- spec/thinking_sphinx/active_record/association_spec.rb
|
479
|
-
- spec/thinking_sphinx/active_record/associations_spec.rb
|
480
503
|
- spec/thinking_sphinx/active_record/attribute/type_spec.rb
|
481
504
|
- spec/thinking_sphinx/active_record/base_spec.rb
|
482
505
|
- spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb
|
@@ -528,4 +551,5 @@ test_files:
|
|
528
551
|
- spec/thinking_sphinx/search/glaze_spec.rb
|
529
552
|
- spec/thinking_sphinx/search/query_spec.rb
|
530
553
|
- spec/thinking_sphinx/search_spec.rb
|
554
|
+
- spec/thinking_sphinx/wildcard_spec.rb
|
531
555
|
- spec/thinking_sphinx_spec.rb
|
@@ -1,98 +0,0 @@
|
|
1
|
-
class ThinkingSphinx::ActiveRecord::Associations
|
2
|
-
JoinDependency = ::ActiveRecord::Associations::JoinDependency
|
3
|
-
|
4
|
-
attr_reader :model
|
5
|
-
|
6
|
-
def initialize(model)
|
7
|
-
@model = model
|
8
|
-
@joins = ActiveSupport::OrderedHash.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_join_to(stack)
|
12
|
-
join_for(stack)
|
13
|
-
end
|
14
|
-
|
15
|
-
def aggregate_for?(stack)
|
16
|
-
return false if stack.empty?
|
17
|
-
|
18
|
-
joins_for(stack).compact.any? { |join|
|
19
|
-
[:has_many, :has_and_belongs_to_many].include?(
|
20
|
-
join.reflection.macro
|
21
|
-
)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def alias_for(stack)
|
26
|
-
return model.quoted_table_name if stack.empty?
|
27
|
-
|
28
|
-
join_for(stack).aliased_table_name
|
29
|
-
end
|
30
|
-
|
31
|
-
def join_values
|
32
|
-
@joins.values.compact
|
33
|
-
end
|
34
|
-
|
35
|
-
def model_for(stack)
|
36
|
-
return model if stack.empty?
|
37
|
-
|
38
|
-
join = join_for(stack)
|
39
|
-
join.nil? ? nil : join.reflection.klass
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def base
|
45
|
-
@base ||= JoinDependency.new model, [], []
|
46
|
-
end
|
47
|
-
|
48
|
-
def join_for(stack)
|
49
|
-
@joins[stack] ||= begin
|
50
|
-
reflection = reflection_for stack
|
51
|
-
reflection.nil? ? nil : JoinDependency::JoinAssociation.new(
|
52
|
-
reflection, base, parent_join_for(stack)
|
53
|
-
).tap { |join|
|
54
|
-
join.join_type = Arel::OuterJoin
|
55
|
-
|
56
|
-
rewrite_conditions_for join
|
57
|
-
}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def joins_for(stack)
|
62
|
-
if stack.length == 1
|
63
|
-
[join_for(stack)]
|
64
|
-
else
|
65
|
-
[joins_for(stack[0..-2]), join_for(stack)].flatten
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def parent_for(stack)
|
70
|
-
stack.length == 1 ? base : join_for(stack[0..-2])
|
71
|
-
end
|
72
|
-
|
73
|
-
def parent_join_for(stack)
|
74
|
-
stack.length == 1 ? base.join_base : parent_for(stack)
|
75
|
-
end
|
76
|
-
|
77
|
-
def reflection_for(stack)
|
78
|
-
parent = parent_for(stack)
|
79
|
-
klass = parent.respond_to?(:base_klass) ? parent.base_klass :
|
80
|
-
parent.active_record
|
81
|
-
klass.reflections[stack.last]
|
82
|
-
end
|
83
|
-
|
84
|
-
def rewrite_conditions_for(join)
|
85
|
-
if join.respond_to?(:scope_chain)
|
86
|
-
conditions = Array(join.scope_chain).flatten
|
87
|
-
else
|
88
|
-
conditions = Array(join.conditions).flatten
|
89
|
-
end
|
90
|
-
|
91
|
-
conditions.each do |condition|
|
92
|
-
next unless condition.is_a?(String)
|
93
|
-
|
94
|
-
condition.gsub! /::ts_join_alias::/,
|
95
|
-
model.connection.quote_table_name(join.parent.aliased_table_name)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::ActiveRecord::Associations do
|
4
|
-
JoinDependency = ::ActiveRecord::Associations::JoinDependency
|
5
|
-
|
6
|
-
let(:associations) { ThinkingSphinx::ActiveRecord::Associations.new model }
|
7
|
-
let(:model) { model_double 'articles' }
|
8
|
-
let(:base) {
|
9
|
-
double('base', :active_record => model, :join_base => join_base)
|
10
|
-
}
|
11
|
-
let(:join_base) { double('join base') }
|
12
|
-
let(:join) { join_double 'users' }
|
13
|
-
let(:sub_join) { join_double 'posts' }
|
14
|
-
|
15
|
-
def join_double(table_alias)
|
16
|
-
double 'join',
|
17
|
-
:join_type= => nil,
|
18
|
-
:aliased_table_name => table_alias,
|
19
|
-
:reflection => double('reflection'),
|
20
|
-
:conditions => []
|
21
|
-
end
|
22
|
-
|
23
|
-
def model_double(table_name = nil)
|
24
|
-
double 'model', :quoted_table_name => table_name, :reflections => {}
|
25
|
-
end
|
26
|
-
|
27
|
-
before :each do
|
28
|
-
JoinDependency.stub :new => base
|
29
|
-
JoinDependency::JoinAssociation.stub(:new).and_return(join, sub_join)
|
30
|
-
model.reflections[:user] = join.reflection
|
31
|
-
|
32
|
-
join.stub :active_record => model_double
|
33
|
-
join.active_record.reflections[:posts] = sub_join.reflection
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#add_join_to' do
|
37
|
-
before :each do
|
38
|
-
JoinDependency::JoinAssociation.unstub :new
|
39
|
-
end
|
40
|
-
|
41
|
-
it "adds just one join for a stack with a single association" do
|
42
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
43
|
-
with(join.reflection, base, join_base).once.and_return(join)
|
44
|
-
|
45
|
-
associations.add_join_to([:user])
|
46
|
-
end
|
47
|
-
|
48
|
-
it "does not duplicate joins when given the same stack twice" do
|
49
|
-
JoinDependency::JoinAssociation.should_receive(:new).once.and_return(join)
|
50
|
-
|
51
|
-
associations.add_join_to([:user])
|
52
|
-
associations.add_join_to([:user])
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'multiple joins' do
|
56
|
-
it "adds two joins for a stack with two associations" do
|
57
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
58
|
-
with(join.reflection, base, join_base).once.and_return(join)
|
59
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
60
|
-
with(sub_join.reflection, base, join).once.and_return(sub_join)
|
61
|
-
|
62
|
-
associations.add_join_to([:user, :posts])
|
63
|
-
end
|
64
|
-
|
65
|
-
it "extends upon existing joins when given stacks where parts are already mapped" do
|
66
|
-
JoinDependency::JoinAssociation.should_receive(:new).twice.
|
67
|
-
and_return(join, sub_join)
|
68
|
-
|
69
|
-
associations.add_join_to([:user])
|
70
|
-
associations.add_join_to([:user, :posts])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'join with conditions' do
|
75
|
-
let(:connection) { double }
|
76
|
-
let(:parent) { double :aliased_table_name => 'qux' }
|
77
|
-
|
78
|
-
before :each do
|
79
|
-
JoinDependency::JoinAssociation.stub :new => join
|
80
|
-
|
81
|
-
join.stub :parent => parent
|
82
|
-
model.stub :connection => connection
|
83
|
-
connection.stub(:quote_table_name) { |table| "\"#{table}\"" }
|
84
|
-
end
|
85
|
-
|
86
|
-
it "leaves standard conditions untouched" do
|
87
|
-
join.stub :conditions => 'foo = bar'
|
88
|
-
|
89
|
-
associations.add_join_to [:user]
|
90
|
-
|
91
|
-
join.conditions.should == 'foo = bar'
|
92
|
-
end
|
93
|
-
|
94
|
-
it "modifies filtered polymorphic conditions" do
|
95
|
-
join.stub :conditions => '::ts_join_alias::.foo = bar'
|
96
|
-
|
97
|
-
associations.add_join_to [:user]
|
98
|
-
|
99
|
-
join.conditions.should == '"qux".foo = bar'
|
100
|
-
end
|
101
|
-
|
102
|
-
it "modifies filtered polymorphic conditions within arrays" do
|
103
|
-
join.stub :conditions => ['::ts_join_alias::.foo = bar']
|
104
|
-
|
105
|
-
associations.add_join_to [:user]
|
106
|
-
|
107
|
-
join.conditions.should == ['"qux".foo = bar']
|
108
|
-
end
|
109
|
-
|
110
|
-
it "does not modify conditions as hashes" do
|
111
|
-
join.stub :conditions => [{:foo => 'bar'}]
|
112
|
-
|
113
|
-
associations.add_join_to [:user]
|
114
|
-
|
115
|
-
join.conditions.should == [{:foo => 'bar'}]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe '#aggregate_for?' do
|
121
|
-
it "is false when the stack is empty" do
|
122
|
-
associations.aggregate_for?([]).should be_false
|
123
|
-
end
|
124
|
-
|
125
|
-
it "is true when a reflection is a has_many" do
|
126
|
-
join.reflection.stub!(:macro => :has_many)
|
127
|
-
|
128
|
-
associations.aggregate_for?([:user]).should be_true
|
129
|
-
end
|
130
|
-
|
131
|
-
it "is true when a reflection is a has_and_belongs_to_many" do
|
132
|
-
join.reflection.stub!(:macro => :has_and_belongs_to_many)
|
133
|
-
|
134
|
-
associations.aggregate_for?([:user]).should be_true
|
135
|
-
end
|
136
|
-
|
137
|
-
it "is false when a reflection is a belongs_to" do
|
138
|
-
join.reflection.stub!(:macro => :belongs_to)
|
139
|
-
|
140
|
-
associations.aggregate_for?([:user]).should be_false
|
141
|
-
end
|
142
|
-
|
143
|
-
it "is false when a reflection is a has_one" do
|
144
|
-
join.reflection.stub!(:macro => :has_one)
|
145
|
-
|
146
|
-
associations.aggregate_for?([:user]).should be_false
|
147
|
-
end
|
148
|
-
|
149
|
-
it "is true when one level is aggregate" do
|
150
|
-
join.reflection.stub!(:macro => :belongs_to)
|
151
|
-
sub_join.reflection.stub!(:macro => :has_many)
|
152
|
-
|
153
|
-
associations.aggregate_for?([:user, :posts]).should be_true
|
154
|
-
end
|
155
|
-
|
156
|
-
it "is true when both levels are aggregates" do
|
157
|
-
join.reflection.stub!(:macro => :has_many)
|
158
|
-
sub_join.reflection.stub!(:macro => :has_many)
|
159
|
-
|
160
|
-
associations.aggregate_for?([:user, :posts]).should be_true
|
161
|
-
end
|
162
|
-
|
163
|
-
it "is false when both levels are not aggregates" do
|
164
|
-
join.reflection.stub!(:macro => :belongs_to)
|
165
|
-
sub_join.reflection.stub!(:macro => :belongs_to)
|
166
|
-
|
167
|
-
associations.aggregate_for?([:user, :posts]).should be_false
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe '#alias_for' do
|
172
|
-
it "returns the model's table name when no stack is given" do
|
173
|
-
associations.alias_for([]).should == 'articles'
|
174
|
-
end
|
175
|
-
|
176
|
-
it "adds just one join for a stack with a single association" do
|
177
|
-
JoinDependency::JoinAssociation.unstub :new
|
178
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
179
|
-
with(join.reflection, base, join_base).once.and_return(join)
|
180
|
-
|
181
|
-
associations.alias_for([:user])
|
182
|
-
end
|
183
|
-
|
184
|
-
it "returns the aliased table name for the join" do
|
185
|
-
associations.alias_for([:user]).should == 'users'
|
186
|
-
end
|
187
|
-
|
188
|
-
it "does not duplicate joins when given the same stack twice" do
|
189
|
-
JoinDependency::JoinAssociation.unstub :new
|
190
|
-
JoinDependency::JoinAssociation.should_receive(:new).once.and_return(join)
|
191
|
-
|
192
|
-
associations.alias_for([:user])
|
193
|
-
associations.alias_for([:user])
|
194
|
-
end
|
195
|
-
|
196
|
-
context 'multiple joins' do
|
197
|
-
it "adds two joins for a stack with two associations" do
|
198
|
-
JoinDependency::JoinAssociation.unstub :new
|
199
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
200
|
-
with(join.reflection, base, join_base).once.and_return(join)
|
201
|
-
JoinDependency::JoinAssociation.should_receive(:new).
|
202
|
-
with(sub_join.reflection, base, join).once.and_return(sub_join)
|
203
|
-
|
204
|
-
associations.alias_for([:user, :posts])
|
205
|
-
end
|
206
|
-
|
207
|
-
it "returns the sub join's aliased table name" do
|
208
|
-
associations.alias_for([:user, :posts]).should == 'posts'
|
209
|
-
end
|
210
|
-
|
211
|
-
it "extends upon existing joins when given stacks where parts are already mapped" do
|
212
|
-
JoinDependency::JoinAssociation.unstub :new
|
213
|
-
JoinDependency::JoinAssociation.should_receive(:new).twice.
|
214
|
-
and_return(join, sub_join)
|
215
|
-
|
216
|
-
associations.alias_for([:user])
|
217
|
-
associations.alias_for([:user, :posts])
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe '#join_values' do
|
223
|
-
it "returns all joins that have been created" do
|
224
|
-
associations.alias_for([:user])
|
225
|
-
associations.alias_for([:user, :posts])
|
226
|
-
|
227
|
-
associations.join_values.should == [join, sub_join]
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|