sunspot_rails 2.2.7 → 2.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/Appraisals +60 -0
- data/Gemfile +3 -0
- data/gemfiles/.gitkeep +0 -0
- data/lib/sunspot/rails/solr_logging.rb +3 -3
- data/spec/configuration_spec.rb +67 -67
- data/spec/model_lifecycle_spec.rb +8 -8
- data/spec/model_spec.rb +72 -71
- data/spec/rails_app/app/controllers/application_controller.rb +4 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +16 -0
- data/spec/{rails_template → rails_app}/app/models/author.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/location.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +14 -0
- data/spec/rails_app/config/boot.rb +6 -0
- data/spec/rails_app/config/database.yml +5 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/test.rb +38 -0
- data/spec/{rails_template → rails_app}/config/initializers/rails_5_override.rb +0 -0
- data/spec/rails_app/config/initializers/secret_token.rb +1 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/{rails_template → rails_app}/config/routes.rb +0 -0
- data/spec/{rails_template → rails_app}/config/sunspot.yml +0 -0
- data/spec/rails_app/db/schema.rb +26 -0
- data/spec/rake_task_spec.rb +8 -8
- data/spec/request_lifecycle_spec.rb +12 -16
- data/spec/schema.rb +8 -9
- data/spec/searchable_spec.rb +4 -4
- data/spec/server_spec.rb +7 -7
- data/spec/session_spec.rb +3 -3
- data/spec/shared_examples/indexed_after_save.rb +1 -1
- data/spec/shared_examples/not_indexed_after_save.rb +1 -1
- data/spec/spec_helper.rb +18 -51
- data/spec/stub_session_proxy_spec.rb +36 -36
- data/sunspot_rails.gemspec +6 -3
- metadata +94 -58
- data/dev_tasks/spec.rake +0 -97
- data/gemfiles/rails-3.0.0 +0 -21
- data/gemfiles/rails-3.1.0 +0 -21
- data/gemfiles/rails-3.2.0 +0 -21
- data/gemfiles/rails-4.0.0 +0 -25
- data/gemfiles/rails-4.1.0 +0 -24
- data/gemfiles/rails-4.2.0 +0 -24
- data/gemfiles/rails-5.0 +0 -20
- data/spec/rails_template/app/controllers/application_controller.rb +0 -10
- data/spec/rails_template/app/controllers/posts_controller.rb +0 -6
- data/spec/rails_template/config/database.yml +0 -11
- data/spec/rails_template/db/schema.rb +0 -27
@@ -8,7 +8,7 @@ describe 'searchable with lifecycle' do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should automatically index' do
|
11
|
-
PostWithAuto.search.results.
|
11
|
+
expect(PostWithAuto.search.results).to eq([@post])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -20,20 +20,20 @@ describe 'searchable with lifecycle' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should automatically update index' do
|
23
|
-
PostWithAuto.search { with :title, 'Test 1' }.results.
|
23
|
+
expect(PostWithAuto.search { with :title, 'Test 1' }.results).to eq([@post])
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should index model if relevant attribute changed" do
|
27
27
|
@post = PostWithAuto.create!
|
28
28
|
@post.title = 'new title'
|
29
|
-
@post.
|
29
|
+
expect(@post).to receive :solr_index
|
30
30
|
@post.save!
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should not index model if relevant attribute not changed" do
|
34
34
|
@post = PostWithAuto.create!
|
35
35
|
@post.updated_at = Date.tomorrow
|
36
|
-
@post.
|
36
|
+
expect(@post).not_to receive :solr_index
|
37
37
|
@post.save!
|
38
38
|
end
|
39
39
|
end
|
@@ -46,7 +46,7 @@ describe 'searchable with lifecycle' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should automatically remove it from the index' do
|
49
|
-
PostWithAuto.search_ids.
|
49
|
+
expect(PostWithAuto.search_ids).to be_empty
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -56,7 +56,7 @@ describe 'searchable with lifecycle' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should not reindex the object on an update_at change, because it is marked as to-ignore" do
|
59
|
-
Sunspot.
|
59
|
+
expect(Sunspot).not_to receive(:index).with(@post)
|
60
60
|
@post.update_attribute :updated_at, 123.seconds.from_now
|
61
61
|
end
|
62
62
|
end
|
@@ -67,12 +67,12 @@ describe 'searchable with lifecycle' do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should not reindex the object on an update_at change, because it is not in the whitelist" do
|
70
|
-
Sunspot.
|
70
|
+
expect(Sunspot).not_to receive(:index).with(@post)
|
71
71
|
@post.update_attribute :updated_at, 123.seconds.from_now
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should reindex the object on a title change, because it is in the whitelist" do
|
75
|
-
Sunspot.
|
75
|
+
expect(Sunspot).to receive(:index).with(@post)
|
76
76
|
@post.update_attribute :title, "brand new title"
|
77
77
|
end
|
78
78
|
|
data/spec/model_spec.rb
CHANGED
@@ -8,17 +8,17 @@ describe 'ActiveRecord mixin' do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should not commit the model' do
|
11
|
-
Post.search.results.
|
11
|
+
expect(Post.search.results).to be_empty
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should index the model' do
|
15
15
|
Sunspot.commit
|
16
|
-
Post.search.results.
|
16
|
+
expect(Post.search.results).to eq([@post])
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should not blow up if there's a default scope specifying order" do
|
20
20
|
posts = Array.new(2) { |j| PostWithDefaultScope.create! :title => (10-j).to_s }
|
21
|
-
|
21
|
+
expect { PostWithDefaultScope.index(:batch_size => 1) }.not_to raise_error
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe 'ActiveRecord mixin' do
|
|
29
29
|
|
30
30
|
it 'should not break auto-indexing' do
|
31
31
|
@post.title = 'Title'
|
32
|
-
|
32
|
+
expect { @post.save! }.not_to raise_error
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe 'ActiveRecord mixin' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should immediately index and commit' do
|
43
|
-
Post.search.results.
|
43
|
+
expect(Post.search.results).to eq([@post])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -52,12 +52,12 @@ describe 'ActiveRecord mixin' do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should not commit immediately' do
|
55
|
-
Post.search.results.
|
55
|
+
expect(Post.search.results).to eq([@post])
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should remove the model from the index' do
|
59
59
|
Sunspot.commit
|
60
|
-
Post.search.results.
|
60
|
+
expect(Post.search.results).to be_empty
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -69,7 +69,7 @@ describe 'ActiveRecord mixin' do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should immediately remove the model and commit' do
|
72
|
-
Post.search.results.
|
72
|
+
expect(Post.search.results).to be_empty
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -81,12 +81,12 @@ describe 'ActiveRecord mixin' do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should not commit immediately' do
|
84
|
-
Post.search.results.to_set.
|
84
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should remove all instances from the index' do
|
88
88
|
Sunspot.commit
|
89
|
-
Post.search.results.
|
89
|
+
expect(Post.search.results).to be_empty
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -98,7 +98,7 @@ describe 'ActiveRecord mixin' do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should remove all instances from the index and commit immediately' do
|
101
|
-
Post.search.results.
|
101
|
+
expect(Post.search.results).to be_empty
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -109,25 +109,25 @@ describe 'ActiveRecord mixin' do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should return results specified by search' do
|
112
|
-
Post.search do
|
112
|
+
expect(Post.search do
|
113
113
|
with :title, 'Test Post'
|
114
|
-
end.results.
|
114
|
+
end.results).to eq([@post])
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should not return results excluded by search' do
|
118
|
-
Post.search do
|
118
|
+
expect(Post.search do
|
119
119
|
with :title, 'Bogus Post'
|
120
|
-
end.results.
|
120
|
+
end.results).to be_empty
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should not allow bogus options to search' do
|
124
|
-
|
124
|
+
expect { Post.search(:bogus => :option) }.to raise_error(ArgumentError)
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should pass :include option from search call to data accessor' do
|
128
|
-
Post.search(:include => [:location]) do
|
128
|
+
expect(Post.search(:include => [:location]) do
|
129
129
|
with :title, 'Test Post'
|
130
|
-
end.data_accessor_for(Post).include.
|
130
|
+
end.data_accessor_for(Post).include).to eq([:location])
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'should use the include option on the data accessor when specified' do
|
@@ -137,38 +137,38 @@ describe 'ActiveRecord mixin' do
|
|
137
137
|
data_accessor_for(Post).include = [:location]
|
138
138
|
end.results.first
|
139
139
|
|
140
|
-
(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).
|
140
|
+
expect(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).to be_truthy # Rails 3.1 removed "loaded_#{association}" method
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'should use the select option from search call to data accessor' do
|
144
|
-
Post.search(:select => 'id, title, body') do
|
144
|
+
expect(Post.search(:select => 'id, title, body') do
|
145
145
|
with :title, 'Test Post'
|
146
|
-
end.data_accessor_for(Post).select.
|
146
|
+
end.data_accessor_for(Post).select).to eq('id, title, body')
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should use the select option on the data accessor when specified' do
|
150
|
-
Post.search do
|
150
|
+
expect(Post.search do
|
151
151
|
with :title, 'Test Post'
|
152
152
|
data_accessor_for(Post).select = 'id, title, body'
|
153
|
-
end.results.first.attribute_names.sort.
|
153
|
+
end.results.first.attribute_names.sort).to eq(['body', 'id', 'title'])
|
154
154
|
end
|
155
155
|
|
156
156
|
it 'should not use the select option on the data accessor when not specified' do
|
157
|
-
Post.search do
|
157
|
+
expect(Post.search do
|
158
158
|
with :title, 'Test Post'
|
159
|
-
end.results.first.attribute_names.
|
159
|
+
end.results.first.attribute_names).to eq(Post.first.attribute_names)
|
160
160
|
end
|
161
161
|
|
162
162
|
it 'should accept an array as a select option' do
|
163
|
-
Post.search(:select => ['id', 'title', 'body']) do
|
163
|
+
expect(Post.search(:select => ['id', 'title', 'body']) do
|
164
164
|
with :title, 'Test Post'
|
165
|
-
end.results.first.attribute_names.sort.
|
165
|
+
end.results.first.attribute_names.sort).to eq(['body', 'id', 'title'])
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'should use the scoped option from search call to data accessor' do
|
169
|
-
Post.search(:scopes => [:includes_location]) do
|
169
|
+
expect(Post.search(:scopes => [:includes_location]) do
|
170
170
|
with :title, 'Test Post'
|
171
|
-
end.data_accessor_for(Post).scopes.
|
171
|
+
end.data_accessor_for(Post).scopes).to eq([:includes_location])
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should use the scopes option on the data accessor when specified' do
|
@@ -178,16 +178,16 @@ describe 'ActiveRecord mixin' do
|
|
178
178
|
data_accessor_for(Post).scopes = [:includes_location]
|
179
179
|
end.results.first
|
180
180
|
|
181
|
-
(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).
|
181
|
+
expect(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).to be_truthy # Rails 3.1 removed "loaded_#{association}" method
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should gracefully handle nonexistent records' do
|
185
185
|
post2 = Post.create!(:title => 'Test Post')
|
186
186
|
post2.index!
|
187
187
|
post2.destroy
|
188
|
-
Post.search do
|
188
|
+
expect(Post.search do
|
189
189
|
with :title, 'Test Post'
|
190
|
-
end.results.
|
190
|
+
end.results).to eq([@post])
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'should use an ActiveRecord object for coordinates' do
|
@@ -195,7 +195,7 @@ describe 'ActiveRecord mixin' do
|
|
195
195
|
post.location = Location.create!(:lat => 40.0, :lng => -70.0)
|
196
196
|
post.save
|
197
197
|
post.index!
|
198
|
-
Post.search { with(:location).near(40.0, -70.0) }.results.
|
198
|
+
expect(Post.search { with(:location).near(40.0, -70.0) }.results).to eq([post])
|
199
199
|
end
|
200
200
|
|
201
201
|
end
|
@@ -207,17 +207,17 @@ describe 'ActiveRecord mixin' do
|
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'should return IDs' do
|
210
|
-
Post.search_ids.to_set.
|
210
|
+
expect(Post.search_ids.to_set).to eq(@posts.map { |post| post.id }.to_set)
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
214
|
describe 'searchable?()' do
|
215
215
|
it 'should not be true for models that have not been configured for search' do
|
216
|
-
Location.
|
216
|
+
expect(Location).not_to be_searchable
|
217
217
|
end
|
218
218
|
|
219
219
|
it 'should be true for models that have been configured for search' do
|
220
|
-
Post.
|
220
|
+
expect(Post).to be_searchable
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -229,7 +229,7 @@ describe 'ActiveRecord mixin' do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'should return IDs of objects that are in the index but not the database' do
|
232
|
-
Post.index_orphans.
|
232
|
+
expect(Post.index_orphans).to eq([@posts.first.id])
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -243,7 +243,7 @@ describe 'ActiveRecord mixin' do
|
|
243
243
|
it 'should remove orphans from the index' do
|
244
244
|
Post.clean_index_orphans
|
245
245
|
Sunspot.commit
|
246
|
-
Post.search.results.
|
246
|
+
expect(Post.search.results).to eq([@posts.last])
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
@@ -255,7 +255,7 @@ describe 'ActiveRecord mixin' do
|
|
255
255
|
it 'should index all instances' do
|
256
256
|
Post.reindex(:batch_size => nil)
|
257
257
|
Sunspot.commit
|
258
|
-
Post.search.results.to_set.
|
258
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
259
259
|
end
|
260
260
|
|
261
261
|
it 'should remove all currently indexed instances' do
|
@@ -264,7 +264,7 @@ describe 'ActiveRecord mixin' do
|
|
264
264
|
old_post.destroy
|
265
265
|
Post.reindex
|
266
266
|
Sunspot.commit
|
267
|
-
Post.search.results.to_set.
|
267
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
268
268
|
end
|
269
269
|
|
270
270
|
end
|
@@ -277,7 +277,7 @@ describe 'ActiveRecord mixin' do
|
|
277
277
|
it 'should index all instances' do
|
278
278
|
Post.reindex(:batch_size => nil)
|
279
279
|
Sunspot.commit
|
280
|
-
Post.search.results.to_set.
|
280
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'should remove all currently indexed instances' do
|
@@ -286,14 +286,14 @@ describe 'ActiveRecord mixin' do
|
|
286
286
|
old_post.destroy
|
287
287
|
Post.reindex
|
288
288
|
Sunspot.commit
|
289
|
-
Post.search.results.to_set.
|
289
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
290
290
|
end
|
291
291
|
|
292
292
|
describe "using batch sizes" do
|
293
293
|
it 'should index with a specified batch size' do
|
294
294
|
Post.reindex(:batch_size => 1)
|
295
295
|
Sunspot.commit
|
296
|
-
Post.search.results.to_set.
|
296
|
+
expect(Post.search.results.to_set).to eq(@posts.to_set)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
end
|
@@ -307,19 +307,19 @@ describe 'ActiveRecord mixin' do
|
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should use batches if the batch_size is specified" do
|
310
|
-
relation(Post).class.
|
310
|
+
expect_any_instance_of(relation(Post).class).to receive(:find_in_batches)
|
311
311
|
Post.reindex(:batch_size => 50)
|
312
312
|
end
|
313
313
|
|
314
314
|
it "should select all if the batch_size isn't greater than 0" do
|
315
|
-
relation(Post).class.
|
315
|
+
expect_any_instance_of(relation(Post).class).not_to receive(:find_in_batches)
|
316
316
|
Post.reindex(:batch_size => nil)
|
317
317
|
Post.reindex(:batch_size => 0)
|
318
318
|
end
|
319
319
|
|
320
320
|
describe "when not using batches" do
|
321
321
|
it "should search for models with includes" do
|
322
|
-
Post.
|
322
|
+
expect(Post).to receive(:includes).with(:author).and_return(relation(Post))
|
323
323
|
Post.reindex(:batch_size => nil, :include => :author)
|
324
324
|
end
|
325
325
|
|
@@ -335,7 +335,7 @@ describe 'ActiveRecord mixin' do
|
|
335
335
|
it 'should only index those models where :if constraints pass' do
|
336
336
|
Post.reindex(:batch_size => nil)
|
337
337
|
|
338
|
-
Post.search.results.
|
338
|
+
expect(Post.search.results).not_to include(@posts.first)
|
339
339
|
end
|
340
340
|
end
|
341
341
|
|
@@ -343,12 +343,12 @@ describe 'ActiveRecord mixin' do
|
|
343
343
|
|
344
344
|
describe "when using batches" do
|
345
345
|
it "should commit after indexing each batch" do
|
346
|
-
Sunspot.
|
346
|
+
expect(Sunspot).to receive(:commit).twice
|
347
347
|
Post.reindex(:batch_size => 1)
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should commit after indexing everything" do
|
351
|
-
Sunspot.
|
351
|
+
expect(Sunspot).to receive(:commit).once
|
352
352
|
Post.reindex(:batch_commit => false)
|
353
353
|
end
|
354
354
|
|
@@ -364,7 +364,7 @@ describe 'ActiveRecord mixin' do
|
|
364
364
|
it 'should only index those models where :if constraints pass' do
|
365
365
|
Post.reindex(:batch_size => 50)
|
366
366
|
|
367
|
-
Post.search.results.
|
367
|
+
expect(Post.search.results).not_to include(@posts.first)
|
368
368
|
end
|
369
369
|
end
|
370
370
|
end
|
@@ -386,12 +386,13 @@ describe 'ActiveRecord mixin' do
|
|
386
386
|
end
|
387
387
|
|
388
388
|
it "should return results" do
|
389
|
-
@posts.first.more_like_this.results.
|
389
|
+
expect(@posts.first.more_like_this.results).to eq([@posts[3], @posts[1]])
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should return results for specified classes" do
|
393
|
-
@posts.first.more_like_this(Post, PostWithAuto).results.to_set.
|
393
|
+
expect(@posts.first.more_like_this(Post, PostWithAuto).results.to_set).to eq(
|
394
394
|
Set[@posts_with_auto[0], @posts[1], @posts[3]]
|
395
|
+
)
|
395
396
|
end
|
396
397
|
end
|
397
398
|
|
@@ -407,7 +408,7 @@ describe 'ActiveRecord mixin' do
|
|
407
408
|
end
|
408
409
|
|
409
410
|
it 'should return IDs' do
|
410
|
-
@posts.first.more_like_this_ids.to_set.
|
411
|
+
expect(@posts.first.more_like_this_ids.to_set).to eq([@posts[3], @posts[1]].map { |post| post.id }.to_set)
|
411
412
|
end
|
412
413
|
end
|
413
414
|
|
@@ -424,7 +425,7 @@ describe 'ActiveRecord mixin' do
|
|
424
425
|
context 'constraint returns true' do
|
425
426
|
# searchable :if => :returns_true
|
426
427
|
before do
|
427
|
-
subject.
|
428
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
428
429
|
subject.class.sunspot_options[:if] = :returns_true
|
429
430
|
end
|
430
431
|
|
@@ -434,7 +435,7 @@ describe 'ActiveRecord mixin' do
|
|
434
435
|
context 'constraint returns false' do
|
435
436
|
# searchable :if => :returns_false
|
436
437
|
before do
|
437
|
-
subject.
|
438
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
438
439
|
subject.class.sunspot_options[:if] = :returns_false
|
439
440
|
end
|
440
441
|
|
@@ -446,7 +447,7 @@ describe 'ActiveRecord mixin' do
|
|
446
447
|
context 'constraint returns true' do
|
447
448
|
# searchable :if => 'returns_true'
|
448
449
|
before do
|
449
|
-
subject.
|
450
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
450
451
|
subject.class.sunspot_options[:if] = 'returns_true'
|
451
452
|
end
|
452
453
|
|
@@ -456,7 +457,7 @@ describe 'ActiveRecord mixin' do
|
|
456
457
|
context 'constraint returns false' do
|
457
458
|
# searchable :if => 'returns_false'
|
458
459
|
before do
|
459
|
-
subject.
|
460
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
460
461
|
subject.class.sunspot_options[:if] = 'returns_false'
|
461
462
|
end
|
462
463
|
|
@@ -488,8 +489,8 @@ describe 'ActiveRecord mixin' do
|
|
488
489
|
context 'all constraints returns true' do
|
489
490
|
# searchable :if => [:returns_true_1, :returns_true_2]
|
490
491
|
before do
|
491
|
-
subject.
|
492
|
-
subject.
|
492
|
+
expect(subject).to receive(:returns_true_1).and_return(true)
|
493
|
+
expect(subject).to receive(:returns_true_2).and_return(true)
|
493
494
|
subject.class.sunspot_options[:if] = [:returns_true_1, 'returns_true_2']
|
494
495
|
end
|
495
496
|
|
@@ -499,8 +500,8 @@ describe 'ActiveRecord mixin' do
|
|
499
500
|
context 'one constraint returns false' do
|
500
501
|
# searchable :if => [:returns_true, :returns_false]
|
501
502
|
before do
|
502
|
-
subject.
|
503
|
-
subject.
|
503
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
504
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
504
505
|
subject.class.sunspot_options[:if] = [:returns_true, 'returns_false']
|
505
506
|
end
|
506
507
|
|
@@ -511,12 +512,12 @@ describe 'ActiveRecord mixin' do
|
|
511
512
|
it 'removes the model from the index if the constraint does not match' do
|
512
513
|
subject.save!
|
513
514
|
Sunspot.commit
|
514
|
-
subject.class.search.results.
|
515
|
+
expect(subject.class.search.results).to include(subject)
|
515
516
|
|
516
517
|
subject.class.sunspot_options[:if] = proc { false }
|
517
518
|
subject.save!
|
518
519
|
Sunspot.commit
|
519
|
-
subject.class.search.results.
|
520
|
+
expect(subject.class.search.results).not_to include(subject)
|
520
521
|
end
|
521
522
|
end
|
522
523
|
|
@@ -533,7 +534,7 @@ describe 'ActiveRecord mixin' do
|
|
533
534
|
context 'constraint returns true' do
|
534
535
|
# searchable :unless => :returns_true
|
535
536
|
before do
|
536
|
-
subject.
|
537
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
537
538
|
subject.class.sunspot_options[:unless] = :returns_true
|
538
539
|
end
|
539
540
|
|
@@ -543,7 +544,7 @@ describe 'ActiveRecord mixin' do
|
|
543
544
|
context 'constraint returns false' do
|
544
545
|
# searchable :unless => :returns_false
|
545
546
|
before do
|
546
|
-
subject.
|
547
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
547
548
|
subject.class.sunspot_options[:unless] = :returns_false
|
548
549
|
end
|
549
550
|
|
@@ -555,7 +556,7 @@ describe 'ActiveRecord mixin' do
|
|
555
556
|
context 'constraint returns true' do
|
556
557
|
# searchable :unless => 'returns_true'
|
557
558
|
before do
|
558
|
-
subject.
|
559
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
559
560
|
subject.class.sunspot_options[:unless] = 'returns_true'
|
560
561
|
end
|
561
562
|
|
@@ -565,7 +566,7 @@ describe 'ActiveRecord mixin' do
|
|
565
566
|
context 'constraint returns false' do
|
566
567
|
# searchable :unless => 'returns_false'
|
567
568
|
before do
|
568
|
-
subject.
|
569
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
569
570
|
subject.class.sunspot_options[:unless] = 'returns_false'
|
570
571
|
end
|
571
572
|
|
@@ -597,8 +598,8 @@ describe 'ActiveRecord mixin' do
|
|
597
598
|
context 'all constraints returns true' do
|
598
599
|
# searchable :unless => [:returns_true_1, :returns_true_2]
|
599
600
|
before do
|
600
|
-
subject.
|
601
|
-
subject.
|
601
|
+
expect(subject).to receive(:returns_true_1).and_return(true)
|
602
|
+
expect(subject).to receive(:returns_true_2).and_return(true)
|
602
603
|
subject.class.sunspot_options[:unless] = [:returns_true_1, 'returns_true_2']
|
603
604
|
end
|
604
605
|
|
@@ -608,8 +609,8 @@ describe 'ActiveRecord mixin' do
|
|
608
609
|
context 'one constraint returns false' do
|
609
610
|
# searchable :unless => [:returns_true, :returns_false]
|
610
611
|
before do
|
611
|
-
subject.
|
612
|
-
subject.
|
612
|
+
expect(subject).to receive(:returns_true).and_return(true)
|
613
|
+
expect(subject).to receive(:returns_false).and_return(false)
|
613
614
|
subject.class.sunspot_options[:unless] = [:returns_true, 'returns_false']
|
614
615
|
end
|
615
616
|
|