From 2557645f4fa223ba6ea562df0443199b73824f20 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Fri, 4 Sep 2020 12:57:19 +0200 Subject: [PATCH] Rails 5.0 --- Gemfile | 12 +- Gemfile.lock | 213 +++++++++--------- Procfile | 2 +- app/models/user.rb | 4 +- app/views/orders/_form.html.haml | 2 +- bin/rails | 2 +- bin/setup | 34 +++ bin/update | 29 +++ config/application.rb | 10 +- config/boot.rb | 7 +- config/environment.rb | 4 +- config/environments/development.rb.SAMPLE | 32 ++- config/environments/production.rb | 65 +++--- config/environments/test.rb | 24 +- .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 11 + config/initializers/cookies_serializer.rb | 5 + config/initializers/mime_types.rb | 1 - config/initializers/new_framework_defaults.rb | 20 ++ config/initializers/session_store.rb | 7 +- config/initializers/wrap_parameters.rb | 4 +- config/puma.rb | 47 ++++ config/routes.rb | 2 +- config/spring.rb | 6 + .../printer/lib/foodsoft_printer/engine.rb | 2 +- 25 files changed, 367 insertions(+), 186 deletions(-) create mode 100755 bin/setup create mode 100755 bin/update create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/new_framework_defaults.rb create mode 100644 config/puma.rb create mode 100644 config/spring.rb diff --git a/Gemfile b/Gemfile index b39138c82..e91e9f8fb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ # A sample Gemfile source "https://rubygems.org" -gem "rails", '~> 4.2' +gem "rails", '< 5.1' gem 'sass-rails' gem 'less-rails' @@ -19,7 +19,7 @@ gem 'rails-assets-listjs', '0.2.0.beta.4' # remember to maintain list.*.js plugi gem 'i18n-js', '~> 3.0.0.rc8' gem 'rails-i18n' -gem 'mysql2', '~> 0.4.0' # for compatibility with rails 4 +gem 'mysql2' gem 'prawn' gem 'prawn-table' gem 'haml' @@ -36,11 +36,12 @@ gem 'active_model_serializers', '~> 0.10.0' gem 'twitter-bootstrap-rails', '~> 2.2.8' gem 'simple-navigation', '~> 3.14.0' # 3.x for simple_navigation_bootstrap gem 'simple-navigation-bootstrap' +gem 'sprockets', '< 4' gem 'ransack' gem 'acts_as_tree' gem 'rails-settings-cached', '= 0.4.3' # caching breaks tests until Rails 5 https://github.com/huacnlee/rails-settings-cached/issues/73 gem 'resque' -gem 'thin' +gem 'puma' gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb gem 'ruby-units' gem 'attribute_normalizer' @@ -73,7 +74,7 @@ gem 'foodsoft_polls', path: 'plugins/polls' group :development do gem 'sqlite3', '~> 1.3.6' gem 'mailcatcher' - gem 'web-console', '~> 2.0' + gem 'web-console' # Better error output gem 'better_errors' @@ -99,12 +100,11 @@ group :test do gem 'factory_bot_rails' gem 'faker' gem 'capybara' - gem 'puma' # for faster Capybara tests gem 'apparition' # Capybara javascript driver gem 'database_cleaner' gem 'connection_pool' # need to include rspec components before i18n-spec or rake fails in test environment - gem 'rspec-core', '~> 3.2' + gem 'rspec-core' gem 'rspec-rerun' gem 'i18n-spec' # code coverage diff --git a/Gemfile.lock b/Gemfile.lock index b13a050e5..f53b48fdc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,44 +65,47 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.1) - actionview (= 4.2.11.1) - activesupport (= 4.2.11.1) - 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.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.1) - activesupport (= 4.2.11.1) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) 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) active_model_serializers (0.10.10) actionpack (>= 4.1, < 6.1) activemodel (>= 4.1, < 6.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (4.2.11.1) - activesupport (= 4.2.11.1) - globalid (>= 0.3.0) - activemodel (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - activerecord (4.2.11.1) - activemodel (= 4.2.11.1) - activesupport (= 4.2.11.1) - arel (~> 6.0) - activesupport (4.2.11.1) - i18n (~> 0.7) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) + 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_tree (2.9.1) activerecord (>= 3.0.0) @@ -118,13 +121,14 @@ GEM apparition (0.6.0) capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) - arel (6.0.4) + arel (7.1.4) attribute_normalizer (1.2.0) base32 (0.3.4) better_errors (2.7.1) coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) + bindex (0.8.1) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) bootstrap-datepicker-rails (1.9.0.1) @@ -176,9 +180,10 @@ GEM diff-lcs (1.4.4) diffy (3.4.0) docile (1.3.2) - doorkeeper (5.0.3) - railties (>= 4.2) - doorkeeper-i18n (5.0.3) + doorkeeper (5.4.0) + railties (>= 5) + doorkeeper-i18n (5.2.2) + doorkeeper (>= 5.2) email_reply_trimmer (0.1.13) erubi (1.9.0) erubis (2.7.0) @@ -188,13 +193,13 @@ GEM activesupport (>= 4.0, < 7) execjs (2.7.0) expression_parser (0.9.0) - factory_bot (5.2.0) - activesupport (>= 4.2.0) - factory_bot_rails (5.2.0) - factory_bot (~> 5.2.0) - railties (>= 4.2.0) - faker (2.2.1) - i18n (>= 0.8) + factory_bot (6.1.0) + activesupport (>= 5.0.0) + factory_bot_rails (6.1.0) + factory_bot (~> 6.1.0) + railties (>= 5.0.0) + faker (2.13.0) + i18n (>= 1.6, < 2) ffi (1.13.1) gaffe (1.2.0) rails (>= 4.0.0) @@ -219,18 +224,18 @@ GEM nokogiri (>= 1.6.0) ruby_parser (~> 3.5) htmlentities (4.3.4) - i18n (0.9.5) + i18n (1.8.5) concurrent-ruby (~> 1.0) i18n-js (3.0.11) i18n (>= 0.6.6, < 2) i18n-spec (0.6.0) iso ice_cube (0.16.3) - inherited_resources (1.9.0) - actionpack (>= 4.2, < 5.3) + inherited_resources (1.11.0) + actionpack (>= 5.0, < 6.1) has_scope (~> 0.6) - railties (>= 4.2, < 5.3) - responders + railties (>= 5.0, < 6.1) + responders (>= 2, < 4) interception (0.5) iso (0.3.0) i18n @@ -256,10 +261,10 @@ GEM kaminari-core (1.2.1) less (2.6.0) commonjs (~> 0.2.7) - less-rails (4.0.0) - actionpack (>= 4) + less-rails (5.0.0) + actionpack (>= 5.0) less (~> 2.6.0) - sprockets (>= 2) + sprockets (~> 3.0) libv8 (3.16.14.19) loofah (2.7.0) crass (~> 1.0.2) @@ -289,11 +294,15 @@ GEM minitest (5.14.2) mono_logger (1.1.0) multi_json (1.15.0) - mysql2 (0.4.10) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + mysql2 (0.5.3) nio4r (2.5.2) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) pdf-core (0.8.1) + polyamorous (2.3.0) + activerecord (>= 5.0) polyglot (0.3.5) prawn (2.3.0) pdf-core (~> 0.8.1) @@ -312,55 +321,55 @@ GEM public_suffix (4.0.6) puma (4.3.5) nio4r (~> 2.0) - rack (1.6.13) - rack-contrib (1.8.0) - rack (~> 1.4) - rack-cors (1.0.6) - rack (>= 1.6.0) - rack-protection (1.5.5) + rack (2.2.3) + rack-contrib (2.2.0) + rack (~> 2.0) + rack-cors (1.1.1) + rack (>= 2.0.0) + rack-protection (2.1.0) rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.11.1) - actionmailer (= 4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - activemodel (= 4.2.11.1) - activerecord (= 4.2.11.1) - activesupport (= 4.2.11.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.1) - sprockets-rails + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) rails-assets-listjs (0.2.0.beta.4) railties (>= 3.1) - 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.3.0) loofah (~> 2.3) - rails-i18n (4.0.9) - i18n (~> 0.7) - railties (~> 4.0) + rails-i18n (5.1.3) + i18n (>= 0.7, < 2) + railties (>= 5.0, < 6) rails-settings-cached (0.4.3) rails (>= 4.2.0) rails_tokeninput (1.7.0) railties (>= 3.1.0) - railties (4.2.11.1) - actionpack (= 4.2.11.1) - activesupport (= 4.2.11.1) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) rake (13.0.1) - ransack (1.8.10) - actionpack (>= 3.0, < 5.2) - activerecord (>= 3.0, < 5.2) - activesupport (>= 3.0, < 5.2) + ransack (2.3.0) + actionpack (>= 5.0) + activerecord (>= 5.0) + activesupport (>= 5.0) i18n + polyamorous (= 2.3.0) recurring_select (2.1.0) coffee-rails (>= 3.1) ice_cube (>= 0.11) @@ -372,9 +381,9 @@ GEM redis (>= 3.0.4) ref (2.0.0) regexp_parser (1.7.1) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) resque (2.0.0) mono_logger (~> 1.0) multi_json (~> 1.0) @@ -417,6 +426,7 @@ GEM ruby-ole (1.2.12.2) ruby-prof (1.4.1) ruby-units (2.3.1) + ruby2_keywords (0.0.2) ruby_parser (3.15.0) sexp_processor (~> 4.9) rubyzip (2.3.0) @@ -437,17 +447,18 @@ GEM simple-navigation-bootstrap (1.0.2) railties (>= 3.1) simple-navigation (>= 3.7.0, < 4.0.0) - simple_form (4.0.0) - actionpack (> 4) - activemodel (> 4) + simple_form (5.0.2) + actionpack (>= 5.0) + activemodel (>= 5.0) simplecov (0.19.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov-html (0.12.2) - sinatra (1.4.8) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) + sinatra (2.1.0) + mustermann (~> 1.0) + rack (~> 2.2) + rack-protection (= 2.1.0) + tilt (~> 2.0) skinny (0.2.2) eventmachine (~> 1.0) thin @@ -495,12 +506,12 @@ GEM uniform_notifier (1.13.0) vegas (0.1.11) rack (>= 1.0.0) - web-console (2.3.0) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) - websocket-driver (0.7.3) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (1.0.0) @@ -561,14 +572,14 @@ DEPENDENCIES meta_request midi-smtp-server mime-types - mysql2 (~> 0.4.0) + mysql2 prawn prawn-table pry-rescue pry-stack_explorer puma rack-cors - rails (~> 4.2) + rails (< 5.1) rails-assets-listjs (= 0.2.0.beta.4) rails-i18n rails-settings-cached (= 0.4.3) @@ -578,7 +589,7 @@ DEPENDENCIES resque roo roo-xls - rspec-core (~> 3.2) + rspec-core rspec-rails rspec-rerun ruby-filemagic @@ -591,12 +602,12 @@ DEPENDENCIES simple_form simplecov spreadsheet + sprockets (< 4) sqlite3 (~> 1.3.6) therubyracer - thin twitter-bootstrap-rails (~> 2.2.8) uglifier (>= 1.0.3) - web-console (~> 2.0) + web-console whenever BUNDLED WITH diff --git a/Procfile b/Procfile index d8e514674..5e384550e 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,4 @@ -web: bundle exec rails server thin --binding=0.0.0.0 --port=$PORT +web: bundle exec rails server --binding=0.0.0.0 --port=$PORT worker: QUEUE=foodsoft_notifier bundle exec rake resque:work mail: bundle exec rake foodsoft:reply_email_smtp_server cron: supercronic crontab diff --git a/app/models/user.rb b/app/models/user.rb index a7c5c6b8c..dff03a4aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -72,7 +72,7 @@ def ordergroup self.settings.merge!(key, value) end if settings_attributes - if ActiveRecord::Type::Boolean.new.type_cast_from_user(create_ordergroup) + if ActiveModel::Type::Boolean.new.cast(create_ordergroup) og = Ordergroup.new({name: name}) og.memberships.build({user: self}) og.save! @@ -82,7 +82,7 @@ def ordergroup end def send_welcome_mail? - ActiveRecord::Type::Boolean.new.type_cast_from_user(send_welcome_mail) + ActiveModel::Type::Boolean.new.cast(send_welcome_mail) end # sorted by display name diff --git a/app/views/orders/_form.html.haml b/app/views/orders/_form.html.haml index b4f53f101..ec3db1f30 100644 --- a/app/views/orders/_form.html.haml +++ b/app/views/orders/_form.html.haml @@ -13,7 +13,7 @@ %h2= t '.title' - if @order.errors.has_key?(:articles) .alert.alert-error - = @order.errors.get(:articles).join(" ") + = @order.errors.messages[:articles].join(" ") %table.table.table-hover#articleList %tr %th= check_box_tag 'checkall', "1", false, { 'data-check-all' => '#articleList' } diff --git a/bin/rails b/bin/rails index 728cd85aa..073966023 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..e620b4dad --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..a8e4462f2 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config/application.rb b/config/application.rb index 30482d1f2..efd086589 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,10 +1,10 @@ -require File.expand_path('../boot', __FILE__) +require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) +Bundler.require(*Rails.groups) module Foodsoft class Application < Rails::Application @@ -13,7 +13,7 @@ class Application < Rails::Application # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - config.autoload_paths += %W(#{config.root}/lib) + config.eager_load_paths << Rails.root.join('lib') # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. @@ -27,6 +27,7 @@ class Application < Rails::Application config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.yml')] config.i18n.available_locales = Pathname.glob(Rails.root.join('config', 'locales', '{??,???}{-*,}.yml')).map{|p| p.basename('.yml').to_s } config.i18n.default_locale = :en + config.i18n.fallbacks = [:en] # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" @@ -34,9 +35,6 @@ class Application < Rails::Application # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true - # This will be the Rails 5 default - config.active_record.raise_in_transactional_callbacks = true - # Use SQL instead of Active Record's schema dumper when creating the database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types diff --git a/config/boot.rb b/config/boot.rb index 4489e5868..30f5120df 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,3 @@ -require 'rubygems' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index ad09bf0ce..426333bb4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. -Foodsoft::Application.initialize! +Rails.application.initialize! diff --git a/config/environments/development.rb.SAMPLE b/config/environments/development.rb.SAMPLE index a689d8002..749ecbd1d 100644 --- a/config/environments/development.rb.SAMPLE +++ b/config/environments/development.rb.SAMPLE @@ -2,7 +2,7 @@ # # This file is in the public domain. -Foodsoft::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -13,17 +13,32 @@ Foodsoft::Application.configure do # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise an error on page load if there are pending migrations + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. @@ -45,6 +60,13 @@ Foodsoft::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: ENV.fetch("MAILCATCHER_PORT_25_TCP_ADDR", "localhost"), port: ENV.fetch("MAILCATCHER_PORT_25_TCP_PORT", 1025) } + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Run resque tasks as part of the main app (not recommended for production) Resque.inline = true unless ENV['REDIS_URL'] end diff --git a/config/environments/production.rb b/config/environments/production.rb index 4dd705970..628de5bf2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -2,14 +2,14 @@ # # This file is in the public domain. -Foodsoft::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers + # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true @@ -18,13 +18,9 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. - # config.action_dispatch.rack_cache = true - - # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -33,15 +29,17 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Generate digests for assets URLs. - config.assets.digest = true - - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # 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.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = ENV["RAILS_FORCE_SSL"] != "false" @@ -50,16 +48,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # https://github.com/heroku/rails_12factor/issues/25#issuecomment-231103483 - if ENV["RAILS_LOG_TO_STDOUT"].present? - STDOUT.sync = true - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end + config.log_tags = [ :request_id ] # Don't dump schema in production (especially useful for Docker) config.active_record.dump_schema_after_migration = false @@ -67,19 +56,18 @@ # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" + # 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 = "foodsoft_#{Rails.env}" - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) + config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found). + # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. @@ -108,4 +96,17 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + + # 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 + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index c7331a3bd..ae5801e1f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -2,7 +2,7 @@ # # This file is in the public domain. -Foodsoft::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -11,20 +11,16 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # We clear the cache for each test, let's do that in memory. - config.cache_store = :memory_store - # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Required for i18n-js - config.assets.initialize_on_precompile = true - - # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -35,9 +31,7 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - - # Configure hostname for action mailer (can be overridden in foodcoop config) - config.action_mailer.default_url_options = { host: 'localhost', port: 3000, protocol: 'http' } + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the @@ -47,6 +41,6 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Run resque tasks as part of the main app - Resque.inline = true + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# 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 diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..01ef3e663 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..1389e86a3 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 72aca7e44..dc1899682 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,3 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 000000000..a2bfed300 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,20 @@ +# 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. + +# 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 diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 77ee1486d..17e027eab 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -5,21 +5,20 @@ module Session class SlugCookieStore < CookieStore alias_method :orig_set_cookie, :set_cookie - def set_cookie(env, session_id, cookie) + def set_cookie(request, session_id, cookie) if script_name = FoodsoftConfig[:script_name] - request = ActionDispatch::Request.new env path = request.original_fullpath[script_name.size..-1] slug = path.split('/', 2).first return if slug.blank? cookie[:path] = script_name + slug end - orig_set_cookie env, session_id, cookie + orig_set_cookie request, session_id, cookie end end end end -Foodsoft::Application.config.session_store :slug_cookie_store, key: '_foodsoft_session' +Rails.application.config.session_store :slug_cookie_store, key: '_foodsoft_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 33725e95f..bbfc3961b 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 000000000..39da293c3 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 1 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +workers ENV.fetch("WEB_CONCURRENCY") { 8 } + +# 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. +# +preload_app! + +# 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 `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, 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 diff --git a/config/routes.rb b/config/routes.rb index 540fbbe27..d68995080 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -Foodsoft::Application.routes.draw do +Rails.application.routes.draw do get "order_comments/new" diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..c9119b40c --- /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) } diff --git a/plugins/printer/lib/foodsoft_printer/engine.rb b/plugins/printer/lib/foodsoft_printer/engine.rb index 9e7adb862..22c3768f8 100644 --- a/plugins/printer/lib/foodsoft_printer/engine.rb +++ b/plugins/printer/lib/foodsoft_printer/engine.rb @@ -17,7 +17,7 @@ def default_foodsoft_config(cfg) if Rails.configuration.cache_classes OrderPrinterJobs.install else - ActionDispatch::Reloader.to_prepare do + ActiveSupport::Reloader.to_prepare do OrderPrinterJobs.install end end