bullet 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.rails-5.2 +15 -0
  4. data/Guardfile +2 -2
  5. data/Rakefile +16 -17
  6. data/bullet.gemspec +11 -11
  7. data/lib/bullet/active_record52.rb +225 -0
  8. data/lib/bullet/dependency.rb +6 -0
  9. data/lib/bullet/detector/association.rb +3 -2
  10. data/lib/bullet/detector/counter_cache.rb +4 -3
  11. data/lib/bullet/detector/n_plus_one_query.rb +6 -5
  12. data/lib/bullet/detector/unused_eager_loading.rb +4 -3
  13. data/lib/bullet/ext/string.rb +1 -1
  14. data/lib/bullet/mongoid4x.rb +1 -1
  15. data/lib/bullet/mongoid5x.rb +1 -1
  16. data/lib/bullet/mongoid6x.rb +1 -1
  17. data/lib/bullet/notification/base.rb +9 -8
  18. data/lib/bullet/notification/counter_cache.rb +1 -1
  19. data/lib/bullet/notification/n_plus_one_query.rb +2 -1
  20. data/lib/bullet/notification/unused_eager_loading.rb +2 -1
  21. data/lib/bullet/rack.rb +5 -5
  22. data/lib/bullet/stack_trace_filter.rb +2 -2
  23. data/lib/bullet/version.rb +2 -2
  24. data/lib/bullet.rb +15 -7
  25. data/lib/generators/bullet/install_generator.rb +5 -5
  26. data/perf/benchmark.rb +6 -8
  27. data/spec/bullet/detector/association_spec.rb +4 -4
  28. data/spec/bullet/detector/counter_cache_spec.rb +11 -11
  29. data/spec/bullet/detector/n_plus_one_query_spec.rb +35 -35
  30. data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -19
  31. data/spec/bullet/ext/object_spec.rb +7 -7
  32. data/spec/bullet/ext/string_spec.rb +5 -5
  33. data/spec/bullet/notification/base_spec.rb +32 -33
  34. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  35. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
  36. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  37. data/spec/bullet/notification_collector_spec.rb +10 -10
  38. data/spec/bullet/rack_spec.rb +46 -46
  39. data/spec/bullet/registry/association_spec.rb +10 -10
  40. data/spec/bullet/registry/base_spec.rb +20 -20
  41. data/spec/bullet/registry/object_spec.rb +4 -4
  42. data/spec/bullet_spec.rb +20 -1
  43. data/spec/integration/active_record/association_spec.rb +106 -106
  44. data/spec/integration/counter_cache_spec.rb +12 -12
  45. data/spec/integration/mongoid/association_spec.rb +33 -33
  46. data/spec/models/comment.rb +1 -1
  47. data/spec/models/document.rb +2 -2
  48. data/spec/models/mongoid/address.rb +1 -1
  49. data/spec/models/mongoid/category.rb +2 -2
  50. data/spec/models/mongoid/comment.rb +1 -1
  51. data/spec/models/mongoid/company.rb +1 -1
  52. data/spec/models/mongoid/entry.rb +1 -1
  53. data/spec/models/mongoid/post.rb +3 -3
  54. data/spec/models/newspaper.rb +1 -1
  55. data/spec/spec_helper.rb +12 -12
  56. data/spec/support/mongo_seed.rb +6 -6
  57. data/spec/support/rack_double.rb +4 -3
  58. data/spec/support/sqlite_seed.rb +6 -7
  59. data/tasks/bullet_tasks.rake +2 -2
  60. data/test.sh +2 -0
  61. data/update.sh +2 -0
  62. metadata +5 -3
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  if active_record?
4
4
  describe Bullet::Detector::Association, 'has_many' do
5
- context "post => comments" do
6
- it "should detect non preload post => comments" do
5
+ context 'post => comments' do
6
+ it 'should detect non preload post => comments' do
7
7
  Post.all.each do |post|
8
8
  post.comments.map(&:name)
9
9
  end
@@ -13,8 +13,8 @@ if active_record?
13
13
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
14
14
  end
15
15
 
16
- it "should detect non preload post => comments for find_by_sql" do
17
- Post.find_by_sql("SELECT * FROM posts").each do |post|
16
+ it 'should detect non preload post => comments for find_by_sql' do
17
+ Post.find_by_sql('SELECT * FROM posts').each do |post|
18
18
  post.comments.map(&:name)
19
19
  end
20
20
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -23,7 +23,7 @@ if active_record?
23
23
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
24
24
  end
25
25
 
26
- it "should detect preload with post => comments" do
26
+ it 'should detect preload with post => comments' do
27
27
  Post.includes(:comments).each do |post|
28
28
  post.comments.map(&:name)
29
29
  end
@@ -33,7 +33,7 @@ if active_record?
33
33
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
34
34
  end
35
35
 
36
- it "should detect unused preload post => comments" do
36
+ it 'should detect unused preload post => comments' do
37
37
  Post.includes(:comments).map(&:name)
38
38
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
39
39
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Post, :comments)
@@ -41,7 +41,7 @@ if active_record?
41
41
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
42
42
  end
43
43
 
44
- it "should not detect unused preload post => comments" do
44
+ it 'should not detect unused preload post => comments' do
45
45
  Post.all.map(&:name)
46
46
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
47
47
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -49,7 +49,7 @@ if active_record?
49
49
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
50
50
  end
51
51
 
52
- it "should detect non preload comment => post with inverse_of" do
52
+ it 'should detect non preload comment => post with inverse_of' do
53
53
  Post.includes(:comments).each do |post|
54
54
  post.comments.each do |comment|
55
55
  comment.name
@@ -62,7 +62,7 @@ if active_record?
62
62
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
63
63
  end
64
64
 
65
- it "should detect non preload post => comments with empty?" do
65
+ it 'should detect non preload post => comments with empty?' do
66
66
  Post.all.each do |post|
67
67
  post.comments.empty?
68
68
  end
@@ -72,7 +72,7 @@ if active_record?
72
72
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
73
73
  end
74
74
 
75
- it "should detect non preload post => comments with include?" do
75
+ it 'should detect non preload post => comments with include?' do
76
76
  comment = Comment.last
77
77
  Post.all.each do |post|
78
78
  post.comments.include?(comment)
@@ -83,7 +83,7 @@ if active_record?
83
83
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
84
84
  end
85
85
 
86
- it "should not detect unused preload person => pets with empty?" do
86
+ it 'should not detect unused preload person => pets with empty?' do
87
87
  Person.all.each do |person|
88
88
  person.pets.empty?
89
89
  end
@@ -94,8 +94,8 @@ if active_record?
94
94
  end
95
95
  end
96
96
 
97
- context "category => posts => comments" do
98
- it "should detect non preload category => posts => comments" do
97
+ context 'category => posts => comments' do
98
+ it 'should detect non preload category => posts => comments' do
99
99
  Category.all.each do |category|
100
100
  category.posts.each do |post|
101
101
  post.comments.map(&:name)
@@ -108,7 +108,7 @@ if active_record?
108
108
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
109
109
  end
110
110
 
111
- it "should detect preload category => posts, but no post => comments" do
111
+ it 'should detect preload category => posts, but no post => comments' do
112
112
  Category.includes(:posts).each do |category|
113
113
  category.posts.each do |post|
114
114
  post.comments.map(&:name)
@@ -121,8 +121,8 @@ if active_record?
121
121
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
122
122
  end
123
123
 
124
- it "should detect preload with category => posts => comments" do
125
- Category.includes({:posts => :comments}).each do |category|
124
+ it 'should detect preload with category => posts => comments' do
125
+ Category.includes({ :posts => :comments }).each do |category|
126
126
  category.posts.each do |post|
127
127
  post.comments.map(&:name)
128
128
  end
@@ -133,8 +133,8 @@ if active_record?
133
133
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
134
134
  end
135
135
 
136
- it "should detect preload with category => posts => comments with posts.id > 0" do
137
- Category.includes({:posts => :comments}).where('posts.id > 0').references(:posts).each do |category|
136
+ it 'should detect preload with category => posts => comments with posts.id > 0' do
137
+ Category.includes({ :posts => :comments }).where('posts.id > 0').references(:posts).each do |category|
138
138
  category.posts.each do |post|
139
139
  post.comments.map(&:name)
140
140
  end
@@ -145,16 +145,16 @@ if active_record?
145
145
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
146
146
  end
147
147
 
148
- it "should detect unused preload with category => posts => comments" do
149
- Category.includes({:posts => :comments}).map(&:name)
148
+ it 'should detect unused preload with category => posts => comments' do
149
+ Category.includes({ :posts => :comments }).map(&:name)
150
150
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
151
151
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Post, :comments)
152
152
 
153
153
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
154
154
  end
155
155
 
156
- it "should detect unused preload with post => commnets, no category => posts" do
157
- Category.includes({:posts => :comments}).each do |category|
156
+ it 'should detect unused preload with post => commnets, no category => posts' do
157
+ Category.includes({ :posts => :comments }).each do |category|
158
158
  category.posts.map(&:name)
159
159
  end
160
160
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -164,8 +164,8 @@ if active_record?
164
164
  end
165
165
  end
166
166
 
167
- context "category => posts, category => entries" do
168
- it "should detect non preload with category => [posts, entries]" do
167
+ context 'category => posts, category => entries' do
168
+ it 'should detect non preload with category => [posts, entries]' do
169
169
  Category.all.each do |category|
170
170
  category.posts.map(&:name)
171
171
  category.entries.map(&:name)
@@ -177,7 +177,7 @@ if active_record?
177
177
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Category, :entries)
178
178
  end
179
179
 
180
- it "should detect preload with category => posts, but not with category => entries" do
180
+ it 'should detect preload with category => posts, but not with category => entries' do
181
181
  Category.includes(:posts).each do |category|
182
182
  category.posts.map(&:name)
183
183
  category.entries.map(&:name)
@@ -189,7 +189,7 @@ if active_record?
189
189
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Category, :entries)
190
190
  end
191
191
 
192
- it "should detect preload with category => [posts, entries]" do
192
+ it 'should detect preload with category => [posts, entries]' do
193
193
  Category.includes([:posts, :entries]).each do |category|
194
194
  category.posts.map(&:name)
195
195
  category.entries.map(&:name)
@@ -200,7 +200,7 @@ if active_record?
200
200
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
201
201
  end
202
202
 
203
- it "should detect unused preload with category => [posts, entries]" do
203
+ it 'should detect unused preload with category => [posts, entries]' do
204
204
  Category.includes([:posts, :entries]).map(&:name)
205
205
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
206
206
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Category, :posts)
@@ -209,7 +209,7 @@ if active_record?
209
209
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
210
210
  end
211
211
 
212
- it "should detect unused preload with category => entries, but not with category => posts" do
212
+ it 'should detect unused preload with category => entries, but not with category => posts' do
213
213
  Category.includes([:posts, :entries]).each do |category|
214
214
  category.posts.map(&:name)
215
215
  end
@@ -221,8 +221,8 @@ if active_record?
221
221
  end
222
222
  end
223
223
 
224
- context "post => comment" do
225
- it "should detect unused preload with post => comments" do
224
+ context 'post => comment' do
225
+ it 'should detect unused preload with post => comments' do
226
226
  Post.includes(:comments).each do |post|
227
227
  post.comments.first.name if post.comments.first
228
228
  end
@@ -232,7 +232,7 @@ if active_record?
232
232
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
233
233
  end
234
234
 
235
- it "should detect preload with post => commnets" do
235
+ it 'should detect preload with post => commnets' do
236
236
  Post.first.comments.map(&:name)
237
237
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
238
238
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -240,7 +240,7 @@ if active_record?
240
240
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
241
241
  end
242
242
 
243
- it "should not detect unused preload with category => posts" do
243
+ it 'should not detect unused preload with category => posts' do
244
244
  category = Category.first
245
245
  category.draft_post.destroy!
246
246
  post = category.draft_post
@@ -255,9 +255,9 @@ if active_record?
255
255
  end
256
256
  end
257
257
 
258
- context "category => posts => writer" do
259
- it "should not detect unused preload associations" do
260
- category = Category.includes({:posts => :writer}).order("id DESC").find_by_name('first')
258
+ context 'category => posts => writer' do
259
+ it 'should not detect unused preload associations' do
260
+ category = Category.includes({ :posts => :writer }).order('id DESC').find_by_name('first')
261
261
  category.posts.map do |post|
262
262
  post.name
263
263
  post.writer.name
@@ -268,8 +268,8 @@ if active_record?
268
268
  end
269
269
  end
270
270
 
271
- context "scope for_category_name" do
272
- it "should detect preload with post => category" do
271
+ context 'scope for_category_name' do
272
+ it 'should detect preload with post => category' do
273
273
  Post.in_category_name('first').references(:categories).each do |post|
274
274
  post.category.name
275
275
  end
@@ -279,7 +279,7 @@ if active_record?
279
279
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
280
280
  end
281
281
 
282
- it "should not be unused preload post => category" do
282
+ it 'should not be unused preload post => category' do
283
283
  Post.in_category_name('first').references(:categories).map(&:name)
284
284
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
285
285
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -288,8 +288,8 @@ if active_record?
288
288
  end
289
289
  end
290
290
 
291
- context "scope preload_comments" do
292
- it "should detect preload post => comments with scope" do
291
+ context 'scope preload_comments' do
292
+ it 'should detect preload post => comments with scope' do
293
293
  Post.preload_comments.each do |post|
294
294
  post.comments.map(&:name)
295
295
  end
@@ -299,7 +299,7 @@ if active_record?
299
299
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
300
300
  end
301
301
 
302
- it "should detect unused preload with scope" do
302
+ it 'should detect unused preload with scope' do
303
303
  Post.preload_comments.map(&:name)
304
304
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
305
305
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Post, :comments)
@@ -310,8 +310,8 @@ if active_record?
310
310
  end
311
311
 
312
312
  describe Bullet::Detector::Association, 'belongs_to' do
313
- context "comment => post" do
314
- it "should detect non preload with comment => post" do
313
+ context 'comment => post' do
314
+ it 'should detect non preload with comment => post' do
315
315
  Comment.all.each do |comment|
316
316
  comment.post.name
317
317
  end
@@ -321,7 +321,7 @@ if active_record?
321
321
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Comment, :post)
322
322
  end
323
323
 
324
- it "should detect preload with one comment => post" do
324
+ it 'should detect preload with one comment => post' do
325
325
  Comment.first.post.name
326
326
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
327
327
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -329,7 +329,7 @@ if active_record?
329
329
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
330
330
  end
331
331
 
332
- it "should dtect preload with comment => post" do
332
+ it 'should dtect preload with comment => post' do
333
333
  Comment.includes(:post).each do |comment|
334
334
  comment.post.name
335
335
  end
@@ -339,7 +339,7 @@ if active_record?
339
339
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
340
340
  end
341
341
 
342
- it "should not detect preload with comment => post" do
342
+ it 'should not detect preload with comment => post' do
343
343
  Comment.all.map(&:name)
344
344
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
345
345
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -347,7 +347,7 @@ if active_record?
347
347
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
348
348
  end
349
349
 
350
- it "should detect unused preload with comment => post" do
350
+ it 'should detect unused preload with comment => post' do
351
351
  Comment.includes(:post).map(&:name)
352
352
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
353
353
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Comment, :post)
@@ -356,8 +356,8 @@ if active_record?
356
356
  end
357
357
  end
358
358
 
359
- context "comment => post => category" do
360
- it "should detect non preload association with comment => post" do
359
+ context 'comment => post => category' do
360
+ it 'should detect non preload association with comment => post' do
361
361
  Comment.all.each do |comment|
362
362
  comment.post.category.name
363
363
  end
@@ -367,7 +367,7 @@ if active_record?
367
367
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Comment, :post)
368
368
  end
369
369
 
370
- it "should not detect non preload association with only one comment" do
370
+ it 'should not detect non preload association with only one comment' do
371
371
  Comment.first.post.category.name
372
372
 
373
373
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -376,7 +376,7 @@ if active_record?
376
376
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
377
377
  end
378
378
 
379
- it "should detect non preload association with post => category" do
379
+ it 'should detect non preload association with post => category' do
380
380
  Comment.includes(:post).each do |comment|
381
381
  comment.post.category.name
382
382
  end
@@ -386,7 +386,7 @@ if active_record?
386
386
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :category)
387
387
  end
388
388
 
389
- it "should not detect unpreload association" do
389
+ it 'should not detect unpreload association' do
390
390
  Comment.includes(:post => :category).each do |comment|
391
391
  comment.post.category.name
392
392
  end
@@ -397,9 +397,9 @@ if active_record?
397
397
  end
398
398
  end
399
399
 
400
- context "comment => author, post => writer" do
401
- it "should detect non preloaded writer" do
402
- Comment.includes([:author, :post]).where(["base_users.id = ?", BaseUser.first]).references(:base_users).each do |comment|
400
+ context 'comment => author, post => writer' do
401
+ it 'should detect non preloaded writer' do
402
+ Comment.includes([:author, :post]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
403
403
  comment.post.writer.name
404
404
  end
405
405
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -408,8 +408,8 @@ if active_record?
408
408
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :writer)
409
409
  end
410
410
 
411
- it "should detect unused preload with comment => author" do
412
- Comment.includes([:author, {:post => :writer}]).where(["base_users.id = ?", BaseUser.first]).references(:base_users).each do |comment|
411
+ it 'should detect unused preload with comment => author' do
412
+ Comment.includes([:author, { :post => :writer }]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
413
413
  comment.post.writer.name
414
414
  end
415
415
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -418,7 +418,7 @@ if active_record?
418
418
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
419
419
  end
420
420
 
421
- it "should detect non preloading with writer => newspaper" do
421
+ it 'should detect non preloading with writer => newspaper' do
422
422
  Comment.includes(:post => :writer).where("posts.name like '%first%'").references(:posts).each do |comment|
423
423
  comment.post.writer.newspaper.name
424
424
  end
@@ -428,9 +428,9 @@ if active_record?
428
428
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Writer, :newspaper)
429
429
  end
430
430
 
431
- it "should not raise a stack error from posts to category" do
431
+ it 'should not raise a stack error from posts to category' do
432
432
  expect {
433
- Comment.includes({:post => :category}).each do |com|
433
+ Comment.includes({ :post => :category }).each do |com|
434
434
  com.post.category
435
435
  end
436
436
  }.not_to raise_error()
@@ -439,8 +439,8 @@ if active_record?
439
439
  end
440
440
 
441
441
  describe Bullet::Detector::Association, 'has_and_belongs_to_many' do
442
- context "students <=> teachers" do
443
- it "should detect non preload associations" do
442
+ context 'students <=> teachers' do
443
+ it 'should detect non preload associations' do
444
444
  Student.all.each do |student|
445
445
  student.teachers.map(&:name)
446
446
  end
@@ -450,7 +450,7 @@ if active_record?
450
450
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
451
451
  end
452
452
 
453
- it "should detect preload associations" do
453
+ it 'should detect preload associations' do
454
454
  Student.includes(:teachers).each do |student|
455
455
  student.teachers.map(&:name)
456
456
  end
@@ -460,7 +460,7 @@ if active_record?
460
460
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
461
461
  end
462
462
 
463
- it "should detect unused preload associations" do
463
+ it 'should detect unused preload associations' do
464
464
  Student.includes(:teachers).map(&:name)
465
465
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
466
466
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Student, :teachers)
@@ -468,7 +468,7 @@ if active_record?
468
468
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
469
469
  end
470
470
 
471
- it "should detect no unused preload associations" do
471
+ it 'should detect no unused preload associations' do
472
472
  Student.all.map(&:name)
473
473
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
474
474
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -476,7 +476,7 @@ if active_record?
476
476
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
477
477
  end
478
478
 
479
- it "should detect non preload student => teachers with empty?" do
479
+ it 'should detect non preload student => teachers with empty?' do
480
480
  Student.all.each do |student|
481
481
  student.teachers.empty?
482
482
  end
@@ -489,8 +489,8 @@ if active_record?
489
489
  end
490
490
 
491
491
  describe Bullet::Detector::Association, 'has_many :through' do
492
- context "firm => clients" do
493
- it "should detect non preload associations" do
492
+ context 'firm => clients' do
493
+ it 'should detect non preload associations' do
494
494
  Firm.all.each do |firm|
495
495
  firm.clients.map(&:name)
496
496
  end
@@ -500,7 +500,7 @@ if active_record?
500
500
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Firm, :clients)
501
501
  end
502
502
 
503
- it "should detect preload associations" do
503
+ it 'should detect preload associations' do
504
504
  Firm.includes(:clients).each do |firm|
505
505
  firm.clients.map(&:name)
506
506
  end
@@ -510,7 +510,7 @@ if active_record?
510
510
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
511
511
  end
512
512
 
513
- it "should not detect preload associations" do
513
+ it 'should not detect preload associations' do
514
514
  Firm.all.map(&:name)
515
515
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
516
516
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -518,7 +518,7 @@ if active_record?
518
518
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
519
519
  end
520
520
 
521
- it "should detect unused preload associations" do
521
+ it 'should detect unused preload associations' do
522
522
  Firm.includes(:clients).map(&:name)
523
523
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
524
524
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Firm, :clients)
@@ -528,9 +528,9 @@ if active_record?
528
528
  end
529
529
  end
530
530
 
531
- describe Bullet::Detector::Association, "has_one" do
532
- context "company => address" do
533
- it "should detect non preload association" do
531
+ describe Bullet::Detector::Association, 'has_one' do
532
+ context 'company => address' do
533
+ it 'should detect non preload association' do
534
534
  Company.all.each do |company|
535
535
  company.address.name
536
536
  end
@@ -540,7 +540,7 @@ if active_record?
540
540
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Company, :address)
541
541
  end
542
542
 
543
- it "should detect preload association" do
543
+ it 'should detect preload association' do
544
544
  Company.includes(:address).each do |company|
545
545
  company.address.name
546
546
  end
@@ -550,7 +550,7 @@ if active_record?
550
550
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
551
551
  end
552
552
 
553
- it "should not detect preload association" do
553
+ it 'should not detect preload association' do
554
554
  Company.all.map(&:name)
555
555
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
556
556
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -558,7 +558,7 @@ if active_record?
558
558
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
559
559
  end
560
560
 
561
- it "should detect unused preload association" do
561
+ it 'should detect unused preload association' do
562
562
  Company.includes(:address).map(&:name)
563
563
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
564
564
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Company, :address)
@@ -568,8 +568,8 @@ if active_record?
568
568
  end
569
569
  end
570
570
 
571
- describe Bullet::Detector::Association, "has_one => has_many" do
572
- it "should not detect preload association" do
571
+ describe Bullet::Detector::Association, 'has_one => has_many' do
572
+ it 'should not detect preload association' do
573
573
  user = User.first
574
574
  user.submission.replies.map(&:name)
575
575
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -579,8 +579,8 @@ if active_record?
579
579
  end
580
580
  end
581
581
 
582
- describe Bullet::Detector::Association, "call one association that in possible objects" do
583
- it "should not detect preload association" do
582
+ describe Bullet::Detector::Association, 'call one association that in possible objects' do
583
+ it 'should not detect preload association' do
584
584
  Post.all
585
585
  Post.first.comments.map(&:name)
586
586
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -590,9 +590,9 @@ if active_record?
590
590
  end
591
591
  end
592
592
 
593
- describe Bullet::Detector::Association, "query immediately after creation" do
594
- context "with save" do
595
- context "document => children" do
593
+ describe Bullet::Detector::Association, 'query immediately after creation' do
594
+ context 'with save' do
595
+ context 'document => children' do
596
596
  it 'should not detect non preload associations' do
597
597
  document1 = Document.new
598
598
  document1.children.build
@@ -612,8 +612,8 @@ if active_record?
612
612
  end
613
613
  end
614
614
 
615
- context "with save!" do
616
- context "document => children" do
615
+ context 'with save!' do
616
+ context 'document => children' do
617
617
  it 'should not detect non preload associations' do
618
618
  document1 = Document.new
619
619
  document1.children.build
@@ -634,9 +634,9 @@ if active_record?
634
634
  end
635
635
  end
636
636
 
637
- describe Bullet::Detector::Association, "STI" do
638
- context "page => author" do
639
- it "should detect non preload associations" do
637
+ describe Bullet::Detector::Association, 'STI' do
638
+ context 'page => author' do
639
+ it 'should detect non preload associations' do
640
640
  Page.all.each do |page|
641
641
  page.author.name
642
642
  end
@@ -646,7 +646,7 @@ if active_record?
646
646
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Page, :author)
647
647
  end
648
648
 
649
- it "should detect preload associations" do
649
+ it 'should detect preload associations' do
650
650
  Page.includes(:author).each do |page|
651
651
  page.author.name
652
652
  end
@@ -656,7 +656,7 @@ if active_record?
656
656
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
657
657
  end
658
658
 
659
- it "should detect unused preload associations" do
659
+ it 'should detect unused preload associations' do
660
660
  Page.includes(:author).map(&:name)
661
661
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
662
662
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Page, :author)
@@ -664,7 +664,7 @@ if active_record?
664
664
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
665
665
  end
666
666
 
667
- it "should not detect preload associations" do
667
+ it 'should not detect preload associations' do
668
668
  Page.all.map(&:name)
669
669
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
670
670
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -673,11 +673,11 @@ if active_record?
673
673
  end
674
674
  end
675
675
 
676
- context "disable n plus one query" do
676
+ context 'disable n plus one query' do
677
677
  before { Bullet.n_plus_one_query_enable = false }
678
678
  after { Bullet.n_plus_one_query_enable = true }
679
679
 
680
- it "should not detect n plus one query" do
680
+ it 'should not detect n plus one query' do
681
681
  Post.all.each do |post|
682
682
  post.comments.map(&:name)
683
683
  end
@@ -687,7 +687,7 @@ if active_record?
687
687
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
688
688
  end
689
689
 
690
- it "should still detect unused eager loading" do
690
+ it 'should still detect unused eager loading' do
691
691
  Post.includes(:comments).map(&:name)
692
692
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
693
693
 
@@ -696,11 +696,11 @@ if active_record?
696
696
  end
697
697
  end
698
698
 
699
- context "disable unused eager loading" do
699
+ context 'disable unused eager loading' do
700
700
  before { Bullet.unused_eager_loading_enable = false }
701
701
  after { Bullet.unused_eager_loading_enable = true }
702
702
 
703
- it "should not detect unused eager loading" do
703
+ it 'should not detect unused eager loading' do
704
704
  Post.includes(:comments).map(&:name)
705
705
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
706
706
 
@@ -708,7 +708,7 @@ if active_record?
708
708
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
709
709
  end
710
710
 
711
- it "should still detect n plus one query" do
711
+ it 'should still detect n plus one query' do
712
712
  Post.all.each do |post|
713
713
  post.comments.map(&:name)
714
714
  end
@@ -719,11 +719,11 @@ if active_record?
719
719
  end
720
720
  end
721
721
 
722
- context "whitelist n plus one query" do
723
- before { Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments }
722
+ context 'whitelist n plus one query' do
723
+ before { Bullet.add_whitelist :type => :n_plus_one_query, :class_name => 'Post', :association => :comments }
724
724
  after { Bullet.clear_whitelist }
725
725
 
726
- it "should not detect n plus one query" do
726
+ it 'should not detect n plus one query' do
727
727
  Post.all.each do |post|
728
728
  post.comments.map(&:name)
729
729
  end
@@ -733,7 +733,7 @@ if active_record?
733
733
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
734
734
  end
735
735
 
736
- it "should still detect unused eager loading" do
736
+ it 'should still detect unused eager loading' do
737
737
  Post.includes(:comments).map(&:name)
738
738
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
739
739
 
@@ -742,11 +742,11 @@ if active_record?
742
742
  end
743
743
  end
744
744
 
745
- context "whitelist unused eager loading" do
746
- before { Bullet.add_whitelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments }
745
+ context 'whitelist unused eager loading' do
746
+ before { Bullet.add_whitelist :type => :unused_eager_loading, :class_name => 'Post', :association => :comments }
747
747
  after { Bullet.clear_whitelist }
748
748
 
749
- it "should not detect unused eager loading" do
749
+ it 'should not detect unused eager loading' do
750
750
  Post.includes(:comments).map(&:name)
751
751
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
752
752
 
@@ -754,7 +754,7 @@ if active_record?
754
754
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
755
755
  end
756
756
 
757
- it "should still detect n plus one query" do
757
+ it 'should still detect n plus one query' do
758
758
  Post.all.each do |post|
759
759
  post.comments.map(&:name)
760
760
  end