bullet 5.5.0 → 6.1.5

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 (123) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +66 -0
  3. data/CHANGELOG.md +83 -1
  4. data/Gemfile +6 -1
  5. data/Gemfile.mongoid-7.0 +15 -0
  6. data/Gemfile.rails-4.0 +1 -1
  7. data/Gemfile.rails-4.1 +1 -1
  8. data/Gemfile.rails-4.2 +1 -1
  9. data/Gemfile.rails-5.0 +2 -2
  10. data/Gemfile.rails-5.1 +15 -0
  11. data/Gemfile.rails-5.2 +15 -0
  12. data/Gemfile.rails-6.0 +15 -0
  13. data/Gemfile.rails-6.1 +15 -0
  14. data/Guardfile +2 -2
  15. data/Hacking.md +1 -1
  16. data/README.md +58 -37
  17. data/Rakefile +20 -21
  18. data/bullet.gemspec +21 -15
  19. data/lib/bullet/active_job.rb +13 -0
  20. data/lib/bullet/active_record4.rb +15 -34
  21. data/lib/bullet/active_record41.rb +14 -31
  22. data/lib/bullet/active_record42.rb +23 -36
  23. data/lib/bullet/active_record5.rb +178 -158
  24. data/lib/bullet/active_record52.rb +251 -0
  25. data/lib/bullet/active_record60.rb +278 -0
  26. data/lib/bullet/active_record61.rb +278 -0
  27. data/lib/bullet/bullet_xhr.js +64 -0
  28. data/lib/bullet/dependency.rb +60 -32
  29. data/lib/bullet/detector/association.rb +41 -32
  30. data/lib/bullet/detector/base.rb +2 -0
  31. data/lib/bullet/detector/counter_cache.rb +25 -17
  32. data/lib/bullet/detector/n_plus_one_query.rb +38 -24
  33. data/lib/bullet/detector/unused_eager_loading.rb +35 -26
  34. data/lib/bullet/detector.rb +2 -0
  35. data/lib/bullet/ext/object.rb +9 -5
  36. data/lib/bullet/ext/string.rb +3 -1
  37. data/lib/bullet/mongoid4x.rb +9 -8
  38. data/lib/bullet/mongoid5x.rb +9 -8
  39. data/lib/bullet/mongoid6x.rb +13 -12
  40. data/lib/bullet/mongoid7x.rb +57 -0
  41. data/lib/bullet/notification/base.rb +28 -25
  42. data/lib/bullet/notification/counter_cache.rb +3 -1
  43. data/lib/bullet/notification/n_plus_one_query.rb +8 -7
  44. data/lib/bullet/notification/unused_eager_loading.rb +8 -7
  45. data/lib/bullet/notification.rb +4 -1
  46. data/lib/bullet/notification_collector.rb +2 -1
  47. data/lib/bullet/rack.rb +66 -35
  48. data/lib/bullet/registry/association.rb +2 -0
  49. data/lib/bullet/registry/base.rb +2 -0
  50. data/lib/bullet/registry/object.rb +2 -0
  51. data/lib/bullet/registry.rb +2 -0
  52. data/lib/bullet/stack_trace_filter.rb +50 -20
  53. data/lib/bullet/version.rb +3 -2
  54. data/lib/bullet.rb +136 -55
  55. data/lib/generators/bullet/install_generator.rb +48 -0
  56. data/perf/benchmark.rb +19 -22
  57. data/rails/init.rb +2 -0
  58. data/spec/bullet/detector/association_spec.rb +6 -4
  59. data/spec/bullet/detector/base_spec.rb +2 -0
  60. data/spec/bullet/detector/counter_cache_spec.rb +17 -15
  61. data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
  62. data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
  63. data/spec/bullet/ext/object_spec.rb +18 -11
  64. data/spec/bullet/ext/string_spec.rb +7 -5
  65. data/spec/bullet/notification/base_spec.rb +38 -39
  66. data/spec/bullet/notification/counter_cache_spec.rb +5 -3
  67. data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
  68. data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
  69. data/spec/bullet/notification_collector_spec.rb +12 -10
  70. data/spec/bullet/rack_spec.rb +200 -48
  71. data/spec/bullet/registry/association_spec.rb +12 -10
  72. data/spec/bullet/registry/base_spec.rb +22 -20
  73. data/spec/bullet/registry/object_spec.rb +6 -4
  74. data/spec/bullet_spec.rb +64 -33
  75. data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
  76. data/spec/integration/counter_cache_spec.rb +26 -44
  77. data/spec/integration/mongoid/association_spec.rb +53 -65
  78. data/spec/models/address.rb +2 -0
  79. data/spec/models/attachment.rb +5 -0
  80. data/spec/models/author.rb +2 -0
  81. data/spec/models/base_user.rb +2 -0
  82. data/spec/models/category.rb +2 -0
  83. data/spec/models/city.rb +2 -0
  84. data/spec/models/client.rb +4 -0
  85. data/spec/models/comment.rb +3 -1
  86. data/spec/models/company.rb +2 -0
  87. data/spec/models/country.rb +2 -0
  88. data/spec/models/deal.rb +5 -0
  89. data/spec/models/document.rb +4 -2
  90. data/spec/models/entry.rb +2 -0
  91. data/spec/models/firm.rb +3 -0
  92. data/spec/models/folder.rb +2 -0
  93. data/spec/models/group.rb +4 -0
  94. data/spec/models/mongoid/address.rb +3 -1
  95. data/spec/models/mongoid/category.rb +4 -2
  96. data/spec/models/mongoid/comment.rb +3 -1
  97. data/spec/models/mongoid/company.rb +3 -1
  98. data/spec/models/mongoid/entry.rb +3 -1
  99. data/spec/models/mongoid/post.rb +6 -4
  100. data/spec/models/mongoid/user.rb +2 -0
  101. data/spec/models/newspaper.rb +3 -1
  102. data/spec/models/page.rb +2 -0
  103. data/spec/models/person.rb +2 -0
  104. data/spec/models/pet.rb +2 -0
  105. data/spec/models/post.rb +19 -0
  106. data/spec/models/relationship.rb +2 -0
  107. data/spec/models/reply.rb +2 -0
  108. data/spec/models/student.rb +2 -0
  109. data/spec/models/submission.rb +3 -0
  110. data/spec/models/teacher.rb +2 -0
  111. data/spec/models/user.rb +3 -0
  112. data/spec/models/writer.rb +2 -0
  113. data/spec/spec_helper.rb +19 -23
  114. data/spec/support/bullet_ext.rb +10 -9
  115. data/spec/support/mongo_seed.rb +38 -57
  116. data/spec/support/rack_double.rb +13 -19
  117. data/spec/support/sqlite_seed.rb +104 -76
  118. data/tasks/bullet_tasks.rake +4 -2
  119. data/test.sh +5 -0
  120. data/update.sh +3 -0
  121. metadata +34 -17
  122. data/.travis.yml +0 -16
  123. data/spec/integration/active_record5/association_spec.rb +0 -768
@@ -1,84 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if !mongoid? && active_record?
4
6
  describe Bullet::Detector::CounterCache do
5
- before(:each) do
6
- Bullet.start_request
7
- end
7
+ before(:each) { Bullet.start_request }
8
8
 
9
- after(:each) do
10
- Bullet.end_request
11
- end
9
+ after(:each) { Bullet.end_request }
12
10
 
13
- it "should need counter cache with all cities" do
14
- Country.all.each do |country|
15
- country.cities.size
16
- end
11
+ it 'should need counter cache with all cities' do
12
+ Country.all.each { |country| country.cities.size }
17
13
  expect(Bullet.collected_counter_cache_notifications).not_to be_empty
18
14
  end
19
15
 
20
- it "should not need counter cache if already define counter_cache" do
21
- Person.all.each do |person|
22
- person.pets.size
23
- end
16
+ it 'should not need counter cache if already define counter_cache' do
17
+ Person.all.each { |person| person.pets.size }
24
18
  expect(Bullet.collected_counter_cache_notifications).to be_empty
25
19
  end
26
20
 
27
- it "should not need counter cache with only one object" do
21
+ it 'should not need counter cache with only one object' do
28
22
  Country.first.cities.size
29
23
  expect(Bullet.collected_counter_cache_notifications).to be_empty
30
24
  end
31
25
 
32
- it "should not need counter cache without size" do
33
- Country.includes(:cities).each do |country|
34
- country.cities.empty?
35
- end
26
+ it 'should not need counter cache without size' do
27
+ Country.includes(:cities).each { |country| country.cities.empty? }
36
28
  expect(Bullet.collected_counter_cache_notifications).to be_empty
37
29
  end
38
30
 
39
- if active_record5?
40
- it "should not need counter cache for has_many through" do
41
- Client.all.each do |client|
42
- client.firms.size
43
- end
31
+ if active_record5? || active_record6?
32
+ it 'should not need counter cache for has_many through' do
33
+ Client.all.each { |client| client.firms.size }
44
34
  expect(Bullet.collected_counter_cache_notifications).to be_empty
45
35
  end
46
36
  else
47
- it "should need counter cache for has_many through" do
48
- Client.all.each do |client|
49
- client.firms.size
50
- end
37
+ it 'should need counter cache for has_many through' do
38
+ Client.all.each { |client| client.firms.size }
51
39
  expect(Bullet.collected_counter_cache_notifications).not_to be_empty
52
40
  end
53
41
  end
54
42
 
55
- it "should not need counter cache with part of cities" do
56
- Country.all.each do |country|
57
- country.cities.where(:name => 'first').size
58
- end
43
+ it 'should not need counter cache with part of cities' do
44
+ Country.all.each { |country| country.cities.where(name: 'first').size }
59
45
  expect(Bullet.collected_counter_cache_notifications).to be_empty
60
46
  end
61
47
 
62
- context "disable" do
48
+ context 'disable' do
63
49
  before { Bullet.counter_cache_enable = false }
64
50
  after { Bullet.counter_cache_enable = true }
65
51
 
66
- it "should not detect counter cache" do
67
- Country.all.each do |country|
68
- country.cities.size
69
- end
52
+ it 'should not detect counter cache' do
53
+ Country.all.each { |country| country.cities.size }
70
54
  expect(Bullet.collected_counter_cache_notifications).to be_empty
71
55
  end
72
56
  end
73
57
 
74
- context "whitelist" do
75
- before { Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities }
76
- after { Bullet.clear_whitelist }
58
+ context 'safelist' do
59
+ before { Bullet.add_safelist type: :counter_cache, class_name: 'Country', association: :cities }
60
+ after { Bullet.clear_safelist }
77
61
 
78
- it "should not detect counter cache" do
79
- Country.all.each do |country|
80
- country.cities.size
81
- end
62
+ it 'should not detect counter cache' do
63
+ Country.all.each { |country| country.cities.size }
82
64
  expect(Bullet.collected_counter_cache_notifications).to be_empty
83
65
  end
84
66
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if mongoid?
4
6
  describe Bullet::Detector::Association do
5
7
  context 'embeds_many' do
6
- context "posts => users" do
7
- it "should detect nothing" do
8
- Mongoid::Post.all.each do |post|
9
- post.users.map(&:name)
10
- end
8
+ context 'posts => users' do
9
+ it 'should detect nothing' do
10
+ Mongoid::Post.all.each { |post| post.users.map(&:name) }
11
11
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
12
12
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
13
13
 
@@ -17,28 +17,24 @@ if mongoid?
17
17
  end
18
18
 
19
19
  context 'has_many' do
20
- context "posts => comments" do
21
- it "should detect non preload posts => comments" do
22
- Mongoid::Post.all.each do |post|
23
- post.comments.map(&:name)
24
- end
20
+ context 'posts => comments' do
21
+ it 'should detect non preload posts => comments' do
22
+ Mongoid::Post.all.each { |post| post.comments.map(&:name) }
25
23
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
26
24
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
27
25
 
28
26
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
29
27
  end
30
28
 
31
- it "should detect preload post => comments" do
32
- Mongoid::Post.includes(:comments).each do |post|
33
- post.comments.map(&:name)
34
- end
29
+ it 'should detect preload post => comments' do
30
+ Mongoid::Post.includes(:comments).each { |post| post.comments.map(&:name) }
35
31
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
36
32
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
37
33
 
38
34
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
39
35
  end
40
36
 
41
- it "should detect unused preload post => comments" do
37
+ it 'should detect unused preload post => comments' do
42
38
  Mongoid::Post.includes(:comments).map(&:name)
43
39
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
44
40
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
@@ -46,7 +42,7 @@ if mongoid?
46
42
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
47
43
  end
48
44
 
49
- it "should not detect unused preload post => comments" do
45
+ it 'should not detect unused preload post => comments' do
50
46
  Mongoid::Post.all.map(&:name)
51
47
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
52
48
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -55,8 +51,8 @@ if mongoid?
55
51
  end
56
52
  end
57
53
 
58
- context "category => posts, category => entries" do
59
- it "should detect non preload with category => [posts, entries]" do
54
+ context 'category => posts, category => entries' do
55
+ it 'should detect non preload with category => [posts, entries]' do
60
56
  Mongoid::Category.all.each do |category|
61
57
  category.posts.map(&:name)
62
58
  category.entries.map(&:name)
@@ -68,7 +64,7 @@ if mongoid?
68
64
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
69
65
  end
70
66
 
71
- it "should detect preload with category => posts, but not with category => entries" do
67
+ it 'should detect preload with category => posts, but not with category => entries' do
72
68
  Mongoid::Category.includes(:posts).each do |category|
73
69
  category.posts.map(&:name)
74
70
  category.entries.map(&:name)
@@ -76,11 +72,14 @@ if mongoid?
76
72
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
77
73
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
78
74
 
79
- expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
75
+ expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(
76
+ Mongoid::Category,
77
+ :posts
78
+ )
80
79
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
81
80
  end
82
81
 
83
- it "should detect preload with category => [posts, entries]" do
82
+ it 'should detect preload with category => [posts, entries]' do
84
83
  Mongoid::Category.includes(:posts, :entries).each do |category|
85
84
  category.posts.map(&:name)
86
85
  category.entries.map(&:name)
@@ -91,7 +90,7 @@ if mongoid?
91
90
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
92
91
  end
93
92
 
94
- it "should detect unused preload with category => [posts, entries]" do
93
+ it 'should detect unused preload with category => [posts, entries]' do
95
94
  Mongoid::Category.includes(:posts, :entries).map(&:name)
96
95
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
97
96
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :posts)
@@ -100,10 +99,8 @@ if mongoid?
100
99
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
101
100
  end
102
101
 
103
- it "should detect unused preload with category => entries, but not with category => posts" do
104
- Mongoid::Category.includes(:posts, :entries).each do |category|
105
- category.posts.map(&:name)
106
- end
102
+ it 'should detect unused preload with category => entries, but not with category => posts' do
103
+ Mongoid::Category.includes(:posts, :entries).each { |category| category.posts.map(&:name) }
107
104
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
108
105
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Category, :posts)
109
106
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
@@ -112,18 +109,16 @@ if mongoid?
112
109
  end
113
110
  end
114
111
 
115
- context "post => comment" do
116
- it "should detect unused preload with post => comments" do
117
- Mongoid::Post.includes(:comments).each do |post|
118
- post.comments.first.name
119
- end
112
+ context 'post => comment' do
113
+ it 'should detect unused preload with post => comments' do
114
+ Mongoid::Post.includes(:comments).each { |post| post.comments.first.name }
120
115
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
121
116
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Post, :comments)
122
117
 
123
118
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
124
119
  end
125
120
 
126
- it "should detect preload with post => commnets" do
121
+ it 'should detect preload with post => comments' do
127
122
  Mongoid::Post.first.comments.map(&:name)
128
123
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
129
124
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -132,18 +127,16 @@ if mongoid?
132
127
  end
133
128
  end
134
129
 
135
- context "scope preload_comments" do
136
- it "should detect preload post => comments with scope" do
137
- Mongoid::Post.preload_comments.each do |post|
138
- post.comments.map(&:name)
139
- end
130
+ context 'scope preload_comments' do
131
+ it 'should detect preload post => comments with scope' do
132
+ Mongoid::Post.preload_comments.each { |post| post.comments.map(&:name) }
140
133
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
141
134
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
142
135
 
143
136
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
144
137
  end
145
138
 
146
- it "should detect unused preload with scope" do
139
+ it 'should detect unused preload with scope' do
147
140
  Mongoid::Post.preload_comments.map(&:name)
148
141
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
149
142
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
@@ -154,18 +147,16 @@ if mongoid?
154
147
  end
155
148
 
156
149
  context 'belongs_to' do
157
- context "comment => post" do
158
- it "should detect non preload with comment => post" do
159
- Mongoid::Comment.all.each do |comment|
160
- comment.post.name
161
- end
150
+ context 'comment => post' do
151
+ it 'should detect non preload with comment => post' do
152
+ Mongoid::Comment.all.each { |comment| comment.post.name }
162
153
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
163
154
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
164
155
 
165
156
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
166
157
  end
167
158
 
168
- it "should detect preload with one comment => post" do
159
+ it 'should detect preload with one comment => post' do
169
160
  Mongoid::Comment.first.post.name
170
161
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
171
162
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -173,17 +164,15 @@ if mongoid?
173
164
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
174
165
  end
175
166
 
176
- it "should detect preload with comment => post" do
177
- Mongoid::Comment.includes(:post).each do |comment|
178
- comment.post.name
179
- end
167
+ it 'should detect preload with comment => post' do
168
+ Mongoid::Comment.includes(:post).each { |comment| comment.post.name }
180
169
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
181
170
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
182
171
 
183
172
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
184
173
  end
185
174
 
186
- it "should not detect preload with comment => post" do
175
+ it 'should not detect preload with comment => post' do
187
176
  Mongoid::Comment.all.map(&:name)
188
177
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
189
178
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -191,7 +180,7 @@ if mongoid?
191
180
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
192
181
  end
193
182
 
194
- it "should detect unused preload with comments => post" do
183
+ it 'should detect unused preload with comments => post' do
195
184
  Mongoid::Comment.includes(:post).map(&:name)
196
185
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
197
186
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Comment, :post)
@@ -201,31 +190,30 @@ if mongoid?
201
190
  end
202
191
  end
203
192
 
204
- context "has_one" do
205
- context "company => address" do
193
+ context 'has_one' do
194
+ context 'company => address' do
206
195
  if Mongoid::VERSION !~ /\A3.0/
207
- it "should detect non preload association" do
208
- Mongoid::Company.all.each do |company|
209
- company.address.name
210
- end
196
+ it 'should detect non preload association' do
197
+ Mongoid::Company.all.each { |company| company.address.name }
211
198
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
212
199
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
213
200
 
214
- expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
201
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(
202
+ Mongoid::Company,
203
+ :address
204
+ )
215
205
  end
216
206
  end
217
207
 
218
- it "should detect preload association" do
219
- Mongoid::Company.includes(:address).each do |company|
220
- company.address.name
221
- end
208
+ it 'should detect preload association' do
209
+ Mongoid::Company.includes(:address).each { |company| company.address.name }
222
210
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
223
211
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
224
212
 
225
213
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
226
214
  end
227
215
 
228
- it "should not detect preload association" do
216
+ it 'should not detect preload association' do
229
217
  Mongoid::Company.all.map(&:name)
230
218
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
231
219
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -233,7 +221,7 @@ if mongoid?
233
221
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
234
222
  end
235
223
 
236
- it "should detect unused preload association" do
224
+ it 'should detect unused preload association' do
237
225
  criteria = Mongoid::Company.includes(:address)
238
226
  criteria.map(&:name)
239
227
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -244,8 +232,8 @@ if mongoid?
244
232
  end
245
233
  end
246
234
 
247
- context "call one association that in possible objects" do
248
- it "should not detect preload association" do
235
+ context 'call one association that in possible objects' do
236
+ it 'should not detect preload association' do
249
237
  Mongoid::Post.all
250
238
  Mongoid::Post.first.comments.map(&:name)
251
239
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Address < ActiveRecord::Base
2
4
  belongs_to :company
3
5
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Attachment < ActiveRecord::Base
4
+ belongs_to :submission
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,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Comment < ActiveRecord::Base
2
4
  belongs_to :post, inverse_of: :comments
3
- belongs_to :author, class_name: "BaseUser"
5
+ belongs_to :author, class_name: 'BaseUser'
4
6
 
5
7
  validates :post, presence: true
6
8
  end
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Deal < ActiveRecord::Base
4
+ has_and_belongs_to_many :posts
5
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Document < ActiveRecord::Base
2
- has_many :children, class_name: "Document", foreign_key: 'parent_id'
3
- belongs_to :parent, class_name: "Document", foreign_key: 'parent_id'
4
+ has_many :children, class_name: 'Document', foreign_key: 'parent_id'
5
+ belongs_to :parent, class_name: 'Document', foreign_key: 'parent_id'
4
6
  belongs_to :author
5
7
  end
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
- has_many :writers, class_name: "BaseUser"
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