From ba280de486a19bf68187a2d2ae2e1e7f4ce7a019 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sun, 3 Dec 2023 21:16:12 -0800 Subject: [PATCH 1/3] upgrade to Rails 7.1 --- Gemfile.lock | 168 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 67 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aa7c3f3..f97445e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,73 +7,84 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) + actioncable (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + zeitwerk (~> 2.6) + actionmailbox (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8) - actionpack (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activesupport (= 7.0.8) + actionmailer (7.1.2) + actionpack (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activesupport (= 7.1.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.8) - actionview (= 7.0.8) - activesupport (= 7.0.8) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.2) + actionview (= 7.1.2) + activesupport (= 7.1.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8) - actionpack (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.2) + actionpack (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8) - activesupport (= 7.0.8) + actionview (7.1.2) + activesupport (= 7.1.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8) - activesupport (= 7.0.8) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.2) + activesupport (= 7.1.2) globalid (>= 0.3.6) - activemodel (7.0.8) - activesupport (= 7.0.8) - activerecord (7.0.8) - activemodel (= 7.0.8) - activesupport (= 7.0.8) - activestorage (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activesupport (= 7.0.8) + activemodel (7.1.2) + activesupport (= 7.1.2) + activerecord (7.1.2) + activemodel (= 7.1.2) + activesupport (= 7.1.2) + timeout (>= 0.4.0) + activestorage (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activesupport (= 7.1.2) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.8) + activesupport (7.1.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + base64 (0.2.0) + bigdecimal (3.1.4) builder (3.2.4) capybara (3.39.2) addressable @@ -86,14 +97,21 @@ GEM xpath (~> 3.2) coderay (1.1.3) concurrent-ruby (1.2.2) + connection_pool (2.4.1) crass (1.0.6) date (3.3.4) diff-lcs (1.5.0) + drb (2.2.0) + ruby2_keywords erubi (1.12.0) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.10.0) + rdoc + reline (>= 0.3.8) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -107,7 +125,8 @@ GEM method_source (1.0.0) mini_mime (1.1.5) minitest (5.20.0) - net-imap (0.4.6) + mutex_m (0.2.0) + net-imap (0.4.7) date net-protocol net-pop (0.1.2) @@ -116,7 +135,7 @@ GEM timeout net-smtp (0.4.0) net-protocol - nio4r (2.6.1) + nio4r (2.7.0) nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) nokogiri (1.15.5-x86_64-linux) @@ -124,25 +143,32 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) + psych (5.1.1.1) + stringio public_suffix (5.0.4) racc (1.7.3) - rack (2.2.8) + rack (3.0.8) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8) - actioncable (= 7.0.8) - actionmailbox (= 7.0.8) - actionmailer (= 7.0.8) - actionpack (= 7.0.8) - actiontext (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activemodel (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.2) + actioncable (= 7.1.2) + actionmailbox (= 7.1.2) + actionmailer (= 7.1.2) + actionpack (= 7.1.2) + actiontext (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activemodel (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) bundler (>= 1.15.0) - railties (= 7.0.8) + railties (= 7.1.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -150,15 +176,20 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) - method_source + railties (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rake (13.1.0) + rdoc (6.6.0) + psych (>= 4.0.0) regexp_parser (2.8.2) + reline (0.4.1) + io-console (~> 0.5) rspec-core (3.12.2) rspec-support (~> 3.12.0) rspec-expectations (3.12.3) @@ -176,6 +207,7 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) + ruby2_keywords (0.0.5) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) @@ -185,10 +217,12 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.6.9-arm64-darwin) sqlite3 (1.6.9-x86_64-linux) + stringio (3.1.0) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) From 935b0c3d92e698a4e3ba2b8353398a53c4f52821 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sun, 3 Dec 2023 21:23:04 -0800 Subject: [PATCH 2/3] remove Rails 3 broadcast, add Rails 7.1 broadcast --- lib/rails-footnotes/notes/log_note.rb | 9 +++-- .../notes/log_note/note_logger.rb | 38 ------------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/lib/rails-footnotes/notes/log_note.rb b/lib/rails-footnotes/notes/log_note.rb index 383825e..58f9281 100644 --- a/lib/rails-footnotes/notes/log_note.rb +++ b/lib/rails-footnotes/notes/log_note.rb @@ -17,9 +17,12 @@ def self.start!(controller) else defined?(ActiveSupport::Logger) ? ActiveSupport::Logger::SimpleFormatter.new : Logger::SimpleFormatter.new end - # Rails 3 don't have ActiveSupport::Logger#broadcast so we backported it - extend_module = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger.broadcast(note_logger) : NoteLogger.broadcast(note_logger) - Rails.logger = self.original_logger.clone.extend(extend_module) + + if ::Rails::VERSION::STRING < "7.1" + ::Rails.logger.extend(::ActiveSupport::Logger.broadcast(note_logger)) + else + ::Rails.logger = ::ActiveSupport::BroadcastLogger.new(::Rails.logger, note_logger) + end end def title diff --git a/lib/rails-footnotes/notes/log_note/note_logger.rb b/lib/rails-footnotes/notes/log_note/note_logger.rb index 67f33f5..62e9d23 100644 --- a/lib/rails-footnotes/notes/log_note/note_logger.rb +++ b/lib/rails-footnotes/notes/log_note/note_logger.rb @@ -15,44 +15,6 @@ def add(severity, message = nil, progname = nil, &block) formatter = @formatter || Logger::Formatter.new @logs << formatter.call(format_severity(severity), Time.now, message, progname) end - - ## Backport from rails 4 for handling logging broadcast, should be removed when rails 3 is deprecated : - - # Broadcasts logs to multiple loggers. - def self.broadcast(logger) # :nodoc: - Module.new do - define_method(:add) do |*args, &block| - logger.add(*args, &block) - super(*args, &block) - end - - define_method(:<<) do |x| - logger << x - super(x) - end - - define_method(:close) do - logger.close - super() - end - - define_method(:progname=) do |name| - logger.progname = name - super(name) - end - - define_method(:formatter=) do |formatter| - logger.formatter = formatter - super(formatter) - end - - define_method(:level=) do |level| - logger.level = level - super(level) - end - end - end - end end end From bc4c801895b5f55720e56b6918d15ca66f079dce Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sun, 3 Dec 2023 21:29:46 -0800 Subject: [PATCH 3/3] init class attrs with mutable arrays not frozen --- lib/rails-footnotes.rb | 7 +++++-- lib/rails-footnotes/notes/log_note.rb | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rails-footnotes.rb b/lib/rails-footnotes.rb index 635161c..715bcff 100644 --- a/lib/rails-footnotes.rb +++ b/lib/rails-footnotes.rb @@ -7,8 +7,8 @@ require 'rails-footnotes/extension' module Footnotes - thread_mattr_accessor :before_hooks, default: [] - thread_mattr_accessor :after_hooks, default: [] + thread_mattr_accessor :before_hooks + thread_mattr_accessor :after_hooks thread_mattr_accessor :enabled, default: false class << self @@ -59,6 +59,9 @@ def self.setup end end +Footnotes.before_hooks = [] +Footnotes.after_hooks = [] + ActiveSupport.on_load(:action_controller) do ActionController::Base.send(:include, Footnotes::RailsFootnotesExtension) end diff --git a/lib/rails-footnotes/notes/log_note.rb b/lib/rails-footnotes/notes/log_note.rb index 58f9281..92d27b6 100644 --- a/lib/rails-footnotes/notes/log_note.rb +++ b/lib/rails-footnotes/notes/log_note.rb @@ -4,10 +4,11 @@ class LogNote < AbstractNote autoload :NoteLogger, 'rails-footnotes/notes/log_note/note_logger' - thread_cattr_accessor :logs, default: [] + thread_cattr_accessor :logs thread_cattr_accessor :original_logger def self.start!(controller) + self.logs = [] self.original_logger = Rails.logger note_logger = NoteLogger.new(self.logs) note_logger.level = self.original_logger.level