yoasyo25 / overtime-app

0 stars 0 forks source link

Changes during rails app:update #2

Open yoasyo25 opened 6 years ago

yoasyo25 commented 6 years ago

Modification to Gemfile during bundle update rails

Configuration Files

See the Railsdiff website to for line by line changes in configuration files between different versions of Rails. The richonrails website provides a summarized version of changes in config files introduced in Rails 5. http://railsdiff.org/4.2.10/5.0.0 https://richonrails.com/articles/the-rails-5-0-default-files


config/application.rb

Keep require 'rails/all', which is a rails default and require 'obscenity/active_model' - which is part of the configuration for the 'obscenity', which filters profanity.

Keep config.autoload_paths += %W(#{config.root}/lib) - which is configuration for the gridder gem, which allows emails to be received in the app.

Keep config.active_job.queue_adapter = :sidekiq - which is part of the configuration for sidekiq gem

Investigate if the code below should stay in application.rb or be moved to a file in the assets folder or to config/initializers/assets.rb. For now (March 30, 2018), this stays in application.rb.

     config.assets.precompile += ["print.scss",
                                  "prizmdoc/normalize.min.css",
                                  "prizmdoc/viewercontrol.css", "prizmdoc/viewer.css",
                                  "prizmdoc/nextrequest.css", "prizmdoc/jquery.hotkeys.min.js",
                                  "prizmdoc/legacy.css", "prizmdoc/legacy/html5shiv.js",
                                  "prizmdoc/viewercontrol.js", "prizmdoc/viewer.js",
                                  "prizmdoc/utilities.js", "prizmdoc/utilities_show.js",
                                  "prizmdoc/sample-config.js", "redaction-log.scss"]

Keep configuration for paperclip

config.paperclip_defaults = {
       storage: :s3,
       url: ":s3_domain_url",
       s3_region: ENV["AWS_REGION"],
       s3_credentials: {
         bucket: ENV["S3_BUCKET"],
         access_key_id: ENV["AWS_ACCESS_KEY_ID"],
         secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
         s3_host_name: "s3.amazonaws.com"
       },
       s3_protocol: "https"
     }

Delete the following commented out lines

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
* `config.active_record.raise_in_callbacks = true` is no longer needed. In Rails 4 Active Record suppressed errors raised within after_rollback or after_commit callbacks and only printed them to the logs.  In Rails 5, these errors will no longer be suppressed. Instead, the errors will propagate normally just like in other Active Record callbacks.

config/secrets.yml

the new secret keys provided by the update were declined and the <%= ENV["SECRET_TOKEN"] %> were kept.

The default puma.rb Rails 5 file has the following code

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

port        ENV.fetch("PORT") { 3000 } 

environment ENV.fetch("RAILS_ENV") { "development" }

# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

plugin :tmp_restart

config/environments/development.rb

config.active_record.migration_error = :page_load - This is currently set to false in our application. Setting to :page_load will raise an error on each page refresh if there are migrations that are pending.

Take out config.action_controller.include_all_helpers = true - configures whether all view helpers are available everywhere or are scoped to the corresponding controller. When set to true UsersHelper methods are available everywhere. The default configuration behavior (when this option is not explicitly set to true or false) is that all view helpers are available to each controller. The above is not needed currently but can be useful in the future for raising translation errors in views/helpers. Rails 5 does not explicitly set this, so we can delete it from application.rb/development.rb/test.rb

Check if the upgrade to Rails 5 requires the code below to be moved to another file. config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/ - allows fonts to be placed outside of app/assets/fonts and enables support on different devices. config.assets.precompile += %w( icons/) - allows icons to be precompiled config.assets.precompile += ["styleguide.html"] - allows styleguide.html to be precompiled https://github.com/livingstyleguide/livingstyleguide

config.lograge.enabled = true - added to configure lograge gem which replaces Rails' request logging by reducing the output per request to a single line with all the important information, while removing the from the Rails default output.

config.lograge.custom_options = lambda do |event|
    params = event.payload[:params].reject do |k|
      ['controller', 'action'].include? k
    end

    { "params" => params }
  end

The code above should be maintained since it adds customization to lograge so that the request parameters is accessible in the logs.

environment.rb

Update require File.expand_path('../application', __FILE__) withrequire_relative 'application'and Nextrequest::Application.initialize!withRails.application.initialize!`

Keep the smtp_settings settings for ActionMailer and Rack::MiniProfiler.config.start_hidden = true, which is part of the setting for the "rack-mini-profiler" gem which is a middleware that displays speed badge for every html page.

production.rb

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "nextrequest_#{Rails.env}"
  config.action_mailer.perform_caching = false
  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
   if ENV["RAILS_LOG_TO_STDOUT"].present?
      logger           = ActiveSupport::Logger.new(STDOUT)
      logger.formatter = config.log_formatter
      config.logger = ActiveSupport::TaggedLogging.new(logger)
    end

Does the above code need to be commented out?

  # Version of your assets, change this if you want to expire all your assets.
  config.assets.version = '1.0'

config.assets.precompile and config.assets.version have moved to config/initializers/assets.rb

config.log_level = :info in Rails 4 and Rails 5 the default is config.log_level = :debug - The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, corresponding to the log level numbers from 0 up to 5, respectively.

Update config.log_tags = [ :subdomain, :uuid ] with config.log_tags = [ :request_id ]as the:request_id` log tag ensures that each request is tagged with a unique identifier. While they are still interleaved it is possible to figure out which lines belong to which requests

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

Delete the above comment.

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"

Delete the above comment.

# Disable automatic flushing of the log to improve performance.
-   # config.autoflush_log = false

Delete the above comment.

Delete config.action_controller.include_all_helpers = true

  if ENV['PRODUCTION_PRODUCTION'] == 'true'
    config.force_ssl = true
  else
    config.force_ssl = false
  end
 # Use a different cache store in production.
 # config.cache_store = :mem_cache_store
 # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
  config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
  config.assets.precompile += %w( icons/)
  config.assets.precompile += %w( tinymce/skins/light/skin.min.css )
  config.assets.precompile += %w( tinymce/skins/light/content.min.css )
  config.assets.precompile += %w( print.css )
  config.assets.precompile += ["*prizmdoc/*"]

The above code is used to precompile additional assets. Check if this is where the code should remain in Rails 5.

config.action_mailer.default_url_options = { host: "www.nextrequest.com" } config.i18n.fallbacks = true - Enable locale fallbacks for I18n (no change between Rails 4 and 5) config.active_support.deprecation = :notify - Send deprecation notices to registered listeners (no change between Rails 4 and 5) config.log_formatter = ::Logger::Formatter.new - Use default logging formatter so that PID and timestamp are not suppressed. (no change between Rails 4 and 5)

  config.lograge.enabled = true
  config.lograge.custom_options = lambda do |event|
    params = event.payload[:params].reject do |k|
      ['controller', 'action'].include? k
    end

    { "params" => params }
  end

The code above is used to configure lograge gem which replaces Rails' request logging by reducing the output per request to a single line with all the important information, while removing the from the Rails default output.

config.middleware.use Rack::Attack - configuration for rack-attack gem which blocks & throttles abusive requests. The rules for blocking and throttling are defined in rack-attack.rb.

 # Prepend all log lines with the following tags.
 # config.log_tags = [ :subdomain, :uuid ]

Change the above with what is below

# Prepend all log lines with the following tags.
#config.log_tags = [ :request_id ]```

The :request_id log tag ensures that each request is tagged with a unique identifier. While they are still interleaved it is possible to figure out which lines belong to which requests. Whether you are using components that are setting request ID or not, all production applications can benefit from the additional debugging information of having a unique identifier for all requests.

https://github.com/rails/rails/commit/81d3bec460715d5ca9b039b72db080a733867299

test.rb

Add in test.rb config.action_mailer.perform_caching = false - mailer template will not perform fragment caching in test environment.

 # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

Modify

Update # Configure static asset server for tests with Cache-Control for performance. with # Configure public file server for tests with Cache-Control for performance.

Update config.serve_static_files = true with config.public_file_server.enabled = true as serve_static_files is deprecated in rails Rails 5, wherepublic_file_serveris used to unify the static options under thepublic_file_serverwing.config.public_file_server.enabled` configures Rails to serve static files from the public directory.

Update config.static_cache_control = "public, max-age=3600" with

config.public_file_server.headers = {
     'Cache-Control' => 'public, max-age=3600'
 }

config.static_cache_control is deprecated in Rails 5 in favor of config.public_file_server.headers. The above code adds the ability of returning arbitrary headers to ActionDispatch::Static. https://github.com/rails/rails/commit/52260581638406d910e09e8d2e66b51acb76c5c6

Maintain in test.rb config.assets.debug = true - disables concatenation and preprocessing of assets config.consider_all_requests_local = true - when set to true then any error will cause detailed debugging information to be dumped in the HTTP response, and the Rails::Info controller will show the application runtime context in /rails/info/properties.

config.action_controller.perform_caching = true - enables caching in test environment.

# Raise exceptions instead of rendering exception templates.
    config.action_dispatch.show_exceptions = false

 # Disable request forgery protection in test environment.
    config.action_controller.allow_forgery_protection = false
 # Tell Action Mailer not to deliver emails to the real world.
    # The :test delivery method accumulates sent emails in the
    # ActionMailer::Base.deliveries array.
    config.action_mailer.delivery_method = :test

config.action_mailer.default_url_options = { host: 'localhost:3000' } - set default host that will be used for mailers in test environment.

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

Delete in test.rb config.action_controller.include_all_helpers = true - In Rails 5 the default configuration behavior (when this option is not explicitly set to true or false) is that all view helpers are available to each controller.

config.active_record.raise_in_transactional_callbacks = true - Active Record no longer suppresses errors raised within after_rollback or after_commit callbacks in Rails 5. Hence I don't think this line is needed.

boot.rb

Rails 5 uses require 'bundler/setup' without checkingif File.exist?(ENV['BUNDLE_GEMFILE']) . The if check was causing Gemfile related errors. https://github.com/rails/rails/pull/16046

config/initializers/cookies_serializer.rb

Replace Nextrequest::Application.config.session_store :cookie_store, key: '_recordquest_session' with Rails.application.config.session_store :cookie_store, key: '_nextrequest_session' - the code specifies what class to use to store the session.

initializers/wrap_parameters.rb

Replace wrap_parameters format: [:json] if respond_to?(:wrap_parameters) with wrap_parameters format: [:json] - as checking if controller responds to wrap_parameter is not longer required. Keep the rest of the code as is.

initializers/mime_types.rb

Delete # Mime::Type.register_alias "text/html", :iphone - Rails 5 takes out this line so as not to encourage the use of aliases.

locales/en.yml

Keep as is. Local changes were made to this file for testing and error handling purposes.

Rakefile

Update require File.expand_path("../config/application", __FILE__) with require_relative "config/application" and Nextrequest::Application.load_tasks with Rails.application.load_tasks and keep the code below, which was added to added rerun rspec to cut down on failing tests

require "rspec-rerun/tasks"
task default: "rspec-rerun:spec"

Additional Features

Rails 5 brings consistency by wrapping all rake commands using rails https://blog.bigbinary.com/2016/01/14/rails-5-supports-rake-commands-using-rails.html

Rails 5 Diff

*[ ] In /bin/rails APP_PATH = File.expand_path('../config/application', __dir__) check what the change with FILE accomplishes.