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.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +13 -0
  4. data/Gemfile +2 -1
  5. data/HISTORY +19 -0
  6. data/README.textile +3 -2
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +2 -1
  9. data/gemfiles/rails_4_1.gemfile +2 -1
  10. data/gemfiles/rails_4_2.gemfile +2 -1
  11. data/gemfiles/rails_5_0.gemfile +12 -0
  12. data/lib/thinking_sphinx.rb +2 -0
  13. data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
  15. data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/configuration.rb +3 -2
  19. data/lib/thinking_sphinx/connection.rb +23 -10
  20. data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
  21. data/lib/thinking_sphinx/errors.rb +25 -0
  22. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
  23. data/lib/thinking_sphinx/railtie.rb +1 -1
  24. data/lib/thinking_sphinx/rake_interface.rb +71 -23
  25. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
  26. data/lib/thinking_sphinx/real_time/populator.rb +3 -3
  27. data/lib/thinking_sphinx/tasks.rb +7 -8
  28. data/lib/thinking_sphinx/wildcard.rb +1 -1
  29. data/spec/acceptance/association_scoping_spec.rb +5 -5
  30. data/spec/acceptance/attribute_access_spec.rb +4 -4
  31. data/spec/acceptance/attribute_updates_spec.rb +3 -3
  32. data/spec/acceptance/batch_searching_spec.rb +4 -4
  33. data/spec/acceptance/big_integers_spec.rb +6 -6
  34. data/spec/acceptance/connection_spec.rb +23 -0
  35. data/spec/acceptance/excerpts_spec.rb +8 -8
  36. data/spec/acceptance/facets_spec.rb +13 -13
  37. data/spec/acceptance/geosearching_spec.rb +8 -8
  38. data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
  39. data/spec/acceptance/index_options_spec.rb +16 -16
  40. data/spec/acceptance/indexing_spec.rb +3 -3
  41. data/spec/acceptance/paginating_search_results_spec.rb +3 -3
  42. data/spec/acceptance/real_time_updates_spec.rb +4 -4
  43. data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
  44. data/spec/acceptance/search_counts_spec.rb +2 -2
  45. data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
  46. data/spec/acceptance/searching_across_models_spec.rb +6 -6
  47. data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
  48. data/spec/acceptance/searching_on_fields_spec.rb +9 -9
  49. data/spec/acceptance/searching_with_filters_spec.rb +16 -16
  50. data/spec/acceptance/searching_with_sti_spec.rb +9 -9
  51. data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
  52. data/spec/acceptance/sorting_search_results_spec.rb +6 -6
  53. data/spec/acceptance/specifying_sql_spec.rb +62 -62
  54. data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
  55. data/spec/acceptance/sql_deltas_spec.rb +7 -7
  56. data/spec/acceptance/support/database_cleaner.rb +1 -1
  57. data/spec/acceptance/support/sphinx_controller.rb +4 -1
  58. data/spec/acceptance/support/sphinx_helpers.rb +4 -0
  59. data/spec/acceptance/suspended_deltas_spec.rb +9 -9
  60. data/spec/internal/app/indices/article_index.rb +2 -2
  61. data/spec/internal/app/indices/book_index.rb +2 -1
  62. data/spec/internal/app/indices/product_index.rb +0 -2
  63. data/spec/internal/app/models/categorisation.rb +8 -1
  64. data/spec/spec_helper.rb +2 -0
  65. data/spec/support/json_column.rb +5 -1
  66. data/spec/support/multi_schema.rb +3 -1
  67. data/spec/support/sphinx_yaml_helpers.rb +1 -1
  68. data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
  69. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
  70. data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
  71. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
  72. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
  73. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
  74. data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
  75. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
  76. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
  77. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
  78. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
  79. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
  80. data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
  81. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
  82. data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
  83. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
  84. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
  85. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
  86. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
  87. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
  88. data/spec/thinking_sphinx/configuration_spec.rb +81 -81
  89. data/spec/thinking_sphinx/connection_spec.rb +13 -13
  90. data/spec/thinking_sphinx/deletion_spec.rb +11 -11
  91. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
  92. data/spec/thinking_sphinx/deltas_spec.rb +12 -12
  93. data/spec/thinking_sphinx/errors_spec.rb +30 -30
  94. data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
  95. data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
  96. data/spec/thinking_sphinx/index_set_spec.rb +7 -7
  97. data/spec/thinking_sphinx/index_spec.rb +24 -24
  98. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
  99. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
  100. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
  101. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
  102. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
  103. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
  104. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
  105. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
  106. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
  107. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
  108. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
  109. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
  110. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
  111. data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
  112. data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
  113. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
  114. data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
  115. data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
  116. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
  117. data/spec/thinking_sphinx/scopes_spec.rb +5 -5
  118. data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
  119. data/spec/thinking_sphinx/search/query_spec.rb +10 -10
  120. data/spec/thinking_sphinx/search_spec.rb +28 -28
  121. data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
  122. data/spec/thinking_sphinx_spec.rb +6 -6
  123. data/thinking-sphinx.gemspec +4 -4
  124. 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.stub! :instance => config
26
- ThinkingSphinx::ActiveRecord::PropertySQLPresenter.stub! :new => presenter
27
- Joiner::Joins.stub! :new => associations
28
- relation.stub! :select => relation, :where => relation, :group => 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.stub!(:quote_column_name) { |column| "`#{column}`"}
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.stub! :type => 'mysql'
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.should_receive(:add_join_to).with([:user, :posts])
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.should_receive(:joins).with(['my string']).and_return(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.stub! :type => 'mysql'
58
+ allow(source).to receive_messages :type => 'mysql'
59
59
  end
60
60
 
61
61
  it "returns the relation's query" do
62
- relation.stub! :to_sql => 'SELECT * FROM people'
62
+ allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
63
63
 
64
- builder.sql_query.should == 'SELECT * FROM people'
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.should_receive(:select) do |string|
69
- string.should match(/^SQL_NO_CACHE /)
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.should_receive(:select) do |string|
78
- string.should match(/`users`.`id` \* 5 \+ 3 AS `id`/)
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.should_receive(:select) do |string|
89
- string.should match(/`name` AS `name`/)
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.stub!(:to_select => '`created_at` AS `created_at`')
98
+ allow(presenter).to receive_messages(:to_select => '`created_at` AS `created_at`')
99
99
 
100
- relation.should_receive(:select) do |string|
101
- string.should match(/`created_at` AS `created_at`/)
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.should_receive(:where) do |string|
110
- string.should match(/`users`.`id` BETWEEN \$start AND \$end/)
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.stub! :disable_range? => true
118
+ allow(source).to receive_messages :disable_range? => true
119
119
 
120
- relation.should_receive(:where) do |string|
121
- string.should_not match(/`users`.`id` BETWEEN \$start AND \$end/)
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.should_receive(:where) do |string|
132
- string.should match(/created_at > NOW()/)
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.should_receive(:group) do |string|
141
- string.should match(/`users`.`id`/)
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.should_receive(:group) do |string|
152
- string.should match(/`name`/)
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.stub!(:to_group => '`created_at`')
161
+ allow(presenter).to receive_messages(:to_group => '`created_at`')
162
162
 
163
- relation.should_receive(:group) do |string|
164
- string.should match(/`created_at`/)
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.should_receive(:group) do |string|
175
- string.should match(/`latitude`/)
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.should_receive(:order).with('NULL').and_return(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.stub! :descends_from_active_record? => false
192
- model.stub! :store_full_sti_class => true
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.should_receive(:group) do |string|
197
- string.should match(/`users`.`type`/)
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.stub :inheritance_column => 'custom_type'
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.should_receive(:group) do |string|
212
- string.should match(/`users`.`custom_type`/)
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.stub! :delta_processor => processor
226
- source.stub! :delta? => true
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.should_receive(:clause).with(true).and_return('`delta` = 1')
231
- relation.should_receive(:where) do |string|
232
- string.should match(/`delta` = 1/)
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.stub! :type => 'pgsql'
247
- model.stub! :quoted_table_name => '"users"'
248
- connection.stub!(:quote_column_name) { |column| "\"#{column}\""}
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.stub! :to_sql => 'SELECT * FROM people'
252
+ allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
253
253
 
254
- builder.sql_query.should == 'SELECT * FROM people'
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.should_receive(:select) do |string|
259
- string.should match(/"users"."id" \* 5 \+ 3 AS "id"/)
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.should_receive(:select) do |string|
270
- string.should match(/"name" AS "name"/)
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.stub!(:to_select => '"created_at" AS "created_at"')
279
+ allow(presenter).to receive_messages(:to_select => '"created_at" AS "created_at"')
280
280
 
281
- relation.should_receive(:select) do |string|
282
- string.should match(/"created_at" AS "created_at"/)
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.should_receive(:where) do |string|
291
- string.should match(/"users"."id" BETWEEN \$start AND \$end/)
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.stub! :disable_range? => true
299
+ allow(source).to receive_messages :disable_range? => true
300
300
 
301
- relation.should_receive(:where) do |string|
302
- string.should_not match(/"users"."id" BETWEEN \$start AND \$end/)
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.should_receive(:where) do |string|
313
- string.should match(/created_at > NOW()/)
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.should_receive(:group) do |string|
322
- string.should match(/"users"."id"/)
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.should_receive(:group) do |string|
333
- string.should match(/"name"/)
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.stub!(:to_group => '"created_at"')
342
+ allow(presenter).to receive_messages(:to_group => '"created_at"')
343
343
 
344
- relation.should_receive(:group) do |string|
345
- string.should match(/"created_at"/)
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.should_receive(:group) do |string|
356
- string.should match(/"latitude"/)
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.should_not_receive(:order)
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.should_receive(:group) do |string|
376
- string.should match(/"users"."id"/)
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.should_receive(:group) do |string|
387
- string.should_not match(/"name"/)
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.stub!(:to_group => '"created_at"')
396
+ allow(presenter).to receive_messages(:to_group => '"created_at"')
397
397
 
398
- relation.should_receive(:group) do |string|
399
- string.should_not match(/"created_at"/)
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.should_receive(:group) do |string|
410
- string.should match(/"latitude"/)
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.should_receive(:group) do |string|
425
- string.should match(/"users"."id"/)
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.should_receive(:group) do |string|
436
- string.should_not match(/"name"/)
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.stub!(:to_group => '"created_at"')
445
+ allow(presenter).to receive_messages(:to_group => '"created_at"')
446
446
 
447
- relation.should_receive(:group) do |string|
448
- string.should_not match(/"created_at"/)
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.should_receive(:group) do |string|
459
- string.should match(/"latitude"/)
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.stub! :descends_from_active_record? => false
471
- model.stub! :store_full_sti_class => true
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.should_receive(:group) do |string|
476
- string.should match(/"users"."type"/)
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.stub :inheritance_column => 'custom_type'
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.should_receive(:group) do |string|
491
- string.should match(/"users"."custom_type"/)
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.stub! :delta_processor => processor
505
- source.stub! :delta? => true
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.should_receive(:clause).with(true).and_return('"delta" = 1')
510
- relation.should_receive(:where) do |string|
511
- string.should match(/"delta" = 1/)
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.stub :options => {}, :delta_processor => nil, :delta? => false
526
- adapter.stub :utf8_query_pre => ['SET UTF8']
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.stub :delta_processor => processor
530
+ allow(source).to receive_messages :delta_processor => processor
531
531
 
532
- builder.sql_query_pre.should include('RESET DELTAS')
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.should_not include('RESET DELTAS')
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.stub :delta_processor => processor
541
- source.stub :delta? => true
540
+ allow(source).to receive_messages :delta_processor => processor
541
+ allow(source).to receive_messages :delta? => true
542
542
 
543
- builder.sql_query_pre.should_not include('RESET DELTAS')
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
- should include('SET SESSION group_concat_max_len = 123')
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
- }.should be_empty
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.should include('SET UTF8')
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.should_not include('SET UTF8')
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.stub!(:convert_nulls) { |string, default|
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.stub! :to_sql => 'SELECT * FROM people'
592
+ allow(relation).to receive_messages :to_sql => 'SELECT * FROM people'
593
593
 
594
- builder.sql_query_range.should == 'SELECT * FROM people'
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.stub! :disable_range? => true
598
+ allow(source).to receive_messages :disable_range? => true
599
599
 
600
- builder.sql_query_range.should be_nil
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.should_receive(:select) do |string|
605
- string.should match(/ISNULL\(MIN\(`users`.`id`\), 1\)/)
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.should_receive(:select) do |string|
614
- string.should match(/ISNULL\(MAX\(`users`.`id`\), 1\)/)
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.should_receive(:where) do |string|
623
- string.should_not match(/`users`.`id` BETWEEN \$start AND \$end/)
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.should_receive(:where) do |string|
634
- string.should_not match(/created_at > NOW()/)
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.stub! :delta_processor => processor
646
- source.stub! :delta? => true
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.should_receive(:clause).with(true).and_return('`delta` = 1')
651
- relation.should_receive(:where) do |string|
652
- string.should match(/`delta` = 1/)
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