bullet 5.7.0 → 6.0.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 (114) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +27 -1
  4. data/Gemfile.mongoid-7.0 +15 -0
  5. data/Gemfile.rails-4.0 +1 -1
  6. data/Gemfile.rails-4.1 +1 -1
  7. data/Gemfile.rails-4.2 +1 -1
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/Gemfile.rails-5.1 +1 -1
  10. data/Gemfile.rails-5.2 +2 -2
  11. data/Gemfile.rails-6.0 +15 -0
  12. data/Guardfile +1 -1
  13. data/README.md +10 -5
  14. data/Rakefile +5 -5
  15. data/bullet.gemspec +12 -6
  16. data/lib/bullet/active_record4.rb +10 -14
  17. data/lib/bullet/active_record41.rb +8 -14
  18. data/lib/bullet/active_record42.rb +16 -22
  19. data/lib/bullet/active_record5.rb +69 -49
  20. data/lib/bullet/active_record52.rb +40 -40
  21. data/lib/bullet/active_record60.rb +245 -0
  22. data/lib/bullet/bullet_xhr.js +58 -0
  23. data/lib/bullet/dependency.rb +19 -5
  24. data/lib/bullet/detector/association.rb +18 -16
  25. data/lib/bullet/detector/base.rb +2 -0
  26. data/lib/bullet/detector/counter_cache.rb +13 -10
  27. data/lib/bullet/detector/n_plus_one_query.rb +21 -19
  28. data/lib/bullet/detector/unused_eager_loading.rb +27 -22
  29. data/lib/bullet/detector.rb +2 -0
  30. data/lib/bullet/ext/object.rb +9 -5
  31. data/lib/bullet/ext/string.rb +3 -1
  32. data/lib/bullet/mongoid4x.rb +7 -2
  33. data/lib/bullet/mongoid5x.rb +7 -2
  34. data/lib/bullet/mongoid6x.rb +11 -6
  35. data/lib/bullet/mongoid7x.rb +61 -0
  36. data/lib/bullet/notification/base.rb +21 -15
  37. data/lib/bullet/notification/counter_cache.rb +2 -0
  38. data/lib/bullet/notification/n_plus_one_query.rb +6 -4
  39. data/lib/bullet/notification/unused_eager_loading.rb +6 -4
  40. data/lib/bullet/notification.rb +2 -0
  41. data/lib/bullet/notification_collector.rb +2 -1
  42. data/lib/bullet/rack.rb +52 -31
  43. data/lib/bullet/registry/association.rb +2 -0
  44. data/lib/bullet/registry/base.rb +2 -0
  45. data/lib/bullet/registry/object.rb +2 -0
  46. data/lib/bullet/registry.rb +2 -0
  47. data/lib/bullet/stack_trace_filter.rb +57 -21
  48. data/lib/bullet/version.rb +2 -1
  49. data/lib/bullet.rb +48 -31
  50. data/lib/generators/bullet/install_generator.rb +5 -3
  51. data/perf/benchmark.rb +9 -7
  52. data/rails/init.rb +2 -0
  53. data/spec/bullet/detector/association_spec.rb +2 -0
  54. data/spec/bullet/detector/base_spec.rb +2 -0
  55. data/spec/bullet/detector/counter_cache_spec.rb +2 -0
  56. data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -8
  57. data/spec/bullet/detector/unused_eager_loading_spec.rb +2 -0
  58. data/spec/bullet/ext/object_spec.rb +12 -5
  59. data/spec/bullet/ext/string_spec.rb +2 -0
  60. data/spec/bullet/notification/base_spec.rb +8 -6
  61. data/spec/bullet/notification/counter_cache_spec.rb +3 -1
  62. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -1
  63. data/spec/bullet/notification/unused_eager_loading_spec.rb +3 -1
  64. data/spec/bullet/notification_collector_spec.rb +2 -0
  65. data/spec/bullet/rack_spec.rb +22 -12
  66. data/spec/bullet/registry/association_spec.rb +4 -2
  67. data/spec/bullet/registry/base_spec.rb +5 -3
  68. data/spec/bullet/registry/object_spec.rb +2 -0
  69. data/spec/bullet_spec.rb +9 -7
  70. data/spec/integration/active_record/association_spec.rb +70 -19
  71. data/spec/integration/counter_cache_spec.rb +5 -3
  72. data/spec/integration/mongoid/association_spec.rb +2 -0
  73. data/spec/models/address.rb +2 -0
  74. data/spec/models/author.rb +2 -0
  75. data/spec/models/base_user.rb +2 -0
  76. data/spec/models/category.rb +2 -0
  77. data/spec/models/city.rb +2 -0
  78. data/spec/models/client.rb +4 -0
  79. data/spec/models/comment.rb +2 -0
  80. data/spec/models/company.rb +2 -0
  81. data/spec/models/country.rb +2 -0
  82. data/spec/models/document.rb +2 -0
  83. data/spec/models/entry.rb +2 -0
  84. data/spec/models/firm.rb +3 -0
  85. data/spec/models/folder.rb +2 -0
  86. data/spec/models/group.rb +4 -0
  87. data/spec/models/mongoid/address.rb +3 -1
  88. data/spec/models/mongoid/category.rb +4 -2
  89. data/spec/models/mongoid/comment.rb +3 -1
  90. data/spec/models/mongoid/company.rb +3 -1
  91. data/spec/models/mongoid/entry.rb +3 -1
  92. data/spec/models/mongoid/post.rb +6 -4
  93. data/spec/models/mongoid/user.rb +2 -0
  94. data/spec/models/newspaper.rb +2 -0
  95. data/spec/models/page.rb +2 -0
  96. data/spec/models/person.rb +2 -0
  97. data/spec/models/pet.rb +2 -0
  98. data/spec/models/post.rb +17 -0
  99. data/spec/models/relationship.rb +2 -0
  100. data/spec/models/reply.rb +2 -0
  101. data/spec/models/student.rb +2 -0
  102. data/spec/models/submission.rb +2 -0
  103. data/spec/models/teacher.rb +2 -0
  104. data/spec/models/user.rb +2 -0
  105. data/spec/models/writer.rb +2 -0
  106. data/spec/spec_helper.rb +3 -1
  107. data/spec/support/bullet_ext.rb +2 -0
  108. data/spec/support/mongo_seed.rb +32 -30
  109. data/spec/support/rack_double.rb +9 -16
  110. data/spec/support/sqlite_seed.rb +84 -75
  111. data/tasks/bullet_tasks.rake +2 -0
  112. data/test.sh +2 -0
  113. data/update.sh +1 -0
  114. metadata +17 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if active_record?
@@ -122,7 +124,7 @@ if active_record?
122
124
  end
123
125
 
124
126
  it 'should detect preload with category => posts => comments' do
125
- Category.includes({ :posts => :comments }).each do |category|
127
+ Category.includes(posts: :comments).each do |category|
126
128
  category.posts.each do |post|
127
129
  post.comments.map(&:name)
128
130
  end
@@ -134,7 +136,7 @@ if active_record?
134
136
  end
135
137
 
136
138
  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|
139
+ Category.includes(posts: :comments).where('posts.id > 0').references(:posts).each do |category|
138
140
  category.posts.each do |post|
139
141
  post.comments.map(&:name)
140
142
  end
@@ -146,7 +148,7 @@ if active_record?
146
148
  end
147
149
 
148
150
  it 'should detect unused preload with category => posts => comments' do
149
- Category.includes({ :posts => :comments }).map(&:name)
151
+ Category.includes(posts: :comments).map(&:name)
150
152
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
151
153
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Post, :comments)
152
154
 
@@ -154,7 +156,7 @@ if active_record?
154
156
  end
155
157
 
156
158
  it 'should detect unused preload with post => commnets, no category => posts' do
157
- Category.includes({ :posts => :comments }).each do |category|
159
+ Category.includes(posts: :comments).each do |category|
158
160
  category.posts.map(&:name)
159
161
  end
160
162
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -190,7 +192,7 @@ if active_record?
190
192
  end
191
193
 
192
194
  it 'should detect preload with category => [posts, entries]' do
193
- Category.includes([:posts, :entries]).each do |category|
195
+ Category.includes(%i[posts entries]).each do |category|
194
196
  category.posts.map(&:name)
195
197
  category.entries.map(&:name)
196
198
  end
@@ -201,7 +203,7 @@ if active_record?
201
203
  end
202
204
 
203
205
  it 'should detect unused preload with category => [posts, entries]' do
204
- Category.includes([:posts, :entries]).map(&:name)
206
+ Category.includes(%i[posts entries]).map(&:name)
205
207
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
206
208
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Category, :posts)
207
209
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Category, :entries)
@@ -210,7 +212,7 @@ if active_record?
210
212
  end
211
213
 
212
214
  it 'should detect unused preload with category => entries, but not with category => posts' do
213
- Category.includes([:posts, :entries]).each do |category|
215
+ Category.includes(%i[posts entries]).each do |category|
214
216
  category.posts.map(&:name)
215
217
  end
216
218
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -224,7 +226,7 @@ if active_record?
224
226
  context 'post => comment' do
225
227
  it 'should detect unused preload with post => comments' do
226
228
  Post.includes(:comments).each do |post|
227
- post.comments.first.name if post.comments.first
229
+ post.comments.first&.name
228
230
  end
229
231
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
230
232
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
@@ -244,7 +246,7 @@ if active_record?
244
246
  category = Category.first
245
247
  category.draft_post.destroy!
246
248
  post = category.draft_post
247
- post.update_attributes!(link: true)
249
+ post.update!(link: true)
248
250
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
249
251
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
250
252
 
@@ -257,7 +259,7 @@ if active_record?
257
259
 
258
260
  context 'category => posts => writer' do
259
261
  it 'should not detect unused preload associations' do
260
- category = Category.includes({ :posts => :writer }).order('id DESC').find_by_name('first')
262
+ category = Category.includes(posts: :writer).order('id DESC').find_by_name('first')
261
263
  category.posts.map do |post|
262
264
  post.name
263
265
  post.writer.name
@@ -329,7 +331,7 @@ if active_record?
329
331
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
330
332
  end
331
333
 
332
- it 'should dtect preload with comment => post' do
334
+ it 'should detect preload with comment => post' do
333
335
  Comment.includes(:post).each do |comment|
334
336
  comment.post.name
335
337
  end
@@ -354,6 +356,17 @@ if active_record?
354
356
 
355
357
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
356
358
  end
359
+
360
+ it 'should not detect newly assigned object in an after_save' do
361
+ new_post = Post.new(category: Category.first)
362
+
363
+ new_post.trigger_after_save = true
364
+ new_post.save!
365
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
366
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
367
+
368
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
369
+ end
357
370
  end
358
371
 
359
372
  context 'comment => post => category' do
@@ -387,7 +400,7 @@ if active_record?
387
400
  end
388
401
 
389
402
  it 'should not detect unpreload association' do
390
- Comment.includes(:post => :category).each do |comment|
403
+ Comment.includes(post: :category).each do |comment|
391
404
  comment.post.category.name
392
405
  end
393
406
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -399,7 +412,7 @@ if active_record?
399
412
 
400
413
  context 'comment => author, post => writer' do
401
414
  it 'should detect non preloaded writer' do
402
- Comment.includes([:author, :post]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
415
+ Comment.includes(%i[author post]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
403
416
  comment.post.writer.name
404
417
  end
405
418
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -409,7 +422,7 @@ if active_record?
409
422
  end
410
423
 
411
424
  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|
425
+ Comment.includes([:author, { post: :writer }]).where(['base_users.id = ?', BaseUser.first]).references(:base_users).each do |comment|
413
426
  comment.post.writer.name
414
427
  end
415
428
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -419,7 +432,7 @@ if active_record?
419
432
  end
420
433
 
421
434
  it 'should detect non preloading with writer => newspaper' do
422
- Comment.includes(:post => :writer).where("posts.name like '%first%'").references(:posts).each do |comment|
435
+ Comment.includes(post: :writer).where("posts.name like '%first%'").references(:posts).each do |comment|
423
436
  comment.post.writer.newspaper.name
424
437
  end
425
438
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -430,10 +443,10 @@ if active_record?
430
443
 
431
444
  it 'should not raise a stack error from posts to category' do
432
445
  expect {
433
- Comment.includes({ :post => :category }).each do |com|
446
+ Comment.includes(post: :category).each do |com|
434
447
  com.post.category
435
448
  end
436
- }.not_to raise_error()
449
+ }.not_to raise_error
437
450
  end
438
451
  end
439
452
  end
@@ -526,6 +539,44 @@ if active_record?
526
539
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
527
540
  end
528
541
  end
542
+
543
+ context 'firm => clients => groups' do
544
+ it 'should detect non preload associations' do
545
+ Firm.all.each do |firm|
546
+ firm.groups.map(&:name)
547
+ end
548
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
549
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
550
+
551
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Firm, :groups)
552
+ end
553
+
554
+ it 'should detect preload associations' do
555
+ Firm.includes(:groups).each do |firm|
556
+ firm.groups.map(&:name)
557
+ end
558
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
559
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
560
+
561
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
562
+ end
563
+
564
+ it 'should not detect preload associations' do
565
+ Firm.all.map(&:name)
566
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
567
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
568
+
569
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
570
+ end
571
+
572
+ it 'should detect unused preload associations' do
573
+ Firm.includes(:groups).map(&:name)
574
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
575
+ expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Firm, :groups)
576
+
577
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
578
+ end
579
+ end
529
580
  end
530
581
 
531
582
  describe Bullet::Detector::Association, 'has_one' do
@@ -720,7 +771,7 @@ if active_record?
720
771
  end
721
772
 
722
773
  context 'whitelist n plus one query' do
723
- before { Bullet.add_whitelist :type => :n_plus_one_query, :class_name => 'Post', :association => :comments }
774
+ before { Bullet.add_whitelist type: :n_plus_one_query, class_name: 'Post', association: :comments }
724
775
  after { Bullet.clear_whitelist }
725
776
 
726
777
  it 'should not detect n plus one query' do
@@ -743,7 +794,7 @@ if active_record?
743
794
  end
744
795
 
745
796
  context 'whitelist unused eager loading' do
746
- before { Bullet.add_whitelist :type => :unused_eager_loading, :class_name => 'Post', :association => :comments }
797
+ before { Bullet.add_whitelist type: :unused_eager_loading, class_name: 'Post', association: :comments }
747
798
  after { Bullet.clear_whitelist }
748
799
 
749
800
  it 'should not detect unused eager loading' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if !mongoid? && active_record?
@@ -36,7 +38,7 @@ if !mongoid? && active_record?
36
38
  expect(Bullet.collected_counter_cache_notifications).to be_empty
37
39
  end
38
40
 
39
- if active_record5?
41
+ if active_record5? || active_record6?
40
42
  it 'should not need counter cache for has_many through' do
41
43
  Client.all.each do |client|
42
44
  client.firms.size
@@ -54,7 +56,7 @@ if !mongoid? && active_record?
54
56
 
55
57
  it 'should not need counter cache with part of cities' do
56
58
  Country.all.each do |country|
57
- country.cities.where(:name => 'first').size
59
+ country.cities.where(name: 'first').size
58
60
  end
59
61
  expect(Bullet.collected_counter_cache_notifications).to be_empty
60
62
  end
@@ -72,7 +74,7 @@ if !mongoid? && active_record?
72
74
  end
73
75
 
74
76
  context 'whitelist' do
75
- before { Bullet.add_whitelist :type => :counter_cache, :class_name => 'Country', :association => :cities }
77
+ before { Bullet.add_whitelist type: :counter_cache, class_name: 'Country', association: :cities }
76
78
  after { Bullet.clear_whitelist }
77
79
 
78
80
  it 'should not detect counter cache' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if mongoid?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Address < ActiveRecord::Base
2
4
  belongs_to :company
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Author < ActiveRecord::Base
2
4
  has_many :documents
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class BaseUser < ActiveRecord::Base
2
4
  has_many :comments
3
5
  has_many :posts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Category < ActiveRecord::Base
2
4
  has_many :posts, inverse_of: :category
3
5
  has_many :entries
data/spec/models/city.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class City < ActiveRecord::Base
2
4
  belongs_to :country
3
5
  end
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Client < ActiveRecord::Base
4
+ belongs_to :group
5
+
2
6
  has_many :relationships
3
7
  has_many :firms, through: :relationships
4
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Comment < ActiveRecord::Base
2
4
  belongs_to :post, inverse_of: :comments
3
5
  belongs_to :author, class_name: 'BaseUser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Company < ActiveRecord::Base
2
4
  has_one :address
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Country < ActiveRecord::Base
2
4
  has_many :cities
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Document < ActiveRecord::Base
2
4
  has_many :children, class_name: 'Document', foreign_key: 'parent_id'
3
5
  belongs_to :parent, class_name: 'Document', foreign_key: 'parent_id'
data/spec/models/entry.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Entry < ActiveRecord::Base
2
4
  belongs_to :category
3
5
  end
data/spec/models/firm.rb CHANGED
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Firm < ActiveRecord::Base
2
4
  has_many :relationships
3
5
  has_many :clients, through: :relationships
6
+ has_many :groups, through: :clients
4
7
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Folder < Document
2
4
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Group < ActiveRecord::Base
4
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Address
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- belongs_to :company, :class_name => 'Mongoid::Company'
8
+ belongs_to :company, class_name: 'Mongoid::Company'
7
9
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Category
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- has_many :posts, :class_name => 'Mongoid::Post'
7
- has_many :entries, :class_name => 'Mongoid::Entry'
8
+ has_many :posts, class_name: 'Mongoid::Post'
9
+ has_many :entries, class_name: 'Mongoid::Entry'
8
10
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Comment
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- belongs_to :post, :class_name => 'Mongoid::Post'
8
+ belongs_to :post, class_name: 'Mongoid::Post'
7
9
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Company
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- has_one :address, :class_name => 'Mongoid::Address'
8
+ has_one :address, class_name: 'Mongoid::Address'
7
9
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Entry
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- belongs_to :category, :class_name => 'Mongoid::Category'
8
+ belongs_to :category, class_name: 'Mongoid::Category'
7
9
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::Post
2
4
  include Mongoid::Document
3
5
 
4
6
  field :name
5
7
 
6
- has_many :comments, :class_name => 'Mongoid::Comment'
7
- belongs_to :category, :class_name => 'Mongoid::Category'
8
+ has_many :comments, class_name: 'Mongoid::Comment'
9
+ belongs_to :category, class_name: 'Mongoid::Category'
8
10
 
9
- embeds_many :users, :class_name => 'Mongoid::User'
11
+ embeds_many :users, class_name: 'Mongoid::User'
10
12
 
11
- scope :preload_comments, lambda { includes(:comments) }
13
+ scope :preload_comments, -> { includes(:comments) }
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Mongoid::User
2
4
  include Mongoid::Document
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Newspaper < ActiveRecord::Base
2
4
  has_many :writers, class_name: 'BaseUser'
3
5
  end
data/spec/models/page.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Page < Document
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Person < ActiveRecord::Base
2
4
  has_many :pets
3
5
  end
data/spec/models/pet.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pet < ActiveRecord::Base
2
4
  belongs_to :person, counter_cache: true
3
5
  end
data/spec/models/post.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Post < ActiveRecord::Base
2
4
  belongs_to :category, inverse_of: :posts
3
5
  belongs_to :writer
@@ -12,4 +14,19 @@ class Post < ActiveRecord::Base
12
14
  def link=(*)
13
15
  comments.new
14
16
  end
17
+
18
+ # see association_spec.rb 'should not detect newly assigned object in an after_save'
19
+ attr_accessor :trigger_after_save
20
+ after_save do
21
+ next unless trigger_after_save
22
+
23
+ temp_comment = Comment.new(post: self)
24
+ # this triggers self to be "possible", even though it's
25
+ # not saved yet
26
+ temp_comment.post
27
+
28
+ # category should NOT whine about not being pre-loaded, because
29
+ # it's obviously attached to a new object
30
+ category
31
+ end
15
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Relationship < ActiveRecord::Base
2
4
  belongs_to :firm
3
5
  belongs_to :client
data/spec/models/reply.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Reply < ActiveRecord::Base
2
4
  belongs_to :submission
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Student < ActiveRecord::Base
2
4
  has_and_belongs_to_many :teachers
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Submission < ActiveRecord::Base
2
4
  belongs_to :user
3
5
  has_many :replies
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Teacher < ActiveRecord::Base
2
4
  has_and_belongs_to_many :students
3
5
  end
data/spec/models/user.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
4
  has_one :submission
3
5
  belongs_to :category
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Writer < BaseUser
2
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec'
2
4
  begin
3
5
  require 'active_record'
@@ -33,7 +35,7 @@ Dir[File.join(SUPPORT, '*.rb')].reject { |filename| filename =~ /_seed.rb$/ }.so
33
35
  RSpec.configure do |config|
34
36
  config.extend Bullet::Dependency
35
37
 
36
- config.filter_run :focus => true
38
+ config.filter_run focus: true
37
39
  config.run_all_when_everything_filtered = true
38
40
  end
39
41
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bullet
2
4
  def self.collected_notifications_of_class(notification_class)
3
5
  Bullet.notification_collector.collection.select do |notification|