bullet 7.0.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fbdfd6fe2f412c6632b877352fdf912b56fd54e255101dc16ae414a218fc2ee
4
- data.tar.gz: 0a765e969ccae1ef685051350324052225fea00e80d7d37a6b8cce6d8ad1f28e
3
+ metadata.gz: 823bcc1af2be934ec4f10df71ea2951223834d3146e9c323afada99ba4ae4254
4
+ data.tar.gz: 4cda048b45bd219d62bee22e0041027561c943d283ee262ea71686a15e6e4345
5
5
  SHA512:
6
- metadata.gz: 35c561cc6534f355a56d1aa0e880bb51941c126ce8a9c704bbc8c0f59c67cf5890a00d650919d5a458a913f4d6a125b17e57c92130d48baa9b6a90db190db763
7
- data.tar.gz: 4f29d4316862401ad1d5d4edfdf21f6f8045a37e21acc4d12f3cdd80e528b12924a9f0a2ab5fdb366432ea5c8e656210887112fc338da8539a34586da88710e9
6
+ metadata.gz: 9a2398eb23da7201bb8ab3fb1dbea3d48089d6c51d4a0e473d25009841aab41c68a5b0c27fb6ac6b77084e2465a836a5b848ffda63a2ea3b457a9571b04d428f
7
+ data.tar.gz: ab3debd03dc9cafbbd8ef9237f747c67d14bf3d8bf116b7dbed4e145176cf3f10045862b32641036e9bb00caca6eee841c75f9b3defad83ca681d0d70a5c6f0d
@@ -76,7 +76,7 @@ jobs:
76
76
  - name: Set up Ruby
77
77
  uses: ruby/setup-ruby@v1
78
78
  with:
79
- ruby-version: 3.0
79
+ ruby-version: 3.1
80
80
  bundler-cache: true
81
81
  - name: Run tests
82
82
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Next Release
2
2
 
3
+ ## 7.0.1 (01/15/2022)
4
+
5
+ * Get rid of *_whitelist methods
6
+ * Hack ActiveRecord::Associations::Preloader::Batch in rails 7
7
+
3
8
  ## 7.0.0 (12/18/2021)
4
9
 
5
10
  * Support rails 7
data/README.md CHANGED
@@ -270,8 +270,7 @@ Bullet outputs some details info, to enable debug mode, set
270
270
  ## Demo
271
271
 
272
272
  Bullet is designed to function as you browse through your application in development. To see it in action,
273
- you can visit [https://github.com/flyerhzm/bullet_test](https://github.com/flyerhzm/bullet_test) or
274
- follow these steps to create, detect, and fix example query problems.
273
+ you can follow these steps to create, detect, and fix example query problems.
275
274
 
276
275
  1\. Create an example application
277
276
 
@@ -482,4 +481,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
482
481
  Post => [:comments]
483
482
  ```
484
483
 
485
- Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
484
+ Copyright (c) 2009 - 2022 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -60,6 +60,20 @@ module Bullet
60
60
  end
61
61
  )
62
62
 
63
+ ::ActiveRecord::Associations::Preloader::Batch.prepend(
64
+ Module.new do
65
+ def call
66
+ if Bullet.start?
67
+ @preloaders.each do |preloader|
68
+ preloader.records.each { |record| Bullet::Detector::Association.add_object_associations(record, preloader.associations) }
69
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(preloader.records, preloader.associations)
70
+ end
71
+ end
72
+ super
73
+ end
74
+ end
75
+ )
76
+
63
77
  ::ActiveRecord::Associations::Preloader::Branch.prepend(
64
78
  Module.new do
65
79
  def preloaders_for_reflection(reflection, reflection_records)
data/lib/bullet/rack.rb CHANGED
@@ -42,6 +42,7 @@ module Bullet
42
42
  def empty?(response)
43
43
  # response may be ["Not Found"], ["Move Permanently"], etc, but
44
44
  # those should not happen if the status is 200
45
+ return true if !response.respond_to?(:body) && !response.respond_to?(:first)
45
46
  body = response_body(response)
46
47
  body.nil? || body.empty?
47
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '7.0.0'
4
+ VERSION = '7.0.1'
5
5
  end
data/lib/bullet.rb CHANGED
@@ -120,51 +120,6 @@ module Bullet
120
120
  @safelist = nil
121
121
  end
122
122
 
123
- def add_whitelist(options)
124
- ActiveSupport::Deprecation.warn(<<~WARN.strip
125
- add_whitelist is deprecated in favor of add_safelist. It will be removed from the next major release.
126
- WARN
127
- )
128
-
129
- add_safelist(options)
130
- end
131
-
132
- def delete_whitelist(options)
133
- ActiveSupport::Deprecation.warn(<<~WARN.strip
134
- delete_whitelist is deprecated in favor of delete_safelist. It will be removed from the next major release.
135
- WARN
136
- )
137
-
138
- delete_safelist(options)
139
- end
140
-
141
- def get_whitelist_associations(type, class_name)
142
- ActiveSupport::Deprecation.warn(<<~WARN.strip
143
- get_whitelist_associations is deprecated in favor of get_safelist_associations. It will be removed from the next major release.
144
- WARN
145
- )
146
-
147
- get_safelist_associations(type, class_name)
148
- end
149
-
150
- def reset_whitelist
151
- ActiveSupport::Deprecation.warn(<<~WARN.strip
152
- reset_whitelist is deprecated in favor of reset_safelist. It will be removed from the next major release.
153
- WARN
154
- )
155
-
156
- reset_safelist
157
- end
158
-
159
- def clear_whitelist
160
- ActiveSupport::Deprecation.warn(<<~WARN.strip
161
- clear_whitelist is deprecated in favor of clear_safelist. It will be removed from the next major release.
162
- WARN
163
- )
164
-
165
- clear_safelist
166
- end
167
-
168
123
  def bullet_logger=(active)
169
124
  if active
170
125
  require 'fileutils'
@@ -54,6 +54,11 @@ module Bullet
54
54
  response = double(body: '')
55
55
  expect(middleware).to be_empty(response)
56
56
  end
57
+
58
+ it 'should be true if no response body' do
59
+ response = double()
60
+ expect(middleware).to be_empty(response)
61
+ end
57
62
  end
58
63
 
59
64
  context '#call' do
data/spec/bullet_spec.rb CHANGED
@@ -83,15 +83,6 @@ describe Bullet, focused: true do
83
83
  end
84
84
  end
85
85
 
86
- describe '#add_whitelist' do
87
- context "for 'special' class names" do
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
86
  describe '#delete_safelist' do
96
87
  context "for 'special' class names" do
97
88
  it 'is deleted from the safelist successfully' do
@@ -112,26 +103,6 @@ describe Bullet, focused: true do
112
103
  end
113
104
  end
114
105
 
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
131
- end
132
- end
133
- end
134
-
135
106
  describe '#perform_out_of_channel_notifications' do
136
107
  let(:notification) { double }
137
108
 
@@ -451,6 +451,16 @@ if active_record?
451
451
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
452
452
  end
453
453
  end
454
+
455
+ context 'user => roles' do
456
+ it 'should detect preload associations' do
457
+ User.first.roles.includes(:resource).each { |role| role.resource }
458
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
459
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
460
+
461
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
462
+ end
463
+ end
454
464
  end
455
465
 
456
466
  describe Bullet::Detector::Association, 'has_many :through' do
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Role < ActiveRecord::Base
4
+ has_and_belongs_to_many :users
5
+
6
+ belongs_to :resource, polymorphic: true
7
+ end
data/spec/models/user.rb CHANGED
@@ -4,4 +4,5 @@ class User < ActiveRecord::Base
4
4
  has_one :submission
5
5
  has_one :submission_attachment, through: :submission, source: :attachment, class_name: 'Attachment'
6
6
  belongs_to :category
7
+ has_and_belongs_to_many :roles
7
8
  end
@@ -92,9 +92,16 @@ module Support
92
92
  page3 = Page.create(name: 'page3', parent_id: folder2.id, author_id: author2.id)
93
93
  page4 = Page.create(name: 'page4', parent_id: folder2.id, author_id: author2.id)
94
94
 
95
+ role1 = Role.create(name: 'Amdin')
96
+ role2 = Role.create(name: 'User')
97
+
95
98
  user1 = User.create(name: 'user1', category: category1)
96
99
  user2 = User.create(name: 'user2', category: category1)
97
100
 
101
+ user1.roles << role1
102
+ user1.roles << role2
103
+ user2.roles << role2
104
+
98
105
  submission1 = user1.create_submission(name: 'submission1')
99
106
  submission2 = user2.create_submission(name: 'submission2')
100
107
 
@@ -246,6 +253,17 @@ module Support
246
253
  t.column :submission_id, :integer
247
254
  end
248
255
 
256
+ create_table :roles do |t|
257
+ t.column :name, :string
258
+ t.column :resource_id, :integer
259
+ t.column :resource_type, :string
260
+ end
261
+
262
+ create_table :roles_users do |t|
263
+ t.column :role_id, :integer
264
+ t.column :user_id, :integer
265
+ end
266
+
249
267
  create_table :submissions do |t|
250
268
  t.column :name, :string
251
269
  t.column :user_id, :integer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-18 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -160,6 +160,7 @@ files:
160
160
  - spec/models/post.rb
161
161
  - spec/models/relationship.rb
162
162
  - spec/models/reply.rb
163
+ - spec/models/role.rb
163
164
  - spec/models/student.rb
164
165
  - spec/models/submission.rb
165
166
  - spec/models/teacher.rb
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  - !ruby/object:Gem::Version
195
196
  version: 1.3.6
196
197
  requirements: []
197
- rubygems_version: 3.2.22
198
+ rubygems_version: 3.2.32
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: help to kill N+1 queries and unused eager loading.
@@ -249,6 +250,7 @@ test_files:
249
250
  - spec/models/post.rb
250
251
  - spec/models/relationship.rb
251
252
  - spec/models/reply.rb
253
+ - spec/models/role.rb
252
254
  - spec/models/student.rb
253
255
  - spec/models/submission.rb
254
256
  - spec/models/teacher.rb