DEV: Upgrade Discourse to Rails 6 (#8083)

DEV: Upgrade Discourse to Rails 6 (#8083)

  • Adjustments to pass specs on Rails 6.0.0
  • Use classic autoloader instead of Zeitwerk
  • Update Rails 6.0.0 deprecated methods
  • Rails 6.0.0 not allowing column with integer name
  • Drop freedom_patches/rails6.rb
  • Default value for trigger_transactional_callbacks? is true
  • Bump rspec-rails version to 4.0.0.beta2
diff --git a/Gemfile b/Gemfile
index 1e9fe98..98e165f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -16,13 +16,13 @@ if rails_master?
 else
   # until rubygems gives us optional dependencies we are stuck with this
   # bundle update actionmailer actionpack actionview activemodel activerecord activesupport railties
-  gem 'actionmailer', '5.2.3'
-  gem 'actionpack', '5.2.3'
-  gem 'actionview', '5.2.3'
-  gem 'activemodel', '5.2.3'
-  gem 'activerecord', '5.2.3'
-  gem 'activesupport', '5.2.3'
-  gem 'railties', '5.2.3'
+  gem 'actionmailer', '6.0.0'
+  gem 'actionpack', '6.0.0'
+  gem 'actionview', '6.0.0'
+  gem 'activemodel', '6.0.0'
+  gem 'activerecord', '6.0.0'
+  gem 'activesupport', '6.0.0'
+  gem 'railties', '6.0.0'
   gem 'sprockets-rails'
 end
 
@@ -140,7 +140,7 @@ group :test, :development do
   gem 'mocha', require: false
   gem 'rb-fsevent', require: RUBY_PLATFORM =~ /darwin/i ? 'rb-fsevent' : false
   gem 'rb-inotify', '~> 0.9', require: RUBY_PLATFORM =~ /linux/i ? 'rb-inotify' : false
-  gem 'rspec-rails', require: false
+  gem 'rspec-rails', '4.0.0.beta2', require: false
   gem 'shoulda-matchers', '~> 3.1', '>= 3.1.3', require: false
   gem 'rspec-html-matchers'
   gem 'pry-nav'
diff --git a/Gemfile.lock b/Gemfile.lock
index 7fc71a5..55e2d27 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,47 +1,46 @@
 GEM
   remote: https://rubygems.org/
   specs:
-    actionmailer (5.2.3)
-      actionpack (= 5.2.3)
-      actionview (= 5.2.3)
-      activejob (= 5.2.3)
+    actionmailer (6.0.0)
+      actionpack (= 6.0.0)
+      actionview (= 6.0.0)
+      activejob (= 6.0.0)
       mail (~> 2.5, >= 2.5.4)
       rails-dom-testing (~> 2.0)
-    actionpack (5.2.3)
-      actionview (= 5.2.3)
-      activesupport (= 5.2.3)
+    actionpack (6.0.0)
+      actionview (= 6.0.0)
+      activesupport (= 6.0.0)
       rack (~> 2.0)
       rack-test (>= 0.6.3)
       rails-dom-testing (~> 2.0)
-      rails-html-sanitizer (~> 1.0, >= 1.0.2)
-    actionview (5.2.3)
-      activesupport (= 5.2.3)
+      rails-html-sanitizer (~> 1.0, >= 1.2.0)
+    actionview (6.0.0)
+      activesupport (= 6.0.0)
       builder (~> 3.1)
       erubi (~> 1.4)
       rails-dom-testing (~> 2.0)
-      rails-html-sanitizer (~> 1.0, >= 1.0.3)
+      rails-html-sanitizer (~> 1.1, >= 1.2.0)
     active_model_serializers (0.8.4)
       activemodel (>= 3.0)
-    activejob (5.2.3)
-      activesupport (= 5.2.3)
+    activejob (6.0.0)
+      activesupport (= 6.0.0)
       globalid (>= 0.3.6)
-    activemodel (5.2.3)
-      activesupport (= 5.2.3)
-    activerecord (5.2.3)
-      activemodel (= 5.2.3)
-      activesupport (= 5.2.3)
-      arel (>= 9.0)
-    activesupport (5.2.3)
+    activemodel (6.0.0)
+      activesupport (= 6.0.0)
+    activerecord (6.0.0)
+      activemodel (= 6.0.0)
+      activesupport (= 6.0.0)
+    activesupport (6.0.0)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 0.7, < 2)
       minitest (~> 5.1)
       tzinfo (~> 1.1)
+      zeitwerk (~> 2.1, >= 2.1.8)
     addressable (2.5.2)
       public_suffix (>= 2.0.2, < 4.0)
     annotate (2.7.5)
       activerecord (>= 3.2, < 7.0)
       rake (>= 10.4, < 13.0)
-    arel (9.0.0)
     ast (2.4.0)
     aws-eventstream (1.0.3)
     aws-partitions (1.154.0)
@@ -183,7 +182,7 @@ GEM
       rack (>= 1.1.3)
     metaclass (0.0.4)
     method_source (0.9.2)
-    mini_mime (1.0.1)
+    mini_mime (1.0.2)
     mini_portile2 (2.4.0)
     mini_racer (0.2.6)
       libv8 (>= 6.9.411)
@@ -282,20 +281,20 @@ GEM
     rails-dom-testing (2.0.3)
       activesupport (>= 4.2.0)
       nokogiri (>= 1.6)
-    rails-html-sanitizer (1.0.4)
+    rails-html-sanitizer (1.2.0)
       loofah (~> 2.2, >= 2.2.2)
     rails_multisite (2.0.7)
       activerecord (> 4.2, < 7)
       railties (> 4.2, < 7)
-    railties (5.2.3)
-      actionpack (= 5.2.3)
-      activesupport (= 5.2.3)
+    railties (6.0.0)
+      actionpack (= 6.0.0)
+      activesupport (= 6.0.0)
       method_source
       rake (>= 0.8.7)
-      thor (>= 0.19.0, < 2.0)
+      thor (>= 0.20.3, < 2.0)
     rainbow (3.0.0)
     raindrops (0.19.0)
-    rake (12.3.2)
+    rake (12.3.3)
     rake-compiler (1.0.7)
       rake
     rb-fsevent (0.10.3)
@@ -330,14 +329,14 @@ GEM
     rspec-mocks (3.8.0)
       diff-lcs (>= 1.2.0, < 2.0)
       rspec-support (~> 3.8.0)
-    rspec-rails (3.8.2)
-      actionpack (>= 3.0)
-      activesupport (>= 3.0)
-      railties (>= 3.0)
-      rspec-core (~> 3.8.0)
-      rspec-expectations (~> 3.8.0)
-      rspec-mocks (~> 3.8.0)
-      rspec-support (~> 3.8.0)
+    rspec-rails (4.0.0.beta2)
+      actionpack (>= 4.2)
+      activesupport (>= 4.2)
+      railties (>= 4.2)
+      rspec-core (~> 3.8)
+      rspec-expectations (~> 3.8)
+      rspec-mocks (~> 3.8)
+      rspec-support (~> 3.8)
     rspec-support (3.8.0)
     rtlit (0.0.5)
     rubocop (0.69.0)
@@ -417,18 +416,19 @@ GEM
       hkdf (~> 0.2)
       jwt (~> 2.0)
     yaml-lint (0.0.10)
+    zeitwerk (2.1.10)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
-  actionmailer (= 5.2.3)
-  actionpack (= 5.2.3)
-  actionview (= 5.2.3)
+  actionmailer (= 6.0.0)
+  actionpack (= 6.0.0)
+  actionview (= 6.0.0)
   active_model_serializers (~> 0.8.3)
-  activemodel (= 5.2.3)
-  activerecord (= 5.2.3)
-  activesupport (= 5.2.3)
+  activemodel (= 6.0.0)
+  activerecord (= 6.0.0)
+  activesupport (= 6.0.0)
   annotate
   aws-sdk-s3
   aws-sdk-sns
@@ -504,7 +504,7 @@ DEPENDENCIES
   rack-mini-profiler
   rack-protection
   rails_multisite
-  railties (= 5.2.3)
+  railties (= 6.0.0)
   rake
   rb-fsevent
   rb-inotify (~> 0.9)
@@ -517,7 +517,7 @@ DEPENDENCIES
   rqrcode
   rspec
   rspec-html-matchers
-  rspec-rails
+  rspec-rails (= 4.0.0.beta2)
   rtlit
   rubocop
   ruby-prof
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 55f9b38..007a600 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -1,5 +1,5 @@
 <div class="user-crawler">
-	<img src='<%= UrlHelper.local_cdn_url(get_absolute_image_url(@user.small_avatar_url)) %>' alt='<%= @user.username %>' title='<%= @user.username %>' />
+	<img src='<%= ::UrlHelper.local_cdn_url(get_absolute_image_url(@user.small_avatar_url)) %>' alt='<%= @user.username %>' title='<%= @user.username %>' />
 	<h2 class='username'><%= @user.username %></h2>
 </div>
 
diff --git a/config/application.rb b/config/application.rb
index 2d946b3..932aed2 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -93,6 +93,8 @@ module Discourse
     # issue is image_optim crashes on missing dependencies
     config.assets.image_optim = false
 
+    config.autoloader = :classic
+
     # Custom directories with classes and modules you want to be autoloadable.
     config.autoload_paths += Dir["#{config.root}/app/serializers"]
     config.autoload_paths += Dir["#{config.root}/lib/validators/"]
diff --git a/db/migrate/20130430052751_add_topic_allowed_groups.rb b/db/migrate/20130430052751_add_topic_allowed_groups.rb
index 27eb250..aae1768 100644
--- a/db/migrate/20130430052751_add_topic_allowed_groups.rb
+++ b/db/migrate/20130430052751_add_topic_allowed_groups.rb
@@ -4,8 +4,8 @@ class AddTopicAllowedGroups < ActiveRecord::Migration[4.2]
   def change
     create_table :topic_allowed_groups, force: true do |t|
       # oops
-      t.integer :group_id, :integer, null: false
-      t.integer :topic_id, :integer, null: false
+      t.integer :group_id, null: false
+      t.integer :topic_id, null: false
     end
 
     add_index :topic_allowed_groups, [:group_id, :topic_id], unique: true
diff --git a/db/migrate/20130501105651_fix_topic_allowed_groups.rb b/db/migrate/20130501105651_fix_topic_allowed_groups.rb
index cc0f49f..bb19a27 100644
--- a/db/migrate/20130501105651_fix_topic_allowed_groups.rb
+++ b/db/migrate/20130501105651_fix_topic_allowed_groups.rb
@@ -3,6 +3,6 @@
 class FixTopicAllowedGroups < ActiveRecord::Migration[4.2]
   def change
     # big oops
-    remove_column :topic_allowed_groups, :integer

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

GitHub sha: 32b8a2cc

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: