sunspot_rails 2.2.6 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/Appraisals +64 -0
  4. data/Gemfile +3 -0
  5. data/lib/sunspot/rails/configuration.rb +4 -0
  6. data/lib/sunspot/rails/request_lifecycle.rb +3 -1
  7. data/lib/sunspot/rails/searchable.rb +15 -7
  8. data/lib/sunspot/rails/solr_instrumentation.rb +2 -2
  9. data/lib/sunspot/rails/solr_logging.rb +5 -10
  10. data/lib/sunspot/rails/stub_session_proxy.rb +9 -2
  11. data/lib/sunspot/rails/tasks.rb +0 -1
  12. data/lib/sunspot/rails.rb +2 -0
  13. data/spec/configuration_spec.rb +77 -69
  14. data/spec/model_lifecycle_spec.rb +8 -8
  15. data/spec/model_spec.rb +72 -71
  16. data/spec/rails_app/app/controllers/application_controller.rb +4 -0
  17. data/spec/rails_app/app/controllers/posts_controller.rb +16 -0
  18. data/spec/{rails_template → rails_app}/app/models/author.rb +0 -2
  19. data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -2
  20. data/spec/{rails_template → rails_app}/app/models/location.rb +0 -1
  21. data/spec/{rails_template → rails_app}/app/models/post.rb +0 -2
  22. data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -2
  23. data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -2
  24. data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -2
  25. data/spec/rails_app/config/application.rb +17 -0
  26. data/spec/rails_app/config/boot.rb +6 -0
  27. data/spec/rails_app/config/database.yml +5 -0
  28. data/spec/rails_app/config/environment.rb +5 -0
  29. data/spec/rails_app/config/environments/test.rb +41 -0
  30. data/spec/rails_app/config/initializers/rails_5_override.rb +1 -0
  31. data/spec/rails_app/config/initializers/secret_token.rb +1 -0
  32. data/spec/rails_app/config/initializers/session_store.rb +3 -0
  33. data/spec/{rails_template → rails_app}/config/sunspot.yml +2 -0
  34. data/spec/rails_app/config.ru +4 -0
  35. data/spec/rails_app/db/schema.rb +26 -0
  36. data/spec/rails_app/vendor/engines/test_engine/app/models/test_engine/rake_task_auto_load_test_model.rb +15 -0
  37. data/spec/rails_app/vendor/engines/test_engine/lib/test_engine/engine.rb +5 -0
  38. data/spec/rails_app/vendor/engines/test_engine/lib/test_engine.rb +4 -0
  39. data/spec/rake_task_spec.rb +9 -9
  40. data/spec/request_lifecycle_spec.rb +17 -21
  41. data/spec/schema.rb +8 -9
  42. data/spec/searchable_spec.rb +4 -4
  43. data/spec/server_spec.rb +7 -7
  44. data/spec/session_spec.rb +3 -3
  45. data/spec/shared_examples/indexed_after_save.rb +1 -1
  46. data/spec/shared_examples/not_indexed_after_save.rb +1 -1
  47. data/spec/spec_helper.rb +18 -51
  48. data/spec/stub_session_proxy_spec.rb +40 -36
  49. data/sunspot_rails.gemspec +15 -8
  50. metadata +102 -58
  51. data/dev_tasks/spec.rake +0 -97
  52. data/gemfiles/rails-3.0.0 +0 -21
  53. data/gemfiles/rails-3.1.0 +0 -21
  54. data/gemfiles/rails-3.2.0 +0 -21
  55. data/gemfiles/rails-4.0.0 +0 -25
  56. data/gemfiles/rails-4.1.0 +0 -24
  57. data/gemfiles/rails-4.2.0 +0 -24
  58. data/spec/rails_template/app/controllers/application_controller.rb +0 -10
  59. data/spec/rails_template/app/controllers/posts_controller.rb +0 -6
  60. data/spec/rails_template/config/database.yml +0 -11
  61. data/spec/rails_template/db/schema.rb +0 -27
  62. /data/{tmp → gemfiles}/.gitkeep +0 -0
  63. /data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
  64. /data/spec/{rails_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
  65. /data/spec/{rails_template → rails_app}/config/routes.rb +0 -0
@@ -2,195 +2,203 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" do
4
4
  before(:each) do
5
- File.stub(:exist?).and_return(false) # simulate sunspot.yml not existing
5
+ allow(File).to receive(:exist?).and_return(false) # simulate sunspot.yml not existing
6
6
  @config = Sunspot::Rails::Configuration.new
7
7
  end
8
8
 
9
9
  it "should handle the 'hostname' property when not set" do
10
- @config.hostname.should == 'localhost'
10
+ expect(@config.hostname).to eq('localhost')
11
11
  end
12
12
 
13
13
  it "should handle the 'path' property when not set" do
14
- @config.path.should == '/solr/default'
14
+ expect(@config.path).to eq('/solr/default')
15
15
  end
16
16
 
17
17
  it "should set the scheme to http" do
18
- @config.scheme.should == "http"
18
+ expect(@config.scheme).to eq("http")
19
19
  end
20
20
 
21
21
  it "should not have userinfo" do
22
- @config.userinfo.should be_nil
22
+ expect(@config.userinfo).to be_nil
23
23
  end
24
24
 
25
25
  it "should not set a proxy" do
26
- @config.proxy.should be_nil
26
+ expect(@config.proxy).to be_nil
27
27
  end
28
28
 
29
29
  describe "port" do
30
30
  it "should default to port 8981 in test" do
31
- ::Rails.stub(:env => 'test')
31
+ allow(::Rails).to receive(:env).and_return('test')
32
32
  @config = Sunspot::Rails::Configuration.new
33
- @config.port.should == 8981
33
+ expect(@config.port).to eq(8981)
34
34
  end
35
35
  it "should default to port 8982 in development" do
36
- ::Rails.stub(:env => 'development')
36
+ allow(::Rails).to receive(:env).and_return('development')
37
37
  @config = Sunspot::Rails::Configuration.new
38
- @config.port.should == 8982
38
+ expect(@config.port).to eq(8982)
39
39
  end
40
40
  it "should default to 8983 in production" do
41
- ::Rails.stub(:env => 'production')
41
+ allow(::Rails).to receive(:env).and_return('production')
42
42
  @config = Sunspot::Rails::Configuration.new
43
- @config.port.should == 8983
43
+ expect(@config.port).to eq(8983)
44
44
  end
45
45
  it "should generally default to 8983" do
46
- ::Rails.stub(:env => 'staging')
46
+ allow(::Rails).to receive(:env).and_return('staging')
47
47
  @config = Sunspot::Rails::Configuration.new
48
- @config.port.should == 8983
48
+ expect(@config.port).to eq(8983)
49
49
  end
50
50
  end
51
51
 
52
52
  it "should set the read timeout to nil when not set" do
53
- @config.read_timeout == nil
53
+ expect(@config.read_timeout).to be_nil
54
54
  end
55
55
 
56
56
  it "should set the open timeout to nil when not set" do
57
- @config.open_timeout == nil
57
+ expect(@config.open_timeout).to be_nil
58
+ end
59
+
60
+ it "should set the update_format to nil when not set" do
61
+ expect(@config.update_format).to be_nil
58
62
  end
59
63
 
60
64
  it "should set 'log_level' property using Rails log level when not set" do
61
- ::Rails.logger.stub(:level){ 3 }
62
- @config.log_level.should == 'SEVERE'
65
+ allow(::Rails.logger).to receive(:level){ 3 }
66
+ expect(@config.log_level).to eq('SEVERE')
63
67
  end
64
68
 
65
69
  it "should handle the 'log_file' property" do
66
- @config.log_file.should =~ /log\/solr_test.log/
70
+ expect(@config.log_file).to match(/log\/solr_test.log/)
67
71
  end
68
72
 
69
73
  it "should handle the 'solr_home' property when not set" do
70
- Rails.should_receive(:root).at_least(1).and_return('/some/path')
71
- @config.solr_home.should == '/some/path/solr'
74
+ expect(Rails).to receive(:root).at_least(1).and_return('/some/path')
75
+ expect(@config.solr_home).to eq('/some/path/solr')
72
76
  end
73
77
 
74
78
  it "should handle the 'pid_dir' property when not set" do
75
- Rails.should_receive(:root).at_least(1).and_return('/some/path')
76
- @config.pid_dir.should == '/some/path/solr/pids/test'
79
+ expect(Rails).to receive(:root).at_least(1).and_return('/some/path')
80
+ expect(@config.pid_dir).to eq('/some/path/solr/pids/test')
77
81
  end
78
82
 
79
83
  it "should handle the 'auto_commit_after_request' propery when not set" do
80
- @config.auto_commit_after_request?.should == true
84
+ expect(@config.auto_commit_after_request?).to eq(true)
81
85
  end
82
86
 
83
87
  it "should handle the 'auto_commit_after_delete_request' propery when not set" do
84
- @config.auto_commit_after_delete_request?.should == false
88
+ expect(@config.auto_commit_after_delete_request?).to eq(false)
85
89
  end
86
90
 
87
91
  it "should handle the 'bind_address' property when not set" do
88
- @config.bind_address.should be_nil
92
+ expect(@config.bind_address).to be_nil
89
93
  end
90
94
 
91
95
  it "should handle the 'disabled' property when not set" do
92
- @config.disabled?.should be_false
96
+ expect(@config.disabled?).to be_falsey
93
97
  end
94
98
 
95
99
  it "should handle the 'auto_index_callback' property when not set" do
96
- @config.auto_index_callback.should == "after_save"
100
+ expect(@config.auto_index_callback).to eq("after_save")
97
101
  end
98
102
 
99
103
  it "should handle the 'auto_remove_callback' property when not set" do
100
- @config.auto_remove_callback.should == "after_destroy"
104
+ expect(@config.auto_remove_callback).to eq("after_destroy")
101
105
  end
102
106
  end
103
107
 
104
108
  describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
105
109
  before(:each) do
106
- ::Rails.stub(:env => 'config_test')
110
+ allow(::Rails).to receive(:env).and_return('config_test')
107
111
  @config = Sunspot::Rails::Configuration.new
108
112
  end
109
113
 
110
114
  it "should handle the 'scheme' property when set" do
111
- @config.scheme.should == "http"
115
+ expect(@config.scheme).to eq("http")
112
116
  end
113
117
 
114
118
  it "should handle the 'user' and 'pass' properties when set" do
115
- @config.userinfo.should == "user:pass"
119
+ expect(@config.userinfo).to eq("user:pass")
116
120
  end
117
121
 
118
122
  it "should handle the 'hostname' property when set" do
119
- @config.hostname.should == 'some.host'
123
+ expect(@config.hostname).to eq('some.host')
120
124
  end
121
125
 
122
126
  it "should handle the 'port' property when set" do
123
- @config.port.should == 1234
127
+ expect(@config.port).to eq(1234)
124
128
  end
125
129
 
126
130
  it "should handle the 'path' property when set" do
127
- @config.path.should == '/solr/idx'
131
+ expect(@config.path).to eq('/solr/idx')
128
132
  end
129
133
 
130
134
  it "should handle the 'log_level' propery when set" do
131
- @config.log_level.should == 'WARNING'
135
+ expect(@config.log_level).to eq('WARNING')
132
136
  end
133
137
 
134
138
  it "should handle the 'solr_home' propery when set" do
135
- @config.solr_home.should == '/my_superior_path'
139
+ expect(@config.solr_home).to eq('/my_superior_path')
136
140
  end
137
141
 
138
142
  it "should handle the 'pid_dir' property when set" do
139
- @config.pid_dir.should == '/my_superior_path/pids'
143
+ expect(@config.pid_dir).to eq('/my_superior_path/pids')
140
144
  end
141
145
 
142
146
  it "should handle the 'solr_home' property when set" do
143
- @config.solr_home.should == '/my_superior_path'
147
+ expect(@config.solr_home).to eq('/my_superior_path')
144
148
  end
145
149
 
146
150
  it "should handle the 'auto_commit_after_request' propery when set" do
147
- @config.auto_commit_after_request?.should == false
151
+ expect(@config.auto_commit_after_request?).to eq(false)
148
152
  end
149
153
 
150
154
  it "should handle the 'auto_commit_after_delete_request' propery when set" do
151
- @config.auto_commit_after_delete_request?.should == true
155
+ expect(@config.auto_commit_after_delete_request?).to eq(true)
152
156
  end
153
157
 
154
158
  it "should handle the 'bind_address' property when set" do
155
- @config.bind_address.should == "127.0.0.1"
159
+ expect(@config.bind_address).to eq("127.0.0.1")
156
160
  end
157
161
 
158
162
  it "should handle the 'read_timeout' property when set" do
159
- @config.read_timeout.should == 2
163
+ expect(@config.read_timeout).to eq(2)
160
164
  end
161
165
 
162
166
  it "should handle the 'open_timeout' property when set" do
163
- @config.open_timeout.should == 0.5
167
+ expect(@config.open_timeout).to eq(0.5)
168
+ end
169
+
170
+ it "should handle the 'update_format' property when set" do
171
+ expect(@config.update_format).to eq('json')
164
172
  end
165
173
 
166
174
  it "should handle the 'proxy' property when set" do
167
- @config.proxy.should == 'http://proxy.com:12345'
175
+ expect(@config.proxy).to eq('http://proxy.com:12345')
168
176
  end
169
177
  end
170
178
 
171
179
  describe Sunspot::Rails::Configuration, "with auto_index_callback and auto_remove_callback set" do
172
180
  before do
173
- ::Rails.stub(:env => 'config_commit_test')
181
+ allow(::Rails).to receive(:env).and_return('config_commit_test')
174
182
  @config = Sunspot::Rails::Configuration.new
175
183
  end
176
184
 
177
185
  it "should handle the 'auto_index_callback' property when set" do
178
- @config.auto_index_callback.should == "after_commit"
186
+ expect(@config.auto_index_callback).to eq("after_commit")
179
187
  end
180
188
 
181
189
  it "should handle the 'auto_remove_callback' property when set" do
182
- @config.auto_remove_callback.should == "after_commit"
190
+ expect(@config.auto_remove_callback).to eq("after_commit")
183
191
  end
184
192
  end
185
193
 
186
194
  describe Sunspot::Rails::Configuration, "with disabled: true in sunspot.yml" do
187
195
  before(:each) do
188
- ::Rails.stub(:env => 'config_disabled_test')
196
+ allow(::Rails).to receive(:env).and_return('config_disabled_test')
189
197
  @config = Sunspot::Rails::Configuration.new
190
198
  end
191
199
 
192
200
  it "should handle the 'disabled' property when set" do
193
- @config.disabled?.should be_true
201
+ expect(@config.disabled?).to be_truthy
194
202
  end
195
203
  end
196
204
 
@@ -200,7 +208,7 @@ describe Sunspot::Rails::Configuration, "with ENV['SOLR_URL'] overriding sunspot
200
208
  end
201
209
 
202
210
  before(:each) do
203
- ::Rails.stub(:env => 'config_test')
211
+ allow(::Rails).to receive(:env).and_return('config_test')
204
212
  @config = Sunspot::Rails::Configuration.new
205
213
  end
206
214
 
@@ -209,15 +217,15 @@ describe Sunspot::Rails::Configuration, "with ENV['SOLR_URL'] overriding sunspot
209
217
  end
210
218
 
211
219
  it "should handle the 'hostname' property when set" do
212
- @config.hostname.should == 'environment.host'
220
+ expect(@config.hostname).to eq('environment.host')
213
221
  end
214
222
 
215
223
  it "should handle the 'port' property when set" do
216
- @config.port.should == 5432
224
+ expect(@config.port).to eq(5432)
217
225
  end
218
226
 
219
227
  it "should handle the 'path' property when set" do
220
- @config.path.should == '/solr/env'
228
+ expect(@config.path).to eq('/solr/env')
221
229
  end
222
230
  end
223
231
 
@@ -227,7 +235,7 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] overriding suns
227
235
  end
228
236
 
229
237
  before(:each) do
230
- ::Rails.stub(:env => 'config_test')
238
+ allow(::Rails).to receive(:env).and_return('config_test')
231
239
  @config = Sunspot::Rails::Configuration.new
232
240
  end
233
241
 
@@ -236,15 +244,15 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] overriding suns
236
244
  end
237
245
 
238
246
  it "should handle the 'hostname' property when set" do
239
- @config.hostname.should == 'index.websolr.test'
247
+ expect(@config.hostname).to eq('index.websolr.test')
240
248
  end
241
249
 
242
250
  it "should handle the 'port' property when set" do
243
- @config.port.should == 80
251
+ expect(@config.port).to eq(80)
244
252
  end
245
253
 
246
254
  it "should handle the 'path' property when set" do
247
- @config.path.should == '/solr/a1b2c3d4e5f'
255
+ expect(@config.path).to eq('/solr/a1b2c3d4e5f')
248
256
  end
249
257
  end
250
258
 
@@ -254,7 +262,7 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] using https" do
254
262
  end
255
263
 
256
264
  before(:each) do
257
- ::Rails.stub(:env => 'config_test')
265
+ allow(::Rails).to receive(:env).and_return('config_test')
258
266
  @config = Sunspot::Rails::Configuration.new
259
267
  end
260
268
 
@@ -263,19 +271,19 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] using https" do
263
271
  end
264
272
 
265
273
  it "should set the scheme to https" do
266
- @config.scheme.should == "https"
274
+ expect(@config.scheme).to eq("https")
267
275
  end
268
276
 
269
277
  it "should handle the 'hostname' property when set" do
270
- @config.hostname.should == 'index.websolr.test'
278
+ expect(@config.hostname).to eq('index.websolr.test')
271
279
  end
272
280
 
273
281
  it "should handle the 'port' property when set" do
274
- @config.port.should == 443
282
+ expect(@config.port).to eq(443)
275
283
  end
276
284
 
277
285
  it "should handle the 'path' property when set" do
278
- @config.path.should == '/solr/a1b2c3d4e5f'
286
+ expect(@config.path).to eq('/solr/a1b2c3d4e5f')
279
287
  end
280
288
  end
281
289
 
@@ -285,7 +293,7 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] including useri
285
293
  end
286
294
 
287
295
  before(:each) do
288
- ::Rails.stub(:env => 'config_test')
296
+ allow(::Rails).to receive(:env).and_return('config_test')
289
297
  @config = Sunspot::Rails::Configuration.new
290
298
  end
291
299
 
@@ -294,22 +302,22 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] including useri
294
302
  end
295
303
 
296
304
  it "should include username and passowrd" do
297
- @config.userinfo.should == "user:pass"
305
+ expect(@config.userinfo).to eq("user:pass")
298
306
  end
299
307
 
300
308
  it "should set the scheme to https" do
301
- @config.scheme.should == "https"
309
+ expect(@config.scheme).to eq("https")
302
310
  end
303
311
 
304
312
  it "should handle the 'hostname' property when set" do
305
- @config.hostname.should == 'index.websolr.test'
313
+ expect(@config.hostname).to eq('index.websolr.test')
306
314
  end
307
315
 
308
316
  it "should handle the 'port' property when set" do
309
- @config.port.should == 443
317
+ expect(@config.port).to eq(443)
310
318
  end
311
319
 
312
320
  it "should handle the 'path' property when set" do
313
- @config.path.should == '/solr/a1b2c3d4e5f'
321
+ expect(@config.path).to eq('/solr/a1b2c3d4e5f')
314
322
  end
315
323
  end
@@ -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.should == [@post]
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.should == [@post]
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.should_receive :solr_index
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.should_not_receive :solr_index
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.should be_empty
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.should_not_receive(:index).with(@post)
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.should_not_receive(:index).with(@post)
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.should_receive(:index).with(@post)
75
+ expect(Sunspot).to receive(:index).with(@post)
76
76
  @post.update_attribute :title, "brand new title"
77
77
  end
78
78