diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ada37b55..d3f5e5b5 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -63,7 +63,7 @@ jobs: with: name: Rubocop image: "gmmcal/gmmcal:test-${{ github.event.number }}-${{ github.run_number }}" - command: bundle exec rubocop --config .rubocop.yml . + command: bin/rubocop needs: build reek: @@ -81,7 +81,7 @@ jobs: with: name: Brakeman image: "gmmcal/gmmcal:test-${{ github.event.number }}-${{ github.run_number }}" - command: bundle exec brakeman + command: bin/brakeman needs: build scsslint: diff --git a/.rubocop.yml b/.rubocop.yml index 35868a8a..470837a1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,17 +1,18 @@ require: + - rubocop-factory_bot - rubocop-rails - rubocop-rspec - - rubocop-factory_bot + - rubocop-rspec_rails AllCops: - TargetRubyVersion: 3.0 + TargetRubyVersion: 3.3 DisplayCopNames: true NewCops: enable Exclude: - - 'bin/**/*' - - 'db/schema.rb' - - 'node_modules/**/*' - - 'vendor/**/*' + - "bin/**/*" + - "db/schema.rb" + - "node_modules/**/*" + - "vendor/**/*" Rails: Enabled: true @@ -19,9 +20,8 @@ Rails: Style/PercentLiteralDelimiters: PreferredDelimiters: default: () - '%i': '[]' - '%w': '[]' - + "%i": "[]" + "%w": "[]" Style/Documentation: Enabled: false @@ -30,20 +30,20 @@ Lint/ScriptPermission: Metrics/BlockLength: Exclude: - - 'lib/tasks/*' - - 'spec/**/*' - - 'config/routes.rb' + - "lib/tasks/*" + - "spec/**/*" + - "config/routes.rb" Layout/LineLength: Exclude: - - 'config/**/*' - - 'db/**/*' - - 'spec/**/*' + - "config/**/*" + - "db/**/*" + - "spec/**/*" Metrics/MethodLength: Exclude: - - 'db/migrate/*' - - 'lib/seed_manager.rb' + - "db/migrate/*" + - "lib/seed_manager.rb" Rails/LexicallyScopedActionFilter: Enabled: false @@ -59,7 +59,7 @@ Style/MixinUsage: Layout/SpaceInsideArrayLiteralBrackets: Exclude: - - 'config/**/*' + - "config/**/*" Layout/SpaceAroundMethodCallOperator: Enabled: true diff --git a/Dockerfile b/Dockerfile index 96f74006..ff80c973 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax = docker/dockerfile:1 # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile -ARG RUBY_VERSION=3.3 +ARG RUBY_VERSION=3.3.5 FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim AS base # Rails app lives here diff --git a/Gemfile b/Gemfile index 6465ccda..58e5662a 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'bootsnap', require: false # use PostgreSQL as database gem 'pg' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 7.2.2' +gem 'rails', '~> 8.0.0' # Frontend gems gem 'draper' @@ -44,9 +44,10 @@ group :development do gem 'listen' gem 'reek' gem 'rubocop' - gem 'rubocop-factory_bot' - gem 'rubocop-rails' - gem 'rubocop-rspec' + gem 'rubocop-factory_bot', require: false + gem 'rubocop-rails', require: false + gem 'rubocop-rspec', require: false + gem 'rubocop-rspec_rails', require: false gem 'scss_lint', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 62373685..695271cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,70 +1,69 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) + actioncable (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actionmailbox (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) - actionmailer (7.2.2) - actionpack (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activesupport (= 7.2.2) + actionmailer (8.0.0) + actionpack (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.2) - actionview (= 7.2.2) - activesupport (= 7.2.2) + actionpack (8.0.0) + actionview (= 8.0.0) + activesupport (= 8.0.0) nokogiri (>= 1.8.5) - racc - rack (>= 2.2.4, < 3.2) + rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.2) - actionpack (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actiontext (8.0.0) + actionpack (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.2) - activesupport (= 7.2.2) + actionview (8.0.0) + activesupport (= 8.0.0) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.2) - activesupport (= 7.2.2) + activejob (8.0.0) + activesupport (= 8.0.0) globalid (>= 0.3.6) - activemodel (7.2.2) - activesupport (= 7.2.2) + activemodel (8.0.0) + activesupport (= 8.0.0) activemodel-serializers-xml (1.0.3) activemodel (>= 5.0.0.a) activesupport (>= 5.0.0.a) builder (~> 3.1) - activerecord (7.2.2) - activemodel (= 7.2.2) - activesupport (= 7.2.2) + activerecord (8.0.0) + activemodel (= 8.0.0) + activesupport (= 8.0.0) timeout (>= 0.4.0) - activestorage (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activesupport (= 7.2.2) + activestorage (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activesupport (= 8.0.0) marcel (~> 1.0) - activesupport (7.2.2) + activesupport (8.0.0) base64 benchmark (>= 0.3) bigdecimal @@ -76,10 +75,11 @@ GEM minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) ast (2.4.2) base64 (0.2.0) bcrypt (3.1.20) - benchmark (0.3.0) + benchmark (0.4.0) bigdecimal (3.1.8) bootsnap (1.18.4) msgpack (~> 1.2) @@ -227,7 +227,7 @@ GEM matrix (~> 0.4) pdf-core (~> 0.10.0) ttfunk (~> 1.8) - psych (5.1.2) + psych (5.2.0) stringio puma (6.4.3) nio4r (~> 2.0) @@ -243,20 +243,20 @@ GEM rack (>= 1.3) rackup (2.2.0) rack (>= 3) - rails (7.2.2) - actioncable (= 7.2.2) - actionmailbox (= 7.2.2) - actionmailer (= 7.2.2) - actionpack (= 7.2.2) - actiontext (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activemodel (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + rails (8.0.0) + actioncable (= 8.0.0) + actionmailbox (= 8.0.0) + actionmailer (= 8.0.0) + actionpack (= 8.0.0) + actiontext (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activemodel (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) bundler (>= 1.15.0) - railties (= 7.2.2) + railties (= 8.0.0) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -264,9 +264,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) + railties (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -289,7 +289,7 @@ GEM rainbow (>= 2.0, < 4.0) rexml (~> 3.1) regexp_parser (2.9.2) - reline (0.5.10) + reline (0.5.11) io-console (~> 0.5) request_store (1.7.0) rack (>= 1.4) @@ -335,6 +335,9 @@ GEM rubocop-ast (>= 1.31.1, < 2.0) rubocop-rspec (3.2.0) rubocop (~> 1.61) + rubocop-rspec_rails (2.30.0) + rubocop (~> 1.61) + rubocop-rspec (~> 3, >= 3.0.1) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sass (3.7.4) @@ -363,9 +366,9 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - stringio (3.1.1) + stringio (3.1.2) thor (1.3.2) - timeout (0.4.1) + timeout (0.4.2) ttfunk (1.8.0) bigdecimal (~> 3.1) turbo-rails (2.0.11) @@ -374,6 +377,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) + uri (1.0.1) useragent (0.16.10) warden (1.2.9) rack (>= 2.0.9) @@ -417,7 +421,7 @@ DEPENDENCIES puma pundit rack-cors - rails (~> 7.2.2) + rails (~> 8.0.0) redis reek rspec-rails @@ -425,6 +429,7 @@ DEPENDENCIES rubocop-factory_bot rubocop-rails rubocop-rspec + rubocop-rspec_rails scss_lint shoulda-matchers simple_form diff --git a/Procfile b/Procfile deleted file mode 100644 index 96247dde..00000000 --- a/Procfile +++ /dev/null @@ -1,2 +0,0 @@ -web: bin/rails server -p $PORT -e $RAILS_ENV -b 0.0.0.0 -release: bundle exec rake db:migrate db:seed:all db:cache:clear diff --git a/Procfile.dev b/Procfile.dev deleted file mode 100644 index 21e70575..00000000 --- a/Procfile.dev +++ /dev/null @@ -1 +0,0 @@ -web: bin/rails server -p 3000 diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb index 22a56d70..40c0d010 100644 --- a/app/decorators/application_decorator.rb +++ b/app/decorators/application_decorator.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true class ApplicationDecorator < Draper::Decorator + def marshal_load(*); end end diff --git a/app/lib/pdf/format.rb b/app/lib/pdf/format.rb index 4b08df82..f5d634fd 100644 --- a/app/lib/pdf/format.rb +++ b/app/lib/pdf/format.rb @@ -2,8 +2,8 @@ module Pdf module Format - def column(start, finish, &block) - pdf.grid(start, finish).bounding_box(&block) + def column(start, finish, &) + pdf.grid(start, finish).bounding_box(&) end def h1 @@ -48,8 +48,8 @@ def body(color: '000000', padding: 10, &block) end end - def strong_body(&block) - pdf.font 'Helvetica', size: 13, style: :bold, &block + def strong_body(&) + pdf.font('Helvetica', size: 13, style: :bold, &) end def html(content) diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 00000000..ace1c9ba --- /dev/null +++ b/bin/brakeman @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +ARGV.unshift("--ensure-latest") + +load Gem.bin_path("brakeman", "brakeman") diff --git a/bin/dev b/bin/dev index 74ade166..5f91c205 100755 --- a/bin/dev +++ b/bin/dev @@ -1,8 +1,2 @@ -#!/usr/bin/env sh - -if ! gem list foreman -i --silent; then - echo "Installing foreman..." - gem install foreman -fi - -exec foreman start -f Procfile.dev "$@" +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 00000000..40330c0f --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup index 7bf25cd1..4c2b6bd3 100755 --- a/bin/setup +++ b/bin/setup @@ -1,11 +1,10 @@ #!/usr/bin/env ruby require "fileutils" -# path to your application root. APP_ROOT = File.expand_path("..", __dir__) def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") + system(*args, exception: true) end FileUtils.chdir APP_ROOT do @@ -14,9 +13,7 @@ FileUtils.chdir APP_ROOT do # Add necessary setup steps to this file. puts "== Installing dependencies ==" - system! "gem install bundler --conservative" system("bundle check") || system!("bundle install") - system("yarn check") || system!("yarn install") # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") @@ -30,6 +27,9 @@ FileUtils.chdir APP_ROOT do puts "\n== Removing old logs and tempfiles ==" system! "bin/rails log:clear tmp:clear" - puts "\n== Restarting application server ==" - system! "bin/rails restart" + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end end diff --git a/bin/thrust b/bin/thrust new file mode 100755 index 00000000..36bde2d8 --- /dev/null +++ b/bin/thrust @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thruster", "thrust") diff --git a/config/application.rb b/config/application.rb index 4d372b66..c96f4808 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,12 @@ module GmmcalComBr class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.0 + config.load_defaults 8.0 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # @@ -32,6 +37,5 @@ class Application < Rails::Application # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") - config.active_record.strict_loading_by_default = true end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 8b8468e0..98ae1116 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -5,10 +5,8 @@ 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 any time - # it changes. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + # Make code changes take effect immediately without server restart. + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -16,56 +14,60 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - - config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false - - config.cache_store = :null_store end + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Make template changes take effect immediately. config.action_mailer.perform_caching = false + # Set localhost to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise exceptions for disallowed deprecations. - config.active_support.disallowed_deprecation = :raise - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] - # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Suppress logger output for asset requests. - config.assets.quiet = true + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true + config.action_view.annotate_rendered_view_with_filenames = true # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end Rails.application.configure do @@ -81,6 +83,9 @@ # Annotate rendered view with file names. config.action_view.annotate_rendered_view_with_filenames = true + # Avoid any caching. + config.cache_store = :null_store + if ENV['CI'].present? config.log_level = :fatal config.logger = ActiveSupport::Logger.new(nil) diff --git a/config/environments/production.rb b/config/environments/production.rb index 5676ecc3..7f060a60 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -6,89 +6,85 @@ # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false - # Eager load code on boot. This eager loads most of Rails and - # 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. + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). config.eager_load = true - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). - # config.require_master_key = true - - # 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? + # Full error reports are disabled. + config.consider_all_requests_local = false - # Compress CSS using a preprocessor. - # config.assets.css_compressor = :sass + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.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.*/ ] + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true - # Include generic and useful information about system operation, but avoid logging too much - # information to avoid inadvertent exposure of personally identifiable information (PII). - config.log_level = :info + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # Prepend all log lines with the following tags. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger($stdout) - # Use a different cache store in production. - # config.cache_store = :mem_cache_store + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = '/up' - # 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 = "gmmcal_com_br_production" + # Don't log any deprecations. + config.active_support.report_deprecations = false - config.action_mailer.perform_caching = false + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque # 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 + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Don't log any deprecations. - config.active_support.report_deprecations = false - - # 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 + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end Rails.application.configure do diff --git a/config/environments/test.rb b/config/environments/test.rb index c08d8e9e..1fe56098 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'active_support/core_ext/integer/time' - # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped @@ -10,52 +8,47 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # Turn false under Spring and add config.action_view.cache_template_loading = true - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # Eager loading loads your whole application. When running a single test locally, - # this probably isn't necessary. It's a good idea to do in a continuous integration - # system, or in some way before deploying your code. + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. config.eager_load = ENV['CI'].present? - # 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=#{1.hour.to_i}" - } + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' } - # 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 config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - 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 # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raise exceptions for disallowed deprecations. - config.active_support.disallowed_deprecation = :raise - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] - # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true end Rails.application.configure do diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 82daa990..019d0bbb 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -7,10 +7,3 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -# Add Yarn node_modules folder to the asset load path. -# Rails.application.config.assets.paths << Rails.root.join('node_modules') - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -Rails.application.config.assets.precompile += %w[frontend/application.css admin/application.css cv/application.css] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 96bd2228..35ab3fd6 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -2,9 +2,9 @@ # Be sure to restart your server when you modify this file. -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header # Rails.application.configure do # config.content_security_policy do |policy| @@ -18,11 +18,10 @@ # # policy.report_uri "/csp-violation-report-endpoint" # end # -# # Generate session nonces for permitted importmap and inline scripts +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } -# config.content_security_policy_nonce_directives = %w(script-src) +# config.content_security_policy_nonce_directives = %w(script-src style-src) # -# # Report CSP violations to a specified URI. See: -# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# # Report violations without enforcing the policy. # # config.content_security_policy_report_only = true # end diff --git a/config/initializers/cypress_on_rails.rb b/config/initializers/cypress_on_rails.rb index f7c1cf87..1fd4983e 100644 --- a/config/initializers/cypress_on_rails.rb +++ b/config/initializers/cypress_on_rails.rb @@ -2,10 +2,29 @@ if defined?(CypressOnRails) CypressOnRails.configure do |c| + c.api_prefix = '' c.install_folder = File.expand_path("#{__dir__}/../../spec/end-to-end") # WARNING!! CypressOnRails can execute arbitrary ruby code # please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0 c.use_middleware = !Rails.env.production? + # c.use_vcr_middleware = !Rails.env.production? c.logger = Rails.logger + + # If you want to enable a before_request logic, such as authentication, logging, sending metrics, etc. + # Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument. + # Return nil to continue through the Cypress command. Return a response [status, header, body] to halt. + # c.before_request = lambda { |request| + # unless request.env['warden'].authenticate(:secret_key) + # return [403, {}, ["forbidden"]] + # end + # } end + + # # if you compile your asssets on CI + # if ENV['CYPRESS'].present? && ENV['CI'].present? + # Rails.application.configure do + # config.assets.compile = false + # config.assets.unknown_asset_fallback = false + # end + # end end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 3babc73f..d81a902e 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -2,7 +2,9 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += %i[ - passw secret token _key crypt salt certificate otp ssn + passw email secret token _key crypt salt certificate otp ssn cvv cvc ] diff --git a/config/initializers/new_framework_defaults_8_0.rb b/config/initializers/new_framework_defaults_8_0.rb new file mode 100644 index 00000000..5c82f370 --- /dev/null +++ b/config/initializers/new_framework_defaults_8_0.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 8.0 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `8.0`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Specifies whether `to_time` methods preserve the UTC offset of their receivers or preserves the timezone. +# If set to `:zone`, `to_time` methods will use the timezone of their receivers. +# If set to `:offset`, `to_time` methods will use the UTC offset. +# If `false`, `to_time` methods will convert to the local system UTC offset instead. +#++ +# Rails.application.config.active_support.to_time_preserves_timezone = :zone + +### +# When both `If-Modified-Since` and `If-None-Match` are provided by the client +# only consider `If-None-Match` as specified by RFC 7232 Section 6. +# If set to `false` both conditions need to be satisfied. +#++ +# Rails.application.config.action_dispatch.strict_freshness = true + +### +# Set `Regexp.timeout` to `1`s by default to improve security over Regexp Denial-of-Service attacks. +#++ +# Regexp.timeout = 1 + +# FIXME: this was broken by Rails 8 migration. Should be addressed on a separate PR +Rails.application.config.action_controller.raise_on_missing_callback_actions = false diff --git a/config/puma.rb b/config/puma.rb index 8ae6a785..d3983379 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,45 +1,43 @@ # frozen_string_literal: true -# 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. +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) -min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } -threads min_threads_count, max_threads_count - -# Specifies the `worker_timeout` threshold that Puma will use to wait before -# terminating a worker in development environments. +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. # -worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' - -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. # -port ENV.fetch('PORT', 3000) - -# Specifies the `environment` that Puma will run in. +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. # -environment ENV.fetch('RAILS_ENV', 'development') - -# Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked web server 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). +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. # -# 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. +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. # -# preload_app! +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch('RAILS_MAX_THREADS', 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch('PORT', 3000) -# Allow puma to be restarted by `rails restart` command. +# Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV['SOLID_QUEUE_IN_PUMA'] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV['PIDFILE'] if ENV['PIDFILE'] diff --git a/lib/seed_manager.rb b/lib/seed_manager.rb index da534211..46b5cb24 100644 --- a/lib/seed_manager.rb +++ b/lib/seed_manager.rb @@ -3,13 +3,13 @@ require 'factory_bot_rails' require 'faker' -FactoryBot.definition_file_paths = ['spec/backend/factories'] -FactoryBot.find_definitions - class SeedManager def self.all return if production? + FactoryBot.definition_file_paths = ['spec/backend/factories'] + FactoryBot.find_definitions + log('Create About') create(:about, 1) log('Create Work Experiences') diff --git a/public/400.html b/public/400.html new file mode 100644 index 00000000..282dbc8c --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ + + + + + + + The server cannot process the request due to a client error (400 Bad Request) + + + + + + + + + + + + + +
+
+ +
+
+

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/404.html b/public/404.html new file mode 100644 index 00000000..c0670bc8 --- /dev/null +++ b/public/404.html @@ -0,0 +1,114 @@ + + + + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + + + + + + +
+
+ +
+
+

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 00000000..9532a9cc --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ + + + + + + + Your browser is not supported (406 Not Acceptable) + + + + + + + + + + + + + +
+
+ +
+
+

Your browser is not supported.
Please upgrade your browser to continue.

+
+
+ + + + diff --git a/public/422.html b/public/422.html new file mode 100644 index 00000000..8bcf0601 --- /dev/null +++ b/public/422.html @@ -0,0 +1,114 @@ + + + + + + + The change you wanted was rejected (422 Unprocessable Entity) + + + + + + + + + + + + + +
+
+ +
+
+

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 00000000..d77718c3 --- /dev/null +++ b/public/500.html @@ -0,0 +1,114 @@ + + + + + + + We’re sorry, but something went wrong (500 Internal Server Error) + + + + + + + + + + + + + +
+
+ +
+
+

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 00000000..c4c9dbfb Binary files /dev/null and b/public/icon.png differ diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 00000000..04b34bf8 --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/robots.txt b/public/robots.txt index 3c9c7c01..c19f78ab 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1 @@ -# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/end-to-end/e2e_helper.rb b/spec/end-to-end/e2e_helper.rb index 90f499f1..298e3ea0 100644 --- a/spec/end-to-end/e2e_helper.rb +++ b/spec/end-to-end/e2e_helper.rb @@ -26,10 +26,15 @@ factory = FactoryGirl if defined?(FactoryGirl) CypressOnRails::SmartFactoryWrapper.configure( - always_reload: !Rails.configuration.cache_classes, + always_reload: false, factory: factory, files: [ Rails.root.join('spec', 'factories.rb'), Rails.root.join('spec', 'factories', '**', '*.rb') ] ) + +# require 'vcr' +# VCR.configure do |config| +# config.hook_into :webmock +# end diff --git a/spec/end-to-end/support/on-rails.js b/spec/end-to-end/support/on-rails.js index b38e63cf..00166d63 100644 --- a/spec/end-to-end/support/on-rails.js +++ b/spec/end-to-end/support/on-rails.js @@ -1,12 +1,22 @@ +// CypressOnRails: dont remove these command Cypress.Commands.add('appCommands', function (body) { - cy.log('APP: ' + JSON.stringify(body)) + Object.keys(body).forEach(key => body[key] === undefined ? delete body[key] : {}) + const log = Cypress.log({ name: 'APP', message: body, autoEnd: false }) return cy.request({ method: 'POST', url: '/__e2e__/command', body: JSON.stringify(body), - log: true, - failOnStatusCode: true + headers: { + 'Content-Type': 'application/json', + }, + log: false, + failOnStatusCode: false }).then((response) => { + log.end() + if (response.status !== 201) { + expect(response.body.message).to.equal('') + expect(response.status).to.be.equal(201) + } return response.body }) }) @@ -20,3 +30,37 @@ Cypress.Commands.add('app', function (name, command_options) { Cypress.Commands.add('appScenario', function (name, options = {}) { return cy.app('scenarios/' + name, options) }) + +Cypress.Commands.add('appEval', function (code) { + return cy.app('eval', code) +}) + +Cypress.Commands.add('appFactories', function (options) { + return cy.app('factory_bot', options) +}) + +Cypress.Commands.add('appFixtures', function (options) { + cy.app('activerecord_fixtures', options) +}) +// CypressOnRails: end + +// The next is optional +// beforeEach(() => { +// cy.app('clean') // have a look at cypress/app_commands/clean.rb +// }) + +// comment this out if you do not want to attempt to log additional info on test fail +Cypress.on('fail', (err, runnable) => { + // allow app to generate additional logging data + Cypress.$.ajax({ + url: '/__e2e__/command', + data: JSON.stringify({name: 'log_fail', options: {error_message: err.message, runnable_full_title: runnable.fullTitle() }}), + headers: { + 'Content-Type': 'application/json', + }, + async: false, + method: 'POST' + }) + + throw err +})