From f1fc8e581b9f0f19aed3f1bb83555a974885fb2f Mon Sep 17 00:00:00 2001
From: satoru koyanagi
Date: Wed, 22 Jul 2020 11:52:48 +0900
Subject: [PATCH 01/32] fix typo
---
spec/bullet/detector/counter_cache_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/bullet/detector/counter_cache_spec.rb b/spec/bullet/detector/counter_cache_spec.rb
index 454bba0f..138dc074 100644
--- a/spec/bullet/detector/counter_cache_spec.rb
+++ b/spec/bullet/detector/counter_cache_spec.rb
@@ -47,7 +47,7 @@ module Detector
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
end
- it 'should be true when object is possible, and impossible' do
+ it 'should be false when object is possible, and impossible' do
CounterCache.add_possible_objects(@post1)
CounterCache.add_impossible_object(@post1)
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
From 3abac26cc088b58bb5b106a640d6a5ba92a71ac9 Mon Sep 17 00:00:00 2001
From: Nana Adjei Manu
Date: Fri, 11 Sep 2020 05:08:30 +0000
Subject: [PATCH 02/32] Update Readme
---
README.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/README.md b/README.md
index ac394a1e..b75f8fe5 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,13 @@ or add it into a Gemfile (Bundler):
gem 'bullet', group: 'development'
```
+enable the Bullet gem with generate command
+
+```ruby
+bundle exec rails g bullet:install
+```
+The generate command will auto generate the default configuration and may ask to include in the test environment as well. See below for custom configuration.
+
**Note**: make sure `bullet` gem is added after activerecord (rails) and
mongoid.
From 815caf25099e9a56efbd07cdf9d32eae4d3aaffd Mon Sep 17 00:00:00 2001
From: Matt Swanson
Date: Wed, 30 Sep 2020 21:52:50 -0400
Subject: [PATCH 03/32] Update design of footer notification
---
lib/bullet/rack.rb | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/lib/bullet/rack.rb b/lib/bullet/rack.rb
index c683dbc2..37ee02af 100644
--- a/lib/bullet/rack.rb
+++ b/lib/bullet/rack.rb
@@ -15,9 +15,8 @@ def call(env)
status, headers, response = @app.call(env)
response_body = nil
-
if Bullet.notification?
- if Bullet.inject_into_page? && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
+ if !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
if html_request?(headers, response)
response_body = response_body(response)
response_body = append_to_html_body(response_body, footer_note) if Bullet.add_footer
@@ -55,14 +54,14 @@ def append_to_html_body(response_body, content)
end
def footer_note
- "" + footer_header + '
' + Bullet.footer_info.uniq.join('
') + '
'
+ "Bullet Warnings
#{Bullet.footer_info.uniq.join('
')}#{footer_console_message}
"
end
def set_header(headers, header_name, header_array)
# Many proxy applications such as Nginx and AWS ELB limit
# the size a header to 8KB, so truncate the list of reports to
# be under that limit
- header_array.pop while header_array.to_json.length > 8 * 1_024
+ header_array.pop while header_array.to_json.length > 8 * 1024
headers[header_name] = header_array.to_json
end
@@ -88,23 +87,28 @@ def response_body(response)
private
- def footer_div_attributes
+ def details_attributes
+ <<~EOF
+ id="bullet-footer" data-is-bullet-footer
+ style="cursor: pointer; position: fixed; left: 0px; bottom: 0px; z-index: 9999; background: #fdf2f2; color: #9b1c1c; font-size: 12px; border-radius: 0px 8px 0px 0px; border: 1px solid #9b1c1c;"
+ EOF
+ end
+
+ def summary_attributes
<<~EOF
- id="bullet-footer" data-is-bullet-footer ondblclick="this.parentNode.removeChild(this);" style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153);
- -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
- -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
- padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
- color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
+ style="font-weight: 600; padding: 2px 8px"
EOF
end
- def footer_header
- cancel_button =
- "×"
+ def footer_content_attributes
+ <<~EOF
+ style="padding: 8px; border-top: 1px solid #9b1c1c;"
+ EOF
+ end
+
+ def footer_console_message
if Bullet.console_enabled?
- "See 'Uniform Notifier' in JS Console for Stacktrace#{cancel_button}"
- else
- cancel_button
+ "
See 'Uniform Notifier' in JS Console for Stacktrace"
end
end
From b06680b61b5c37013baeadd6d577ec40fb433b39 Mon Sep 17 00:00:00 2001
From: Matt Swanson
Date: Wed, 30 Sep 2020 21:58:32 -0400
Subject: [PATCH 04/32] Revert
---
lib/bullet/rack.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/bullet/rack.rb b/lib/bullet/rack.rb
index 37ee02af..95ac4be0 100644
--- a/lib/bullet/rack.rb
+++ b/lib/bullet/rack.rb
@@ -15,8 +15,9 @@ def call(env)
status, headers, response = @app.call(env)
response_body = nil
+
if Bullet.notification?
- if !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
+ if Bullet.inject_into_page? && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
if html_request?(headers, response)
response_body = response_body(response)
response_body = append_to_html_body(response_body, footer_note) if Bullet.add_footer
From 5f5224326ba7484f1d9cb9960186d474c6f0f79c Mon Sep 17 00:00:00 2001
From: Ryunosuke Sato
Date: Tue, 3 Nov 2020 00:38:32 +0900
Subject: [PATCH 05/32] Fix to render bullet notification as html safe string
In Rails 6, the spec of `ActiveSupport::SafeBuffer#insert` has been changed.
Previously, it behaves like just String, but now `ActiveSupport::SafeBuffer` exactly.
See for details: https://github.com/rails/rails/pull/33990
---
lib/bullet/rack.rb | 1 +
spec/bullet/rack_spec.rb | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/lib/bullet/rack.rb b/lib/bullet/rack.rb
index 95ac4be0..f74eec07 100644
--- a/lib/bullet/rack.rb
+++ b/lib/bullet/rack.rb
@@ -46,6 +46,7 @@ def empty?(response)
def append_to_html_body(response_body, content)
body = response_body.dup
+ content = content.html_safe if content.respond_to?(:html_safe)
if body.include?('
')
position = body.rindex('')
body.insert(position, content)
diff --git a/spec/bullet/rack_spec.rb b/spec/bullet/rack_spec.rb
index 7e8aaf48..47c1e52f 100644
--- a/spec/bullet/rack_spec.rb
+++ b/spec/bullet/rack_spec.rb
@@ -105,6 +105,18 @@ module Bullet
expect(response.first).to include('<')
end
+ it 'should change response body for html safe string if add_footer is true' do
+ expect(Bullet).to receive(:add_footer).twice.and_return(true)
+ app.response = Support::ResponseDouble.new.tap do |response|
+ response.body = ActiveSupport::SafeBuffer.new('