From b66b5378baf3804e9985a7cb9630f6d5a3ddcf97 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Fri, 17 Feb 2017 23:56:48 +0000 Subject: Clear active connections after initialization Any connections that were checked out during initialization should be checked back in before the first request is processed, for two reasons: - Returning the connection to the pool allows it to be health checked before it's used again. If the connection dies before the first request arrives, the health check will replace it with a new one. - If the thread that initialized Rails is not the same thread that will be performing work, checking in the connection will allow it to be reused instead of being stuck to the initialization thread forever. --- railties/test/application/initializers/frameworks_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 90927159dd..eb2c578f91 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -262,5 +262,13 @@ module ApplicationTests Rails.env = orig_rails_env if orig_rails_env end end + + test "connections checked out during initialization are returned to the pool" do + app_file "config/initializers/active_record.rb", <<-RUBY + ActiveRecord::Base.connection + RUBY + require "#{app_path}/config/environment" + assert !ActiveRecord::Base.connection_pool.active_connection? + end end end -- cgit v1.2.3 From 8e6c6d854cdedad4bc082cf45a01d411ea26fb68 Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Mon, 30 May 2016 02:15:18 +0200 Subject: Pass request params to ActionMailer::Preview --- railties/test/application/mailer_previews_test.rb | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb index c3a360e5d4..f5c013dab6 100644 --- a/railties/test/application/mailer_previews_test.rb +++ b/railties/test/application/mailer_previews_test.rb @@ -485,6 +485,57 @@ module ApplicationTests assert_match '
  • foo
  • ', last_response.body end + test "mailer preview receives query params" do + mailer "notifier", <<-RUBY + class Notifier < ActionMailer::Base + default from: "from@example.com" + + def foo(name) + @name = name + mail to: "to@example.org" + end + end + RUBY + + html_template "notifier/foo", <<-RUBY +

    Hello, <%= @name %>!

    + RUBY + + text_template "notifier/foo", <<-RUBY + Hello, <%= @name %>! + RUBY + + mailer_preview "notifier", <<-RUBY + class NotifierPreview < ActionMailer::Preview + def foo + Notifier.foo(params[:name] || "World") + end + end + RUBY + + app("development") + + get "/rails/mailers/notifier/foo.txt" + assert_equal 200, last_response.status + assert_match '