From 36bedfb7f37931a33d9af586296404c02c3ab80e Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Thu, 22 Mar 2018 09:37:57 +1100 Subject: [Rails5] Update files by `rails app:update` --- config/boot.rb | 11 +++++--- config/environment.rb | 8 +++++- config/environments/production.rb | 6 ++++- config/environments/test.rb | 8 +++++- .../application_controller_renderer.rb | 12 +++++++++ config/initializers/new_framework_defaults.rb | 29 ++++++++++++++++++++++ config/spring.rb | 6 +++++ 7 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/new_framework_defaults.rb create mode 100644 config/spring.rb (limited to 'config') diff --git a/config/boot.rb b/config/boot.rb index f2830ae3166..84f390f3228 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,11 @@ -require 'rubygems' +def rails5? + %w[1 true].include?(ENV["RAILS5"]) +end -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +require 'rubygems' unless rails5? + +gemfile = rails5? ? "Gemfile.rails5" : "Gemfile" +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../#{gemfile}", __dir__) +# Set up gems listed in the Gemfile. require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index df3006d349c..487a4564b47 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,11 @@ # Load the rails application -require File.expand_path('../application', __FILE__) + +# Remove this condition when upgraded to rails 5.0. +if %w[1 true].include?(ENV["RAILS5"]) + require_relative 'application' +else + require File.expand_path('../application', __FILE__) +end # Initialize the rails application Rails.application.initialize! diff --git a/config/environments/production.rb b/config/environments/production.rb index c5cbfcf64cf..9941987929c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,11 @@ Rails.application.configure do config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_files = false + if Gitlab.rails5? + config.public_file_server.enabled = false + else + config.serve_static_files = false + end # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier diff --git a/config/environments/test.rb b/config/environments/test.rb index d09e51e766a..1849c984351 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,7 +18,13 @@ Rails.application.configure do # Configure static asset server for tests with Cache-Control for performance config.assets.compile = false if ENV['CI'] - config.serve_static_files = true + + if Gitlab.rails5? + config.public_file_server.enabled = true + else + config.serve_static_files = true + end + config.static_cache_control = "public, max-age=3600" # Show full error reports and disable caching diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000000..a65f8aecf9e --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,12 @@ +# Remove this `if` condition when upgraded to rails 5.0. +# The body must be kept. +if Gitlab.rails5? + # Be sure to restart your server when you modify this file. + + # ActiveSupport::Reloader.to_prepare do + # ApplicationController.renderer.defaults.merge!( + # http_host: 'example.org', + # https: false + # ) + # end +end diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 00000000000..2d130bc0bf8 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,29 @@ +# Remove this `if` condition when upgraded to rails 5.0. +# The body must be kept. +if Gitlab.rails5? + # Be sure to restart your server when you modify this file. + # + # This file contains migration options to ease your Rails 5.0 upgrade. + # + # Once upgraded flip defaults one by one to migrate to the new default. + # + # Read the Guide for Upgrading Ruby on Rails for more info on each option. + + Rails.application.config.action_controller.raise_on_unfiltered_parameters = true + + # Enable per-form CSRF tokens. Previous versions had false. + Rails.application.config.action_controller.per_form_csrf_tokens = false + + # Enable origin-checking CSRF mitigation. Previous versions had false. + Rails.application.config.action_controller.forgery_protection_origin_check = false + + # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. + # Previous versions had false. + ActiveSupport.to_time_preserves_timezone = false + + # Require `belongs_to` associations by default. Previous versions had false. + Rails.application.config.active_record.belongs_to_required_by_default = false + + # Do not halt callback chains when a callback returns false. Previous versions had true. + ActiveSupport.halt_callback_chains_on_return_false = true +end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 00000000000..c9119b40c08 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } -- cgit v1.2.1