bullet 5.7.0 → 5.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/Gemfile.rails-5.2 +1 -1
- data/Guardfile +1 -1
- data/README.md +9 -4
- data/Rakefile +5 -5
- data/bullet.gemspec +11 -6
- data/lib/bullet/active_record4.rb +18 -14
- data/lib/bullet/active_record41.rb +16 -14
- data/lib/bullet/active_record42.rb +24 -22
- data/lib/bullet/active_record5.rb +78 -49
- data/lib/bullet/active_record52.rb +47 -40
- data/lib/bullet/dependency.rb +3 -1
- data/lib/bullet/detector/association.rb +16 -14
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +10 -7
- data/lib/bullet/detector/n_plus_one_query.rb +17 -15
- data/lib/bullet/detector/unused_eager_loading.rb +26 -21
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +6 -4
- data/lib/bullet/ext/string.rb +3 -1
- data/lib/bullet/mongoid4x.rb +7 -2
- data/lib/bullet/mongoid5x.rb +7 -2
- data/lib/bullet/mongoid6x.rb +11 -6
- data/lib/bullet/notification/base.rb +21 -15
- data/lib/bullet/notification/counter_cache.rb +2 -0
- data/lib/bullet/notification/n_plus_one_query.rb +6 -4
- data/lib/bullet/notification/unused_eager_loading.rb +6 -4
- data/lib/bullet/notification.rb +2 -0
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +19 -15
- data/lib/bullet/registry/association.rb +2 -0
- data/lib/bullet/registry/base.rb +2 -0
- data/lib/bullet/registry/object.rb +2 -0
- data/lib/bullet/registry.rb +2 -0
- data/lib/bullet/stack_trace_filter.rb +56 -19
- data/lib/bullet/version.rb +2 -1
- data/lib/bullet.rb +31 -29
- data/lib/generators/bullet/install_generator.rb +5 -3
- data/perf/benchmark.rb +9 -7
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +2 -0
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +2 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -8
- data/spec/bullet/detector/unused_eager_loading_spec.rb +2 -0
- data/spec/bullet/ext/object_spec.rb +3 -1
- data/spec/bullet/ext/string_spec.rb +2 -0
- data/spec/bullet/notification/base_spec.rb +8 -6
- data/spec/bullet/notification/counter_cache_spec.rb +3 -1
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -1
- data/spec/bullet/notification/unused_eager_loading_spec.rb +3 -1
- data/spec/bullet/notification_collector_spec.rb +2 -0
- data/spec/bullet/rack_spec.rb +10 -9
- data/spec/bullet/registry/association_spec.rb +4 -2
- data/spec/bullet/registry/base_spec.rb +5 -3
- data/spec/bullet/registry/object_spec.rb +2 -0
- data/spec/bullet_spec.rb +9 -7
- data/spec/integration/active_record/association_spec.rb +79 -17
- data/spec/integration/counter_cache_spec.rb +4 -2
- data/spec/integration/mongoid/association_spec.rb +2 -0
- data/spec/models/address.rb +2 -0
- data/spec/models/author.rb +2 -0
- data/spec/models/base_user.rb +2 -0
- data/spec/models/category.rb +2 -0
- data/spec/models/city.rb +2 -0
- data/spec/models/client.rb +4 -0
- data/spec/models/comment.rb +2 -0
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/document.rb +2 -0
- data/spec/models/entry.rb +2 -0
- data/spec/models/firm.rb +3 -0
- data/spec/models/folder.rb +2 -0
- data/spec/models/group.rb +4 -0
- data/spec/models/mongoid/address.rb +3 -1
- data/spec/models/mongoid/category.rb +4 -2
- data/spec/models/mongoid/comment.rb +3 -1
- data/spec/models/mongoid/company.rb +3 -1
- data/spec/models/mongoid/entry.rb +3 -1
- data/spec/models/mongoid/post.rb +6 -4
- data/spec/models/mongoid/user.rb +2 -0
- data/spec/models/newspaper.rb +2 -0
- data/spec/models/page.rb +2 -0
- data/spec/models/person.rb +2 -0
- data/spec/models/pet.rb +2 -0
- data/spec/models/post.rb +17 -0
- data/spec/models/relationship.rb +2 -0
- data/spec/models/reply.rb +2 -0
- data/spec/models/student.rb +2 -0
- data/spec/models/submission.rb +2 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +2 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/bullet_ext.rb +2 -0
- data/spec/support/mongo_seed.rb +32 -30
- data/spec/support/rack_double.rb +9 -16
- data/spec/support/sqlite_seed.rb +84 -75
- data/tasks/bullet_tasks.rake +2 -0
- metadata +11 -7
data/spec/models/city.rb
CHANGED
data/spec/models/client.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/company.rb
CHANGED
data/spec/models/country.rb
CHANGED
data/spec/models/document.rb
CHANGED
data/spec/models/entry.rb
CHANGED
data/spec/models/firm.rb
CHANGED
data/spec/models/folder.rb
CHANGED
|
@@ -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, :
|
|
7
|
-
has_many :entries, :
|
|
8
|
+
has_many :posts, class_name: 'Mongoid::Post'
|
|
9
|
+
has_many :entries, class_name: 'Mongoid::Entry'
|
|
8
10
|
end
|
data/spec/models/mongoid/post.rb
CHANGED
|
@@ -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, :
|
|
7
|
-
belongs_to :category, :
|
|
8
|
+
has_many :comments, class_name: 'Mongoid::Comment'
|
|
9
|
+
belongs_to :category, class_name: 'Mongoid::Category'
|
|
8
10
|
|
|
9
|
-
embeds_many :users, :
|
|
11
|
+
embeds_many :users, class_name: 'Mongoid::User'
|
|
10
12
|
|
|
11
|
-
scope :preload_comments,
|
|
13
|
+
scope :preload_comments, -> { includes(:comments) }
|
|
12
14
|
end
|
data/spec/models/mongoid/user.rb
CHANGED
data/spec/models/newspaper.rb
CHANGED
data/spec/models/page.rb
CHANGED
data/spec/models/person.rb
CHANGED
data/spec/models/pet.rb
CHANGED
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
|
data/spec/models/relationship.rb
CHANGED
data/spec/models/reply.rb
CHANGED
data/spec/models/student.rb
CHANGED
data/spec/models/submission.rb
CHANGED
data/spec/models/teacher.rb
CHANGED
data/spec/models/user.rb
CHANGED
data/spec/models/writer.rb
CHANGED
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 :
|
|
38
|
+
config.filter_run focus: true
|
|
37
39
|
config.run_all_when_everything_filtered = true
|
|
38
40
|
end
|
|
39
41
|
|
data/spec/support/bullet_ext.rb
CHANGED
data/spec/support/mongo_seed.rb
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Support
|
|
2
4
|
module MongoSeed
|
|
5
|
+
module_function
|
|
6
|
+
|
|
3
7
|
def seed_db
|
|
4
|
-
category1 = Mongoid::Category.create(:
|
|
5
|
-
category2 = Mongoid::Category.create(:
|
|
8
|
+
category1 = Mongoid::Category.create(name: 'first')
|
|
9
|
+
category2 = Mongoid::Category.create(name: 'second')
|
|
6
10
|
|
|
7
|
-
post1 = category1.posts.create(:
|
|
8
|
-
post1a = category1.posts.create(:
|
|
9
|
-
post2 = category2.posts.create(:
|
|
11
|
+
post1 = category1.posts.create(name: 'first')
|
|
12
|
+
post1a = category1.posts.create(name: 'like first')
|
|
13
|
+
post2 = category2.posts.create(name: 'second')
|
|
10
14
|
|
|
11
|
-
post1.users << Mongoid::User.create(:
|
|
12
|
-
post1.users << Mongoid::User.create(:
|
|
13
|
-
post2.users << Mongoid::User.create(:
|
|
15
|
+
post1.users << Mongoid::User.create(name: 'first')
|
|
16
|
+
post1.users << Mongoid::User.create(name: 'another')
|
|
17
|
+
post2.users << Mongoid::User.create(name: 'second')
|
|
14
18
|
|
|
15
|
-
comment1 = post1.comments.create(:
|
|
16
|
-
comment2 = post1.comments.create(:
|
|
17
|
-
comment3 = post1.comments.create(:
|
|
18
|
-
comment4 = post1.comments.create(:
|
|
19
|
-
comment8 = post1a.comments.create(:
|
|
20
|
-
comment9 = post1a.comments.create(:
|
|
21
|
-
comment5 = post2.comments.create(:
|
|
22
|
-
comment6 = post2.comments.create(:
|
|
23
|
-
comment7 = post2.comments.create(:
|
|
19
|
+
comment1 = post1.comments.create(name: 'first')
|
|
20
|
+
comment2 = post1.comments.create(name: 'first2')
|
|
21
|
+
comment3 = post1.comments.create(name: 'first3')
|
|
22
|
+
comment4 = post1.comments.create(name: 'second')
|
|
23
|
+
comment8 = post1a.comments.create(name: 'like first 1')
|
|
24
|
+
comment9 = post1a.comments.create(name: 'like first 2')
|
|
25
|
+
comment5 = post2.comments.create(name: 'third')
|
|
26
|
+
comment6 = post2.comments.create(name: 'fourth')
|
|
27
|
+
comment7 = post2.comments.create(name: 'fourth')
|
|
24
28
|
|
|
25
|
-
entry1 = category1.entries.create(:
|
|
26
|
-
entry2 = category1.entries.create(:
|
|
29
|
+
entry1 = category1.entries.create(name: 'first')
|
|
30
|
+
entry2 = category1.entries.create(name: 'second')
|
|
27
31
|
|
|
28
|
-
company1 = Mongoid::Company.create(:
|
|
29
|
-
company2 = Mongoid::Company.create(:
|
|
32
|
+
company1 = Mongoid::Company.create(name: 'first')
|
|
33
|
+
company2 = Mongoid::Company.create(name: 'second')
|
|
30
34
|
|
|
31
|
-
Mongoid::Address.create(:
|
|
32
|
-
Mongoid::Address.create(:
|
|
35
|
+
Mongoid::Address.create(name: 'first', company: company1)
|
|
36
|
+
Mongoid::Address.create(name: 'second', company: company2)
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
def setup_db
|
|
@@ -47,12 +51,12 @@ module Support
|
|
|
47
51
|
else
|
|
48
52
|
Mongoid.configure do |config|
|
|
49
53
|
config.load_configuration(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
54
|
+
clients: {
|
|
55
|
+
default: {
|
|
56
|
+
database: 'bullet',
|
|
57
|
+
hosts: ['localhost:27017']
|
|
55
58
|
}
|
|
59
|
+
}
|
|
56
60
|
)
|
|
57
61
|
end
|
|
58
62
|
# Increase the level from DEBUG in order to avoid excessive logging to the screen
|
|
@@ -64,7 +68,5 @@ module Support
|
|
|
64
68
|
Mongoid.purge!
|
|
65
69
|
Mongoid::IdentityMap.clear if Mongoid.const_defined?(:IdentityMap)
|
|
66
70
|
end
|
|
67
|
-
|
|
68
|
-
extend self
|
|
69
71
|
end
|
|
70
72
|
end
|
data/spec/support/rack_double.rb
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Support
|
|
2
4
|
class AppDouble
|
|
3
|
-
def call
|
|
5
|
+
def call(_env)
|
|
4
6
|
env = @env
|
|
5
7
|
[status, headers, response]
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
@status = status
|
|
10
|
-
end
|
|
10
|
+
attr_writer :status
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
@headers = headers
|
|
14
|
-
end
|
|
12
|
+
attr_writer :headers
|
|
15
13
|
|
|
16
14
|
def headers
|
|
17
15
|
@headers ||= { 'Content-Type' => 'text/html' }
|
|
18
16
|
@headers
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
@response = response
|
|
23
|
-
end
|
|
19
|
+
attr_writer :response
|
|
24
20
|
|
|
25
21
|
private
|
|
26
22
|
|
|
@@ -34,7 +30,7 @@ module Support
|
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
class ResponseDouble
|
|
37
|
-
def initialize
|
|
33
|
+
def initialize(actual_body = nil)
|
|
38
34
|
@actual_body = actual_body
|
|
39
35
|
end
|
|
40
36
|
|
|
@@ -42,15 +38,12 @@ module Support
|
|
|
42
38
|
@body ||= '<html><head></head><body></body></html>'
|
|
43
39
|
end
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
@body = body
|
|
47
|
-
end
|
|
41
|
+
attr_writer :body
|
|
48
42
|
|
|
49
43
|
def each
|
|
50
44
|
yield body
|
|
51
45
|
end
|
|
52
46
|
|
|
53
|
-
def close
|
|
54
|
-
end
|
|
47
|
+
def close; end
|
|
55
48
|
end
|
|
56
49
|
end
|