DEV: Upgrade Rails to 6.1.3.1 (#12688)

DEV: Upgrade Rails to 6.1.3.1 (#12688)

Rails 6.1.3.1 deprecates a few API and has some internal changes that break our tests suite, so this commit fixes all the deprecations and errors and now Discourse should be fully compatible with Rails 6.1.3.1. We also have a new release of the rails_failover gem that’s compatible with Rails 6.1.3.1.

diff --git a/Gemfile b/Gemfile
index e496302..b009cc8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -18,13 +18,13 @@ else
   # this allows us to include the bits of rails we use without pieces we do not.
   #
   # To issue a rails update bump the version number here
-  gem 'actionmailer', '6.0.3.5'
-  gem 'actionpack', '6.0.3.5'
-  gem 'actionview', '6.0.3.5'
-  gem 'activemodel', '6.0.3.5'
-  gem 'activerecord', '6.0.3.5'
-  gem 'activesupport', '6.0.3.5'
-  gem 'railties', '6.0.3.5'
+  gem 'actionmailer', '6.1.3.1'
+  gem 'actionpack', '6.1.3.1'
+  gem 'actionview', '6.1.3.1'
+  gem 'activemodel', '6.1.3.1'
+  gem 'activerecord', '6.1.3.1'
+  gem 'activesupport', '6.1.3.1'
+  gem 'railties', '6.1.3.1'
   gem 'sprockets-rails'
 end
 
diff --git a/Gemfile.lock b/Gemfile.lock
index 6dd7ee8..7507db8 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,21 +8,22 @@ GIT
 GEM
   remote: https://rubygems.org/
   specs:
-    actionmailer (6.0.3.5)
-      actionpack (= 6.0.3.5)
-      actionview (= 6.0.3.5)
-      activejob (= 6.0.3.5)
+    actionmailer (6.1.3.1)
+      actionpack (= 6.1.3.1)
+      actionview (= 6.1.3.1)
+      activejob (= 6.1.3.1)
+      activesupport (= 6.1.3.1)
       mail (~> 2.5, >= 2.5.4)
       rails-dom-testing (~> 2.0)
-    actionpack (6.0.3.5)
-      actionview (= 6.0.3.5)
-      activesupport (= 6.0.3.5)
-      rack (~> 2.0, >= 2.0.8)
+    actionpack (6.1.3.1)
+      actionview (= 6.1.3.1)
+      activesupport (= 6.1.3.1)
+      rack (~> 2.0, >= 2.0.9)
       rack-test (>= 0.6.3)
       rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.2.0)
-    actionview (6.0.3.5)
-      activesupport (= 6.0.3.5)
+    actionview (6.1.3.1)
+      activesupport (= 6.1.3.1)
       builder (~> 3.1)
       erubi (~> 1.4)
       rails-dom-testing (~> 2.0)
@@ -31,20 +32,20 @@ GEM
       actionview (>= 6.0.a)
     active_model_serializers (0.8.4)
       activemodel (>= 3.0)
-    activejob (6.0.3.5)
-      activesupport (= 6.0.3.5)
+    activejob (6.1.3.1)
+      activesupport (= 6.1.3.1)
       globalid (>= 0.3.6)
-    activemodel (6.0.3.5)
-      activesupport (= 6.0.3.5)
-    activerecord (6.0.3.5)
-      activemodel (= 6.0.3.5)
-      activesupport (= 6.0.3.5)
-    activesupport (6.0.3.5)
+    activemodel (6.1.3.1)
+      activesupport (= 6.1.3.1)
+    activerecord (6.1.3.1)
+      activemodel (= 6.1.3.1)
+      activesupport (= 6.1.3.1)
+    activesupport (6.1.3.1)
       concurrent-ruby (~> 1.0, >= 1.0.2)
-      i18n (>= 0.7, < 2)
-      minitest (~> 5.1)
-      tzinfo (~> 1.1)
-      zeitwerk (~> 2.2, >= 2.2.2)
+      i18n (>= 1.6, < 2)
+      minitest (>= 5.1)
+      tzinfo (~> 2.0)
+      zeitwerk (~> 2.3)
     addressable (2.7.0)
       public_suffix (>= 2.0.2, < 5.0)
     annotate (3.1.1)
@@ -315,19 +316,19 @@ GEM
       nokogiri (>= 1.6)
     rails-html-sanitizer (1.3.0)
       loofah (~> 2.3)
-    rails_failover (0.6.5)
+    rails_failover (0.7.3)
       activerecord (~> 6.0)
       concurrent-ruby
       railties (~> 6.0)
-    rails_multisite (2.5.0)
+    rails_multisite (3.0.0)
       activerecord (> 5.0, < 7)
       railties (> 5.0, < 7)
-    railties (6.0.3.5)
-      actionpack (= 6.0.3.5)
-      activesupport (= 6.0.3.5)
+    railties (6.1.3.1)
+      actionpack (= 6.1.3.1)
+      activesupport (= 6.1.3.1)
       method_source
       rake (>= 0.8.7)
-      thor (>= 0.20.3, < 2.0)
+      thor (~> 1.0)
     rainbow (3.0.0)
     raindrops (0.19.1)
     rake (13.0.3)
@@ -444,10 +445,9 @@ GEM
     stackprof (0.2.16)
     test-prof (1.0.2)
     thor (1.1.0)
-    thread_safe (0.3.6)
     tilt (2.0.10)
-    tzinfo (1.2.9)
-      thread_safe (~> 0.1)
+    tzinfo (2.0.4)
+      concurrent-ruby (~> 1.0)
     uglifier (4.2.0)
       execjs (>= 0.3.0, < 3)
     unf (0.1.4)
@@ -479,14 +479,14 @@ PLATFORMS
   x86_64-linux
 
 DEPENDENCIES
-  actionmailer (= 6.0.3.5)
-  actionpack (= 6.0.3.5)
-  actionview (= 6.0.3.5)
+  actionmailer (= 6.1.3.1)
+  actionpack (= 6.1.3.1)
+  actionview (= 6.1.3.1)
   actionview_precompiler
   active_model_serializers (~> 0.8.3)
-  activemodel (= 6.0.3.5)
-  activerecord (= 6.0.3.5)
-  activesupport (= 6.0.3.5)
+  activemodel (= 6.1.3.1)
+  activerecord (= 6.1.3.1)
+  activesupport (= 6.1.3.1)
   addressable
   annotate
   aws-sdk-s3
@@ -566,7 +566,7 @@ DEPENDENCIES
   rack-protection
   rails_failover
   rails_multisite
-  railties (= 6.0.3.5)
+  railties (= 6.1.3.1)
   rake
   rb-fsevent
   rbtrace
diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb
index c49b6ae..f8b3300 100644
--- a/app/controllers/admin/backups_controller.rb
+++ b/app/controllers/admin/backups_controller.rb
@@ -72,7 +72,7 @@ class Admin::BackupsController < Admin::AdminController
   def show
     if !EmailBackupToken.compare(current_user.id, params.fetch(:token))
       @error = I18n.t('download_backup_mailer.no_token')
-      return render template: 'admin/backups/show.html.erb', layout: 'no_ember', status: 422
+      return render layout: 'no_ember', status: 422, formats: [:html]
     end
 
     store = BackupRestore::BackupStore.create
diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb
index 8c13f2e..4721303 100644
--- a/app/controllers/metadata_controller.rb
+++ b/app/controllers/metadata_controller.rb
@@ -11,7 +11,7 @@ class MetadataController < ApplicationController
 
   def opensearch
     expires_in 1.minutes
-    render template: "metadata/opensearch.xml"
+    render template: "metadata/opensearch", formats: [:xml]
   end
 
   def app_association_android
diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb
index 5ef7704..63064c7 100644
--- a/app/controllers/static_controller.rb
+++ b/app/controllers/static_controller.rb
@@ -29,7 +29,7 @@ class StaticController < ApplicationController
     if map.has_key?(@page)
       site_setting_key = map[@page][:redirect]
       url = SiteSetting.get(site_setting_key)
-      return redirect_to(url) unless url.blank?
+      return redirect_to(url) if url.present?
     end
 
     # The /guidelines route ALWAYS shows our FAQ, ignoring the faq_url site setting.
@@ -70,12 +70,8 @@ class StaticController < ApplicationController
       cookies[:email] = { value: params[:email], expires: 1.day.from_now }
     end
 
-    file = "static/#{@page}.#{I18n.locale}"
-    file = "static/#{@page}.en" if lookup_context.find_all("#{file}.html").empty?
-    file = "static/#{@page}"    if lookup_context.find_all("#{file}.html").empty?
-
-    if lookup_context.find_all("#{file}.html").any?
-      render file, layout: !request.xhr?, formats: [:html]
+    if lookup_context.find_all("static/#{@page}").any?
+      render "static/#{@page}", layout: !request.xhr?, formats: [:html]
       return
     end
 
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0e53e27..2df54fc 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -369,6 +369,8 @@ module ApplicationHelper
 
   def loading_admin?
     return false unless defined?(controller)
+    return false if controller.class.name.blank?
+
     controller.class.name.split("::").first == "Admin"
   end
 
diff --git a/app/models/email_token.rb b/app/models/email_token.rb
index 00e91a4..8472881 100644
--- a/app/models/email_token.rb
+++ b/app/models/email_token.rb
@@ -77,7 +77,7 @@ class EmailToken < ActiveRecord::Base
 
       if user
         if Invite.redeem_from_email(user.email).present?
-          return user.reload
+          user.reload
         end
         user
       end
diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb
index f8c607a..a6353d1 100644
--- a/app/models/invite_redeemer.rb
+++ b/app/models/invite_redeemer.rb
@@ -6,11 +6,9 @@ InviteRedeemer = Struct.new(:invite, :email, :username, :name, :password, :user_
     Invite.transaction do
       if invite_was_redeemed?
         process_invitation
-        return invited_user

[... diff too long, it was truncated ...]

GitHub sha: 45ccadee

This commit appears in #12688 which was approved by CvX. It was merged by OsamaSayegh.