thinking-sphinx 3.2.0 → 3.3.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 +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
@@ -13,38 +13,38 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
13
13
|
let(:adapter) { double('adapter') }
|
14
14
|
|
15
15
|
before :each do
|
16
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
17
|
-
|
18
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters.
|
19
|
-
|
16
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
17
|
+
to receive_messages(:=== => true)
|
18
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
|
19
|
+
to receive_messages(:adapter_for => adapter)
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#adapter' do
|
23
23
|
it "returns a database adapter for the model" do
|
24
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters.
|
25
|
-
|
24
|
+
expect(ThinkingSphinx::ActiveRecord::DatabaseAdapters).
|
25
|
+
to receive(:adapter_for).with(model).and_return(adapter)
|
26
26
|
|
27
|
-
source.adapter.
|
27
|
+
expect(source.adapter).to eq(adapter)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#attributes' do
|
32
32
|
it "has the internal id attribute by default" do
|
33
|
-
source.attributes.collect(&:name).
|
33
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_internal_id')
|
34
34
|
end
|
35
35
|
|
36
36
|
it "has the class name attribute by default" do
|
37
|
-
source.attributes.collect(&:name).
|
37
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_internal_class')
|
38
38
|
end
|
39
39
|
|
40
40
|
it "has the internal deleted attribute by default" do
|
41
|
-
source.attributes.collect(&:name).
|
41
|
+
expect(source.attributes.collect(&:name)).to include('sphinx_deleted')
|
42
42
|
end
|
43
43
|
|
44
44
|
it "marks the internal class attribute as a facet" do
|
45
|
-
source.attributes.detect { |attribute|
|
45
|
+
expect(source.attributes.detect { |attribute|
|
46
46
|
attribute.name == 'sphinx_internal_class'
|
47
|
-
}.options[:facet].
|
47
|
+
}.options[:facet]).to be_truthy
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -64,18 +64,18 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
64
64
|
}
|
65
65
|
|
66
66
|
it "loads the processor with the adapter" do
|
67
|
-
processor_class.
|
67
|
+
expect(processor_class).to receive(:try).with(:new, adapter, {}).
|
68
68
|
and_return processor
|
69
69
|
|
70
70
|
source.delta_processor
|
71
71
|
end
|
72
72
|
|
73
73
|
it "returns the given processor" do
|
74
|
-
source.delta_processor.
|
74
|
+
expect(source.delta_processor).to eq(processor)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "passes given options to the processor" do
|
78
|
-
processor_class.
|
78
|
+
expect(processor_class).to receive(:try).with(:new, adapter, {:opt_key => :opt_value})
|
79
79
|
source_with_options.delta_processor
|
80
80
|
end
|
81
81
|
end
|
@@ -86,7 +86,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
86
86
|
:delta? => true,
|
87
87
|
:primary_key => model.primary_key || :id
|
88
88
|
|
89
|
-
source.
|
89
|
+
expect(source).to be_a_delta
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -96,46 +96,46 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
96
96
|
:disable_range? => true,
|
97
97
|
:primary_key => model.primary_key || :id
|
98
98
|
|
99
|
-
source.disable_range
|
99
|
+
expect(source.disable_range?).to be_truthy
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe '#fields' do
|
104
104
|
it "has the internal class field by default" do
|
105
|
-
source.fields.collect(&:name).
|
106
|
-
|
105
|
+
expect(source.fields.collect(&:name)).
|
106
|
+
to include('sphinx_internal_class_name')
|
107
107
|
end
|
108
108
|
|
109
109
|
it "sets the sphinx class field to use a string of the class name" do
|
110
|
-
source.fields.detect { |field|
|
110
|
+
expect(source.fields.detect { |field|
|
111
111
|
field.name == 'sphinx_internal_class_name'
|
112
|
-
}.columns.first.__name.
|
112
|
+
}.columns.first.__name).to eq("'User'")
|
113
113
|
end
|
114
114
|
|
115
115
|
it "uses the inheritance column if it exists for the sphinx class field" do
|
116
|
-
adapter.
|
117
|
-
adapter.
|
116
|
+
allow(adapter).to receive_messages :quoted_table_name => '"users"', :quote => '"type"'
|
117
|
+
allow(adapter).to receive(:convert_blank) { |clause, default|
|
118
118
|
"coalesce(nullif(#{clause}, ''), #{default})"
|
119
119
|
}
|
120
|
-
model.
|
120
|
+
allow(model).to receive_messages :column_names => ['type'], :sti_name => 'User'
|
121
121
|
|
122
|
-
source.fields.detect { |field|
|
122
|
+
expect(source.fields.detect { |field|
|
123
123
|
field.name == 'sphinx_internal_class_name'
|
124
|
-
}.columns.first.__name.
|
125
|
-
|
124
|
+
}.columns.first.__name).
|
125
|
+
to eq("coalesce(nullif(\"users\".\"type\", ''), 'User')")
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe '#name' do
|
130
130
|
it "defaults to the model name downcased with the given position" do
|
131
|
-
source.name.
|
131
|
+
expect(source.name).to eq('user_3')
|
132
132
|
end
|
133
133
|
|
134
134
|
it "allows for custom names, but adds the position suffix" do
|
135
135
|
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
136
136
|
:name => 'people', :position => 2, :primary_key => model.primary_key || :id
|
137
137
|
|
138
|
-
source.name.
|
138
|
+
expect(source.name).to eq('people_2')
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -144,19 +144,19 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
144
144
|
source = ThinkingSphinx::ActiveRecord::SQLSource.new model,
|
145
145
|
:offset => 12, :primary_key => model.primary_key || :id
|
146
146
|
|
147
|
-
source.offset.
|
147
|
+
expect(source.offset).to eq(12)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
describe '#options' do
|
152
152
|
it "defaults to having utf8? set to false" do
|
153
|
-
source.options[:utf8?].
|
153
|
+
expect(source.options[:utf8?]).to be_falsey
|
154
154
|
end
|
155
155
|
|
156
156
|
it "sets utf8? to true if the database encoding is utf8" do
|
157
157
|
db_config[:encoding] = 'utf8'
|
158
158
|
|
159
|
-
source.options[:utf8?].
|
159
|
+
expect(source.options[:utf8?]).to be_truthy
|
160
160
|
end
|
161
161
|
|
162
162
|
describe "#primary key" do
|
@@ -182,34 +182,34 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
182
182
|
let(:template) { double('template', :apply => true) }
|
183
183
|
|
184
184
|
before :each do
|
185
|
-
ThinkingSphinx::ActiveRecord::SQLBuilder.
|
186
|
-
ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter.
|
187
|
-
ThinkingSphinx::ActiveRecord::SQLSource::Template.
|
188
|
-
ThinkingSphinx::Configuration.
|
185
|
+
allow(ThinkingSphinx::ActiveRecord::SQLBuilder).to receive_messages :new => builder
|
186
|
+
allow(ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter).to receive_messages :new => presenter
|
187
|
+
allow(ThinkingSphinx::ActiveRecord::SQLSource::Template).to receive_messages :new => template
|
188
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
189
189
|
end
|
190
190
|
|
191
191
|
it "uses the builder's sql_query value" do
|
192
|
-
builder.
|
192
|
+
allow(builder).to receive_messages :sql_query => 'select * from table'
|
193
193
|
|
194
194
|
source.render
|
195
195
|
|
196
|
-
source.sql_query.
|
196
|
+
expect(source.sql_query).to eq('select * from table')
|
197
197
|
end
|
198
198
|
|
199
199
|
it "uses the builder's sql_query_range value" do
|
200
|
-
builder.
|
200
|
+
allow(builder).to receive_messages :sql_query_range => 'select 0, 10 from table'
|
201
201
|
|
202
202
|
source.render
|
203
203
|
|
204
|
-
source.sql_query_range.
|
204
|
+
expect(source.sql_query_range).to eq('select 0, 10 from table')
|
205
205
|
end
|
206
206
|
|
207
207
|
it "appends the builder's sql_query_pre value" do
|
208
|
-
builder.
|
208
|
+
allow(builder).to receive_messages :sql_query_pre => ['Change Setting']
|
209
209
|
|
210
210
|
source.render
|
211
211
|
|
212
|
-
source.sql_query_pre.
|
212
|
+
expect(source.sql_query_pre).to eq(['Change Setting'])
|
213
213
|
end
|
214
214
|
|
215
215
|
it "adds fields with attributes to sql_field_string" do
|
@@ -218,7 +218,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
218
218
|
|
219
219
|
source.render
|
220
220
|
|
221
|
-
source.sql_field_string.
|
221
|
+
expect(source.sql_field_string).to include('title')
|
222
222
|
end
|
223
223
|
|
224
224
|
it "adds any joined or file fields" do
|
@@ -227,7 +227,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
227
227
|
|
228
228
|
source.render
|
229
229
|
|
230
|
-
source.sql_file_field.
|
230
|
+
expect(source.sql_file_field).to include('title')
|
231
231
|
end
|
232
232
|
|
233
233
|
it "adds wordcounted fields to sql_field_str2wordcount" do
|
@@ -236,11 +236,11 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
236
236
|
|
237
237
|
source.render
|
238
238
|
|
239
|
-
source.sql_field_str2wordcount.
|
239
|
+
expect(source.sql_field_str2wordcount).to include('title')
|
240
240
|
end
|
241
241
|
|
242
242
|
it "adds any joined fields" do
|
243
|
-
ThinkingSphinx::ActiveRecord::PropertyQuery.
|
243
|
+
allow(ThinkingSphinx::ActiveRecord::PropertyQuery).to receive_messages(
|
244
244
|
:new => double(:to_s => 'query for title')
|
245
245
|
)
|
246
246
|
source.fields << double('field', :name => 'title',
|
@@ -249,99 +249,99 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
249
249
|
|
250
250
|
source.render
|
251
251
|
|
252
|
-
source.sql_joined_field.
|
252
|
+
expect(source.sql_joined_field).to include('query for title')
|
253
253
|
end
|
254
254
|
|
255
255
|
it "adds integer attributes to sql_attr_uint" do
|
256
256
|
source.attributes << double('attribute')
|
257
|
-
presenter.
|
257
|
+
allow(presenter).to receive_messages :declaration => 'count', :collection_type => :uint
|
258
258
|
|
259
259
|
source.render
|
260
260
|
|
261
|
-
source.sql_attr_uint.
|
261
|
+
expect(source.sql_attr_uint).to include('count')
|
262
262
|
end
|
263
263
|
|
264
264
|
it "adds boolean attributes to sql_attr_bool" do
|
265
265
|
source.attributes << double('attribute')
|
266
|
-
presenter.
|
266
|
+
allow(presenter).to receive_messages :declaration => 'published', :collection_type => :bool
|
267
267
|
|
268
268
|
source.render
|
269
269
|
|
270
|
-
source.sql_attr_bool.
|
270
|
+
expect(source.sql_attr_bool).to include('published')
|
271
271
|
end
|
272
272
|
|
273
273
|
it "adds string attributes to sql_attr_string" do
|
274
274
|
source.attributes << double('attribute')
|
275
|
-
presenter.
|
275
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :string
|
276
276
|
|
277
277
|
source.render
|
278
278
|
|
279
|
-
source.sql_attr_string.
|
279
|
+
expect(source.sql_attr_string).to include('name')
|
280
280
|
end
|
281
281
|
|
282
282
|
it "adds timestamp attributes to sql_attr_timestamp" do
|
283
283
|
source.attributes << double('attribute')
|
284
|
-
presenter.
|
284
|
+
allow(presenter).to receive_messages :declaration => 'created_at',
|
285
285
|
:collection_type => :timestamp
|
286
286
|
|
287
287
|
source.render
|
288
288
|
|
289
|
-
source.sql_attr_timestamp.
|
289
|
+
expect(source.sql_attr_timestamp).to include('created_at')
|
290
290
|
end
|
291
291
|
|
292
292
|
it "adds float attributes to sql_attr_float" do
|
293
293
|
source.attributes << double('attribute')
|
294
|
-
presenter.
|
294
|
+
allow(presenter).to receive_messages :declaration => 'rating', :collection_type => :float
|
295
295
|
|
296
296
|
source.render
|
297
297
|
|
298
|
-
source.sql_attr_float.
|
298
|
+
expect(source.sql_attr_float).to include('rating')
|
299
299
|
end
|
300
300
|
|
301
301
|
it "adds bigint attributes to sql_attr_bigint" do
|
302
302
|
source.attributes << double('attribute')
|
303
|
-
presenter.
|
303
|
+
allow(presenter).to receive_messages :declaration => 'super_id', :collection_type => :bigint
|
304
304
|
|
305
305
|
source.render
|
306
306
|
|
307
|
-
source.sql_attr_bigint.
|
307
|
+
expect(source.sql_attr_bigint).to include('super_id')
|
308
308
|
end
|
309
309
|
|
310
310
|
it "adds ordinal strings to sql_attr_str2ordinal" do
|
311
311
|
source.attributes << double('attribute')
|
312
|
-
presenter.
|
312
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2ordinal
|
313
313
|
|
314
314
|
source.render
|
315
315
|
|
316
|
-
source.sql_attr_str2ordinal.
|
316
|
+
expect(source.sql_attr_str2ordinal).to include('name')
|
317
317
|
end
|
318
318
|
|
319
319
|
it "adds multi-value attributes to sql_attr_multi" do
|
320
320
|
source.attributes << double('attribute')
|
321
|
-
presenter.
|
321
|
+
allow(presenter).to receive_messages :declaration => 'uint tag_ids from field',
|
322
322
|
:collection_type => :multi
|
323
323
|
|
324
324
|
source.render
|
325
325
|
|
326
|
-
source.sql_attr_multi.
|
326
|
+
expect(source.sql_attr_multi).to include('uint tag_ids from field')
|
327
327
|
end
|
328
328
|
|
329
329
|
it "adds word count attributes to sql_attr_str2wordcount" do
|
330
330
|
source.attributes << double('attribute')
|
331
|
-
presenter.
|
331
|
+
allow(presenter).to receive_messages :declaration => 'name', :collection_type => :str2wordcount
|
332
332
|
|
333
333
|
source.render
|
334
334
|
|
335
|
-
source.sql_attr_str2wordcount.
|
335
|
+
expect(source.sql_attr_str2wordcount).to include('name')
|
336
336
|
end
|
337
337
|
|
338
338
|
it "adds json attributes to sql_attr_json" do
|
339
339
|
source.attributes << double('attribute')
|
340
|
-
presenter.
|
340
|
+
allow(presenter).to receive_messages :declaration => 'json', :collection_type => :json
|
341
341
|
|
342
342
|
source.render
|
343
343
|
|
344
|
-
source.sql_attr_json.
|
344
|
+
expect(source.sql_attr_json).to include('json')
|
345
345
|
end
|
346
346
|
|
347
347
|
it "adds relevant settings from thinking_sphinx.yml" do
|
@@ -350,7 +350,7 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
350
350
|
|
351
351
|
source.render
|
352
352
|
|
353
|
-
source.mysql_ssl_cert.
|
353
|
+
expect(source.mysql_ssl_cert).to eq('foo.cert')
|
354
354
|
end
|
355
355
|
end
|
356
356
|
|
@@ -358,102 +358,104 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
358
358
|
it "sets the sql_host setting from the model's database settings" do
|
359
359
|
source.set_database_settings :host => '12.34.56.78'
|
360
360
|
|
361
|
-
source.sql_host.
|
361
|
+
expect(source.sql_host).to eq('12.34.56.78')
|
362
362
|
end
|
363
363
|
|
364
364
|
it "defaults sql_host to localhost if the model has no host" do
|
365
365
|
source.set_database_settings :host => nil
|
366
366
|
|
367
|
-
source.sql_host.
|
367
|
+
expect(source.sql_host).to eq('localhost')
|
368
368
|
end
|
369
369
|
|
370
370
|
it "sets the sql_user setting from the model's database settings" do
|
371
371
|
source.set_database_settings :username => 'pat'
|
372
372
|
|
373
|
-
source.sql_user.
|
373
|
+
expect(source.sql_user).to eq('pat')
|
374
374
|
end
|
375
375
|
|
376
376
|
it "uses the user setting if username is not set in the model" do
|
377
377
|
source.set_database_settings :username => nil, :user => 'pat'
|
378
378
|
|
379
|
-
source.sql_user.
|
379
|
+
expect(source.sql_user).to eq('pat')
|
380
380
|
end
|
381
381
|
|
382
382
|
it "sets the sql_pass setting from the model's database settings" do
|
383
383
|
source.set_database_settings :password => 'swordfish'
|
384
384
|
|
385
|
-
source.sql_pass.
|
385
|
+
expect(source.sql_pass).to eq('swordfish')
|
386
386
|
end
|
387
387
|
|
388
388
|
it "escapes hashes in the password for sql_pass" do
|
389
389
|
source.set_database_settings :password => 'sword#fish'
|
390
390
|
|
391
|
-
source.sql_pass.
|
391
|
+
expect(source.sql_pass).to eq('sword\#fish')
|
392
392
|
end
|
393
393
|
|
394
394
|
it "sets the sql_db setting from the model's database settings" do
|
395
395
|
source.set_database_settings :database => 'rails_app'
|
396
396
|
|
397
|
-
source.sql_db.
|
397
|
+
expect(source.sql_db).to eq('rails_app')
|
398
398
|
end
|
399
399
|
|
400
400
|
it "sets the sql_port setting from the model's database settings" do
|
401
401
|
source.set_database_settings :port => 5432
|
402
402
|
|
403
|
-
source.sql_port.
|
403
|
+
expect(source.sql_port).to eq(5432)
|
404
404
|
end
|
405
405
|
|
406
406
|
it "sets the sql_sock setting from the model's database settings" do
|
407
407
|
source.set_database_settings :socket => '/unix/socket'
|
408
408
|
|
409
|
-
source.sql_sock.
|
409
|
+
expect(source.sql_sock).to eq('/unix/socket')
|
410
410
|
end
|
411
411
|
|
412
412
|
it "sets the mysql_ssl_cert from the model's database settings" do
|
413
413
|
source.set_database_settings :sslcert => '/path/to/cert.pem'
|
414
414
|
|
415
|
-
source.mysql_ssl_cert.
|
415
|
+
expect(source.mysql_ssl_cert).to eq '/path/to/cert.pem'
|
416
416
|
end
|
417
417
|
|
418
418
|
it "sets the mysql_ssl_key from the model's database settings" do
|
419
419
|
source.set_database_settings :sslkey => '/path/to/key.pem'
|
420
420
|
|
421
|
-
source.mysql_ssl_key.
|
421
|
+
expect(source.mysql_ssl_key).to eq '/path/to/key.pem'
|
422
422
|
end
|
423
423
|
|
424
424
|
it "sets the mysql_ssl_ca from the model's database settings" do
|
425
425
|
source.set_database_settings :sslca => '/path/to/ca.pem'
|
426
426
|
|
427
|
-
source.mysql_ssl_ca.
|
427
|
+
expect(source.mysql_ssl_ca).to eq '/path/to/ca.pem'
|
428
428
|
end
|
429
429
|
end
|
430
430
|
|
431
431
|
describe '#type' do
|
432
432
|
it "is mysql when using the MySQL Adapter" do
|
433
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
434
|
-
|
435
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
436
|
-
|
433
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
434
|
+
to receive_messages(:=== => true)
|
435
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
436
|
+
to receive_messages(:=== => false)
|
437
437
|
|
438
|
-
source.type.
|
438
|
+
expect(source.type).to eq('mysql')
|
439
439
|
end
|
440
440
|
|
441
441
|
it "is pgsql when using the PostgreSQL Adapter" do
|
442
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
443
|
-
|
444
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
445
|
-
|
442
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
443
|
+
to receive_messages(:=== => false)
|
444
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
445
|
+
to receive_messages(:=== => true)
|
446
446
|
|
447
|
-
source.type.
|
447
|
+
expect(source.type).to eq('pgsql')
|
448
448
|
end
|
449
449
|
|
450
450
|
it "raises an exception for any other adapter" do
|
451
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
|
452
|
-
|
453
|
-
ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter.
|
454
|
-
|
451
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter).
|
452
|
+
to receive_messages(:=== => false)
|
453
|
+
allow(ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter).
|
454
|
+
to receive_messages(:=== => false)
|
455
455
|
|
456
|
-
|
456
|
+
expect { source.type }.to raise_error(
|
457
|
+
ThinkingSphinx::UnknownDatabaseAdapter
|
458
|
+
)
|
457
459
|
end
|
458
460
|
end
|
459
461
|
end
|