bullet 6.0.0 → 6.1.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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile.rails-6.0 +1 -1
  5. data/README.md +23 -9
  6. data/lib/bullet.rb +26 -16
  7. data/lib/bullet/active_job.rb +9 -0
  8. data/lib/bullet/active_record4.rb +9 -24
  9. data/lib/bullet/active_record41.rb +7 -19
  10. data/lib/bullet/active_record42.rb +8 -16
  11. data/lib/bullet/active_record5.rb +188 -170
  12. data/lib/bullet/active_record52.rb +176 -161
  13. data/lib/bullet/active_record60.rb +193 -171
  14. data/lib/bullet/bullet_xhr.js +20 -15
  15. data/lib/bullet/dependency.rb +36 -34
  16. data/lib/bullet/detector/association.rb +24 -18
  17. data/lib/bullet/detector/base.rb +1 -2
  18. data/lib/bullet/detector/counter_cache.rb +10 -6
  19. data/lib/bullet/detector/n_plus_one_query.rb +18 -8
  20. data/lib/bullet/detector/unused_eager_loading.rb +5 -2
  21. data/lib/bullet/mongoid4x.rb +2 -6
  22. data/lib/bullet/mongoid5x.rb +2 -6
  23. data/lib/bullet/mongoid6x.rb +2 -6
  24. data/lib/bullet/mongoid7x.rb +2 -6
  25. data/lib/bullet/notification/base.rb +14 -18
  26. data/lib/bullet/notification/n_plus_one_query.rb +2 -4
  27. data/lib/bullet/notification/unused_eager_loading.rb +2 -4
  28. data/lib/bullet/rack.rb +5 -3
  29. data/lib/bullet/stack_trace_filter.rb +5 -10
  30. data/lib/bullet/version.rb +1 -1
  31. data/lib/generators/bullet/install_generator.rb +4 -2
  32. data/perf/benchmark.rb +8 -14
  33. data/spec/bullet/detector/counter_cache_spec.rb +5 -5
  34. data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
  35. data/spec/bullet/detector/unused_eager_loading_spec.rb +29 -12
  36. data/spec/bullet/notification/base_spec.rb +1 -3
  37. data/spec/bullet/notification/n_plus_one_query_spec.rb +18 -3
  38. data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
  39. data/spec/bullet/rack_spec.rb +20 -5
  40. data/spec/bullet/registry/association_spec.rb +2 -2
  41. data/spec/bullet/registry/base_spec.rb +1 -1
  42. data/spec/bullet_spec.rb +10 -29
  43. data/spec/integration/active_record/association_spec.rb +42 -122
  44. data/spec/integration/counter_cache_spec.rb +10 -30
  45. data/spec/integration/mongoid/association_spec.rb +18 -32
  46. data/spec/models/folder.rb +1 -2
  47. data/spec/models/group.rb +1 -2
  48. data/spec/models/page.rb +1 -2
  49. data/spec/models/writer.rb +1 -2
  50. data/spec/spec_helper.rb +6 -10
  51. data/spec/support/bullet_ext.rb +8 -9
  52. data/spec/support/mongo_seed.rb +2 -16
  53. metadata +3 -2
@@ -6,9 +6,7 @@ if active_record?
6
6
  describe Bullet::Detector::Association, 'has_many' do
7
7
  context 'post => comments' do
8
8
  it 'should detect non preload post => comments' do
9
- Post.all.each do |post|
10
- post.comments.map(&:name)
11
- end
9
+ Post.all.each { |post| post.comments.map(&:name) }
12
10
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
13
11
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
14
12
 
@@ -16,9 +14,7 @@ if active_record?
16
14
  end
17
15
 
18
16
  it 'should detect non preload post => comments for find_by_sql' do
19
- Post.find_by_sql('SELECT * FROM posts').each do |post|
20
- post.comments.map(&:name)
21
- end
17
+ Post.find_by_sql('SELECT * FROM posts').each { |post| post.comments.map(&:name) }
22
18
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
23
19
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
24
20
 
@@ -26,9 +22,7 @@ if active_record?
26
22
  end
27
23
 
28
24
  it 'should detect preload with post => comments' do
29
- Post.includes(:comments).each do |post|
30
- post.comments.map(&:name)
31
- end
25
+ Post.includes(:comments).each { |post| post.comments.map(&:name) }
32
26
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
33
27
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
34
28
 
@@ -65,9 +59,7 @@ if active_record?
65
59
  end
66
60
 
67
61
  it 'should detect non preload post => comments with empty?' do
68
- Post.all.each do |post|
69
- post.comments.empty?
70
- end
62
+ Post.all.each { |post| post.comments.empty? }
71
63
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
72
64
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
73
65
 
@@ -76,9 +68,7 @@ if active_record?
76
68
 
77
69
  it 'should detect non preload post => comments with include?' do
78
70
  comment = Comment.last
79
- Post.all.each do |post|
80
- post.comments.include?(comment)
81
- end
71
+ Post.all.each { |post| post.comments.include?(comment) }
82
72
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
83
73
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
84
74
 
@@ -86,9 +76,7 @@ if active_record?
86
76
  end
87
77
 
88
78
  it 'should not detect unused preload person => pets with empty?' do
89
- Person.all.each do |person|
90
- person.pets.empty?
91
- end
79
+ Person.all.each { |person| person.pets.empty? }
92
80
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
93
81
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
94
82
 
@@ -98,11 +86,7 @@ if active_record?
98
86
 
99
87
  context 'category => posts => comments' do
100
88
  it 'should detect non preload category => posts => comments' do
101
- Category.all.each do |category|
102
- category.posts.each do |post|
103
- post.comments.map(&:name)
104
- end
105
- end
89
+ Category.all.each { |category| category.posts.each { |post| post.comments.map(&:name) } }
106
90
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
107
91
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
108
92
 
@@ -111,11 +95,7 @@ if active_record?
111
95
  end
112
96
 
113
97
  it 'should detect preload category => posts, but no post => comments' do
114
- Category.includes(:posts).each do |category|
115
- category.posts.each do |post|
116
- post.comments.map(&:name)
117
- end
118
- end
98
+ Category.includes(:posts).each { |category| category.posts.each { |post| post.comments.map(&:name) } }
119
99
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
120
100
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
121
101
 
@@ -124,11 +104,7 @@ if active_record?
124
104
  end
125
105
 
126
106
  it 'should detect preload with category => posts => comments' do
127
- Category.includes(posts: :comments).each do |category|
128
- category.posts.each do |post|
129
- post.comments.map(&:name)
130
- end
131
- end
107
+ Category.includes(posts: :comments).each { |category| category.posts.each { |post| post.comments.map(&:name) } }
132
108
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
133
109
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
134
110
 
@@ -137,9 +113,7 @@ if active_record?
137
113
 
138
114
  it 'should detect preload with category => posts => comments with posts.id > 0' do
139
115
  Category.includes(posts: :comments).where('posts.id > 0').references(:posts).each do |category|
140
- category.posts.each do |post|
141
- post.comments.map(&:name)
142
- end
116
+ category.posts.each { |post| post.comments.map(&:name) }
143
117
  end
144
118
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
145
119
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -156,9 +130,7 @@ if active_record?
156
130
  end
157
131
 
158
132
  it 'should detect unused preload with post => commnets, no category => posts' do
159
- Category.includes(posts: :comments).each do |category|
160
- category.posts.map(&:name)
161
- end
133
+ Category.includes(posts: :comments).each { |category| category.posts.map(&:name) }
162
134
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
163
135
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Post, :comments)
164
136
 
@@ -212,9 +184,7 @@ if active_record?
212
184
  end
213
185
 
214
186
  it 'should detect unused preload with category => entries, but not with category => posts' do
215
- Category.includes(%i[posts entries]).each do |category|
216
- category.posts.map(&:name)
217
- end
187
+ Category.includes(%i[posts entries]).each { |category| category.posts.map(&:name) }
218
188
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
219
189
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Category, :posts)
220
190
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Category, :entries)
@@ -225,9 +195,7 @@ if active_record?
225
195
 
226
196
  context 'post => comment' do
227
197
  it 'should detect unused preload with post => comments' do
228
- Post.includes(:comments).each do |post|
229
- post.comments.first&.name
230
- end
198
+ Post.includes(:comments).each { |post| post.comments.first&.name }
231
199
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
232
200
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
233
201
 
@@ -272,9 +240,7 @@ if active_record?
272
240
 
273
241
  context 'scope for_category_name' do
274
242
  it 'should detect preload with post => category' do
275
- Post.in_category_name('first').references(:categories).each do |post|
276
- post.category.name
277
- end
243
+ Post.in_category_name('first').references(:categories).each { |post| post.category.name }
278
244
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
279
245
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
280
246
 
@@ -292,9 +258,7 @@ if active_record?
292
258
 
293
259
  context 'scope preload_comments' do
294
260
  it 'should detect preload post => comments with scope' do
295
- Post.preload_comments.each do |post|
296
- post.comments.map(&:name)
297
- end
261
+ Post.preload_comments.each { |post| post.comments.map(&:name) }
298
262
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
299
263
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
300
264
 
@@ -314,9 +278,7 @@ if active_record?
314
278
  describe Bullet::Detector::Association, 'belongs_to' do
315
279
  context 'comment => post' do
316
280
  it 'should detect non preload with comment => post' do
317
- Comment.all.each do |comment|
318
- comment.post.name
319
- end
281
+ Comment.all.each { |comment| comment.post.name }
320
282
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
321
283
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
322
284
 
@@ -332,9 +294,7 @@ if active_record?
332
294
  end
333
295
 
334
296
  it 'should detect preload with comment => post' do
335
- Comment.includes(:post).each do |comment|
336
- comment.post.name
337
- end
297
+ Comment.includes(:post).each { |comment| comment.post.name }
338
298
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
339
299
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
340
300
 
@@ -371,9 +331,7 @@ if active_record?
371
331
 
372
332
  context 'comment => post => category' do
373
333
  it 'should detect non preload association with comment => post' do
374
- Comment.all.each do |comment|
375
- comment.post.category.name
376
- end
334
+ Comment.all.each { |comment| comment.post.category.name }
377
335
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
378
336
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
379
337
 
@@ -390,9 +348,7 @@ if active_record?
390
348
  end
391
349
 
392
350
  it 'should detect non preload association with post => category' do
393
- Comment.includes(:post).each do |comment|
394
- comment.post.category.name
395
- end
351
+ Comment.includes(:post).each { |comment| comment.post.category.name }
396
352
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
397
353
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
398
354
 
@@ -400,9 +356,7 @@ if active_record?
400
356
  end
401
357
 
402
358
  it 'should not detect unpreload association' do
403
- Comment.includes(post: :category).each do |comment|
404
- comment.post.category.name
405
- end
359
+ Comment.includes(post: :category).each { |comment| comment.post.category.name }
406
360
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
407
361
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
408
362
 
@@ -412,9 +366,8 @@ if active_record?
412
366
 
413
367
  context 'comment => author, post => writer' do
414
368
  it 'should detect non preloaded writer' do
415
- Comment.includes(%i[author post]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
416
- comment.post.writer.name
417
- end
369
+ Comment.includes(%i[author post]).where(['base_users.id = ?', BaseUser.first]).references(:base_users)
370
+ .each { |comment| comment.post.writer.name }
418
371
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
419
372
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
420
373
 
@@ -422,9 +375,10 @@ if active_record?
422
375
  end
423
376
 
424
377
  it 'should detect unused preload with comment => author' do
425
- Comment.includes([:author, { post: :writer }]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
426
- comment.post.writer.name
427
- end
378
+ Comment.includes([:author, { post: :writer }]).where(['base_users.id = ?', BaseUser.first]).references(
379
+ :base_users
380
+ )
381
+ .each { |comment| comment.post.writer.name }
428
382
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
429
383
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
430
384
 
@@ -442,11 +396,7 @@ if active_record?
442
396
  end
443
397
 
444
398
  it 'should not raise a stack error from posts to category' do
445
- expect {
446
- Comment.includes(post: :category).each do |com|
447
- com.post.category
448
- end
449
- }.not_to raise_error
399
+ expect { Comment.includes(post: :category).each { |com| com.post.category } }.not_to raise_error
450
400
  end
451
401
  end
452
402
  end
@@ -454,9 +404,7 @@ if active_record?
454
404
  describe Bullet::Detector::Association, 'has_and_belongs_to_many' do
455
405
  context 'students <=> teachers' do
456
406
  it 'should detect non preload associations' do
457
- Student.all.each do |student|
458
- student.teachers.map(&:name)
459
- end
407
+ Student.all.each { |student| student.teachers.map(&:name) }
460
408
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
461
409
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
462
410
 
@@ -464,9 +412,7 @@ if active_record?
464
412
  end
465
413
 
466
414
  it 'should detect preload associations' do
467
- Student.includes(:teachers).each do |student|
468
- student.teachers.map(&:name)
469
- end
415
+ Student.includes(:teachers).each { |student| student.teachers.map(&:name) }
470
416
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
471
417
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
472
418
 
@@ -490,9 +436,7 @@ if active_record?
490
436
  end
491
437
 
492
438
  it 'should detect non preload student => teachers with empty?' do
493
- Student.all.each do |student|
494
- student.teachers.empty?
495
- end
439
+ Student.all.each { |student| student.teachers.empty? }
496
440
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
497
441
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
498
442
 
@@ -504,9 +448,7 @@ if active_record?
504
448
  describe Bullet::Detector::Association, 'has_many :through' do
505
449
  context 'firm => clients' do
506
450
  it 'should detect non preload associations' do
507
- Firm.all.each do |firm|
508
- firm.clients.map(&:name)
509
- end
451
+ Firm.all.each { |firm| firm.clients.map(&:name) }
510
452
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
511
453
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
512
454
 
@@ -514,9 +456,7 @@ if active_record?
514
456
  end
515
457
 
516
458
  it 'should detect preload associations' do
517
- Firm.includes(:clients).each do |firm|
518
- firm.clients.map(&:name)
519
- end
459
+ Firm.includes(:clients).each { |firm| firm.clients.map(&:name) }
520
460
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
521
461
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
522
462
 
@@ -542,9 +482,7 @@ if active_record?
542
482
 
543
483
  context 'firm => clients => groups' do
544
484
  it 'should detect non preload associations' do
545
- Firm.all.each do |firm|
546
- firm.groups.map(&:name)
547
- end
485
+ Firm.all.each { |firm| firm.groups.map(&:name) }
548
486
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
549
487
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
550
488
 
@@ -552,9 +490,7 @@ if active_record?
552
490
  end
553
491
 
554
492
  it 'should detect preload associations' do
555
- Firm.includes(:groups).each do |firm|
556
- firm.groups.map(&:name)
557
- end
493
+ Firm.includes(:groups).each { |firm| firm.groups.map(&:name) }
558
494
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
559
495
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
560
496
 
@@ -582,9 +518,7 @@ if active_record?
582
518
  describe Bullet::Detector::Association, 'has_one' do
583
519
  context 'company => address' do
584
520
  it 'should detect non preload association' do
585
- Company.all.each do |company|
586
- company.address.name
587
- end
521
+ Company.all.each { |company| company.address.name }
588
522
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
589
523
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
590
524
 
@@ -592,9 +526,7 @@ if active_record?
592
526
  end
593
527
 
594
528
  it 'should detect preload association' do
595
- Company.includes(:address).each do |company|
596
- company.address.name
597
- end
529
+ Company.includes(:address).each { |company| company.address.name }
598
530
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
599
531
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
600
532
 
@@ -688,9 +620,7 @@ if active_record?
688
620
  describe Bullet::Detector::Association, 'STI' do
689
621
  context 'page => author' do
690
622
  it 'should detect non preload associations' do
691
- Page.all.each do |page|
692
- page.author.name
693
- end
623
+ Page.all.each { |page| page.author.name }
694
624
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
695
625
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
696
626
 
@@ -698,9 +628,7 @@ if active_record?
698
628
  end
699
629
 
700
630
  it 'should detect preload associations' do
701
- Page.includes(:author).each do |page|
702
- page.author.name
703
- end
631
+ Page.includes(:author).each { |page| page.author.name }
704
632
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
705
633
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
706
634
 
@@ -729,9 +657,7 @@ if active_record?
729
657
  after { Bullet.n_plus_one_query_enable = true }
730
658
 
731
659
  it 'should not detect n plus one query' do
732
- Post.all.each do |post|
733
- post.comments.map(&:name)
734
- end
660
+ Post.all.each { |post| post.comments.map(&:name) }
735
661
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
736
662
 
737
663
  expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(Post, :comments)
@@ -760,9 +686,7 @@ if active_record?
760
686
  end
761
687
 
762
688
  it 'should still detect n plus one query' do
763
- Post.all.each do |post|
764
- post.comments.map(&:name)
765
- end
689
+ Post.all.each { |post| post.comments.map(&:name) }
766
690
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
767
691
 
768
692
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
@@ -775,9 +699,7 @@ if active_record?
775
699
  after { Bullet.clear_whitelist }
776
700
 
777
701
  it 'should not detect n plus one query' do
778
- Post.all.each do |post|
779
- post.comments.map(&:name)
780
- end
702
+ Post.all.each { |post| post.comments.map(&:name) }
781
703
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
782
704
 
783
705
  expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(Post, :comments)
@@ -806,9 +728,7 @@ if active_record?
806
728
  end
807
729
 
808
730
  it 'should still detect n plus one query' do
809
- Post.all.each do |post|
810
- post.comments.map(&:name)
811
- end
731
+ Post.all.each { |post| post.comments.map(&:name) }
812
732
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
813
733
 
814
734
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
@@ -4,25 +4,17 @@ require 'spec_helper'
4
4
 
5
5
  if !mongoid? && active_record?
6
6
  describe Bullet::Detector::CounterCache do
7
- before(:each) do
8
- Bullet.start_request
9
- end
7
+ before(:each) { Bullet.start_request }
10
8
 
11
- after(:each) do
12
- Bullet.end_request
13
- end
9
+ after(:each) { Bullet.end_request }
14
10
 
15
11
  it 'should need counter cache with all cities' do
16
- Country.all.each do |country|
17
- country.cities.size
18
- end
12
+ Country.all.each { |country| country.cities.size }
19
13
  expect(Bullet.collected_counter_cache_notifications).not_to be_empty
20
14
  end
21
15
 
22
16
  it 'should not need counter cache if already define counter_cache' do
23
- Person.all.each do |person|
24
- person.pets.size
25
- end
17
+ Person.all.each { |person| person.pets.size }
26
18
  expect(Bullet.collected_counter_cache_notifications).to be_empty
27
19
  end
28
20
 
@@ -32,32 +24,24 @@ if !mongoid? && active_record?
32
24
  end
33
25
 
34
26
  it 'should not need counter cache without size' do
35
- Country.includes(:cities).each do |country|
36
- country.cities.empty?
37
- end
27
+ Country.includes(:cities).each { |country| country.cities.empty? }
38
28
  expect(Bullet.collected_counter_cache_notifications).to be_empty
39
29
  end
40
30
 
41
31
  if active_record5? || active_record6?
42
32
  it 'should not need counter cache for has_many through' do
43
- Client.all.each do |client|
44
- client.firms.size
45
- end
33
+ Client.all.each { |client| client.firms.size }
46
34
  expect(Bullet.collected_counter_cache_notifications).to be_empty
47
35
  end
48
36
  else
49
37
  it 'should need counter cache for has_many through' do
50
- Client.all.each do |client|
51
- client.firms.size
52
- end
38
+ Client.all.each { |client| client.firms.size }
53
39
  expect(Bullet.collected_counter_cache_notifications).not_to be_empty
54
40
  end
55
41
  end
56
42
 
57
43
  it 'should not need counter cache with part of cities' do
58
- Country.all.each do |country|
59
- country.cities.where(name: 'first').size
60
- end
44
+ Country.all.each { |country| country.cities.where(name: 'first').size }
61
45
  expect(Bullet.collected_counter_cache_notifications).to be_empty
62
46
  end
63
47
 
@@ -66,9 +50,7 @@ if !mongoid? && active_record?
66
50
  after { Bullet.counter_cache_enable = true }
67
51
 
68
52
  it 'should not detect counter cache' do
69
- Country.all.each do |country|
70
- country.cities.size
71
- end
53
+ Country.all.each { |country| country.cities.size }
72
54
  expect(Bullet.collected_counter_cache_notifications).to be_empty
73
55
  end
74
56
  end
@@ -78,9 +60,7 @@ if !mongoid? && active_record?
78
60
  after { Bullet.clear_whitelist }
79
61
 
80
62
  it 'should not detect counter cache' do
81
- Country.all.each do |country|
82
- country.cities.size
83
- end
63
+ Country.all.each { |country| country.cities.size }
84
64
  expect(Bullet.collected_counter_cache_notifications).to be_empty
85
65
  end
86
66
  end