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.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +66 -0
- data/CHANGELOG.md +83 -1
- data/Gemfile +6 -1
- data/Gemfile.mongoid-7.0 +15 -0
- data/Gemfile.rails-4.0 +1 -1
- data/Gemfile.rails-4.1 +1 -1
- data/Gemfile.rails-4.2 +1 -1
- data/Gemfile.rails-5.0 +2 -2
- data/Gemfile.rails-5.1 +15 -0
- data/Gemfile.rails-5.2 +15 -0
- data/Gemfile.rails-6.0 +15 -0
- data/Gemfile.rails-6.1 +15 -0
- data/Guardfile +2 -2
- data/Hacking.md +1 -1
- data/README.md +58 -37
- data/Rakefile +20 -21
- data/bullet.gemspec +21 -15
- data/lib/bullet/active_job.rb +13 -0
- data/lib/bullet/active_record4.rb +15 -34
- data/lib/bullet/active_record41.rb +14 -31
- data/lib/bullet/active_record42.rb +23 -36
- data/lib/bullet/active_record5.rb +178 -158
- data/lib/bullet/active_record52.rb +251 -0
- data/lib/bullet/active_record60.rb +278 -0
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +64 -0
- data/lib/bullet/dependency.rb +60 -32
- data/lib/bullet/detector/association.rb +41 -32
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +25 -17
- data/lib/bullet/detector/n_plus_one_query.rb +38 -24
- data/lib/bullet/detector/unused_eager_loading.rb +35 -26
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +9 -5
- data/lib/bullet/ext/string.rb +3 -1
- data/lib/bullet/mongoid4x.rb +9 -8
- data/lib/bullet/mongoid5x.rb +9 -8
- data/lib/bullet/mongoid6x.rb +13 -12
- data/lib/bullet/mongoid7x.rb +57 -0
- data/lib/bullet/notification/base.rb +28 -25
- data/lib/bullet/notification/counter_cache.rb +3 -1
- data/lib/bullet/notification/n_plus_one_query.rb +8 -7
- data/lib/bullet/notification/unused_eager_loading.rb +8 -7
- data/lib/bullet/notification.rb +4 -1
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +66 -35
- 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 +50 -20
- data/lib/bullet/version.rb +3 -2
- data/lib/bullet.rb +136 -55
- data/lib/generators/bullet/install_generator.rb +48 -0
- data/perf/benchmark.rb +19 -22
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +6 -4
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +17 -15
- data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
- data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
- data/spec/bullet/ext/object_spec.rb +18 -11
- data/spec/bullet/ext/string_spec.rb +7 -5
- data/spec/bullet/notification/base_spec.rb +38 -39
- data/spec/bullet/notification/counter_cache_spec.rb +5 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
- data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
- data/spec/bullet/notification_collector_spec.rb +12 -10
- data/spec/bullet/rack_spec.rb +200 -48
- data/spec/bullet/registry/association_spec.rb +12 -10
- data/spec/bullet/registry/base_spec.rb +22 -20
- data/spec/bullet/registry/object_spec.rb +6 -4
- data/spec/bullet_spec.rb +64 -33
- data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
- data/spec/integration/counter_cache_spec.rb +26 -44
- data/spec/integration/mongoid/association_spec.rb +53 -65
- data/spec/models/address.rb +2 -0
- data/spec/models/attachment.rb +5 -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 +3 -1
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/deal.rb +5 -0
- data/spec/models/document.rb +4 -2
- 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 +3 -1
- 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 +19 -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 +3 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +3 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +19 -23
- data/spec/support/bullet_ext.rb +10 -9
- data/spec/support/mongo_seed.rb +38 -57
- data/spec/support/rack_double.rb +13 -19
- data/spec/support/sqlite_seed.rb +104 -76
- data/tasks/bullet_tasks.rake +4 -2
- data/test.sh +5 -0
- data/update.sh +3 -0
- metadata +34 -17
- data/.travis.yml +0 -16
- data/spec/integration/active_record5/association_spec.rb +0 -768
data/spec/bullet_spec.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Bullet, focused: true do
|
|
4
6
|
subject { Bullet }
|
|
5
7
|
|
|
6
8
|
describe '#enable' do
|
|
7
|
-
|
|
8
9
|
context 'enable Bullet' do
|
|
9
10
|
before do
|
|
10
11
|
# Bullet.enable
|
|
@@ -16,9 +17,7 @@ describe Bullet, focused: true do
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
context 'disable Bullet' do
|
|
19
|
-
before
|
|
20
|
-
Bullet.enable = false
|
|
21
|
-
end
|
|
20
|
+
before { Bullet.enable = false }
|
|
22
21
|
|
|
23
22
|
it 'should be disabled' do
|
|
24
23
|
expect(subject).to_not be_enable
|
|
@@ -26,8 +25,8 @@ describe Bullet, focused: true do
|
|
|
26
25
|
|
|
27
26
|
context 'enable Bullet again without patching again the orms' do
|
|
28
27
|
before do
|
|
29
|
-
expect(Bullet::Mongoid).not_to receive(:enable) if defined?
|
|
30
|
-
expect(Bullet::ActiveRecord).not_to receive(:enable) if defined?
|
|
28
|
+
expect(Bullet::Mongoid).not_to receive(:enable) if defined?(Bullet::Mongoid)
|
|
29
|
+
expect(Bullet::ActiveRecord).not_to receive(:enable) if defined?(Bullet::ActiveRecord)
|
|
31
30
|
Bullet.enable = true
|
|
32
31
|
end
|
|
33
32
|
|
|
@@ -41,9 +40,7 @@ describe Bullet, focused: true do
|
|
|
41
40
|
|
|
42
41
|
describe '#start?' do
|
|
43
42
|
context 'when bullet is disabled' do
|
|
44
|
-
before(:each)
|
|
45
|
-
Bullet.enable = false
|
|
46
|
-
end
|
|
43
|
+
before(:each) { Bullet.enable = false }
|
|
47
44
|
|
|
48
45
|
it 'should not be started' do
|
|
49
46
|
expect(Bullet).not_to be_start
|
|
@@ -52,28 +49,19 @@ describe Bullet, focused: true do
|
|
|
52
49
|
end
|
|
53
50
|
|
|
54
51
|
describe '#debug' do
|
|
55
|
-
before(:each)
|
|
56
|
-
$stdout = StringIO.new
|
|
57
|
-
end
|
|
52
|
+
before(:each) { $stdout = StringIO.new }
|
|
58
53
|
|
|
59
|
-
after(:each)
|
|
60
|
-
$stdout = STDOUT
|
|
61
|
-
end
|
|
54
|
+
after(:each) { $stdout = STDOUT }
|
|
62
55
|
|
|
63
56
|
context 'when debug is enabled' do
|
|
64
|
-
before(:each)
|
|
65
|
-
ENV['BULLET_DEBUG'] = 'true'
|
|
66
|
-
end
|
|
57
|
+
before(:each) { ENV['BULLET_DEBUG'] = 'true' }
|
|
67
58
|
|
|
68
|
-
after(:each)
|
|
69
|
-
ENV['BULLET_DEBUG'] = 'false'
|
|
70
|
-
end
|
|
59
|
+
after(:each) { ENV['BULLET_DEBUG'] = 'false' }
|
|
71
60
|
|
|
72
61
|
it 'should output debug information' do
|
|
73
62
|
Bullet.debug('debug_message', 'this is helpful information')
|
|
74
63
|
|
|
75
|
-
expect($stdout.string)
|
|
76
|
-
.to eq("[Bullet][debug_message] this is helpful information\n")
|
|
64
|
+
expect($stdout.string).to eq("[Bullet][debug_message] this is helpful information\n")
|
|
77
65
|
end
|
|
78
66
|
end
|
|
79
67
|
|
|
@@ -86,11 +74,60 @@ describe Bullet, focused: true do
|
|
|
86
74
|
end
|
|
87
75
|
end
|
|
88
76
|
|
|
77
|
+
describe '#add_safelist' do
|
|
78
|
+
context "for 'special' class names" do
|
|
79
|
+
it 'is added to the safelist successfully' do
|
|
80
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
81
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
89
86
|
describe '#add_whitelist' do
|
|
90
87
|
context "for 'special' class names" do
|
|
91
|
-
it 'is added to the
|
|
92
|
-
Bullet.add_whitelist(:
|
|
93
|
-
expect(Bullet.
|
|
88
|
+
it 'is added to the safelist successfully' do
|
|
89
|
+
Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
90
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe '#delete_safelist' do
|
|
96
|
+
context "for 'special' class names" do
|
|
97
|
+
it 'is deleted from the safelist successfully' do
|
|
98
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
99
|
+
Bullet.delete_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
100
|
+
expect(Bullet.safelist[:n_plus_one_query]).to eq({})
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context 'when exists multiple definitions' do
|
|
105
|
+
it 'is deleted from the safelist successfully' do
|
|
106
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
107
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
|
108
|
+
Bullet.delete_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
|
109
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
|
110
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe '#delete_whitelist' do
|
|
116
|
+
context "for 'special' class names" do
|
|
117
|
+
it 'is deleted from the safelist successfully' do
|
|
118
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
119
|
+
Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
120
|
+
expect(Bullet.safelist[:n_plus_one_query]).to eq({})
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'when exists multiple definitions' do
|
|
125
|
+
it 'is deleted from the safelist successfully' do
|
|
126
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
|
127
|
+
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
|
128
|
+
Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
|
129
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
|
130
|
+
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
|
|
94
131
|
end
|
|
95
132
|
end
|
|
96
133
|
end
|
|
@@ -104,13 +141,7 @@ describe Bullet, focused: true do
|
|
|
104
141
|
end
|
|
105
142
|
|
|
106
143
|
context 'when called with Rack environment hash' do
|
|
107
|
-
let(:env) {
|
|
108
|
-
{
|
|
109
|
-
'REQUEST_METHOD' => 'GET',
|
|
110
|
-
'PATH_INFO' => '/path',
|
|
111
|
-
'QUERY_STRING' => 'foo=bar',
|
|
112
|
-
}
|
|
113
|
-
}
|
|
144
|
+
let(:env) { { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/path', 'QUERY_STRING' => 'foo=bar' } }
|
|
114
145
|
|
|
115
146
|
context "when env['REQUEST_URI'] is nil" do
|
|
116
147
|
before { env['REQUEST_URI'] = nil }
|