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
@@ -13,23 +13,23 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
13
13
  let(:block) { Proc.new { } }
14
14
 
15
15
  before :each do
16
- ThinkingSphinx::ActiveRecord::SQLSource.stub! :new => source
17
- source.stub :model => model
16
+ allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages :new => source
17
+ allow(source).to receive_messages :model => model
18
18
  end
19
19
 
20
20
  describe '.translate!' do
21
21
  let(:instance) { double('interpreter', :translate! => true) }
22
22
 
23
23
  it "creates a new interpreter instance with the given block and index" do
24
- ThinkingSphinx::ActiveRecord::Interpreter.should_receive(:new).
24
+ expect(ThinkingSphinx::ActiveRecord::Interpreter).to receive(:new).
25
25
  with(index, block).and_return(instance)
26
26
 
27
27
  ThinkingSphinx::ActiveRecord::Interpreter.translate! index, block
28
28
  end
29
29
 
30
30
  it "calls translate! on the instance" do
31
- ThinkingSphinx::ActiveRecord::Interpreter.stub!(:new => instance)
32
- instance.should_receive(:translate!)
31
+ allow(ThinkingSphinx::ActiveRecord::Interpreter).to receive_messages(:new => instance)
32
+ expect(instance).to receive(:translate!)
33
33
 
34
34
  ThinkingSphinx::ActiveRecord::Interpreter.translate! index, block
35
35
  end
@@ -37,13 +37,13 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
37
37
 
38
38
  describe '#group_by' do
39
39
  it "adds a source to the index" do
40
- index.should_receive(:append_source).and_return(source)
40
+ expect(index).to receive(:append_source).and_return(source)
41
41
 
42
42
  instance.group_by 'lat'
43
43
  end
44
44
 
45
45
  it "only adds a single source for the given context" do
46
- index.should_receive(:append_source).once.and_return(source)
46
+ expect(index).to receive(:append_source).once.and_return(source)
47
47
 
48
48
  instance.group_by 'lat'
49
49
  instance.group_by 'lng'
@@ -52,7 +52,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
52
52
  it "appends a new grouping statement to the source" do
53
53
  instance.group_by 'lat'
54
54
 
55
- source.groupings.should include('lat')
55
+ expect(source.groupings).to include('lat')
56
56
  end
57
57
  end
58
58
 
@@ -61,31 +61,31 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
61
61
  let(:attribute) { double('attribute') }
62
62
 
63
63
  before :each do
64
- ThinkingSphinx::ActiveRecord::Attribute.stub! :new => attribute
64
+ allow(ThinkingSphinx::ActiveRecord::Attribute).to receive_messages :new => attribute
65
65
  end
66
66
 
67
67
  it "adds a source to the index" do
68
- index.should_receive(:append_source).and_return(source)
68
+ expect(index).to receive(:append_source).and_return(source)
69
69
 
70
70
  instance.has column
71
71
  end
72
72
 
73
73
  it "only adds a single source for the given context" do
74
- index.should_receive(:append_source).once.and_return(source)
74
+ expect(index).to receive(:append_source).once.and_return(source)
75
75
 
76
76
  instance.has column
77
77
  instance.has column
78
78
  end
79
79
 
80
80
  it "creates a new attribute with the provided column" do
81
- ThinkingSphinx::ActiveRecord::Attribute.should_receive(:new).
81
+ expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
82
82
  with(model, column, {}).and_return(attribute)
83
83
 
84
84
  instance.has column
85
85
  end
86
86
 
87
87
  it "passes through options to the attribute" do
88
- ThinkingSphinx::ActiveRecord::Attribute.should_receive(:new).
88
+ expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
89
89
  with(model, column, :as => :other_name).and_return(attribute)
90
90
 
91
91
  instance.has column, :as => :other_name
@@ -94,15 +94,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
94
94
  it "adds an attribute to the source" do
95
95
  instance.has column
96
96
 
97
- source.attributes.should include(attribute)
97
+ expect(source.attributes).to include(attribute)
98
98
  end
99
99
 
100
100
  it "adds multiple attributes when passed multiple columns" do
101
101
  instance.has column, column
102
102
 
103
- source.attributes.select { |saved_attribute|
103
+ expect(source.attributes.select { |saved_attribute|
104
104
  saved_attribute == attribute
105
- }.length.should == 2
105
+ }.length).to eq(2)
106
106
  end
107
107
  end
108
108
 
@@ -111,31 +111,31 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
111
111
  let(:field) { double('field') }
112
112
 
113
113
  before :each do
114
- ThinkingSphinx::ActiveRecord::Field.stub! :new => field
114
+ allow(ThinkingSphinx::ActiveRecord::Field).to receive_messages :new => field
115
115
  end
116
116
 
117
117
  it "adds a source to the index" do
118
- index.should_receive(:append_source).and_return(source)
118
+ expect(index).to receive(:append_source).and_return(source)
119
119
 
120
120
  instance.indexes column
121
121
  end
122
122
 
123
123
  it "only adds a single source for the given context" do
124
- index.should_receive(:append_source).once.and_return(source)
124
+ expect(index).to receive(:append_source).once.and_return(source)
125
125
 
126
126
  instance.indexes column
127
127
  instance.indexes column
128
128
  end
129
129
 
130
130
  it "creates a new field with the provided column" do
131
- ThinkingSphinx::ActiveRecord::Field.should_receive(:new).
131
+ expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
132
132
  with(model, column, {}).and_return(field)
133
133
 
134
134
  instance.indexes column
135
135
  end
136
136
 
137
137
  it "passes through options to the field" do
138
- ThinkingSphinx::ActiveRecord::Field.should_receive(:new).
138
+ expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
139
139
  with(model, column, :as => :other_name).and_return(field)
140
140
 
141
141
  instance.indexes column, :as => :other_name
@@ -144,15 +144,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
144
144
  it "adds a field to the source" do
145
145
  instance.indexes column
146
146
 
147
- source.fields.should include(field)
147
+ expect(source.fields).to include(field)
148
148
  end
149
149
 
150
150
  it "adds multiple fields when passed multiple columns" do
151
151
  instance.indexes column, column
152
152
 
153
- source.fields.select { |saved_field|
153
+ expect(source.fields.select { |saved_field|
154
154
  saved_field == field
155
- }.length.should == 2
155
+ }.length).to eq(2)
156
156
  end
157
157
  end
158
158
 
@@ -161,24 +161,24 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
161
161
  let(:association) { double('association') }
162
162
 
163
163
  before :each do
164
- ThinkingSphinx::ActiveRecord::Association.stub! :new => association
164
+ allow(ThinkingSphinx::ActiveRecord::Association).to receive_messages :new => association
165
165
  end
166
166
 
167
167
  it "adds a source to the index" do
168
- index.should_receive(:append_source).and_return(source)
168
+ expect(index).to receive(:append_source).and_return(source)
169
169
 
170
170
  instance.join column
171
171
  end
172
172
 
173
173
  it "only adds a single source for the given context" do
174
- index.should_receive(:append_source).once.and_return(source)
174
+ expect(index).to receive(:append_source).once.and_return(source)
175
175
 
176
176
  instance.join column
177
177
  instance.join column
178
178
  end
179
179
 
180
180
  it "creates a new association with the provided column" do
181
- ThinkingSphinx::ActiveRecord::Association.should_receive(:new).
181
+ expect(ThinkingSphinx::ActiveRecord::Association).to receive(:new).
182
182
  with(column).and_return(association)
183
183
 
184
184
  instance.join column
@@ -187,15 +187,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
187
187
  it "adds an association to the source" do
188
188
  instance.join column
189
189
 
190
- source.associations.should include(association)
190
+ expect(source.associations).to include(association)
191
191
  end
192
192
 
193
193
  it "adds multiple fields when passed multiple columns" do
194
194
  instance.join column, column
195
195
 
196
- source.associations.select { |saved_assoc|
196
+ expect(source.associations.select { |saved_assoc|
197
197
  saved_assoc == association
198
- }.length.should == 2
198
+ }.length).to eq(2)
199
199
  end
200
200
  end
201
201
 
@@ -203,15 +203,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
203
203
  let(:column) { double('column') }
204
204
 
205
205
  before :each do
206
- ThinkingSphinx::ActiveRecord::Column.stub!(:new => column)
206
+ allow(ThinkingSphinx::ActiveRecord::Column).to receive_messages(:new => column)
207
207
  end
208
208
 
209
209
  it "returns a new column for the given method" do
210
- instance.id.should == column
210
+ expect(instance.id).to eq(column)
211
211
  end
212
212
 
213
213
  it "should initialise the column with the method name and arguments" do
214
- ThinkingSphinx::ActiveRecord::Column.should_receive(:new).
214
+ expect(ThinkingSphinx::ActiveRecord::Column).to receive(:new).
215
215
  with(:users, :posts, :subject).and_return(column)
216
216
 
217
217
  instance.users(:posts, :subject)
@@ -220,26 +220,26 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
220
220
 
221
221
  describe '#set_database' do
222
222
  before :each do
223
- source.stub :set_database_settings => true
223
+ allow(source).to receive_messages :set_database_settings => true
224
224
 
225
225
  stub_const 'ActiveRecord::Base',
226
226
  double(:configurations => {'other' => {'baz' => 'qux'}})
227
227
  end
228
228
 
229
229
  it "sends through a hash if provided" do
230
- source.should_receive(:set_database_settings).with(:foo => :bar)
230
+ expect(source).to receive(:set_database_settings).with(:foo => :bar)
231
231
 
232
232
  instance.set_database :foo => :bar
233
233
  end
234
234
 
235
235
  it "finds the environment settings if given a string key" do
236
- source.should_receive(:set_database_settings).with(:baz => 'qux')
236
+ expect(source).to receive(:set_database_settings).with(:baz => 'qux')
237
237
 
238
238
  instance.set_database 'other'
239
239
  end
240
240
 
241
241
  it "finds the environment settings if given a symbol key" do
242
- source.should_receive(:set_database_settings).with(:baz => 'qux')
242
+ expect(source).to receive(:set_database_settings).with(:baz => 'qux')
243
243
 
244
244
  instance.set_database :other
245
245
  end
@@ -247,19 +247,19 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
247
247
 
248
248
  describe '#set_property' do
249
249
  before :each do
250
- index.class.stub :settings => [:morphology]
251
- source.class.stub :settings => [:mysql_ssl_cert]
250
+ allow(index.class).to receive_messages :settings => [:morphology]
251
+ allow(source.class).to receive_messages :settings => [:mysql_ssl_cert]
252
252
  end
253
253
 
254
254
  it 'saves other settings as index options' do
255
255
  instance.set_property :field_weights => {:name => 10}
256
256
 
257
- index.options[:field_weights].should == {:name => 10}
257
+ expect(index.options[:field_weights]).to eq({:name => 10})
258
258
  end
259
259
 
260
260
  context 'index settings' do
261
261
  it "sets the provided setting" do
262
- index.should_receive(:morphology=).with('stem_en')
262
+ expect(index).to receive(:morphology=).with('stem_en')
263
263
 
264
264
  instance.set_property :morphology => 'stem_en'
265
265
  end
@@ -267,24 +267,24 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
267
267
 
268
268
  context 'source settings' do
269
269
  before :each do
270
- source.stub :mysql_ssl_cert= => true
270
+ allow(source).to receive_messages :mysql_ssl_cert= => true
271
271
  end
272
272
 
273
273
  it "adds a source to the index" do
274
- index.should_receive(:append_source).and_return(source)
274
+ expect(index).to receive(:append_source).and_return(source)
275
275
 
276
276
  instance.set_property :mysql_ssl_cert => 'private.cert'
277
277
  end
278
278
 
279
279
  it "only adds a single source for the given context" do
280
- index.should_receive(:append_source).once.and_return(source)
280
+ expect(index).to receive(:append_source).once.and_return(source)
281
281
 
282
282
  instance.set_property :mysql_ssl_cert => 'private.cert'
283
283
  instance.set_property :mysql_ssl_cert => 'private.cert'
284
284
  end
285
285
 
286
286
  it "sets the provided setting" do
287
- source.should_receive(:mysql_ssl_cert=).with('private.cert')
287
+ expect(source).to receive(:mysql_ssl_cert=).with('private.cert')
288
288
 
289
289
  instance.set_property :mysql_ssl_cert => 'private.cert'
290
290
  end
@@ -298,20 +298,20 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
298
298
  }
299
299
 
300
300
  interpreter = ThinkingSphinx::ActiveRecord::Interpreter.new index, block
301
- interpreter.translate!.
302
- should == interpreter.__id__
301
+ expect(interpreter.translate!).
302
+ to eq(interpreter.__id__)
303
303
  end
304
304
  end
305
305
 
306
306
  describe '#where' do
307
307
  it "adds a source to the index" do
308
- index.should_receive(:append_source).and_return(source)
308
+ expect(index).to receive(:append_source).and_return(source)
309
309
 
310
310
  instance.where 'id > 100'
311
311
  end
312
312
 
313
313
  it "only adds a single source for the given context" do
314
- index.should_receive(:append_source).once.and_return(source)
314
+ expect(index).to receive(:append_source).once.and_return(source)
315
315
 
316
316
  instance.where 'id > 100'
317
317
  instance.where 'id < 150'
@@ -320,7 +320,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
320
320
  it "appends a new grouping statement to the source" do
321
321
  instance.where 'id > 100'
322
322
 
323
- source.conditions.should include('id > 100')
323
+ expect(source.conditions).to include('id > 100')
324
324
  end
325
325
  end
326
326
  end
@@ -23,29 +23,29 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
23
23
  let(:animal_reflection) { double 'Animal Reflection' }
24
24
 
25
25
  before :each do
26
- ThinkingSphinx::ActiveRecord::FilterReflection.
27
- stub(:call).
26
+ allow(ThinkingSphinx::ActiveRecord::FilterReflection).
27
+ to receive(:call).
28
28
  and_return(article_reflection, animal_reflection)
29
29
 
30
- model.stub(:reflect_on_association) do |name|
30
+ allow(model).to receive(:reflect_on_association) do |name|
31
31
  name == :foo ? reflection : nil
32
32
  end
33
33
 
34
34
  if ActiveRecord::Reflection.respond_to?(:add_reflection)
35
- ActiveRecord::Reflection.stub :add_reflection
35
+ allow(ActiveRecord::Reflection).to receive :add_reflection
36
36
  end
37
37
  end
38
38
 
39
39
  it "creates a new reflection for each class" do
40
- ThinkingSphinx::ActiveRecord::FilterReflection.
41
- unstub :call
40
+ allow(ThinkingSphinx::ActiveRecord::FilterReflection).
41
+ to receive(:call).and_call_original
42
42
 
43
- ThinkingSphinx::ActiveRecord::FilterReflection.
44
- should_receive(:call).
43
+ expect(ThinkingSphinx::ActiveRecord::FilterReflection).
44
+ to receive(:call).
45
45
  with(reflection, :foo_article, 'Article').
46
46
  and_return(article_reflection)
47
- ThinkingSphinx::ActiveRecord::FilterReflection.
48
- should_receive(:call).
47
+ expect(ThinkingSphinx::ActiveRecord::FilterReflection).
48
+ to receive(:call).
49
49
  with(reflection, :foo_animal, 'Animal').
50
50
  and_return(animal_reflection)
51
51
 
@@ -54,9 +54,9 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
54
54
 
55
55
  it "adds the new reflections to the end-of-stack model" do
56
56
  if ActiveRecord::Reflection.respond_to?(:add_reflection)
57
- ActiveRecord::Reflection.should_receive(:add_reflection).
57
+ expect(ActiveRecord::Reflection).to receive(:add_reflection).
58
58
  with(model, :foo_article, article_reflection)
59
- ActiveRecord::Reflection.should_receive(:add_reflection).
59
+ expect(ActiveRecord::Reflection).to receive(:add_reflection).
60
60
  with(model, :foo_animal, animal_reflection)
61
61
 
62
62
  polymorpher.morph!
@@ -69,14 +69,14 @@ describe ThinkingSphinx::ActiveRecord::Polymorpher do
69
69
  end
70
70
 
71
71
  it "rebases each field" do
72
- field.should_receive(:rebase).with([:a, :b, :foo],
72
+ expect(field).to receive(:rebase).with([:a, :b, :foo],
73
73
  :to => [[:a, :b, :foo_article], [:a, :b, :foo_animal]])
74
74
 
75
75
  polymorpher.morph!
76
76
  end
77
77
 
78
78
  it "rebases each attribute" do
79
- attribute.should_receive(:rebase).with([:a, :b, :foo],
79
+ expect(attribute).to receive(:rebase).with([:a, :b, :foo],
80
80
  :to => [[:a, :b, :foo_article], [:a, :b, :foo_animal]])
81
81
 
82
82
  polymorpher.morph!
@@ -7,7 +7,7 @@ describe ThinkingSphinx::ActiveRecord::PropertySQLPresenter do
7
7
  let(:path) { double :aggregate? => false, :model => model }
8
8
 
9
9
  before :each do
10
- adapter.stub(:quote) { |column| column }
10
+ allow(adapter).to receive(:quote) { |column| column }
11
11
 
12
12
  stub_const 'Joiner::Path', double(:new => path)
13
13
  end
@@ -25,95 +25,95 @@ describe ThinkingSphinx::ActiveRecord::PropertySQLPresenter do
25
25
 
26
26
  describe '#to_group' do
27
27
  it "returns the column name as a string" do
28
- presenter.to_group.should == 'articles.title'
28
+ expect(presenter.to_group).to eq('articles.title')
29
29
  end
30
30
 
31
31
  it "gets the column's table alias from the associations object" do
32
- column.stub!(:__stack => [:users, :posts])
32
+ allow(column).to receive_messages(:__stack => [:users, :posts])
33
33
 
34
- associations.should_receive(:alias_for).with([:users, :posts]).
34
+ expect(associations).to receive(:alias_for).with([:users, :posts]).
35
35
  and_return('posts')
36
36
 
37
37
  presenter.to_group
38
38
  end
39
39
 
40
40
  it "returns nil if the property is an aggregate" do
41
- path.stub! :aggregate? => true
41
+ allow(path).to receive_messages :aggregate? => true
42
42
 
43
- presenter.to_group.should be_nil
43
+ expect(presenter.to_group).to be_nil
44
44
  end
45
45
 
46
46
  it "returns nil if the field is sourced via a separate query" do
47
- field.stub :source_type => 'query'
47
+ allow(field).to receive_messages :source_type => 'query'
48
48
 
49
- presenter.to_group.should be_nil
49
+ expect(presenter.to_group).to be_nil
50
50
  end
51
51
  end
52
52
 
53
53
  describe '#to_select' do
54
54
  it "returns the column name as a string" do
55
- presenter.to_select.should == 'articles.title AS title'
55
+ expect(presenter.to_select).to eq('articles.title AS title')
56
56
  end
57
57
 
58
58
  it "gets the column's table alias from the associations object" do
59
- column.stub!(:__stack => [:users, :posts])
59
+ allow(column).to receive_messages(:__stack => [:users, :posts])
60
60
 
61
- associations.should_receive(:alias_for).with([:users, :posts]).
61
+ expect(associations).to receive(:alias_for).with([:users, :posts]).
62
62
  and_return('posts')
63
63
 
64
64
  presenter.to_select
65
65
  end
66
66
 
67
67
  it "returns the column name with an alias when provided" do
68
- field.stub!(:name => :subject)
68
+ allow(field).to receive_messages(:name => :subject)
69
69
 
70
- presenter.to_select.should == 'articles.title AS subject'
70
+ expect(presenter.to_select).to eq('articles.title AS subject')
71
71
  end
72
72
 
73
73
  it "groups and concatenates aggregated columns" do
74
- adapter.stub :group_concatenate do |clause, separator|
74
+ allow(adapter).to receive :group_concatenate do |clause, separator|
75
75
  "GROUP_CONCAT(#{clause} SEPARATOR '#{separator}')"
76
76
  end
77
77
 
78
- path.stub! :aggregate? => true
78
+ allow(path).to receive_messages :aggregate? => true
79
79
 
80
- presenter.to_select.
81
- should == "GROUP_CONCAT(articles.title SEPARATOR ' ') AS title"
80
+ expect(presenter.to_select).
81
+ to eq("GROUP_CONCAT(articles.title SEPARATOR ' ') AS title")
82
82
  end
83
83
 
84
84
  it "concatenates multiple columns" do
85
- adapter.stub :concatenate do |clause, separator|
85
+ allow(adapter).to receive :concatenate do |clause, separator|
86
86
  "CONCAT_WS('#{separator}', #{clause})"
87
87
  end
88
88
 
89
- field.stub!(:columns => [column, column])
89
+ allow(field).to receive_messages(:columns => [column, column])
90
90
 
91
- presenter.to_select.
92
- should == "CONCAT_WS(' ', articles.title, articles.title) AS title"
91
+ expect(presenter.to_select).
92
+ to eq("CONCAT_WS(' ', articles.title, articles.title) AS title")
93
93
  end
94
94
 
95
95
  it "does not include columns that don't exist" do
96
- adapter.stub :concatenate do |clause, separator|
96
+ allow(adapter).to receive :concatenate do |clause, separator|
97
97
  "CONCAT_WS('#{separator}', #{clause})"
98
98
  end
99
99
 
100
- field.stub!(:columns => [column, double('column', :string? => false,
100
+ allow(field).to receive_messages(:columns => [column, double('column', :string? => false,
101
101
  :__stack => [], :__name => 'body')])
102
102
 
103
- presenter.to_select.
104
- should == "CONCAT_WS(' ', articles.title) AS title"
103
+ expect(presenter.to_select).
104
+ to eq("CONCAT_WS(' ', articles.title) AS title")
105
105
  end
106
106
 
107
107
  it "returns nil for query sourced fields" do
108
- field.stub :source_type => :query
108
+ allow(field).to receive_messages :source_type => :query
109
109
 
110
- presenter.to_select.should be_nil
110
+ expect(presenter.to_select).to be_nil
111
111
  end
112
112
 
113
113
  it "returns nil for ranged query sourced fields" do
114
- field.stub :source_type => :ranged_query
114
+ allow(field).to receive_messages :source_type => :ranged_query
115
115
 
116
- presenter.to_select.should be_nil
116
+ expect(presenter.to_select).to be_nil
117
117
  end
118
118
  end
119
119
  end
@@ -131,131 +131,131 @@ describe ThinkingSphinx::ActiveRecord::PropertySQLPresenter do
131
131
  :__name => 'created_at') }
132
132
 
133
133
  before :each do
134
- adapter.stub :cast_to_timestamp do |clause|
134
+ allow(adapter).to receive :cast_to_timestamp do |clause|
135
135
  "UNIX_TIMESTAMP(#{clause})"
136
136
  end
137
137
  end
138
138
 
139
139
  describe '#to_group' do
140
140
  it "returns the column name as a string" do
141
- presenter.to_group.should == 'articles.created_at'
141
+ expect(presenter.to_group).to eq('articles.created_at')
142
142
  end
143
143
 
144
144
  it "gets the column's table alias from the associations object" do
145
- column.stub!(:__stack => [:users, :posts])
145
+ allow(column).to receive_messages(:__stack => [:users, :posts])
146
146
 
147
- associations.should_receive(:alias_for).with([:users, :posts]).
147
+ expect(associations).to receive(:alias_for).with([:users, :posts]).
148
148
  and_return('posts')
149
149
 
150
150
  presenter.to_group
151
151
  end
152
152
 
153
153
  it "returns nil if the column is a string" do
154
- column.stub!(:string? => true)
154
+ allow(column).to receive_messages(:string? => true)
155
155
 
156
- presenter.to_group.should be_nil
156
+ expect(presenter.to_group).to be_nil
157
157
  end
158
158
 
159
159
  it "returns nil if the property is an aggregate" do
160
- path.stub! :aggregate? => true
160
+ allow(path).to receive_messages :aggregate? => true
161
161
 
162
- presenter.to_group.should be_nil
162
+ expect(presenter.to_group).to be_nil
163
163
  end
164
164
 
165
165
  it "returns nil if the attribute is sourced via a separate query" do
166
- attribute.stub :source_type => 'query'
166
+ allow(attribute).to receive_messages :source_type => 'query'
167
167
 
168
- presenter.to_group.should be_nil
168
+ expect(presenter.to_group).to be_nil
169
169
  end
170
170
  end
171
171
 
172
172
  describe '#to_select' do
173
173
  it "returns the column name as a string" do
174
- presenter.to_select.should == 'articles.created_at AS created_at'
174
+ expect(presenter.to_select).to eq('articles.created_at AS created_at')
175
175
  end
176
176
 
177
177
  it "gets the column's table alias from the associations object" do
178
- column.stub!(:__stack => [:users, :posts])
178
+ allow(column).to receive_messages(:__stack => [:users, :posts])
179
179
 
180
- associations.should_receive(:alias_for).with([:users, :posts]).
180
+ expect(associations).to receive(:alias_for).with([:users, :posts]).
181
181
  and_return('posts')
182
182
 
183
183
  presenter.to_select
184
184
  end
185
185
 
186
186
  it "returns the column name with an alias when provided" do
187
- attribute.stub!(:name => :creation_timestamp)
187
+ allow(attribute).to receive_messages(:name => :creation_timestamp)
188
188
 
189
- presenter.to_select.
190
- should == 'articles.created_at AS creation_timestamp'
189
+ expect(presenter.to_select).
190
+ to eq('articles.created_at AS creation_timestamp')
191
191
  end
192
192
 
193
193
  it "ensures datetime attributes are converted to timestamps" do
194
- attribute.stub :type => :timestamp
194
+ allow(attribute).to receive_messages :type => :timestamp
195
195
 
196
- presenter.to_select.
197
- should == 'UNIX_TIMESTAMP(articles.created_at) AS created_at'
196
+ expect(presenter.to_select).
197
+ to eq('UNIX_TIMESTAMP(articles.created_at) AS created_at')
198
198
  end
199
199
 
200
200
  it "does not include columns that don't exist" do
201
- adapter.stub :concatenate do |clause, separator|
201
+ allow(adapter).to receive :concatenate do |clause, separator|
202
202
  "CONCAT_WS('#{separator}', #{clause})"
203
203
  end
204
- adapter.stub :cast_to_string do |clause|
204
+ allow(adapter).to receive :cast_to_string do |clause|
205
205
  "CAST(#{clause} AS varchar)"
206
206
  end
207
207
 
208
- attribute.stub!(:columns => [column, double('column',
208
+ allow(attribute).to receive_messages(:columns => [column, double('column',
209
209
  :string? => false, :__stack => [], :__name => 'updated_at')])
210
210
 
211
- presenter.to_select.should == "CONCAT_WS(',', CAST(articles.created_at AS varchar)) AS created_at"
211
+ expect(presenter.to_select).to eq("CONCAT_WS(',', CAST(articles.created_at AS varchar)) AS created_at")
212
212
  end
213
213
 
214
214
  it "casts and concatenates multiple columns for attributes" do
215
- adapter.stub :concatenate do |clause, separator|
215
+ allow(adapter).to receive :concatenate do |clause, separator|
216
216
  "CONCAT_WS('#{separator}', #{clause})"
217
217
  end
218
- adapter.stub :cast_to_string do |clause|
218
+ allow(adapter).to receive :cast_to_string do |clause|
219
219
  "CAST(#{clause} AS varchar)"
220
220
  end
221
221
 
222
- attribute.stub!(:columns => [column, column])
222
+ allow(attribute).to receive_messages(:columns => [column, column])
223
223
 
224
- presenter.to_select.should == "CONCAT_WS(',', CAST(articles.created_at AS varchar), CAST(articles.created_at AS varchar)) AS created_at"
224
+ expect(presenter.to_select).to eq("CONCAT_WS(',', CAST(articles.created_at AS varchar), CAST(articles.created_at AS varchar)) AS created_at")
225
225
  end
226
226
 
227
227
  it "double-casts and concatenates multiple columns for timestamp attributes" do
228
- adapter.stub :concatenate do |clause, separator|
228
+ allow(adapter).to receive :concatenate do |clause, separator|
229
229
  "CONCAT_WS('#{separator}', #{clause})"
230
230
  end
231
- adapter.stub :cast_to_string do |clause|
231
+ allow(adapter).to receive :cast_to_string do |clause|
232
232
  "CAST(#{clause} AS varchar)"
233
233
  end
234
234
 
235
- attribute.stub :columns => [column, column], :type => :timestamp
235
+ allow(attribute).to receive_messages :columns => [column, column], :type => :timestamp
236
236
 
237
- presenter.to_select.should == "CONCAT_WS(',', CAST(UNIX_TIMESTAMP(articles.created_at) AS varchar), CAST(UNIX_TIMESTAMP(articles.created_at) AS varchar)) AS created_at"
237
+ expect(presenter.to_select).to eq("CONCAT_WS(',', CAST(UNIX_TIMESTAMP(articles.created_at) AS varchar), CAST(UNIX_TIMESTAMP(articles.created_at) AS varchar)) AS created_at")
238
238
  end
239
239
 
240
240
  it "does not split attribute clause for timestamp casting if it looks like a function call" do
241
- column.stub :__name => "COALESCE(articles.updated_at, articles.created_at)", :string? => true
241
+ allow(column).to receive_messages :__name => "COALESCE(articles.updated_at, articles.created_at)", :string? => true
242
242
 
243
- attribute.stub :name => 'mod_date', :columns => [column],
243
+ allow(attribute).to receive_messages :name => 'mod_date', :columns => [column],
244
244
  :type => :timestamp
245
245
 
246
- presenter.to_select.should == "UNIX_TIMESTAMP(COALESCE(articles.updated_at, articles.created_at)) AS mod_date"
246
+ expect(presenter.to_select).to eq("UNIX_TIMESTAMP(COALESCE(articles.updated_at, articles.created_at)) AS mod_date")
247
247
  end
248
248
 
249
249
  it "returns nil for query sourced attributes" do
250
- attribute.stub :source_type => :query
250
+ allow(attribute).to receive_messages :source_type => :query
251
251
 
252
- presenter.to_select.should be_nil
252
+ expect(presenter.to_select).to be_nil
253
253
  end
254
254
 
255
255
  it "returns nil for ranged query sourced attributes" do
256
- attribute.stub :source_type => :ranged_query
256
+ allow(attribute).to receive_messages :source_type => :ranged_query
257
257
 
258
- presenter.to_select.should be_nil
258
+ expect(presenter.to_select).to be_nil
259
259
  end
260
260
  end
261
261
  end