From 2f074fa909fb68508bb3e5ab977b31dd5680bf80 Mon Sep 17 00:00:00 2001 From: Mateus Rambo Strey <mars11@inf.ufpr.br> Date: Tue, 5 Jul 2016 15:55:45 -0300 Subject: [PATCH] until step 5 --- app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application.rb | 2 +- app/models/application_record.rb | 3 + app/models/bookmark.rb | 2 +- app/models/carousel.rb | 2 +- app/models/collection.rb | 2 +- app/models/collection_item.rb | 2 +- app/models/complaint.rb | 2 +- app/models/complaint_reason.rb | 2 +- app/models/download.rb | 2 +- app/models/follow.rb | 2 +- app/models/institution.rb | 2 +- app/models/language.rb | 2 +- app/models/learning_object.rb | 2 +- app/models/learning_object/attachment.rb | 2 +- app/models/license.rb | 2 +- app/models/like.rb | 2 +- app/models/mime_type.rb | 2 +- app/models/object_type.rb | 2 +- app/models/rate.rb | 2 +- app/models/rating.rb | 2 +- app/models/review.rb | 2 +- app/models/review_rating.rb | 2 +- app/models/role.rb | 2 +- app/models/score.rb | 2 +- app/models/score_user_category.rb | 2 +- app/models/share.rb | 2 +- app/models/tag.rb | 2 +- app/models/tagging.rb | 2 +- app/models/user.rb | 2 +- app/models/user_category.rb | 2 +- app/models/view.rb | 2 +- app/views/layouts/mailer.html.erb | 8 ++ bin/rails | 7 +- bin/rake | 5 -- bin/setup | 36 +++++---- bin/update | 29 ++++++++ config/application.rb | 9 ++- config/boot.rb | 2 +- config/cable.yml | 9 +++ config/database.yml | 2 +- config/environment.rb | 2 +- config/environments/development.rb | 35 +++++++-- config/environments/production.rb | 74 ++++++++++--------- config/environments/test.rb | 5 +- .../application_controller_renderer.rb | 6 ++ config/initializers/assets.rb | 11 +++ config/initializers/cookies_serializer.rb | 5 ++ config/initializers/new_framework_defaults.rb | 17 +++++ config/initializers/wrap_parameters.rb | 4 +- config/puma.rb | 62 ++++++++++++---- config/routes.rb | 4 +- config/spring.rb | 6 ++ 54 files changed, 283 insertions(+), 124 deletions(-) create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/views/layouts/mailer.html.erb create mode 100755 bin/update create mode 100644 config/cable.yml 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/spring.rb diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 000000000..a009ace51 --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..286b2239d --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application.rb b/app/models/application.rb index b3b3e3468..8156eaddb 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -1,4 +1,4 @@ -class Application < ActiveRecord::Base +class Application < ApplicationRecord belongs_to :user validates :domain, presence: true, uniqueness: true diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index d49ca0269..df1fc1901 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class Bookmark < ActiveRecord::Base +class Bookmark < ApplicationRecord # Example of Trackable: # *current_user* create bookmark *bookmarkable* include Trackable diff --git a/app/models/carousel.rb b/app/models/carousel.rb index e44675b5c..5959c79b4 100644 --- a/app/models/carousel.rb +++ b/app/models/carousel.rb @@ -13,7 +13,7 @@ # image_updated_at :datetime # -class Carousel < ActiveRecord::Base +class Carousel < ApplicationRecord has_attached_file :image, styles: { larger: "600x600>", thumbnail: "100x100>" diff --git a/app/models/collection.rb b/app/models/collection.rb index ae5893b54..4d3427784 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -22,7 +22,7 @@ # thumbnail_updated_at :datetime # -class Collection < ActiveRecord::Base +class Collection < ApplicationRecord include Reviewable include Sociable include Followable diff --git a/app/models/collection_item.rb b/app/models/collection_item.rb index 02eedcbe1..3a7241ea0 100644 --- a/app/models/collection_item.rb +++ b/app/models/collection_item.rb @@ -11,7 +11,7 @@ # updated_at :datetime not null # -class CollectionItem < ActiveRecord::Base +class CollectionItem < ApplicationRecord # *current_user* add item *collectionable* to *collection* include Trackable diff --git a/app/models/complaint.rb b/app/models/complaint.rb index abe53017e..9dc2333ec 100644 --- a/app/models/complaint.rb +++ b/app/models/complaint.rb @@ -12,7 +12,7 @@ # updated_at :datetime not null # -class Complaint < ActiveRecord::Base +class Complaint < ApplicationRecord # *current_user* create complaint about *complaint_reason* for *complaintable* include Trackable diff --git a/app/models/complaint_reason.rb b/app/models/complaint_reason.rb index 468f59d30..9a94b7005 100644 --- a/app/models/complaint_reason.rb +++ b/app/models/complaint_reason.rb @@ -8,7 +8,7 @@ # updated_at :datetime not null # -class ComplaintReason < ActiveRecord::Base +class ComplaintReason < ApplicationRecord # *current_user* create complaint reason # Only admins can create complaint reasons include Trackable diff --git a/app/models/download.rb b/app/models/download.rb index 3435d9bcf..4b64617e7 100644 --- a/app/models/download.rb +++ b/app/models/download.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class Download < ActiveRecord::Base +class Download < ApplicationRecord # *current_user* download *downloadable* include Trackable diff --git a/app/models/follow.rb b/app/models/follow.rb index 7c32adc1b..cbdb5fcfd 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class Follow < ActiveRecord::Base +class Follow < ApplicationRecord # *current_user* follows *followable* include Trackable diff --git a/app/models/institution.rb b/app/models/institution.rb index 5c380822a..3d04651fd 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -12,7 +12,7 @@ # updated_at :datetime not null # -class Institution < ActiveRecord::Base +class Institution < ApplicationRecord include Tagger # *current_user* add member for instituion *name* diff --git a/app/models/language.rb b/app/models/language.rb index b9370bc7d..4b91ae32e 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -9,7 +9,7 @@ # code :string # -class Language < ActiveRecord::Base +class Language < ApplicationRecord has_many :learning_objects validates_uniqueness_of :code diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index d2fa453d1..d86ea428a 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -30,7 +30,7 @@ # attachment_id :integer # -class LearningObject < ActiveRecord::Base +class LearningObject < ApplicationRecord include Metadatable include Reviewable include Sociable diff --git a/app/models/learning_object/attachment.rb b/app/models/learning_object/attachment.rb index d947f39bb..532fb009e 100644 --- a/app/models/learning_object/attachment.rb +++ b/app/models/learning_object/attachment.rb @@ -22,7 +22,7 @@ # cache_link :string # -class LearningObject::Attachment < ActiveRecord::Base +class LearningObject::Attachment < ApplicationRecord include ::Thumbnailable belongs_to :learning_object scope :unknown_mime_type, ->() { where(format: 'Unknown') } diff --git a/app/models/license.rb b/app/models/license.rb index 5bc15243c..fd0060301 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,3 +1,3 @@ -class License < ActiveRecord::Base +class License < ApplicationRecord validates :name, presence: true end diff --git a/app/models/like.rb b/app/models/like.rb index d9e98d20d..10ba05dd5 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class Like < ActiveRecord::Base +class Like < ApplicationRecord # *current_user* likes *likeable* # *current_user* unlikes *likeable* include Trackable diff --git a/app/models/mime_type.rb b/app/models/mime_type.rb index 6c6baa1ac..6de9f9040 100644 --- a/app/models/mime_type.rb +++ b/app/models/mime_type.rb @@ -7,6 +7,6 @@ # mime_type :string # -class MimeType < ActiveRecord::Base +class MimeType < ApplicationRecord has_and_belongs_to_many :object_types end diff --git a/app/models/object_type.rb b/app/models/object_type.rb index 0aedd137e..e652def2c 100644 --- a/app/models/object_type.rb +++ b/app/models/object_type.rb @@ -1,4 +1,4 @@ -class ObjectType < ActiveRecord::Base +class ObjectType < ApplicationRecord has_many :learning_objects has_and_belongs_to_many :mime_types diff --git a/app/models/rate.rb b/app/models/rate.rb index 5b7a27e63..7bf069868 100644 --- a/app/models/rate.rb +++ b/app/models/rate.rb @@ -8,7 +8,7 @@ # review_id :integer # created_at :datetime not null # updated_at :datetime not null -class Rate < ActiveRecord::Base +class Rate < ApplicationRecord # *current_user* rate a review *review* include Trackable diff --git a/app/models/rating.rb b/app/models/rating.rb index a28b192f5..89bbc66d1 100644 --- a/app/models/rating.rb +++ b/app/models/rating.rb @@ -9,7 +9,7 @@ # description :string # -class Rating < ActiveRecord::Base +class Rating < ApplicationRecord has_many :review_ratings has_many :reviews, through: :review_ratings end diff --git a/app/models/review.rb b/app/models/review.rb index cb8cdb03a..3f5b08543 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -15,7 +15,7 @@ # rates_count :integer default("0") # -class Review < ActiveRecord::Base +class Review < ApplicationRecord # *current_user* review *reviewable* include Trackable diff --git a/app/models/review_rating.rb b/app/models/review_rating.rb index d356332f0..65f4e9f67 100644 --- a/app/models/review_rating.rb +++ b/app/models/review_rating.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class ReviewRating < ActiveRecord::Base +class ReviewRating < ApplicationRecord belongs_to :review belongs_to :rating diff --git a/app/models/role.rb b/app/models/role.rb index 52eefd8a8..890aa2675 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -9,7 +9,7 @@ # updated_at :datetime not null # -class Role < ActiveRecord::Base +class Role < ApplicationRecord has_and_belongs_to_many :users validates_presence_of :name diff --git a/app/models/score.rb b/app/models/score.rb index d7e981210..c6d7ddea5 100644 --- a/app/models/score.rb +++ b/app/models/score.rb @@ -12,7 +12,7 @@ # score_type :string default("{}"), is an Array # -class Score < ActiveRecord::Base +class Score < ApplicationRecord has_many :score_user_categories has_many :user_categories, through: :score_user_categories diff --git a/app/models/score_user_category.rb b/app/models/score_user_category.rb index f249ec23c..29eb10b19 100644 --- a/app/models/score_user_category.rb +++ b/app/models/score_user_category.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class ScoreUserCategory < ActiveRecord::Base +class ScoreUserCategory < ApplicationRecord belongs_to :score belongs_to :user_category diff --git a/app/models/share.rb b/app/models/share.rb index 4816f94a6..94e3682ef 100644 --- a/app/models/share.rb +++ b/app/models/share.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class Share < ActiveRecord::Base +class Share < ApplicationRecord # *current_user* shares *shareable* include Trackable diff --git a/app/models/tag.rb b/app/models/tag.rb index ed25f592c..d2745a06e 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,4 @@ -class Tag < ActiveRecord::Base +class Tag < ApplicationRecord has_many :taggings validates_presence_of :name end diff --git a/app/models/tagging.rb b/app/models/tagging.rb index d926c6db5..613a8e9c2 100644 --- a/app/models/tagging.rb +++ b/app/models/tagging.rb @@ -1,4 +1,4 @@ -class Tagging < ActiveRecord::Base +class Tagging < ApplicationRecord # *current_user* tag *taggable* with *tag* include Trackable diff --git a/app/models/user.rb b/app/models/user.rb index ecfd18263..9147299a8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,7 +33,7 @@ # follows_count :integer default("0") # -class User < ActiveRecord::Base +class User < ApplicationRecord include Followable include Reputationable include Tagger diff --git a/app/models/user_category.rb b/app/models/user_category.rb index d4603f14f..bf0567cbb 100644 --- a/app/models/user_category.rb +++ b/app/models/user_category.rb @@ -9,7 +9,7 @@ # updated_at :datetime not null # -class UserCategory < ActiveRecord::Base +class UserCategory < ApplicationRecord has_many :score_user_categories has_many :scores, through: :score_user_categories diff --git a/app/models/view.rb b/app/models/view.rb index 94f27f19e..3f80ab25b 100644 --- a/app/models/view.rb +++ b/app/models/view.rb @@ -10,7 +10,7 @@ # updated_at :datetime not null # -class View < ActiveRecord::Base +class View < ApplicationRecord # *current_user* views *viewable* include Trackable diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..91431f120 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body><%= yield %></body> +</html> diff --git a/bin/rails b/bin/rails index 0138d79b7..073966023 100755 --- a/bin/rails +++ b/bin/rails @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -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/rake b/bin/rake index d87d5f578..17240489f 100755 --- a/bin/rake +++ b/bin/rake @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index c54141a04..ca5ca8bdf 100755 --- a/bin/setup +++ b/bin/setup @@ -1,30 +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__) +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) -Dir.chdir APP_ROOT do +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: + # Add necessary setup steps to this file. - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install --jobs $(nproc)" + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') - puts "\n== Checks database config file ==" - unless File.exist?("config/database.yml") - puts "\n You need create config/database.yml. Please follow our README" - exit - end + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end - puts "\n== Preparing databases, importing data and setup PortalMEC ==" - system "bundle exec rake portalmec:setup" + puts "\n== Preparing database ==" + system! 'bundle exec rake portalmec:setup' puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" + 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 5226631d4..dde53ed5d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,9 +1,14 @@ -require File.expand_path('../boot', __FILE__) +require_relative 'boot' -# require 'rails/all' +require 'rails' +require 'active_model/railtie' +# require 'active_job/railtie' require 'active_record/railtie' require 'action_controller/railtie' require 'action_mailer/railtie' +require 'action_view/railtie' +# require 'action_cable/engine' +# require 'sprockets/railtie' require 'rails/test_unit/railtie' require 'rack/redis_throttle' diff --git a/config/boot.rb b/config/boot.rb index 6b750f00b..30f5120df 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,3 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..0bbde6f74 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/database.yml b/config/database.yml index b398a1ba4..d369a1d5c 100644 --- a/config/database.yml +++ b/config/database.yml @@ -15,7 +15,7 @@ test: database: portalmec_test username: portalmec password: 123mudar - host: postgres + # host: postgres production: <<: *defaults diff --git a/config/environment.rb b/config/environment.rb index ee8d90dc6..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. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 987efaf25..38cf023ef 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -21,32 +21,55 @@ Rails.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. config.active_record.migration_error = :page_load + + # 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 + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. - config.assets.debug = true + # config.assets.debug = true # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. - config.assets.digest = true + # config.assets.digest = true # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # config.assets.raise_runtime_errors = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 8aa3f9970..25fb84be8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,33 +14,23 @@ Rails.application.configure do 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 serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? - - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = true + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # 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 + # 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 = true @@ -49,32 +39,19 @@ Rails.application.configure do config.log_level = :debug # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # memcached server specified in ENV["MEMCACHE_SERVERS"] - config.cache_store = :dalli_store, nil, { :namespace => 'portalmec', :expires_in => 1.day, :compress => true, :pool_size => 5 } - # 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 = "portalmec_#{Rails.env}" + 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 - config.action_mailer.default_url_options = { host: ENV['ACTION_MAILER_HOST'] } - - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { - address: ENV['SMTP_ADDRESS'], - port: ENV['SMTP_PORT'], - openssl_verify_mode: 'none', - domain: ENV['ACTION_MAILER_HOST'] - } - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -86,6 +63,31 @@ Rails.application.configure do # 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 + + config.cache_store = :dalli_store, nil, { :namespace => 'portalmec', :expires_in => 1.day, :compress => true, :pool_size => 5 } + + # 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 + config.action_mailer.default_url_options = { host: ENV['ACTION_MAILER_HOST'] } + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: ENV['SMTP_ADDRESS'], + port: ENV['SMTP_PORT'], + openssl_verify_mode: 'none', + domain: ENV['ACTION_MAILER_HOST'] + } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08b2..6e619ea81 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -14,7 +14,10 @@ Rails.application.configure do # Configure static file server for tests with Cache-Control for performance. config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } + # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..51639b67a --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..ff2d2299a --- /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/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 000000000..9c2499594 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,17 @@ +# 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 Rails 5.0 release notes for more info on each option. + +# 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 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 index 0e238cb77..f4d68e83b 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,15 +1,53 @@ -# Change to match your CPU core count -workers 2 +# 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') { 5 }.to_i +threads threads_count, threads_count -# Min and Max threads per worker -threads 1, 6 +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch('PORT') { 3000 } -app_dir = File.expand_path("../..", __FILE__) -shared_dir = "#{app_dir}/shared" +# 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') { 2 } + +# 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 -# Default to production -rails_env = ENV['RAILS_ENV'] || "production" -environment rails_env +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart + +app_dir = File.expand_path('../..', __FILE__) +shared_dir = "#{app_dir}/shared" # Set up socket location bind "unix://#{shared_dir}/sockets/puma.sock" @@ -23,9 +61,3 @@ end pidfile "#{shared_dir}/pids/puma.pid" state_path "#{shared_dir}/pids/puma.state" activate_control_app - -on_worker_boot do - require "active_record" - ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished - ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env]) -end diff --git a/config/routes.rb b/config/routes.rb index 4b045a9eb..797ca0bff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do - require 'sidekiq/web' - mount Sidekiq::Web, at: '/sidekiq' + # require 'sidekiq/web' + # mount Sidekiq::Web, at: '/sidekiq' concern :deletable do collection do 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) } -- GitLab