From 84cad15213ea5447ea0890a4f017b44ad85b901a Mon Sep 17 00:00:00 2001
From: Matthew Draper <matthew@trebex.net>
Date: Mon, 27 Nov 2017 23:39:30 +1030
Subject: Drop the before_fork/on_worker_boot advice

It's no longer required for Active Record, and other common libraries
(dalli, redis-rb) all seem to be fork-proof too.
---
 .../rails/app/templates/config/puma.rb.tt          | 24 +---------------------
 1 file changed, 1 insertion(+), 23 deletions(-)

(limited to 'railties')

diff --git a/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt
index 1e19380dcb..a5eccf816b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt
@@ -26,31 +26,9 @@ environment ENV.fetch("RAILS_ENV") { "development" }
 # Use the `preload_app!` method when specifying a `workers` number.
 # This directive tells Puma to first boot the application and load code
 # before forking the application. This takes advantage of Copy On Write
-# process behavior so workers use less memory. If you use this option
-# you need to make sure to reconnect any threads in the `on_worker_boot`
-# block.
+# process behavior so workers use less memory.
 #
 # preload_app!
 
-# If you are preloading your application and using Active Record, it's
-# recommended that you close any connections to the database before workers
-# are forked to prevent connection leakage.
-#
-# before_fork do
-#   ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
-# end
-
-# The code in the `on_worker_boot` will be called if you are using
-# clustered mode by specifying a number of `workers`. After each worker
-# process is booted, this block will be run. If you are using the `preload_app!`
-# option, you will want to use this block to reconnect to any threads
-# or connections that may have been created at application boot, as Ruby
-# cannot share connections between processes.
-#
-# on_worker_boot do
-#   ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
-# end
-#
-
 # Allow puma to be restarted by `rails restart` command.
 plugin :tmp_restart
-- 
cgit v1.2.3


From eb9ff5fd39ca3af20cb95b723ee622ceef10310d Mon Sep 17 00:00:00 2001
From: Anton Rieder <aried3r@gmail.com>
Date: Thu, 30 Nov 2017 16:34:06 +0100
Subject: Move system test dependencies to test group

---
 .../lib/rails/generators/rails/app/templates/Gemfile.tt | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

(limited to 'railties')

diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt
index 61026f5182..e3ed3e7c11 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt
@@ -41,13 +41,6 @@ gem 'bootsnap', '>= 1.1.0', require: false
 group :development, :test do
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
   gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
-  <%- if depends_on_system_test? -%>
-  # Adds support for Capybara system testing and selenium driver
-  gem 'capybara', '~> 2.15'
-  gem 'selenium-webdriver'
-  # Easy installation and use of chromedriver to run system tests with Chrome
-  gem 'chromedriver-helper'
-  <%- end -%>
 end
 
 group :development do
@@ -70,6 +63,16 @@ group :development do
 <% end -%>
 <% end -%>
 end
+
+<%- if depends_on_system_test? -%>
+group :test do
+  # Adds support for Capybara system testing and selenium driver
+  gem 'capybara', '~> 2.15'
+  gem 'selenium-webdriver'
+  # Easy installation and use of chromedriver to run system tests with Chrome
+  gem 'chromedriver-helper'
+end
+<%- end -%>
 <% end -%>
 
 # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
-- 
cgit v1.2.3


From a71bbed76aab9e8a9a6b2da18bcacd8ee32a0dd0 Mon Sep 17 00:00:00 2001
From: claudiob <claudiob@users.noreply.github.com>
Date: Sat, 2 Dec 2017 12:00:09 -0800
Subject: Fix typo in test error message

With the current code, a failing test shows this error, which is missing
the number of times called and has two periods at the end.

```
/railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install

Failure:
AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]:
active_storage:install expected to be called once, but was called  times..
Expected: 1
  Actual: 2
```

After the fix, the error message looks correct:

```
/railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install

Failure:
AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]:
active_storage:install expected to be called once, but was called 2 times.
Expected: 1
  Actual: 2
```
---
 railties/test/generators/app_generator_test.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties')

diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 774fd0f315..8d12f4e5a7 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -310,7 +310,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
       case command
       when "active_storage:install"
         @binstub_called += 1
-        assert_equal 1, @binstub_called, "active_storage:install expected to be called once, but was called #{@install_called} times."
+        assert_equal 1, @binstub_called, "active_storage:install expected to be called once, but was called #{@binstub_called} times"
       end
     end
 
-- 
cgit v1.2.3


From dbee80bca0ef504120219e6c7686437456511060 Mon Sep 17 00:00:00 2001
From: "yuuji.yaginuma" <yuuji.yaginuma@gmail.com>
Date: Fri, 1 Dec 2017 18:16:06 +0900
Subject: Make `Migrator.current_version` work without a current database

This is necessary in order to make the processing dependent on
`Migrator.current_version` work even without database.

Context: https://github.com/rails/rails/pull/31135#issuecomment-348404326
---
 railties/test/application/rake/dbs_test.rb | 14 ++++++++++++++
 railties/test/isolation/abstract_unit.rb   | 15 +++++++++++++++
 2 files changed, 29 insertions(+)

(limited to 'railties')

diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index 0235210fdd..2082e9fa9f 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -98,6 +98,20 @@ module ApplicationTests
         end
       end
 
+      test "db:create works when schema cache exists and database does not exist" do
+        use_postgresql
+
+        begin
+          rails %w(db:create db:migrate db:schema:cache:dump)
+
+          rails "db:drop"
+          rails "db:create"
+          assert_equal 0, $?.exitstatus
+        ensure
+          rails "db:drop" rescue nil
+        end
+      end
+
       test "db:drop failure because database does not exist" do
         output = rails("db:drop:_unsafe", "--trace")
         assert_match(/does not exist/, output)
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 7522237a38..5b1c06d4e5 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -381,6 +381,21 @@ module TestHelpers
 
       $:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' }
     end
+
+    def use_postgresql
+      File.open("#{app_path}/config/database.yml", "w") do |f|
+        f.puts <<-YAML
+        default: &default
+          adapter: postgresql
+          pool: 5
+          database: railties_test
+        development:
+          <<: *default
+        test:
+          <<: *default
+        YAML
+      end
+    end
   end
 end
 
-- 
cgit v1.2.3


From 915f0e682cecf80080914d0390ce22eb06f41470 Mon Sep 17 00:00:00 2001
From: Tsukuru Tanimichi <info+git@ttanimichi.com>
Date: Wed, 29 Nov 2017 18:44:46 +0900
Subject: Add tests for the `--webpack` option

We probably don't have any tests for the `--webpack` option.
related: #27288
---
 railties/test/generators/app_generator_test.rb | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

(limited to 'railties')

diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 774fd0f315..c9c85078d4 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -743,6 +743,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
     end
   end
 
+  def test_webpack_option
+    command_check = -> command, *_ do
+      @called ||= 0
+      @called += 1 if command == "webpacker:install"
+      assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times."
+    end
+
+    generator([destination_root], webpack: true).stub(:rails_command, command_check) do
+      quietly { generator.invoke_all }
+    end
+
+    assert_gem "webpacker"
+  end
+
   def test_generator_if_skip_turbolinks_is_given
     run_generator [destination_root, "--skip-turbolinks"]
 
-- 
cgit v1.2.3


From b9fb74514b752df3b707fa420e09dca459a3844f Mon Sep 17 00:00:00 2001
From: Tsukuru Tanimichi <info+git@ttanimichi.com>
Date: Tue, 5 Dec 2017 18:41:44 +0900
Subject: Modify `test_webpack_option`

---
 railties/test/generators/app_generator_test.rb | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'railties')

diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index decea77d48..68b31148d6 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -746,11 +746,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
   def test_webpack_option
     command_check = -> command, *_ do
       @called ||= 0
-      @called += 1 if command == "webpacker:install"
-      assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times."
+      if command == "webpacker:install"
+        @called += 1
+        assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times."
+      end
     end
 
-    generator([destination_root], webpack: true).stub(:rails_command, command_check) do
+    generator([destination_root], webpack: "webpack").stub(:rails_command, command_check) do
       quietly { generator.invoke_all }
     end
 
-- 
cgit v1.2.3


From 6a11b0c1549e88a7ca32a73764d8b6634dc326e2 Mon Sep 17 00:00:00 2001
From: Tsukuru Tanimichi <info+git@ttanimichi.com>
Date: Tue, 5 Dec 2017 18:43:15 +0900
Subject: Add more tests for the `--webpack` option

---
 railties/test/generators/app_generator_test.rb | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

(limited to 'railties')

diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 68b31148d6..96803db838 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -759,6 +759,25 @@ class AppGeneratorTest < Rails::Generators::TestCase
     assert_gem "webpacker"
   end
 
+  def test_webpack_option_with_js_framework
+    command_check = -> command, *_ do
+      case command
+      when "webpacker:install"
+        @webpacker ||= 0
+        @webpacker += 1
+        assert_equal 1, @webpacker, "webpacker:install expected to be called once, but was called #{@webpacker} times."
+      when "webpacker:install:react"
+        @react ||= 0
+        @react += 1
+        assert_equal 1, @react, "webpacker:install:react expected to be called once, but was called #{@react} times."
+      end
+    end
+
+    generator([destination_root], webpack: "react").stub(:rails_command, command_check) do
+      quietly { generator.invoke_all }
+    end
+  end
+
   def test_generator_if_skip_turbolinks_is_given
     run_generator [destination_root, "--skip-turbolinks"]
 
-- 
cgit v1.2.3