bullet 6.1.2 → 6.1.3

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: 0363cc75d4facd4a8b4a318312a421040d5b21d7ca81c0b3af21daaf7c2b60cd
4
- data.tar.gz: ac0b0e4ed9c1641b5359b3d885ef854934b85b8ee21bc0486a4c3d2661e20853
3
+ metadata.gz: b574ae38dafed75dc9aded2d6c97ab057593fcda5a49ec4875bc327f99625efd
4
+ data.tar.gz: df882c895e98b91a26371b670ffd439a2a39e80df57ce1b61a87de6e89c10c1a
5
5
  SHA512:
6
- metadata.gz: 199558c8186455fb2ddac94461d611d1c40eb0fb83ac68e36647efe0a34927020967a803cb24645b7ae3d5d045aa0060c604b455476f8c6aad6b5329103a7ebe
7
- data.tar.gz: 86c4bcf9fcca52275229b7fa5e02919c39318d91a60c7fe956d4cab07442cbacfc3d9df134af1ee38bc7f153eeb2cd256faff45815ad83acd296c1831d1fc9ee
6
+ metadata.gz: 475691616eca228e0938effbc8a9a8930d8ab33f673d4cb2a75ff02b2933ba01ee2a570fff1d9d669700fb05cf09dff9149555f1f2b35c4a31c8904620db70e3
7
+ data.tar.gz: 86f37317790084aa7ca3860c1757a41354678a1a0bfbf56fe6f21ebe6793eef5ff257fe75bbad77b999484a9e1abb527d9e9ac877dda04cf9f1236e110e6d561
@@ -1,5 +1,10 @@
1
1
  ## Next Release
2
2
 
3
+ ## 6.1.3 (01/21/2021)
4
+
5
+ * Consider ThroughAssociation at SingularAssociation like CollectionAssociation
6
+ * Add xhr_script only when add_footer is enabled
7
+
3
8
  ## 6.1.2 (12/12/2020)
4
9
 
5
10
  * Revert "Make whitelist thread safe"
@@ -41,7 +41,7 @@ module Bullet
41
41
  attr_reader :whitelist
42
42
  attr_accessor :add_footer, :orm_patches_applied
43
43
 
44
- available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
44
+ available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
45
45
  available_notifiers_options = { to: UniformNotifier }
46
46
  delegate(*available_notifiers, **available_notifiers_options)
47
47
 
@@ -89,11 +89,11 @@ module Bullet
89
89
  end
90
90
 
91
91
  def stacktrace_includes
92
- @stacktrace_includes || []
92
+ @stacktrace_includes ||= []
93
93
  end
94
94
 
95
95
  def stacktrace_excludes
96
- @stacktrace_excludes || []
96
+ @stacktrace_excludes ||= []
97
97
  end
98
98
 
99
99
  def add_whitelist(options)
@@ -241,7 +241,9 @@ module Bullet
241
241
  end
242
242
 
243
243
  def inject_into_page?
244
- !@skip_html_injection && (console_enabled? || add_footer)
244
+ return false if defined?(@skip_html_injection) && @skip_html_injection
245
+
246
+ console_enabled? || add_footer
245
247
  end
246
248
 
247
249
  private
@@ -202,6 +202,17 @@ module Bullet
202
202
 
203
203
  if Bullet.start?
204
204
  if owner.class.name !~ /^HABTM_/ && !@inversed
205
+ if is_a? ::ActiveRecord::Associations::ThroughAssociation
206
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
207
+ association = owner.association reflection.through_reflection.name
208
+ Array(association.target).each do |through_record|
209
+ Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
210
+ end
211
+
212
+ if reflection.through_reflection != through_reflection
213
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
214
+ end
215
+ end
205
216
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
206
217
 
207
218
  if Bullet::Detector::NPlusOneQuery.impossible?(owner)
@@ -229,6 +229,17 @@ module Bullet
229
229
 
230
230
  if Bullet.start?
231
231
  if owner.class.name !~ /^HABTM_/ && !@inversed
232
+ if is_a? ::ActiveRecord::Associations::ThroughAssociation
233
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
234
+ association = owner.association(reflection.through_reflection.name)
235
+ Array(association.target).each do |through_record|
236
+ Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
237
+ end
238
+
239
+ if reflection.through_reflection != through_reflection
240
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
241
+ end
242
+ end
232
243
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
233
244
 
234
245
  if Bullet::Detector::NPlusOneQuery.impossible?(owner)
@@ -229,6 +229,17 @@ module Bullet
229
229
 
230
230
  if Bullet.start?
231
231
  if owner.class.name !~ /^HABTM_/ && !@inversed
232
+ if is_a? ::ActiveRecord::Associations::ThroughAssociation
233
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
234
+ association = owner.association(reflection.through_reflection.name)
235
+ Array(association.target).each do |through_record|
236
+ Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
237
+ end
238
+
239
+ if reflection.through_reflection != through_reflection
240
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
241
+ end
242
+ end
232
243
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
233
244
 
234
245
  if Bullet::Detector::NPlusOneQuery.impossible?(owner)
@@ -23,7 +23,7 @@ module Bullet
23
23
  end
24
24
 
25
25
  def each(&block)
26
- return to_enum unless block_given?
26
+ return to_enum unless block
27
27
 
28
28
  records = []
29
29
  origin_each { |record| records << record }
@@ -23,7 +23,7 @@ module Bullet
23
23
  end
24
24
 
25
25
  def each(&block)
26
- return to_enum unless block_given?
26
+ return to_enum unless block
27
27
 
28
28
  records = []
29
29
  origin_each { |record| records << record }
@@ -23,7 +23,7 @@ module Bullet
23
23
  end
24
24
 
25
25
  def each(&block)
26
- return to_enum unless block_given?
26
+ return to_enum unless block
27
27
 
28
28
  records = []
29
29
  origin_each { |record| records << record }
@@ -23,7 +23,7 @@ module Bullet
23
23
  end
24
24
 
25
25
  def each(&block)
26
- return to_enum unless block_given?
26
+ return to_enum unless block
27
27
 
28
28
  records = []
29
29
  origin_each { |record| records << record }
@@ -22,7 +22,7 @@ module Bullet
22
22
  response_body = response_body(response)
23
23
  response_body = append_to_html_body(response_body, footer_note) if Bullet.add_footer
24
24
  response_body = append_to_html_body(response_body, Bullet.gather_inline_notifications)
25
- response_body = append_to_html_body(response_body, xhr_script)
25
+ response_body = append_to_html_body(response_body, xhr_script) if Bullet.add_footer
26
26
  headers['Content-Length'] = response_body.bytesize.to_s
27
27
  else
28
28
  set_header(headers, 'X-bullet-footer-text', Bullet.footer_info.uniq) if Bullet.add_footer
@@ -59,8 +59,7 @@ module Bullet
59
59
  end
60
60
 
61
61
  def ruby_19?
62
- @ruby_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') if @ruby_19.nil?
63
- @ruby_19
62
+ @ruby_19 ||= Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
64
63
  end
65
64
  end
66
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '6.1.2'
4
+ VERSION = '6.1.3'
5
5
  end
@@ -69,7 +69,6 @@ module Bullet
69
69
  expect(Bullet).to receive(:notification?).and_return(true)
70
70
  expect(Bullet).to receive(:console_enabled?).and_return(true)
71
71
  expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
72
- expect(middleware).to receive(:xhr_script).and_return('')
73
72
  expect(Bullet).to receive(:perform_out_of_channel_notifications)
74
73
  _, headers, response = middleware.call('Content-Type' => 'text/html')
75
74
  expect(headers['Content-Length']).to eq('56')
@@ -84,7 +83,7 @@ module Bullet
84
83
  allow(Bullet).to receive(:console_enabled?).and_return(true)
85
84
  expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
86
85
  _, headers, response = middleware.call('Content-Type' => 'text/html')
87
- expect(headers['Content-Length']).to eq((58 + middleware.send(:xhr_script).length).to_s)
86
+ expect(headers['Content-Length']).to eq('58')
88
87
  end
89
88
 
90
89
  context 'with injection notifiers' do
@@ -97,7 +96,7 @@ module Bullet
97
96
  end
98
97
 
99
98
  it 'should change response body if add_footer is true' do
100
- expect(Bullet).to receive(:add_footer).twice.and_return(true)
99
+ expect(Bullet).to receive(:add_footer).exactly(3).times.and_return(true)
101
100
  _, headers, response = middleware.call('Content-Type' => 'text/html')
102
101
 
103
102
  expect(headers['Content-Length']).to eq((56 + middleware.send(:footer_note).length).to_s)
@@ -106,7 +105,7 @@ module Bullet
106
105
  end
107
106
 
108
107
  it 'should change response body for html safe string if add_footer is true' do
109
- expect(Bullet).to receive(:add_footer).twice.and_return(true)
108
+ expect(Bullet).to receive(:add_footer).exactly(3).times.and_return(true)
110
109
  app.response = Support::ResponseDouble.new.tap do |response|
111
110
  response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>')
112
111
  end
@@ -561,6 +561,42 @@ if active_record?
561
561
  end
562
562
  end
563
563
 
564
+ describe Bullet::Detector::Association, 'has_one :through' do
565
+ context 'user => attachment' do
566
+ it 'should detect non preload associations' do
567
+ User.all.each { |user| user.submission_attachment.file_name }
568
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
569
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
570
+
571
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(User, :submission_attachment)
572
+ end
573
+
574
+ it 'should detect preload associations' do
575
+ User.includes(:submission_attachment).each { |user| user.submission_attachment.file_name }
576
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
577
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
578
+
579
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
580
+ end
581
+
582
+ it 'should not detect preload associations' do
583
+ User.all.map(&:name)
584
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
585
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
586
+
587
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
588
+ end
589
+
590
+ it 'should detect unused preload associations' do
591
+ User.includes(:submission_attachment).map(&:name)
592
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
593
+ expect(Bullet::Detector::Association).to be_unused_preload_associations_for(User, :submission_attachment)
594
+
595
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
596
+ end
597
+ end
598
+ end
599
+
564
600
  describe Bullet::Detector::Association, 'call one association that in possible objects' do
565
601
  it 'should not detect preload association' do
566
602
  Post.all
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Attachment < ActiveRecord::Base
4
+ belongs_to :submission
5
+ end
@@ -3,4 +3,5 @@
3
3
  class Submission < ActiveRecord::Base
4
4
  belongs_to :user
5
5
  has_many :replies
6
+ has_one :attachment
6
7
  end
@@ -2,5 +2,6 @@
2
2
 
3
3
  class User < ActiveRecord::Base
4
4
  has_one :submission
5
+ has_one :submission_attachment, through: :submission, source: :attachment, class_name: 'Attachment'
5
6
  belongs_to :category
6
7
  end
@@ -95,6 +95,9 @@ module Support
95
95
  submission1.replies.create(name: 'reply2')
96
96
  submission2.replies.create(name: 'reply3')
97
97
  submission2.replies.create(name: 'reply4')
98
+
99
+ submission1.create_attachment(file_name: 'submission1 file')
100
+ submission2.create_attachment(file_name: 'submission2 file')
98
101
  end
99
102
 
100
103
  def setup_db
@@ -240,6 +243,11 @@ module Support
240
243
  t.column :name, :string
241
244
  t.column :category_id, :integer
242
245
  end
246
+
247
+ create_table :attachments do |t|
248
+ t.column :file_name, :string
249
+ t.column :submission_id, :integer
250
+ end
243
251
  end
244
252
  end
245
253
  end
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: 6.1.2
4
+ version: 6.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,6 +129,7 @@ files:
129
129
  - spec/integration/counter_cache_spec.rb
130
130
  - spec/integration/mongoid/association_spec.rb
131
131
  - spec/models/address.rb
132
+ - spec/models/attachment.rb
132
133
  - spec/models/author.rb
133
134
  - spec/models/base_user.rb
134
135
  - spec/models/category.rb
@@ -216,6 +217,7 @@ test_files:
216
217
  - spec/integration/counter_cache_spec.rb
217
218
  - spec/integration/mongoid/association_spec.rb
218
219
  - spec/models/address.rb
220
+ - spec/models/attachment.rb
219
221
  - spec/models/author.rb
220
222
  - spec/models/base_user.rb
221
223
  - spec/models/category.rb