From a8acb24e0cc5ba1cbfd3ca6fa763efe0dfba705d Mon Sep 17 00:00:00 2001
From: Heinrich Lee Yu <heinrich@gitlab.com>
Date: Thu, 7 May 2020 14:18:23 +0800
Subject: [PATCH] Upgrade to Rails 6.0.3

This version also requires rack-attack 6.3.0 or else Rails won't boot.

We also remove patches that are no longer needed
---
 Gemfile                                       |   4 +-
 Gemfile.lock                                  | 110 +++++++++---------
 .../active_record_fix_insert_all.rb           |  26 -----
 qa/Gemfile                                    |   2 +-
 qa/Gemfile.lock                               |   6 +-
 spec/support/rails/test_case_patch.rb         |  53 ---------
 6 files changed, 61 insertions(+), 140 deletions(-)
 delete mode 100644 config/initializers/active_record_fix_insert_all.rb
 delete mode 100644 spec/support/rails/test_case_patch.rb

diff --git a/Gemfile b/Gemfile
index 6bf8d63d939d6..f0ff04c076aaa 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,6 @@
 source 'https://rubygems.org'
 
-gem 'rails', '~> 6.0.2.2'
+gem 'rails', '~> 6.0.3'
 
 gem 'bootsnap', '~> 1.4.6'
 
@@ -293,7 +293,7 @@ gem 'base32', '~> 0.3.0'
 gem "gitlab-license", "~> 1.0"
 
 # Protect against bruteforcing
-gem 'rack-attack', '~> 6.2.0'
+gem 'rack-attack', '~> 6.3.0'
 
 # Sentry integration
 gem 'sentry-raven', '~> 2.9'
diff --git a/Gemfile.lock b/Gemfile.lock
index 01431cb3cc073..fe0935a2e5f45 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -6,64 +6,64 @@ GEM
     ace-rails-ap (4.1.2)
     acme-client (2.0.5)
       faraday (~> 0.9, >= 0.9.1)
-    actioncable (6.0.2.2)
-      actionpack (= 6.0.2.2)
+    actioncable (6.0.3)
+      actionpack (= 6.0.3)
       nio4r (~> 2.0)
       websocket-driver (>= 0.6.1)
-    actionmailbox (6.0.2.2)
-      actionpack (= 6.0.2.2)
-      activejob (= 6.0.2.2)
-      activerecord (= 6.0.2.2)
-      activestorage (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    actionmailbox (6.0.3)
+      actionpack (= 6.0.3)
+      activejob (= 6.0.3)
+      activerecord (= 6.0.3)
+      activestorage (= 6.0.3)
+      activesupport (= 6.0.3)
       mail (>= 2.7.1)
-    actionmailer (6.0.2.2)
-      actionpack (= 6.0.2.2)
-      actionview (= 6.0.2.2)
-      activejob (= 6.0.2.2)
+    actionmailer (6.0.3)
+      actionpack (= 6.0.3)
+      actionview (= 6.0.3)
+      activejob (= 6.0.3)
       mail (~> 2.5, >= 2.5.4)
       rails-dom-testing (~> 2.0)
-    actionpack (6.0.2.2)
-      actionview (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    actionpack (6.0.3)
+      actionview (= 6.0.3)
+      activesupport (= 6.0.3)
       rack (~> 2.0, >= 2.0.8)
       rack-test (>= 0.6.3)
       rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.2.0)
-    actiontext (6.0.2.2)
-      actionpack (= 6.0.2.2)
-      activerecord (= 6.0.2.2)
-      activestorage (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    actiontext (6.0.3)
+      actionpack (= 6.0.3)
+      activerecord (= 6.0.3)
+      activestorage (= 6.0.3)
+      activesupport (= 6.0.3)
       nokogiri (>= 1.8.5)
-    actionview (6.0.2.2)
-      activesupport (= 6.0.2.2)
+    actionview (6.0.3)
+      activesupport (= 6.0.3)
       builder (~> 3.1)
       erubi (~> 1.4)
       rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.1, >= 1.2.0)
-    activejob (6.0.2.2)
-      activesupport (= 6.0.2.2)
+    activejob (6.0.3)
+      activesupport (= 6.0.3)
       globalid (>= 0.3.6)
-    activemodel (6.0.2.2)
-      activesupport (= 6.0.2.2)
-    activerecord (6.0.2.2)
-      activemodel (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    activemodel (6.0.3)
+      activesupport (= 6.0.3)
+    activerecord (6.0.3)
+      activemodel (= 6.0.3)
+      activesupport (= 6.0.3)
     activerecord-explain-analyze (0.1.0)
       activerecord (>= 4)
       pg
-    activestorage (6.0.2.2)
-      actionpack (= 6.0.2.2)
-      activejob (= 6.0.2.2)
-      activerecord (= 6.0.2.2)
+    activestorage (6.0.3)
+      actionpack (= 6.0.3)
+      activejob (= 6.0.3)
+      activerecord (= 6.0.3)
       marcel (~> 0.3.1)
-    activesupport (6.0.2.2)
+    activesupport (6.0.3)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 0.7, < 2)
       minitest (~> 5.1)
       tzinfo (~> 1.1)
-      zeitwerk (~> 2.2)
+      zeitwerk (~> 2.2, >= 2.2.2)
     acts-as-taggable-on (6.5.0)
       activerecord (>= 5.0, < 6.1)
     adamantium (0.2.0)
@@ -633,7 +633,7 @@ GEM
     mime-types (3.2.2)
       mime-types-data (~> 3.2015)
     mime-types-data (3.2019.0331)
-    mimemagic (0.3.3)
+    mimemagic (0.3.5)
     mini_histogram (0.1.3)
     mini_magick (4.9.5)
     mini_mime (1.0.2)
@@ -790,7 +790,7 @@ GEM
     rack (2.0.9)
     rack-accept (0.4.5)
       rack (>= 0.4)
-    rack-attack (6.2.0)
+    rack-attack (6.3.0)
       rack (>= 1.0, < 3)
     rack-cors (1.0.6)
       rack (>= 1.6.0)
@@ -807,20 +807,20 @@ GEM
     rack-test (1.1.0)
       rack (>= 1.0, < 3)
     rack-timeout (0.5.1)
-    rails (6.0.2.2)
-      actioncable (= 6.0.2.2)
-      actionmailbox (= 6.0.2.2)
-      actionmailer (= 6.0.2.2)
-      actionpack (= 6.0.2.2)
-      actiontext (= 6.0.2.2)
-      actionview (= 6.0.2.2)
-      activejob (= 6.0.2.2)
-      activemodel (= 6.0.2.2)
-      activerecord (= 6.0.2.2)
-      activestorage (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    rails (6.0.3)
+      actioncable (= 6.0.3)
+      actionmailbox (= 6.0.3)
+      actionmailer (= 6.0.3)
+      actionpack (= 6.0.3)
+      actiontext (= 6.0.3)
+      actionview (= 6.0.3)
+      activejob (= 6.0.3)
+      activemodel (= 6.0.3)
+      activerecord (= 6.0.3)
+      activestorage (= 6.0.3)
+      activesupport (= 6.0.3)
       bundler (>= 1.3.0)
-      railties (= 6.0.2.2)
+      railties (= 6.0.3)
       sprockets-rails (>= 2.0.0)
     rails-controller-testing (1.0.4)
       actionpack (>= 5.0.1.x)
@@ -834,9 +834,9 @@ GEM
     rails-i18n (6.0.0)
       i18n (>= 0.7, < 2)
       railties (>= 6.0.0, < 7)
-    railties (6.0.2.2)
-      actionpack (= 6.0.2.2)
-      activesupport (= 6.0.2.2)
+    railties (6.0.3)
+      actionpack (= 6.0.3)
+      activesupport (= 6.0.3)
       method_source
       rake (>= 0.8.7)
       thor (>= 0.20.3, < 2.0)
@@ -1334,12 +1334,12 @@ DEPENDENCIES
   pry-byebug (~> 3.5.1)
   pry-rails (~> 0.3.9)
   rack (~> 2.0.9)
-  rack-attack (~> 6.2.0)
+  rack-attack (~> 6.3.0)
   rack-cors (~> 1.0.6)
   rack-oauth2 (~> 1.9.3)
   rack-proxy (~> 0.6.0)
   rack-timeout
-  rails (~> 6.0.2.2)
+  rails (~> 6.0.3)
   rails-controller-testing
   rails-i18n (~> 6.0)
   rainbow (~> 3.0)
diff --git a/config/initializers/active_record_fix_insert_all.rb b/config/initializers/active_record_fix_insert_all.rb
deleted file mode 100644
index 08d504734a530..0000000000000
--- a/config/initializers/active_record_fix_insert_all.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-# This fix is needed to properly support
-# columns that perform data mutation to a SQL datatype
-# ex. would be `jsonb` and `enum`
-#
-# This is covered by tests in `BulkInsertSafe`
-# that validates handling of different data types
-
-if Rails.gem_version > Gem::Version.new("6.0.2.2")
-  raise Gem::DependencyError,
-    "Remove patch once the https://github.com/rails/rails/pull/38763 is included"
-end
-
-module ActiveRecordInsertAllBuilderMixin
-  def extract_types_from_columns_on(table_name, keys:)
-    columns = connection.schema_cache.columns_hash(table_name)
-
-    unknown_column = (keys - columns.keys).first
-    raise UnknownAttributeError.new(model.new, unknown_column) if unknown_column
-
-    keys.index_with { |key| model.type_for_attribute(key) }
-  end
-end
-
-ActiveRecord::InsertAll::Builder.prepend(ActiveRecordInsertAllBuilderMixin)
diff --git a/qa/Gemfile b/qa/Gemfile
index b11d5b1b682ad..6eb8733ab419e 100644
--- a/qa/Gemfile
+++ b/qa/Gemfile
@@ -1,7 +1,7 @@
 source 'https://rubygems.org'
 
 gem 'gitlab-qa'
-gem 'activesupport', '~> 6.0.2.2' # This should stay in sync with the root's Gemfile
+gem 'activesupport', '~> 6.0.3' # This should stay in sync with the root's Gemfile
 gem 'capybara', '~> 3.29.0'
 gem 'capybara-screenshot', '~> 1.0.23'
 gem 'rake', '~> 12.3.0'
diff --git a/qa/Gemfile.lock b/qa/Gemfile.lock
index 6b996ca00f533..9aeba236c9646 100644
--- a/qa/Gemfile.lock
+++ b/qa/Gemfile.lock
@@ -1,12 +1,12 @@
 GEM
   remote: https://rubygems.org/
   specs:
-    activesupport (6.0.2.2)
+    activesupport (6.0.3)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 0.7, < 2)
       minitest (~> 5.1)
       tzinfo (~> 1.1)
-      zeitwerk (~> 2.2)
+      zeitwerk (~> 2.2, >= 2.2.2)
     addressable (2.7.0)
       public_suffix (>= 2.0.2, < 5.0)
     airborne (0.3.4)
@@ -116,7 +116,7 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  activesupport (~> 6.0.2.2)
+  activesupport (~> 6.0.3)
   airborne (~> 0.3.4)
   capybara (~> 3.29.0)
   capybara-screenshot (~> 1.0.23)
diff --git a/spec/support/rails/test_case_patch.rb b/spec/support/rails/test_case_patch.rb
deleted file mode 100644
index 161e1ef2a4c98..0000000000000
--- a/spec/support/rails/test_case_patch.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-# frozen_string_literal: true
-#
-# This file pulls in the changes in https://github.com/rails/rails/pull/38063
-# to fix controller specs updated with the latest Rack versions.
-#
-# This file should be removed after that change ships. It is not
-# present in Rails 6.0.2.2.
-module ActionController
-  class TestRequest < ActionDispatch::TestRequest #:nodoc:
-    def self.new_session
-      TestSessionPatched.new
-    end
-  end
-
-  # Methods #destroy and #load! are overridden to avoid calling methods on the
-  # @store object, which does not exist for the TestSession class.
-  class TestSessionPatched < Rack::Session::Abstract::PersistedSecure::SecureSessionHash #:nodoc:
-    DEFAULT_OPTIONS = Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS
-
-    def initialize(session = {})
-      super(nil, nil)
-      @id = Rack::Session::SessionId.new(SecureRandom.hex(16))
-      @data = stringify_keys(session)
-      @loaded = true
-    end
-
-    def exists?
-      true
-    end
-
-    def keys
-      @data.keys
-    end
-
-    def values
-      @data.values
-    end
-
-    def destroy
-      clear
-    end
-
-    def fetch(key, *args, &block)
-      @data.fetch(key.to_s, *args, &block)
-    end
-
-    private
-
-    def load!
-      @id
-    end
-  end
-end
-- 
GitLab