From fb973b606dd6cb9180a5a843c9904f65e71c4cf1 Mon Sep 17 00:00:00 2001
From: Jan Provaznik <jprovaznik@gitlab.com>
Date: Wed, 22 Aug 2018 14:09:28 +0200
Subject: [PATCH] Switch to Rails 5 by default

* updates Gemfile
* uses Rails 5 unless explicitly disable
---
 Gemfile                                    |   2 +-
 Gemfile.lock                               | 139 +++++++++++----------
 Gemfile.rails4                             |   7 ++
 Gemfile.rails5.lock => Gemfile.rails4.lock | 137 ++++++++++----------
 bin/setup                                  |   2 +-
 config/application.rb                      |   2 +-
 config/boot.rb                             |   4 +-
 config/environment.rb                      |   6 +-
 8 files changed, 153 insertions(+), 146 deletions(-)
 create mode 100644 Gemfile.rails4
 rename Gemfile.rails5.lock => Gemfile.rails4.lock (93%)

diff --git a/Gemfile b/Gemfile
index 3ce1d26cad3..9977009a651 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,6 @@
 # --- Special code for migrating to Rails 5.0 ---
 def rails5?
-  %w[1 true].include?(ENV["RAILS5"])
+  !%w[0 false].include?(ENV["RAILS5"])
 end
 
 gem_versions = {}
diff --git a/Gemfile.lock b/Gemfile.lock
index 724a215b243..e01b357f37c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -4,41 +4,44 @@ GEM
     RedCloth (4.3.2)
     abstract_type (0.0.7)
     ace-rails-ap (4.1.2)
-    actionmailer (4.2.10)
-      actionpack (= 4.2.10)
-      actionview (= 4.2.10)
-      activejob (= 4.2.10)
+    actioncable (5.0.7)
+      actionpack (= 5.0.7)
+      nio4r (>= 1.2, < 3.0)
+      websocket-driver (~> 0.6.1)
+    actionmailer (5.0.7)
+      actionpack (= 5.0.7)
+      actionview (= 5.0.7)
+      activejob (= 5.0.7)
       mail (~> 2.5, >= 2.5.4)
-      rails-dom-testing (~> 1.0, >= 1.0.5)
-    actionpack (4.2.10)
-      actionview (= 4.2.10)
-      activesupport (= 4.2.10)
-      rack (~> 1.6)
-      rack-test (~> 0.6.2)
-      rails-dom-testing (~> 1.0, >= 1.0.5)
+      rails-dom-testing (~> 2.0)
+    actionpack (5.0.7)
+      actionview (= 5.0.7)
+      activesupport (= 5.0.7)
+      rack (~> 2.0)
+      rack-test (~> 0.6.3)
+      rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.0.2)
-    actionview (4.2.10)
-      activesupport (= 4.2.10)
+    actionview (5.0.7)
+      activesupport (= 5.0.7)
       builder (~> 3.1)
       erubis (~> 2.7.0)
-      rails-dom-testing (~> 1.0, >= 1.0.5)
+      rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.0.3)
-    activejob (4.2.10)
-      activesupport (= 4.2.10)
-      globalid (>= 0.3.0)
-    activemodel (4.2.10)
-      activesupport (= 4.2.10)
-      builder (~> 3.1)
-    activerecord (4.2.10)
-      activemodel (= 4.2.10)
-      activesupport (= 4.2.10)
-      arel (~> 6.0)
-    activerecord_sane_schema_dumper (0.2)
-      rails (>= 4, < 5)
-    activesupport (4.2.10)
-      i18n (~> 0.7)
+    activejob (5.0.7)
+      activesupport (= 5.0.7)
+      globalid (>= 0.3.6)
+    activemodel (5.0.7)
+      activesupport (= 5.0.7)
+    activerecord (5.0.7)
+      activemodel (= 5.0.7)
+      activesupport (= 5.0.7)
+      arel (~> 7.0)
+    activerecord_sane_schema_dumper (1.0)
+      rails (>= 5, < 6)
+    activesupport (5.0.7)
+      concurrent-ruby (~> 1.0, >= 1.0.2)
+      i18n (>= 0.7, < 2)
       minitest (~> 5.1)
-      thread_safe (~> 0.3, >= 0.3.4)
       tzinfo (~> 1.1)
     acts-as-taggable-on (5.0.0)
       activerecord (>= 4.2.8)
@@ -49,7 +52,7 @@ GEM
       public_suffix (>= 2.0.2, < 4.0)
     aes_key_wrap (1.0.1)
     akismet (2.0.0)
-    arel (6.0.4)
+    arel (7.1.4)
     asana (0.6.0)
       faraday (~> 0.9)
       faraday_middleware (~> 0.9)
@@ -151,8 +154,8 @@ GEM
       html-pipeline
     declarative (0.0.10)
     declarative-option (0.1.0)
-    default_value_for (3.0.2)
-      activerecord (>= 3.2.0, < 5.1)
+    default_value_for (3.0.5)
+      activerecord (>= 3.2.0, < 5.2)
     descendants_tracker (0.0.4)
       thread_safe (~> 0.3, >= 0.3.1)
     device_detector (1.0.0)
@@ -403,7 +406,7 @@ GEM
       json (~> 1.8)
       multi_xml (>= 0.5.2)
     httpclient (2.8.3)
-    i18n (0.9.5)
+    i18n (1.1.0)
       concurrent-ruby (~> 1.0)
     icalendar (2.4.1)
     ice_nine (0.11.2)
@@ -499,6 +502,7 @@ GEM
     net-ntp (2.1.3)
     net-ssh (5.0.1)
     netrc (0.11.0)
+    nio4r (2.3.1)
     nokogiri (1.8.4)
       mini_portile2 (~> 2.3.0)
     nokogumbo (1.5.0)
@@ -571,7 +575,7 @@ GEM
     orm_adapter (0.5.0)
     os (1.0.0)
     parallel (1.12.1)
-    parser (2.5.3.0)
+    parser (2.5.1.2)
       ast (~> 2.4.0)
     parslet (1.8.2)
     peek (1.0.1)
@@ -627,7 +631,7 @@ GEM
       get_process_mem (~> 0.2)
       puma (>= 2.7, < 4)
     pyu-ruby-sasl (0.0.3.3)
-    rack (1.6.11)
+    rack (2.0.5)
     rack-accept (0.4.5)
       rack (>= 0.4)
     rack-attack (4.4.1)
@@ -645,31 +649,36 @@ GEM
       rack
     rack-test (0.6.3)
       rack (>= 1.0)
-    rails (4.2.10)
-      actionmailer (= 4.2.10)
-      actionpack (= 4.2.10)
-      actionview (= 4.2.10)
-      activejob (= 4.2.10)
-      activemodel (= 4.2.10)
-      activerecord (= 4.2.10)
-      activesupport (= 4.2.10)
-      bundler (>= 1.3.0, < 2.0)
-      railties (= 4.2.10)
-      sprockets-rails
+    rails (5.0.7)
+      actioncable (= 5.0.7)
+      actionmailer (= 5.0.7)
+      actionpack (= 5.0.7)
+      actionview (= 5.0.7)
+      activejob (= 5.0.7)
+      activemodel (= 5.0.7)
+      activerecord (= 5.0.7)
+      activesupport (= 5.0.7)
+      bundler (>= 1.3.0)
+      railties (= 5.0.7)
+      sprockets-rails (>= 2.0.0)
+    rails-controller-testing (1.0.2)
+      actionpack (~> 5.x, >= 5.0.1)
+      actionview (~> 5.x, >= 5.0.1)
+      activesupport (~> 5.x)
     rails-deprecated_sanitizer (1.0.3)
       activesupport (>= 4.2.0.alpha)
-    rails-dom-testing (1.0.9)
-      activesupport (>= 4.2.0, < 5.0)
-      nokogiri (~> 1.6)
-      rails-deprecated_sanitizer (>= 1.0.1)
+    rails-dom-testing (2.0.3)
+      activesupport (>= 4.2.0)
+      nokogiri (>= 1.6)
     rails-html-sanitizer (1.0.4)
       loofah (~> 2.2, >= 2.2.2)
-    rails-i18n (4.0.9)
-      i18n (~> 0.7)
-      railties (~> 4.0)
-    railties (4.2.10)
-      actionpack (= 4.2.10)
-      activesupport (= 4.2.10)
+    rails-i18n (5.1.1)
+      i18n (>= 0.7, < 2)
+      railties (>= 5.0, < 6)
+    railties (5.0.7)
+      actionpack (= 5.0.7)
+      activesupport (= 5.0.7)
+      method_source
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
     rainbow (3.0.0)
@@ -760,8 +769,7 @@ GEM
       rspec-core
     rspec-set (0.1.3)
     rspec-support (3.7.1)
-    rspec_junit_formatter (0.2.3)
-      builder (< 4)
+    rspec_junit_formatter (0.4.1)
       rspec-core (>= 2, < 4, != 2.12.0)
     rspec_profiling (0.0.5)
       activerecord
@@ -878,8 +886,6 @@ GEM
     sysexits (1.2.0)
     temple (0.8.0)
     test-prof (0.2.5)
-    test_after_commit (1.1.0)
-      activerecord (>= 3.2)
     text (1.3.1)
     thin (1.7.2)
       daemons (~> 1.0, >= 1.0.9)
@@ -942,6 +948,9 @@ GEM
       hashdiff
     webpack-rails (0.9.11)
       railties (>= 3.2.0)
+    websocket-driver (0.6.5)
+      websocket-extensions (>= 0.1.0)
+    websocket-extensions (0.1.3)
     wikicloth (0.8.1)
       builder
       expression_parser
@@ -957,7 +966,7 @@ PLATFORMS
 DEPENDENCIES
   RedCloth (~> 4.3.2)
   ace-rails-ap (~> 4.1.0)
-  activerecord_sane_schema_dumper (= 0.2)
+  activerecord_sane_schema_dumper (= 1.0)
   acts-as-taggable-on (~> 5.0)
   addressable (~> 2.5.2)
   akismet (~> 2.0)
@@ -992,7 +1001,7 @@ DEPENDENCIES
   creole (~> 0.5.0)
   database_cleaner (~> 1.5.0)
   deckar01-task_list (= 2.0.0)
-  default_value_for (~> 3.0.0)
+  default_value_for (~> 3.0.5)
   device_detector
   devise (~> 4.4)
   devise-two-factor (~> 3.0.0)
@@ -1117,9 +1126,10 @@ DEPENDENCIES
   rack-cors (~> 1.0.0)
   rack-oauth2 (~> 1.2.1)
   rack-proxy (~> 0.6.0)
-  rails (= 4.2.10)
+  rails (= 5.0.7)
+  rails-controller-testing
   rails-deprecated_sanitizer (~> 1.0.3)
-  rails-i18n (~> 4.0.9)
+  rails-i18n (~> 5.1)
   rainbow (~> 3.0)
   raindrops (~> 0.18)
   rblineprof (~> 0.3.6)
@@ -1172,7 +1182,6 @@ DEPENDENCIES
   state_machines-activerecord (~> 0.5.1)
   sys-filesystem (~> 1.1.6)
   test-prof (~> 0.2.5)
-  test_after_commit (~> 1.1)
   thin (~> 1.7.0)
   timecop (~> 0.8.0)
   toml-rb (~> 1.0.0)
diff --git a/Gemfile.rails4 b/Gemfile.rails4
new file mode 100644
index 00000000000..6fae99aa893
--- /dev/null
+++ b/Gemfile.rails4
@@ -0,0 +1,7 @@
+# BUNDLE_GEMFILE=Gemfile.rails5 bundle install
+
+ENV["RAILS5"] = "false"
+
+gemfile = File.expand_path("../Gemfile", __FILE__)
+
+eval(File.read(gemfile), nil, gemfile)
diff --git a/Gemfile.rails5.lock b/Gemfile.rails4.lock
similarity index 93%
rename from Gemfile.rails5.lock
rename to Gemfile.rails4.lock
index 7c4a04599b6..0922ae5fd4f 100644
--- a/Gemfile.rails5.lock
+++ b/Gemfile.rails4.lock
@@ -4,44 +4,41 @@ GEM
     RedCloth (4.3.2)
     abstract_type (0.0.7)
     ace-rails-ap (4.1.2)
-    actioncable (5.0.7)
-      actionpack (= 5.0.7)
-      nio4r (>= 1.2, < 3.0)
-      websocket-driver (~> 0.6.1)
-    actionmailer (5.0.7)
-      actionpack (= 5.0.7)
-      actionview (= 5.0.7)
-      activejob (= 5.0.7)
+    actionmailer (4.2.10)
+      actionpack (= 4.2.10)
+      actionview (= 4.2.10)
+      activejob (= 4.2.10)
       mail (~> 2.5, >= 2.5.4)
-      rails-dom-testing (~> 2.0)
-    actionpack (5.0.7)
-      actionview (= 5.0.7)
-      activesupport (= 5.0.7)
-      rack (~> 2.0)
-      rack-test (~> 0.6.3)
-      rails-dom-testing (~> 2.0)
+      rails-dom-testing (~> 1.0, >= 1.0.5)
+    actionpack (4.2.10)
+      actionview (= 4.2.10)
+      activesupport (= 4.2.10)
+      rack (~> 1.6)
+      rack-test (~> 0.6.2)
+      rails-dom-testing (~> 1.0, >= 1.0.5)
       rails-html-sanitizer (~> 1.0, >= 1.0.2)
-    actionview (5.0.7)
-      activesupport (= 5.0.7)
+    actionview (4.2.10)
+      activesupport (= 4.2.10)
       builder (~> 3.1)
       erubis (~> 2.7.0)
-      rails-dom-testing (~> 2.0)
+      rails-dom-testing (~> 1.0, >= 1.0.5)
       rails-html-sanitizer (~> 1.0, >= 1.0.3)
-    activejob (5.0.7)
-      activesupport (= 5.0.7)
-      globalid (>= 0.3.6)
-    activemodel (5.0.7)
-      activesupport (= 5.0.7)
-    activerecord (5.0.7)
-      activemodel (= 5.0.7)
-      activesupport (= 5.0.7)
-      arel (~> 7.0)
-    activerecord_sane_schema_dumper (1.0)
-      rails (>= 5, < 6)
-    activesupport (5.0.7)
-      concurrent-ruby (~> 1.0, >= 1.0.2)
-      i18n (>= 0.7, < 2)
+    activejob (4.2.10)
+      activesupport (= 4.2.10)
+      globalid (>= 0.3.0)
+    activemodel (4.2.10)
+      activesupport (= 4.2.10)
+      builder (~> 3.1)
+    activerecord (4.2.10)
+      activemodel (= 4.2.10)
+      activesupport (= 4.2.10)
+      arel (~> 6.0)
+    activerecord_sane_schema_dumper (0.2)
+      rails (>= 4, < 5)
+    activesupport (4.2.10)
+      i18n (~> 0.7)
       minitest (~> 5.1)
+      thread_safe (~> 0.3, >= 0.3.4)
       tzinfo (~> 1.1)
     acts-as-taggable-on (5.0.0)
       activerecord (>= 4.2.8)
@@ -52,7 +49,7 @@ GEM
       public_suffix (>= 2.0.2, < 4.0)
     aes_key_wrap (1.0.1)
     akismet (2.0.0)
-    arel (7.1.4)
+    arel (6.0.4)
     asana (0.6.0)
       faraday (~> 0.9)
       faraday_middleware (~> 0.9)
@@ -154,8 +151,8 @@ GEM
       html-pipeline
     declarative (0.0.10)
     declarative-option (0.1.0)
-    default_value_for (3.0.5)
-      activerecord (>= 3.2.0, < 5.2)
+    default_value_for (3.0.2)
+      activerecord (>= 3.2.0, < 5.1)
     descendants_tracker (0.0.4)
       thread_safe (~> 0.3, >= 0.3.1)
     device_detector (1.0.0)
@@ -406,7 +403,7 @@ GEM
       json (~> 1.8)
       multi_xml (>= 0.5.2)
     httpclient (2.8.3)
-    i18n (1.1.0)
+    i18n (0.9.5)
       concurrent-ruby (~> 1.0)
     icalendar (2.4.1)
     ice_nine (0.11.2)
@@ -502,7 +499,6 @@ GEM
     net-ntp (2.1.3)
     net-ssh (5.0.1)
     netrc (0.11.0)
-    nio4r (2.3.1)
     nokogiri (1.8.4)
       mini_portile2 (~> 2.3.0)
     nokogumbo (1.5.0)
@@ -631,7 +627,7 @@ GEM
       get_process_mem (~> 0.2)
       puma (>= 2.7, < 4)
     pyu-ruby-sasl (0.0.3.3)
-    rack (2.0.5)
+    rack (1.6.10)
     rack-accept (0.4.5)
       rack (>= 0.4)
     rack-attack (4.4.1)
@@ -649,36 +645,31 @@ GEM
       rack
     rack-test (0.6.3)
       rack (>= 1.0)
-    rails (5.0.7)
-      actioncable (= 5.0.7)
-      actionmailer (= 5.0.7)
-      actionpack (= 5.0.7)
-      actionview (= 5.0.7)
-      activejob (= 5.0.7)
-      activemodel (= 5.0.7)
-      activerecord (= 5.0.7)
-      activesupport (= 5.0.7)
-      bundler (>= 1.3.0)
-      railties (= 5.0.7)
-      sprockets-rails (>= 2.0.0)
-    rails-controller-testing (1.0.2)
-      actionpack (~> 5.x, >= 5.0.1)
-      actionview (~> 5.x, >= 5.0.1)
-      activesupport (~> 5.x)
+    rails (4.2.10)
+      actionmailer (= 4.2.10)
+      actionpack (= 4.2.10)
+      actionview (= 4.2.10)
+      activejob (= 4.2.10)
+      activemodel (= 4.2.10)
+      activerecord (= 4.2.10)
+      activesupport (= 4.2.10)
+      bundler (>= 1.3.0, < 2.0)
+      railties (= 4.2.10)
+      sprockets-rails
     rails-deprecated_sanitizer (1.0.3)
       activesupport (>= 4.2.0.alpha)
-    rails-dom-testing (2.0.3)
-      activesupport (>= 4.2.0)
-      nokogiri (>= 1.6)
+    rails-dom-testing (1.0.9)
+      activesupport (>= 4.2.0, < 5.0)
+      nokogiri (~> 1.6)
+      rails-deprecated_sanitizer (>= 1.0.1)
     rails-html-sanitizer (1.0.4)
       loofah (~> 2.2, >= 2.2.2)
-    rails-i18n (5.1.1)
-      i18n (>= 0.7, < 2)
-      railties (>= 5.0, < 6)
-    railties (5.0.7)
-      actionpack (= 5.0.7)
-      activesupport (= 5.0.7)
-      method_source
+    rails-i18n (4.0.9)
+      i18n (~> 0.7)
+      railties (~> 4.0)
+    railties (4.2.10)
+      actionpack (= 4.2.10)
+      activesupport (= 4.2.10)
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
     rainbow (3.0.0)
@@ -769,7 +760,8 @@ GEM
       rspec-core
     rspec-set (0.1.3)
     rspec-support (3.7.1)
-    rspec_junit_formatter (0.4.1)
+    rspec_junit_formatter (0.2.3)
+      builder (< 4)
       rspec-core (>= 2, < 4, != 2.12.0)
     rspec_profiling (0.0.5)
       activerecord
@@ -886,6 +878,8 @@ GEM
     sysexits (1.2.0)
     temple (0.8.0)
     test-prof (0.2.5)
+    test_after_commit (1.1.0)
+      activerecord (>= 3.2)
     text (1.3.1)
     thin (1.7.2)
       daemons (~> 1.0, >= 1.0.9)
@@ -948,9 +942,6 @@ GEM
       hashdiff
     webpack-rails (0.9.11)
       railties (>= 3.2.0)
-    websocket-driver (0.6.5)
-      websocket-extensions (>= 0.1.0)
-    websocket-extensions (0.1.3)
     wikicloth (0.8.1)
       builder
       expression_parser
@@ -966,7 +957,7 @@ PLATFORMS
 DEPENDENCIES
   RedCloth (~> 4.3.2)
   ace-rails-ap (~> 4.1.0)
-  activerecord_sane_schema_dumper (= 1.0)
+  activerecord_sane_schema_dumper (= 0.2)
   acts-as-taggable-on (~> 5.0)
   addressable (~> 2.5.2)
   akismet (~> 2.0)
@@ -1001,7 +992,7 @@ DEPENDENCIES
   creole (~> 0.5.0)
   database_cleaner (~> 1.5.0)
   deckar01-task_list (= 2.0.0)
-  default_value_for (~> 3.0.5)
+  default_value_for (~> 3.0.0)
   device_detector
   devise (~> 4.4)
   devise-two-factor (~> 3.0.0)
@@ -1126,10 +1117,9 @@ DEPENDENCIES
   rack-cors (~> 1.0.0)
   rack-oauth2 (~> 1.2.1)
   rack-proxy (~> 0.6.0)
-  rails (= 5.0.7)
-  rails-controller-testing
+  rails (= 4.2.10)
   rails-deprecated_sanitizer (~> 1.0.3)
-  rails-i18n (~> 5.1)
+  rails-i18n (~> 4.0.9)
   rainbow (~> 3.0)
   raindrops (~> 0.18)
   rblineprof (~> 0.3.6)
@@ -1182,6 +1172,7 @@ DEPENDENCIES
   state_machines-activerecord (~> 0.5.1)
   sys-filesystem (~> 1.1.6)
   test-prof (~> 0.2.5)
+  test_after_commit (~> 1.1)
   thin (~> 1.7.0)
   timecop (~> 0.8.0)
   toml-rb (~> 1.0.0)
diff --git a/bin/setup b/bin/setup
index ec1ebe02950..34bb667087a 100755
--- a/bin/setup
+++ b/bin/setup
@@ -1,7 +1,7 @@
 #!/usr/bin/env ruby
 
 def rails5?
-  %w[1 true].include?(ENV["RAILS5"])
+  !%w[0 false].include?(ENV["RAILS5"])
 end
 
 require "pathname"
diff --git a/config/application.rb b/config/application.rb
index e3678b053d0..94deffaa2cb 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -10,7 +10,7 @@ module Gitlab
   # This method is used for smooth upgrading from the current Rails 4.x to Rails 5.0.
   # https://gitlab.com/gitlab-org/gitlab-ce/issues/14286
   def self.rails5?
-    ENV["RAILS5"].in?(%w[1 true])
+    !%w[0 false].include?(ENV["RAILS5"])
   end
 
   class Application < Rails::Application
diff --git a/config/boot.rb b/config/boot.rb
index 655c54ddb84..1aeacdabbad 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -1,10 +1,10 @@
 def rails5?
-  %w[1 true].include?(ENV["RAILS5"])
+  !%w[0 false].include?(ENV["RAILS5"])
 end
 
 require 'rubygems' unless rails5?
 
-gemfile = rails5? ? "Gemfile.rails5" : "Gemfile"
+gemfile = rails5? ? "Gemfile" : "Gemfile.rails4"
 ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../#{gemfile}", __dir__)
 
 # Set up gems listed in the Gemfile.
diff --git a/config/environment.rb b/config/environment.rb
index 5d35937f7c6..3a52656a2c1 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -1,10 +1,10 @@
 # Load the rails application
 
 # Remove this condition when upgraded to rails 5.0.
-if %w[1 true].include?(ENV["RAILS5"])
-  require_relative 'application'
-else
+if %w[0 false].include?(ENV["RAILS5"])
   require File.expand_path('application', __dir__)
+else
+  require_relative 'application'
 end
 
 # Initialize the rails application
-- 
2.30.9