bullet 5.6.0 → 5.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Guardfile +2 -2
  4. data/Rakefile +16 -16
  5. data/bullet.gemspec +11 -11
  6. data/lib/bullet.rb +3 -3
  7. data/lib/bullet/detector/association.rb +2 -2
  8. data/lib/bullet/detector/counter_cache.rb +3 -3
  9. data/lib/bullet/detector/n_plus_one_query.rb +5 -5
  10. data/lib/bullet/detector/unused_eager_loading.rb +2 -2
  11. data/lib/bullet/ext/string.rb +1 -1
  12. data/lib/bullet/notification/base.rb +6 -6
  13. data/lib/bullet/notification/counter_cache.rb +1 -1
  14. data/lib/bullet/rack.rb +4 -4
  15. data/lib/bullet/stack_trace_filter.rb +2 -2
  16. data/lib/bullet/version.rb +2 -2
  17. data/lib/generators/bullet/install_generator.rb +5 -5
  18. data/perf/benchmark.rb +3 -3
  19. data/spec/bullet/detector/association_spec.rb +4 -4
  20. data/spec/bullet/detector/counter_cache_spec.rb +11 -11
  21. data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -33
  22. data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -19
  23. data/spec/bullet/ext/object_spec.rb +7 -7
  24. data/spec/bullet/ext/string_spec.rb +5 -5
  25. data/spec/bullet/notification/base_spec.rb +32 -32
  26. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  27. data/spec/bullet/notification/n_plus_one_query_spec.rb +2 -2
  28. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  29. data/spec/bullet/notification_collector_spec.rb +10 -10
  30. data/spec/bullet/rack_spec.rb +46 -46
  31. data/spec/bullet/registry/association_spec.rb +10 -10
  32. data/spec/bullet/registry/base_spec.rb +20 -20
  33. data/spec/bullet/registry/object_spec.rb +4 -4
  34. data/spec/integration/active_record/association_spec.rb +101 -101
  35. data/spec/integration/counter_cache_spec.rb +12 -12
  36. data/spec/integration/mongoid/association_spec.rb +33 -33
  37. data/spec/models/comment.rb +1 -1
  38. data/spec/models/document.rb +2 -2
  39. data/spec/models/mongoid/address.rb +1 -1
  40. data/spec/models/mongoid/category.rb +2 -2
  41. data/spec/models/mongoid/comment.rb +1 -1
  42. data/spec/models/mongoid/company.rb +1 -1
  43. data/spec/models/mongoid/entry.rb +1 -1
  44. data/spec/models/mongoid/post.rb +3 -3
  45. data/spec/models/newspaper.rb +1 -1
  46. data/spec/spec_helper.rb +12 -12
  47. data/spec/support/mongo_seed.rb +6 -6
  48. data/spec/support/rack_double.rb +2 -2
  49. data/spec/support/sqlite_seed.rb +6 -6
  50. data/tasks/bullet_tasks.rake +2 -2
  51. metadata +2 -2
@@ -10,26 +10,26 @@ if !mongoid? && active_record?
10
10
  Bullet.end_request
11
11
  end
12
12
 
13
- it "should need counter cache with all cities" do
13
+ it 'should need counter cache with all cities' do
14
14
  Country.all.each do |country|
15
15
  country.cities.size
16
16
  end
17
17
  expect(Bullet.collected_counter_cache_notifications).not_to be_empty
18
18
  end
19
19
 
20
- it "should not need counter cache if already define counter_cache" do
20
+ it 'should not need counter cache if already define counter_cache' do
21
21
  Person.all.each do |person|
22
22
  person.pets.size
23
23
  end
24
24
  expect(Bullet.collected_counter_cache_notifications).to be_empty
25
25
  end
26
26
 
27
- it "should not need counter cache with only one object" do
27
+ it 'should not need counter cache with only one object' do
28
28
  Country.first.cities.size
29
29
  expect(Bullet.collected_counter_cache_notifications).to be_empty
30
30
  end
31
31
 
32
- it "should not need counter cache without size" do
32
+ it 'should not need counter cache without size' do
33
33
  Country.includes(:cities).each do |country|
34
34
  country.cities.empty?
35
35
  end
@@ -37,14 +37,14 @@ if !mongoid? && active_record?
37
37
  end
38
38
 
39
39
  if active_record5?
40
- it "should not need counter cache for has_many through" do
40
+ it 'should not need counter cache for has_many through' do
41
41
  Client.all.each do |client|
42
42
  client.firms.size
43
43
  end
44
44
  expect(Bullet.collected_counter_cache_notifications).to be_empty
45
45
  end
46
46
  else
47
- it "should need counter cache for has_many through" do
47
+ it 'should need counter cache for has_many through' do
48
48
  Client.all.each do |client|
49
49
  client.firms.size
50
50
  end
@@ -52,18 +52,18 @@ if !mongoid? && active_record?
52
52
  end
53
53
  end
54
54
 
55
- it "should not need counter cache with part of cities" do
55
+ it 'should not need counter cache with part of cities' do
56
56
  Country.all.each do |country|
57
57
  country.cities.where(:name => 'first').size
58
58
  end
59
59
  expect(Bullet.collected_counter_cache_notifications).to be_empty
60
60
  end
61
61
 
62
- context "disable" do
62
+ context 'disable' do
63
63
  before { Bullet.counter_cache_enable = false }
64
64
  after { Bullet.counter_cache_enable = true }
65
65
 
66
- it "should not detect counter cache" do
66
+ it 'should not detect counter cache' do
67
67
  Country.all.each do |country|
68
68
  country.cities.size
69
69
  end
@@ -71,11 +71,11 @@ if !mongoid? && active_record?
71
71
  end
72
72
  end
73
73
 
74
- context "whitelist" do
75
- before { Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities }
74
+ context 'whitelist' do
75
+ before { Bullet.add_whitelist :type => :counter_cache, :class_name => 'Country', :association => :cities }
76
76
  after { Bullet.clear_whitelist }
77
77
 
78
- it "should not detect counter cache" do
78
+ it 'should not detect counter cache' do
79
79
  Country.all.each do |country|
80
80
  country.cities.size
81
81
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  if mongoid?
4
4
  describe Bullet::Detector::Association do
5
5
  context 'embeds_many' do
6
- context "posts => users" do
7
- it "should detect nothing" do
6
+ context 'posts => users' do
7
+ it 'should detect nothing' do
8
8
  Mongoid::Post.all.each do |post|
9
9
  post.users.map(&:name)
10
10
  end
@@ -17,8 +17,8 @@ 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
20
+ context 'posts => comments' do
21
+ it 'should detect non preload posts => comments' do
22
22
  Mongoid::Post.all.each do |post|
23
23
  post.comments.map(&:name)
24
24
  end
@@ -28,7 +28,7 @@ if mongoid?
28
28
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
29
29
  end
30
30
 
31
- it "should detect preload post => comments" do
31
+ it 'should detect preload post => comments' do
32
32
  Mongoid::Post.includes(:comments).each do |post|
33
33
  post.comments.map(&:name)
34
34
  end
@@ -38,7 +38,7 @@ if mongoid?
38
38
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
39
39
  end
40
40
 
41
- it "should detect unused preload post => comments" do
41
+ it 'should detect unused preload post => comments' do
42
42
  Mongoid::Post.includes(:comments).map(&:name)
43
43
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
44
44
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
@@ -46,7 +46,7 @@ if mongoid?
46
46
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
47
47
  end
48
48
 
49
- it "should not detect unused preload post => comments" do
49
+ it 'should not detect unused preload post => comments' do
50
50
  Mongoid::Post.all.map(&:name)
51
51
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
52
52
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -55,8 +55,8 @@ if mongoid?
55
55
  end
56
56
  end
57
57
 
58
- context "category => posts, category => entries" do
59
- it "should detect non preload with category => [posts, entries]" do
58
+ context 'category => posts, category => entries' do
59
+ it 'should detect non preload with category => [posts, entries]' do
60
60
  Mongoid::Category.all.each do |category|
61
61
  category.posts.map(&:name)
62
62
  category.entries.map(&:name)
@@ -68,7 +68,7 @@ if mongoid?
68
68
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
69
69
  end
70
70
 
71
- it "should detect preload with category => posts, but not with category => entries" do
71
+ it 'should detect preload with category => posts, but not with category => entries' do
72
72
  Mongoid::Category.includes(:posts).each do |category|
73
73
  category.posts.map(&:name)
74
74
  category.entries.map(&:name)
@@ -80,7 +80,7 @@ if mongoid?
80
80
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
81
81
  end
82
82
 
83
- it "should detect preload with category => [posts, entries]" do
83
+ it 'should detect preload with category => [posts, entries]' do
84
84
  Mongoid::Category.includes(:posts, :entries).each do |category|
85
85
  category.posts.map(&:name)
86
86
  category.entries.map(&:name)
@@ -91,7 +91,7 @@ if mongoid?
91
91
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
92
92
  end
93
93
 
94
- it "should detect unused preload with category => [posts, entries]" do
94
+ it 'should detect unused preload with category => [posts, entries]' do
95
95
  Mongoid::Category.includes(:posts, :entries).map(&:name)
96
96
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
97
97
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :posts)
@@ -100,7 +100,7 @@ if mongoid?
100
100
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
101
101
  end
102
102
 
103
- it "should detect unused preload with category => entries, but not with category => posts" do
103
+ it 'should detect unused preload with category => entries, but not with category => posts' do
104
104
  Mongoid::Category.includes(:posts, :entries).each do |category|
105
105
  category.posts.map(&:name)
106
106
  end
@@ -112,8 +112,8 @@ if mongoid?
112
112
  end
113
113
  end
114
114
 
115
- context "post => comment" do
116
- it "should detect unused preload with post => comments" do
115
+ context 'post => comment' do
116
+ it 'should detect unused preload with post => comments' do
117
117
  Mongoid::Post.includes(:comments).each do |post|
118
118
  post.comments.first.name
119
119
  end
@@ -123,7 +123,7 @@ if mongoid?
123
123
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
124
124
  end
125
125
 
126
- it "should detect preload with post => commnets" do
126
+ it 'should detect preload with post => commnets' do
127
127
  Mongoid::Post.first.comments.map(&:name)
128
128
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
129
129
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -132,8 +132,8 @@ if mongoid?
132
132
  end
133
133
  end
134
134
 
135
- context "scope preload_comments" do
136
- it "should detect preload post => comments with scope" do
135
+ context 'scope preload_comments' do
136
+ it 'should detect preload post => comments with scope' do
137
137
  Mongoid::Post.preload_comments.each do |post|
138
138
  post.comments.map(&:name)
139
139
  end
@@ -143,7 +143,7 @@ if mongoid?
143
143
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
144
144
  end
145
145
 
146
- it "should detect unused preload with scope" do
146
+ it 'should detect unused preload with scope' do
147
147
  Mongoid::Post.preload_comments.map(&:name)
148
148
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
149
149
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
@@ -154,8 +154,8 @@ if mongoid?
154
154
  end
155
155
 
156
156
  context 'belongs_to' do
157
- context "comment => post" do
158
- it "should detect non preload with comment => post" do
157
+ context 'comment => post' do
158
+ it 'should detect non preload with comment => post' do
159
159
  Mongoid::Comment.all.each do |comment|
160
160
  comment.post.name
161
161
  end
@@ -165,7 +165,7 @@ if mongoid?
165
165
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
166
166
  end
167
167
 
168
- it "should detect preload with one comment => post" do
168
+ it 'should detect preload with one comment => post' do
169
169
  Mongoid::Comment.first.post.name
170
170
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
171
171
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -173,7 +173,7 @@ if mongoid?
173
173
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
174
174
  end
175
175
 
176
- it "should detect preload with comment => post" do
176
+ it 'should detect preload with comment => post' do
177
177
  Mongoid::Comment.includes(:post).each do |comment|
178
178
  comment.post.name
179
179
  end
@@ -183,7 +183,7 @@ if mongoid?
183
183
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
184
184
  end
185
185
 
186
- it "should not detect preload with comment => post" do
186
+ it 'should not detect preload with comment => post' do
187
187
  Mongoid::Comment.all.map(&:name)
188
188
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
189
189
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -191,7 +191,7 @@ if mongoid?
191
191
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
192
192
  end
193
193
 
194
- it "should detect unused preload with comments => post" do
194
+ it 'should detect unused preload with comments => post' do
195
195
  Mongoid::Comment.includes(:post).map(&:name)
196
196
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
197
197
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Comment, :post)
@@ -201,10 +201,10 @@ if mongoid?
201
201
  end
202
202
  end
203
203
 
204
- context "has_one" do
205
- context "company => address" do
204
+ context 'has_one' do
205
+ context 'company => address' do
206
206
  if Mongoid::VERSION !~ /\A3.0/
207
- it "should detect non preload association" do
207
+ it 'should detect non preload association' do
208
208
  Mongoid::Company.all.each do |company|
209
209
  company.address.name
210
210
  end
@@ -215,7 +215,7 @@ if mongoid?
215
215
  end
216
216
  end
217
217
 
218
- it "should detect preload association" do
218
+ it 'should detect preload association' do
219
219
  Mongoid::Company.includes(:address).each do |company|
220
220
  company.address.name
221
221
  end
@@ -225,7 +225,7 @@ if mongoid?
225
225
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
226
226
  end
227
227
 
228
- it "should not detect preload association" do
228
+ it 'should not detect preload association' do
229
229
  Mongoid::Company.all.map(&:name)
230
230
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
231
231
  expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
@@ -233,7 +233,7 @@ if mongoid?
233
233
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
234
234
  end
235
235
 
236
- it "should detect unused preload association" do
236
+ it 'should detect unused preload association' do
237
237
  criteria = Mongoid::Company.includes(:address)
238
238
  criteria.map(&:name)
239
239
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -244,8 +244,8 @@ if mongoid?
244
244
  end
245
245
  end
246
246
 
247
- context "call one association that in possible objects" do
248
- it "should not detect preload association" do
247
+ context 'call one association that in possible objects' do
248
+ it 'should not detect preload association' do
249
249
  Mongoid::Post.all
250
250
  Mongoid::Post.first.comments.map(&:name)
251
251
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
@@ -1,6 +1,6 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  belongs_to :post, inverse_of: :comments
3
- belongs_to :author, class_name: "BaseUser"
3
+ belongs_to :author, class_name: 'BaseUser'
4
4
 
5
5
  validates :post, presence: true
6
6
  end
@@ -1,5 +1,5 @@
1
1
  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'
2
+ has_many :children, class_name: 'Document', foreign_key: 'parent_id'
3
+ belongs_to :parent, class_name: 'Document', foreign_key: 'parent_id'
4
4
  belongs_to :author
5
5
  end
@@ -3,5 +3,5 @@ class Mongoid::Address
3
3
 
4
4
  field :name
5
5
 
6
- belongs_to :company, :class_name => "Mongoid::Company"
6
+ belongs_to :company, :class_name => 'Mongoid::Company'
7
7
  end
@@ -3,6 +3,6 @@ class Mongoid::Category
3
3
 
4
4
  field :name
5
5
 
6
- has_many :posts, :class_name => "Mongoid::Post"
7
- has_many :entries, :class_name => "Mongoid::Entry"
6
+ has_many :posts, :class_name => 'Mongoid::Post'
7
+ has_many :entries, :class_name => 'Mongoid::Entry'
8
8
  end
@@ -3,5 +3,5 @@ class Mongoid::Comment
3
3
 
4
4
  field :name
5
5
 
6
- belongs_to :post, :class_name => "Mongoid::Post"
6
+ belongs_to :post, :class_name => 'Mongoid::Post'
7
7
  end
@@ -3,5 +3,5 @@ class Mongoid::Company
3
3
 
4
4
  field :name
5
5
 
6
- has_one :address, :class_name => "Mongoid::Address"
6
+ has_one :address, :class_name => 'Mongoid::Address'
7
7
  end
@@ -3,5 +3,5 @@ class Mongoid::Entry
3
3
 
4
4
  field :name
5
5
 
6
- belongs_to :category, :class_name => "Mongoid::Category"
6
+ belongs_to :category, :class_name => 'Mongoid::Category'
7
7
  end
@@ -3,10 +3,10 @@ class Mongoid::Post
3
3
 
4
4
  field :name
5
5
 
6
- has_many :comments, :class_name => "Mongoid::Comment"
7
- belongs_to :category, :class_name => "Mongoid::Category"
6
+ has_many :comments, :class_name => 'Mongoid::Comment'
7
+ belongs_to :category, :class_name => 'Mongoid::Category'
8
8
 
9
- embeds_many :users, :class_name => "Mongoid::User"
9
+ embeds_many :users, :class_name => 'Mongoid::User'
10
10
 
11
11
  scope :preload_comments, lambda { includes(:comments) }
12
12
  end
@@ -1,3 +1,3 @@
1
1
  class Newspaper < ActiveRecord::Base
2
- has_many :writers, class_name: "BaseUser"
2
+ has_many :writers, class_name: 'BaseUser'
3
3
  end
@@ -15,20 +15,20 @@ module Rails
15
15
  end
16
16
 
17
17
  def env
18
- "test"
18
+ 'test'
19
19
  end
20
20
  end
21
21
  end
22
22
 
23
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
23
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
24
24
  require 'bullet'
25
25
  extend Bullet::Dependency
26
26
  Bullet.enable = true
27
27
 
28
- MODELS = File.join(File.dirname(__FILE__), "models")
28
+ MODELS = File.join(File.dirname(__FILE__), 'models')
29
29
  $LOAD_PATH.unshift(MODELS)
30
- SUPPORT = File.join(File.dirname(__FILE__), "support")
31
- Dir[ File.join(SUPPORT, "*.rb") ].reject { |filename| filename =~ /_seed.rb$/ }.sort.each { |file| require file }
30
+ SUPPORT = File.join(File.dirname(__FILE__), 'support')
31
+ Dir[ File.join(SUPPORT, '*.rb') ].reject { |filename| filename =~ /_seed.rb$/ }.sort.each { |file| require file }
32
32
 
33
33
  RSpec.configure do |config|
34
34
  config.extend Bullet::Dependency
@@ -41,11 +41,11 @@ if active_record?
41
41
  ActiveRecord::Migration.verbose = false
42
42
 
43
43
  # Autoload every active_record model for the test suite that sits in spec/models.
44
- Dir[ File.join(MODELS, "*.rb") ].sort.each do |filename|
45
- name = File.basename(filename, ".rb")
44
+ Dir[ File.join(MODELS, '*.rb') ].sort.each do |filename|
45
+ name = File.basename(filename, '.rb')
46
46
  autoload name.camelize.to_sym, name
47
47
  end
48
- require File.join(SUPPORT, "sqlite_seed.rb")
48
+ require File.join(SUPPORT, 'sqlite_seed.rb')
49
49
 
50
50
  RSpec.configure do |config|
51
51
  config.before(:suite) do
@@ -63,7 +63,7 @@ if active_record?
63
63
  end
64
64
  end
65
65
 
66
- if ENV["BULLET_LOG"]
66
+ if ENV['BULLET_LOG']
67
67
  require 'logger'
68
68
  ActiveRecord::Base.logger = Logger.new(STDOUT)
69
69
  end
@@ -71,8 +71,8 @@ end
71
71
 
72
72
  if mongoid?
73
73
  # Autoload every mongoid model for the test suite that sits in spec/models.
74
- Dir[ File.join(MODELS, "mongoid", "*.rb") ].sort.each { |file| require file }
75
- require File.join(SUPPORT, "mongo_seed.rb")
74
+ Dir[ File.join(MODELS, 'mongoid', '*.rb') ].sort.each { |file| require file }
75
+ require File.join(SUPPORT, 'mongo_seed.rb')
76
76
 
77
77
  RSpec.configure do |config|
78
78
  config.before(:suite) do
@@ -94,7 +94,7 @@ if mongoid?
94
94
  end
95
95
  end
96
96
 
97
- if ENV["BULLET_LOG"]
97
+ if ENV['BULLET_LOG']
98
98
  Mongoid.logger = Logger.new(STDOUT)
99
99
  Moped.logger = Logger.new(STDOUT)
100
100
  end