thinking-sphinx 3.2.0 → 3.3.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/Gemfile +2 -1
- data/HISTORY +19 -0
- data/README.textile +3 -2
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/thinking_sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
- data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +3 -2
- data/lib/thinking_sphinx/connection.rb +23 -10
- data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
- data/lib/thinking_sphinx/errors.rb +25 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
- data/lib/thinking_sphinx/railtie.rb +1 -1
- data/lib/thinking_sphinx/rake_interface.rb +71 -23
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
- data/lib/thinking_sphinx/real_time/populator.rb +3 -3
- data/lib/thinking_sphinx/tasks.rb +7 -8
- data/lib/thinking_sphinx/wildcard.rb +1 -1
- data/spec/acceptance/association_scoping_spec.rb +5 -5
- data/spec/acceptance/attribute_access_spec.rb +4 -4
- data/spec/acceptance/attribute_updates_spec.rb +3 -3
- data/spec/acceptance/batch_searching_spec.rb +4 -4
- data/spec/acceptance/big_integers_spec.rb +6 -6
- data/spec/acceptance/connection_spec.rb +23 -0
- data/spec/acceptance/excerpts_spec.rb +8 -8
- data/spec/acceptance/facets_spec.rb +13 -13
- data/spec/acceptance/geosearching_spec.rb +8 -8
- data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
- data/spec/acceptance/index_options_spec.rb +16 -16
- data/spec/acceptance/indexing_spec.rb +3 -3
- data/spec/acceptance/paginating_search_results_spec.rb +3 -3
- data/spec/acceptance/real_time_updates_spec.rb +4 -4
- data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
- data/spec/acceptance/search_counts_spec.rb +2 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
- data/spec/acceptance/searching_across_models_spec.rb +6 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
- data/spec/acceptance/searching_on_fields_spec.rb +9 -9
- data/spec/acceptance/searching_with_filters_spec.rb +16 -16
- data/spec/acceptance/searching_with_sti_spec.rb +9 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
- data/spec/acceptance/sorting_search_results_spec.rb +6 -6
- data/spec/acceptance/specifying_sql_spec.rb +62 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
- data/spec/acceptance/sql_deltas_spec.rb +7 -7
- data/spec/acceptance/support/database_cleaner.rb +1 -1
- data/spec/acceptance/support/sphinx_controller.rb +4 -1
- data/spec/acceptance/support/sphinx_helpers.rb +4 -0
- data/spec/acceptance/suspended_deltas_spec.rb +9 -9
- data/spec/internal/app/indices/article_index.rb +2 -2
- data/spec/internal/app/indices/book_index.rb +2 -1
- data/spec/internal/app/indices/product_index.rb +0 -2
- data/spec/internal/app/models/categorisation.rb +8 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/json_column.rb +5 -1
- data/spec/support/multi_schema.rb +3 -1
- data/spec/support/sphinx_yaml_helpers.rb +1 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
- data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
- data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
- data/spec/thinking_sphinx/configuration_spec.rb +81 -81
- data/spec/thinking_sphinx/connection_spec.rb +13 -13
- data/spec/thinking_sphinx/deletion_spec.rb +11 -11
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
- data/spec/thinking_sphinx/deltas_spec.rb +12 -12
- data/spec/thinking_sphinx/errors_spec.rb +30 -30
- data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
- data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
- data/spec/thinking_sphinx/index_set_spec.rb +7 -7
- data/spec/thinking_sphinx/index_spec.rb +24 -24
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
- data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
- data/spec/thinking_sphinx/scopes_spec.rb +5 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
- data/spec/thinking_sphinx/search/query_spec.rb +10 -10
- data/spec/thinking_sphinx/search_spec.rb +28 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
- data/spec/thinking_sphinx_spec.rb +6 -6
- data/thinking-sphinx.gemspec +4 -4
- metadata +12 -9
|
@@ -22,24 +22,24 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
22
22
|
let(:builder) { ThinkingSphinx::ActiveRecord::SQLBuilder.new source }
|
|
23
23
|
|
|
24
24
|
before :each do
|
|
25
|
-
ThinkingSphinx::Configuration.
|
|
26
|
-
ThinkingSphinx::ActiveRecord::PropertySQLPresenter.
|
|
27
|
-
Joiner::Joins.
|
|
28
|
-
relation.
|
|
25
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
26
|
+
allow(ThinkingSphinx::ActiveRecord::PropertySQLPresenter).to receive_messages :new => presenter
|
|
27
|
+
allow(Joiner::Joins).to receive_messages :new => associations
|
|
28
|
+
allow(relation).to receive_messages :select => relation, :where => relation, :group => relation,
|
|
29
29
|
:order => relation, :joins => relation, :to_sql => ''
|
|
30
|
-
connection.
|
|
30
|
+
allow(connection).to receive(:quote_column_name) { |column| "`#{column}`"}
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
describe 'sql_query' do
|
|
34
34
|
before :each do
|
|
35
|
-
source.
|
|
35
|
+
allow(source).to receive_messages :type => 'mysql'
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "adds source associations to the joins of the query" do
|
|
39
39
|
source.associations << double('association',
|
|
40
40
|
:stack => [:user, :posts], :string? => false)
|
|
41
41
|
|
|
42
|
-
associations.
|
|
42
|
+
expect(associations).to receive(:add_join_to).with([:user, :posts])
|
|
43
43
|
|
|
44
44
|
builder.sql_query
|
|
45
45
|
end
|
|
@@ -48,25 +48,25 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
48
48
|
source.associations << double('association',
|
|
49
49
|
:to_s => 'my string', :string? => true)
|
|
50
50
|
|
|
51
|
-
relation.
|
|
51
|
+
expect(relation).to receive(:joins).with(['my string']).and_return(relation)
|
|
52
52
|
|
|
53
53
|
builder.sql_query
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
context 'MySQL adapter' do
|
|
57
57
|
before :each do
|
|
58
|
-
source.
|
|
58
|
+
allow(source).to receive_messages :type => 'mysql'
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "returns the relation's query" do
|
|
62
|
-
relation.
|
|
62
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
63
63
|
|
|
64
|
-
builder.sql_query.
|
|
64
|
+
expect(builder.sql_query).to eq('SELECT * FROM people')
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "ensures results aren't from cache" do
|
|
68
|
-
relation.
|
|
69
|
-
string.
|
|
68
|
+
expect(relation).to receive(:select) do |string|
|
|
69
|
+
expect(string).to match(/^SQL_NO_CACHE /)
|
|
70
70
|
relation
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -74,8 +74,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "adds the document id using the offset and index count" do
|
|
77
|
-
relation.
|
|
78
|
-
string.
|
|
77
|
+
expect(relation).to receive(:select) do |string|
|
|
78
|
+
expect(string).to match(/`users`.`id` \* 5 \+ 3 AS `id`/)
|
|
79
79
|
relation
|
|
80
80
|
end
|
|
81
81
|
|
|
@@ -85,8 +85,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
85
85
|
it "adds each field to the SELECT clause" do
|
|
86
86
|
source.fields << double('field')
|
|
87
87
|
|
|
88
|
-
relation.
|
|
89
|
-
string.
|
|
88
|
+
expect(relation).to receive(:select) do |string|
|
|
89
|
+
expect(string).to match(/`name` AS `name`/)
|
|
90
90
|
relation
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -95,10 +95,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
95
95
|
|
|
96
96
|
it "adds each attribute to the SELECT clause" do
|
|
97
97
|
source.attributes << double('attribute')
|
|
98
|
-
presenter.
|
|
98
|
+
allow(presenter).to receive_messages(:to_select => '`created_at` AS `created_at`')
|
|
99
99
|
|
|
100
|
-
relation.
|
|
101
|
-
string.
|
|
100
|
+
expect(relation).to receive(:select) do |string|
|
|
101
|
+
expect(string).to match(/`created_at` AS `created_at`/)
|
|
102
102
|
relation
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -106,8 +106,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
it "limits results to a set range" do
|
|
109
|
-
relation.
|
|
110
|
-
string.
|
|
109
|
+
expect(relation).to receive(:where) do |string|
|
|
110
|
+
expect(string).to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
111
111
|
relation
|
|
112
112
|
end
|
|
113
113
|
|
|
@@ -115,10 +115,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
it "shouldn't limit results to a range if ranges are disabled" do
|
|
118
|
-
source.
|
|
118
|
+
allow(source).to receive_messages :disable_range? => true
|
|
119
119
|
|
|
120
|
-
relation.
|
|
121
|
-
string.
|
|
120
|
+
expect(relation).to receive(:where) do |string|
|
|
121
|
+
expect(string).not_to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
122
122
|
relation
|
|
123
123
|
end
|
|
124
124
|
|
|
@@ -128,8 +128,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
128
128
|
it "adds source conditions" do
|
|
129
129
|
source.conditions << 'created_at > NOW()'
|
|
130
130
|
|
|
131
|
-
relation.
|
|
132
|
-
string.
|
|
131
|
+
expect(relation).to receive(:where) do |string|
|
|
132
|
+
expect(string).to match(/created_at > NOW()/)
|
|
133
133
|
relation
|
|
134
134
|
end
|
|
135
135
|
|
|
@@ -137,8 +137,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "groups by the primary key" do
|
|
140
|
-
relation.
|
|
141
|
-
string.
|
|
140
|
+
expect(relation).to receive(:group) do |string|
|
|
141
|
+
expect(string).to match(/`users`.`id`/)
|
|
142
142
|
relation
|
|
143
143
|
end
|
|
144
144
|
|
|
@@ -148,8 +148,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
148
148
|
it "groups each field" do
|
|
149
149
|
source.fields << double('field')
|
|
150
150
|
|
|
151
|
-
relation.
|
|
152
|
-
string.
|
|
151
|
+
expect(relation).to receive(:group) do |string|
|
|
152
|
+
expect(string).to match(/`name`/)
|
|
153
153
|
relation
|
|
154
154
|
end
|
|
155
155
|
|
|
@@ -158,10 +158,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
158
158
|
|
|
159
159
|
it "groups each attribute" do
|
|
160
160
|
source.attributes << double('attribute')
|
|
161
|
-
presenter.
|
|
161
|
+
allow(presenter).to receive_messages(:to_group => '`created_at`')
|
|
162
162
|
|
|
163
|
-
relation.
|
|
164
|
-
string.
|
|
163
|
+
expect(relation).to receive(:group) do |string|
|
|
164
|
+
expect(string).to match(/`created_at`/)
|
|
165
165
|
relation
|
|
166
166
|
end
|
|
167
167
|
|
|
@@ -171,8 +171,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
171
171
|
it "groups by source groupings" do
|
|
172
172
|
source.groupings << '`latitude`'
|
|
173
173
|
|
|
174
|
-
relation.
|
|
175
|
-
string.
|
|
174
|
+
expect(relation).to receive(:group) do |string|
|
|
175
|
+
expect(string).to match(/`latitude`/)
|
|
176
176
|
relation
|
|
177
177
|
end
|
|
178
178
|
|
|
@@ -180,7 +180,7 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
it "orders by NULL" do
|
|
183
|
-
relation.
|
|
183
|
+
expect(relation).to receive(:order).with('NULL').and_return(relation)
|
|
184
184
|
|
|
185
185
|
builder.sql_query
|
|
186
186
|
end
|
|
@@ -188,13 +188,13 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
188
188
|
context 'STI model' do
|
|
189
189
|
before :each do
|
|
190
190
|
model.column_names << 'type'
|
|
191
|
-
model.
|
|
192
|
-
model.
|
|
191
|
+
allow(model).to receive_messages :descends_from_active_record? => false
|
|
192
|
+
allow(model).to receive_messages :store_full_sti_class => true
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
it "groups by the inheritance column" do
|
|
196
|
-
relation.
|
|
197
|
-
string.
|
|
196
|
+
expect(relation).to receive(:group) do |string|
|
|
197
|
+
expect(string).to match(/`users`.`type`/)
|
|
198
198
|
relation
|
|
199
199
|
end
|
|
200
200
|
|
|
@@ -204,12 +204,12 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
204
204
|
context 'with a custom inheritance column' do
|
|
205
205
|
before :each do
|
|
206
206
|
model.column_names << 'custom_type'
|
|
207
|
-
model.
|
|
207
|
+
allow(model).to receive_messages :inheritance_column => 'custom_type'
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
it "groups by the right column" do
|
|
211
|
-
relation.
|
|
212
|
-
string.
|
|
211
|
+
expect(relation).to receive(:group) do |string|
|
|
212
|
+
expect(string).to match(/`users`.`custom_type`/)
|
|
213
213
|
relation
|
|
214
214
|
end
|
|
215
215
|
|
|
@@ -222,14 +222,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
222
222
|
let(:processor) { double('processor') }
|
|
223
223
|
|
|
224
224
|
before :each do
|
|
225
|
-
source.
|
|
226
|
-
source.
|
|
225
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
226
|
+
allow(source).to receive_messages :delta? => true
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
it "filters by the provided clause" do
|
|
230
|
-
processor.
|
|
231
|
-
relation.
|
|
232
|
-
string.
|
|
230
|
+
expect(processor).to receive(:clause).with(true).and_return('`delta` = 1')
|
|
231
|
+
expect(relation).to receive(:where) do |string|
|
|
232
|
+
expect(string).to match(/`delta` = 1/)
|
|
233
233
|
relation
|
|
234
234
|
end
|
|
235
235
|
|
|
@@ -243,20 +243,20 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
243
243
|
:to_group => '"name"') }
|
|
244
244
|
|
|
245
245
|
before :each do
|
|
246
|
-
source.
|
|
247
|
-
model.
|
|
248
|
-
connection.
|
|
246
|
+
allow(source).to receive_messages :type => 'pgsql'
|
|
247
|
+
allow(model).to receive_messages :quoted_table_name => '"users"'
|
|
248
|
+
allow(connection).to receive(:quote_column_name) { |column| "\"#{column}\""}
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
it "returns the relation's query" do
|
|
252
|
-
relation.
|
|
252
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
253
253
|
|
|
254
|
-
builder.sql_query.
|
|
254
|
+
expect(builder.sql_query).to eq('SELECT * FROM people')
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
it "adds the document id using the offset and index count" do
|
|
258
|
-
relation.
|
|
259
|
-
string.
|
|
258
|
+
expect(relation).to receive(:select) do |string|
|
|
259
|
+
expect(string).to match(/"users"."id" \* 5 \+ 3 AS "id"/)
|
|
260
260
|
relation
|
|
261
261
|
end
|
|
262
262
|
|
|
@@ -266,8 +266,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
266
266
|
it "adds each field to the SELECT clause" do
|
|
267
267
|
source.fields << double('field')
|
|
268
268
|
|
|
269
|
-
relation.
|
|
270
|
-
string.
|
|
269
|
+
expect(relation).to receive(:select) do |string|
|
|
270
|
+
expect(string).to match(/"name" AS "name"/)
|
|
271
271
|
relation
|
|
272
272
|
end
|
|
273
273
|
|
|
@@ -276,10 +276,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
276
276
|
|
|
277
277
|
it "adds each attribute to the SELECT clause" do
|
|
278
278
|
source.attributes << double('attribute')
|
|
279
|
-
presenter.
|
|
279
|
+
allow(presenter).to receive_messages(:to_select => '"created_at" AS "created_at"')
|
|
280
280
|
|
|
281
|
-
relation.
|
|
282
|
-
string.
|
|
281
|
+
expect(relation).to receive(:select) do |string|
|
|
282
|
+
expect(string).to match(/"created_at" AS "created_at"/)
|
|
283
283
|
relation
|
|
284
284
|
end
|
|
285
285
|
|
|
@@ -287,8 +287,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
287
287
|
end
|
|
288
288
|
|
|
289
289
|
it "limits results to a set range" do
|
|
290
|
-
relation.
|
|
291
|
-
string.
|
|
290
|
+
expect(relation).to receive(:where) do |string|
|
|
291
|
+
expect(string).to match(/"users"."id" BETWEEN \$start AND \$end/)
|
|
292
292
|
relation
|
|
293
293
|
end
|
|
294
294
|
|
|
@@ -296,10 +296,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
296
296
|
end
|
|
297
297
|
|
|
298
298
|
it "shouldn't limit results to a range if ranges are disabled" do
|
|
299
|
-
source.
|
|
299
|
+
allow(source).to receive_messages :disable_range? => true
|
|
300
300
|
|
|
301
|
-
relation.
|
|
302
|
-
string.
|
|
301
|
+
expect(relation).to receive(:where) do |string|
|
|
302
|
+
expect(string).not_to match(/"users"."id" BETWEEN \$start AND \$end/)
|
|
303
303
|
relation
|
|
304
304
|
end
|
|
305
305
|
|
|
@@ -309,8 +309,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
309
309
|
it "adds source conditions" do
|
|
310
310
|
source.conditions << 'created_at > NOW()'
|
|
311
311
|
|
|
312
|
-
relation.
|
|
313
|
-
string.
|
|
312
|
+
expect(relation).to receive(:where) do |string|
|
|
313
|
+
expect(string).to match(/created_at > NOW()/)
|
|
314
314
|
relation
|
|
315
315
|
end
|
|
316
316
|
|
|
@@ -318,8 +318,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
318
318
|
end
|
|
319
319
|
|
|
320
320
|
it "groups by the primary key" do
|
|
321
|
-
relation.
|
|
322
|
-
string.
|
|
321
|
+
expect(relation).to receive(:group) do |string|
|
|
322
|
+
expect(string).to match(/"users"."id"/)
|
|
323
323
|
relation
|
|
324
324
|
end
|
|
325
325
|
|
|
@@ -329,8 +329,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
329
329
|
it "groups each field" do
|
|
330
330
|
source.fields << double('field')
|
|
331
331
|
|
|
332
|
-
relation.
|
|
333
|
-
string.
|
|
332
|
+
expect(relation).to receive(:group) do |string|
|
|
333
|
+
expect(string).to match(/"name"/)
|
|
334
334
|
relation
|
|
335
335
|
end
|
|
336
336
|
|
|
@@ -339,10 +339,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
339
339
|
|
|
340
340
|
it "groups each attribute" do
|
|
341
341
|
source.attributes << double('attribute')
|
|
342
|
-
presenter.
|
|
342
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
343
343
|
|
|
344
|
-
relation.
|
|
345
|
-
string.
|
|
344
|
+
expect(relation).to receive(:group) do |string|
|
|
345
|
+
expect(string).to match(/"created_at"/)
|
|
346
346
|
relation
|
|
347
347
|
end
|
|
348
348
|
|
|
@@ -352,8 +352,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
352
352
|
it "groups by source groupings" do
|
|
353
353
|
source.groupings << '"latitude"'
|
|
354
354
|
|
|
355
|
-
relation.
|
|
356
|
-
string.
|
|
355
|
+
expect(relation).to receive(:group) do |string|
|
|
356
|
+
expect(string).to match(/"latitude"/)
|
|
357
357
|
relation
|
|
358
358
|
end
|
|
359
359
|
|
|
@@ -361,7 +361,7 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
361
361
|
end
|
|
362
362
|
|
|
363
363
|
it "has no ORDER clause" do
|
|
364
|
-
relation.
|
|
364
|
+
expect(relation).not_to receive(:order)
|
|
365
365
|
|
|
366
366
|
builder.sql_query
|
|
367
367
|
end
|
|
@@ -372,8 +372,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
372
372
|
end
|
|
373
373
|
|
|
374
374
|
it "groups by the primary key" do
|
|
375
|
-
relation.
|
|
376
|
-
string.
|
|
375
|
+
expect(relation).to receive(:group) do |string|
|
|
376
|
+
expect(string).to match(/"users"."id"/)
|
|
377
377
|
relation
|
|
378
378
|
end
|
|
379
379
|
|
|
@@ -383,8 +383,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
383
383
|
it "does not group by fields" do
|
|
384
384
|
source.fields << double('field')
|
|
385
385
|
|
|
386
|
-
relation.
|
|
387
|
-
string.
|
|
386
|
+
expect(relation).to receive(:group) do |string|
|
|
387
|
+
expect(string).not_to match(/"name"/)
|
|
388
388
|
relation
|
|
389
389
|
end
|
|
390
390
|
|
|
@@ -393,10 +393,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
393
393
|
|
|
394
394
|
it "does not group by attributes" do
|
|
395
395
|
source.attributes << double('attribute')
|
|
396
|
-
presenter.
|
|
396
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
397
397
|
|
|
398
|
-
relation.
|
|
399
|
-
string.
|
|
398
|
+
expect(relation).to receive(:group) do |string|
|
|
399
|
+
expect(string).not_to match(/"created_at"/)
|
|
400
400
|
relation
|
|
401
401
|
end
|
|
402
402
|
|
|
@@ -406,8 +406,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
406
406
|
it "groups by source groupings" do
|
|
407
407
|
source.groupings << '"latitude"'
|
|
408
408
|
|
|
409
|
-
relation.
|
|
410
|
-
string.
|
|
409
|
+
expect(relation).to receive(:group) do |string|
|
|
410
|
+
expect(string).to match(/"latitude"/)
|
|
411
411
|
relation
|
|
412
412
|
end
|
|
413
413
|
|
|
@@ -421,8 +421,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
421
421
|
end
|
|
422
422
|
|
|
423
423
|
it "groups by the primary key" do
|
|
424
|
-
relation.
|
|
425
|
-
string.
|
|
424
|
+
expect(relation).to receive(:group) do |string|
|
|
425
|
+
expect(string).to match(/"users"."id"/)
|
|
426
426
|
relation
|
|
427
427
|
end
|
|
428
428
|
|
|
@@ -432,8 +432,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
432
432
|
it "does not group by fields" do
|
|
433
433
|
source.fields << double('field')
|
|
434
434
|
|
|
435
|
-
relation.
|
|
436
|
-
string.
|
|
435
|
+
expect(relation).to receive(:group) do |string|
|
|
436
|
+
expect(string).not_to match(/"name"/)
|
|
437
437
|
relation
|
|
438
438
|
end
|
|
439
439
|
|
|
@@ -442,10 +442,10 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
442
442
|
|
|
443
443
|
it "does not group by attributes" do
|
|
444
444
|
source.attributes << double('attribute')
|
|
445
|
-
presenter.
|
|
445
|
+
allow(presenter).to receive_messages(:to_group => '"created_at"')
|
|
446
446
|
|
|
447
|
-
relation.
|
|
448
|
-
string.
|
|
447
|
+
expect(relation).to receive(:group) do |string|
|
|
448
|
+
expect(string).not_to match(/"created_at"/)
|
|
449
449
|
relation
|
|
450
450
|
end
|
|
451
451
|
|
|
@@ -455,8 +455,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
455
455
|
it "groups by source groupings" do
|
|
456
456
|
source.groupings << '"latitude"'
|
|
457
457
|
|
|
458
|
-
relation.
|
|
459
|
-
string.
|
|
458
|
+
expect(relation).to receive(:group) do |string|
|
|
459
|
+
expect(string).to match(/"latitude"/)
|
|
460
460
|
relation
|
|
461
461
|
end
|
|
462
462
|
|
|
@@ -467,13 +467,13 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
467
467
|
context 'STI model' do
|
|
468
468
|
before :each do
|
|
469
469
|
model.column_names << 'type'
|
|
470
|
-
model.
|
|
471
|
-
model.
|
|
470
|
+
allow(model).to receive_messages :descends_from_active_record? => false
|
|
471
|
+
allow(model).to receive_messages :store_full_sti_class => true
|
|
472
472
|
end
|
|
473
473
|
|
|
474
474
|
it "groups by the inheritance column" do
|
|
475
|
-
relation.
|
|
476
|
-
string.
|
|
475
|
+
expect(relation).to receive(:group) do |string|
|
|
476
|
+
expect(string).to match(/"users"."type"/)
|
|
477
477
|
relation
|
|
478
478
|
end
|
|
479
479
|
|
|
@@ -483,12 +483,12 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
483
483
|
context 'with a custom inheritance column' do
|
|
484
484
|
before :each do
|
|
485
485
|
model.column_names << 'custom_type'
|
|
486
|
-
model.
|
|
486
|
+
allow(model).to receive_messages :inheritance_column => 'custom_type'
|
|
487
487
|
end
|
|
488
488
|
|
|
489
489
|
it "groups by the right column" do
|
|
490
|
-
relation.
|
|
491
|
-
string.
|
|
490
|
+
expect(relation).to receive(:group) do |string|
|
|
491
|
+
expect(string).to match(/"users"."custom_type"/)
|
|
492
492
|
relation
|
|
493
493
|
end
|
|
494
494
|
|
|
@@ -501,14 +501,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
501
501
|
let(:processor) { double('processor') }
|
|
502
502
|
|
|
503
503
|
before :each do
|
|
504
|
-
source.
|
|
505
|
-
source.
|
|
504
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
505
|
+
allow(source).to receive_messages :delta? => true
|
|
506
506
|
end
|
|
507
507
|
|
|
508
508
|
it "filters by the provided clause" do
|
|
509
|
-
processor.
|
|
510
|
-
relation.
|
|
511
|
-
string.
|
|
509
|
+
expect(processor).to receive(:clause).with(true).and_return('"delta" = 1')
|
|
510
|
+
expect(relation).to receive(:where) do |string|
|
|
511
|
+
expect(string).to match(/"delta" = 1/)
|
|
512
512
|
relation
|
|
513
513
|
end
|
|
514
514
|
|
|
@@ -522,52 +522,52 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
522
522
|
let(:processor) { double('processor', :reset_query => 'RESET DELTAS') }
|
|
523
523
|
|
|
524
524
|
before :each do
|
|
525
|
-
source.
|
|
526
|
-
adapter.
|
|
525
|
+
allow(source).to receive_messages :options => {}, :delta_processor => nil, :delta? => false
|
|
526
|
+
allow(adapter).to receive_messages :utf8_query_pre => ['SET UTF8']
|
|
527
527
|
end
|
|
528
528
|
|
|
529
529
|
it "adds a reset delta query if there is a delta processor and this is the core source" do
|
|
530
|
-
source.
|
|
530
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
531
531
|
|
|
532
|
-
builder.sql_query_pre.
|
|
532
|
+
expect(builder.sql_query_pre).to include('RESET DELTAS')
|
|
533
533
|
end
|
|
534
534
|
|
|
535
535
|
it "does not add a reset query if there is no delta processor" do
|
|
536
|
-
builder.sql_query_pre.
|
|
536
|
+
expect(builder.sql_query_pre).not_to include('RESET DELTAS')
|
|
537
537
|
end
|
|
538
538
|
|
|
539
539
|
it "does not add a reset query if this is a delta source" do
|
|
540
|
-
source.
|
|
541
|
-
source.
|
|
540
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
541
|
+
allow(source).to receive_messages :delta? => true
|
|
542
542
|
|
|
543
|
-
builder.sql_query_pre.
|
|
543
|
+
expect(builder.sql_query_pre).not_to include('RESET DELTAS')
|
|
544
544
|
end
|
|
545
545
|
|
|
546
546
|
it "sets the group_concat_max_len value if set" do
|
|
547
547
|
source.options[:group_concat_max_len] = 123
|
|
548
548
|
|
|
549
|
-
builder.sql_query_pre.
|
|
550
|
-
|
|
549
|
+
expect(builder.sql_query_pre).
|
|
550
|
+
to include('SET SESSION group_concat_max_len = 123')
|
|
551
551
|
end
|
|
552
552
|
|
|
553
553
|
it "does not set the group_concat_max_len if not provided" do
|
|
554
554
|
source.options[:group_concat_max_len] = nil
|
|
555
555
|
|
|
556
|
-
builder.sql_query_pre.select { |sql|
|
|
556
|
+
expect(builder.sql_query_pre.select { |sql|
|
|
557
557
|
sql[/SET SESSION group_concat_max_len/]
|
|
558
|
-
}.
|
|
558
|
+
}).to be_empty
|
|
559
559
|
end
|
|
560
560
|
|
|
561
561
|
it "sets the connection to use UTF-8 if required" do
|
|
562
562
|
source.options[:utf8?] = true
|
|
563
563
|
|
|
564
|
-
builder.sql_query_pre.
|
|
564
|
+
expect(builder.sql_query_pre).to include('SET UTF8')
|
|
565
565
|
end
|
|
566
566
|
|
|
567
567
|
it "does not set the connection to use UTF-8 if not required" do
|
|
568
568
|
source.options[:utf8?] = false
|
|
569
569
|
|
|
570
|
-
builder.sql_query_pre.
|
|
570
|
+
expect(builder.sql_query_pre).not_to include('SET UTF8')
|
|
571
571
|
end
|
|
572
572
|
|
|
573
573
|
it "adds a time-zone query by default" do
|
|
@@ -583,26 +583,26 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
583
583
|
|
|
584
584
|
describe 'sql_query_range' do
|
|
585
585
|
before :each do
|
|
586
|
-
adapter.
|
|
586
|
+
allow(adapter).to receive(:convert_nulls) { |string, default|
|
|
587
587
|
"ISNULL(#{string}, #{default})"
|
|
588
588
|
}
|
|
589
589
|
end
|
|
590
590
|
|
|
591
591
|
it "returns the relation's query" do
|
|
592
|
-
relation.
|
|
592
|
+
allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
|
|
593
593
|
|
|
594
|
-
builder.sql_query_range.
|
|
594
|
+
expect(builder.sql_query_range).to eq('SELECT * FROM people')
|
|
595
595
|
end
|
|
596
596
|
|
|
597
597
|
it "returns nil if ranges are disabled" do
|
|
598
|
-
source.
|
|
598
|
+
allow(source).to receive_messages :disable_range? => true
|
|
599
599
|
|
|
600
|
-
builder.sql_query_range.
|
|
600
|
+
expect(builder.sql_query_range).to be_nil
|
|
601
601
|
end
|
|
602
602
|
|
|
603
603
|
it "selects the minimum primary key value, allowing for nulls" do
|
|
604
|
-
relation.
|
|
605
|
-
string.
|
|
604
|
+
expect(relation).to receive(:select) do |string|
|
|
605
|
+
expect(string).to match(/ISNULL\(MIN\(`users`.`id`\), 1\)/)
|
|
606
606
|
relation
|
|
607
607
|
end
|
|
608
608
|
|
|
@@ -610,8 +610,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
610
610
|
end
|
|
611
611
|
|
|
612
612
|
it "selects the maximum primary key value, allowing for nulls" do
|
|
613
|
-
relation.
|
|
614
|
-
string.
|
|
613
|
+
expect(relation).to receive(:select) do |string|
|
|
614
|
+
expect(string).to match(/ISNULL\(MAX\(`users`.`id`\), 1\)/)
|
|
615
615
|
relation
|
|
616
616
|
end
|
|
617
617
|
|
|
@@ -619,8 +619,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
619
619
|
end
|
|
620
620
|
|
|
621
621
|
it "shouldn't limit results to a range" do
|
|
622
|
-
relation.
|
|
623
|
-
string.
|
|
622
|
+
expect(relation).to receive(:where) do |string|
|
|
623
|
+
expect(string).not_to match(/`users`.`id` BETWEEN \$start AND \$end/)
|
|
624
624
|
relation
|
|
625
625
|
end
|
|
626
626
|
|
|
@@ -630,8 +630,8 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
630
630
|
it "does not add source conditions" do
|
|
631
631
|
source.conditions << 'created_at > NOW()'
|
|
632
632
|
|
|
633
|
-
relation.
|
|
634
|
-
string.
|
|
633
|
+
expect(relation).to receive(:where) do |string|
|
|
634
|
+
expect(string).not_to match(/created_at > NOW()/)
|
|
635
635
|
relation
|
|
636
636
|
end
|
|
637
637
|
|
|
@@ -642,14 +642,14 @@ describe ThinkingSphinx::ActiveRecord::SQLBuilder do
|
|
|
642
642
|
let(:processor) { double('processor') }
|
|
643
643
|
|
|
644
644
|
before :each do
|
|
645
|
-
source.
|
|
646
|
-
source.
|
|
645
|
+
allow(source).to receive_messages :delta_processor => processor
|
|
646
|
+
allow(source).to receive_messages :delta? => true
|
|
647
647
|
end
|
|
648
648
|
|
|
649
649
|
it "filters by the provided clause" do
|
|
650
|
-
processor.
|
|
651
|
-
relation.
|
|
652
|
-
string.
|
|
650
|
+
expect(processor).to receive(:clause).with(true).and_return('`delta` = 1')
|
|
651
|
+
expect(relation).to receive(:where) do |string|
|
|
652
|
+
expect(string).to match(/`delta` = 1/)
|
|
653
653
|
relation
|
|
654
654
|
end
|
|
655
655
|
|