diff --git a/.rubocop.yml b/.rubocop.yml index c0b35e45..f58b2257 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,7 @@ plugins: - rubocop-rspec_rails AllCops: - TargetRailsVersion: 7.1 + TargetRailsVersion: 8.0 TargetRubyVersion: 3.3 Exclude: - 'db/schema.rb' diff --git a/Gemfile b/Gemfile index 1097cb94..fca8e933 100644 --- a/Gemfile +++ b/Gemfile @@ -30,8 +30,8 @@ gem 'puma', '~> 6.6' gem 'pundit', '~> 2.5' gem 'rack-attack', '~> 6.7' gem 'rack-cors', '~> 2.0', '>= 2.0.2', require: 'rack/cors' -gem 'rails', '~> 7.1.5', '>= 7.1.5.1' -gem 'rails-i18n', '~> 7.0', '>= 7.0.10' +gem 'rails', '~> 8.0', '>= 8.0.1' +gem 'rails-i18n', '~> 8.0', '>= 8.0.0' gem 'redis', '~> 5.4' gem 'roo', '~> 2.10', '>= 2.10.1' gem 'ruby-filemagic', '~> 0.7', '>= 0.7.3' @@ -42,7 +42,7 @@ gem 'sentry-sidekiq', '~> 5.23' gem 'sepa_king', '~> 0.14' gem 'sidekiq', '~> 7.3', '>= 7.3.9' gem 'sidekiq-scheduler', '~> 5.0', '>= 5.0.6' -gem 'validates_timeliness', '~> 7.1.0' +gem 'validates_timeliness', '~> 8.0.0' gem 'vpim', '~> 24.2', '>= 24.2.20' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 38b55dd9..a75d27fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,51 +1,45 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) + actioncable (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.5.1) - actionpack (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) + actionmailer (8.0.1) + actionpack (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.5.1) - actionview (= 7.1.5.1) - activesupport (= 7.1.5.1) + actionpack (8.0.1) + actionview (= 8.0.1) + activesupport (= 8.0.1) nokogiri (>= 1.8.5) - racc rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.5.1) - actionpack (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + useragent (~> 0.16) + actiontext (8.0.1) + actionpack (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.5.1) - activesupport (= 7.1.5.1) + actionview (8.0.1) + activesupport (= 8.0.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -53,34 +47,34 @@ GEM active_model_otp (2.3.4) activemodel rotp (~> 6.3.0) - activejob (7.1.5.1) - activesupport (= 7.1.5.1) + activejob (8.0.1) + activesupport (= 8.0.1) globalid (>= 0.3.6) - activemodel (7.1.5.1) - activesupport (= 7.1.5.1) - activerecord (7.1.5.1) - activemodel (= 7.1.5.1) - activesupport (= 7.1.5.1) + activemodel (8.0.1) + activesupport (= 8.0.1) + activerecord (8.0.1) + activemodel (= 8.0.1) + activesupport (= 8.0.1) timeout (>= 0.4.0) - activestorage (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activesupport (= 7.1.5.1) + activestorage (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activesupport (= 8.0.1) marcel (~> 1.0) - activesupport (7.1.5.1) + activesupport (8.0.1) base64 benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) logger (>= 1.4.2) minitest (>= 5.1) - mutex_m securerandom (>= 0.3) - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) ast (2.4.3) @@ -92,9 +86,10 @@ GEM better_errors (2.10.1) erubi (>= 1.0.0) rack (>= 0.9.0) - rouge (>= 1.0.0) bigdecimal (3.1.9) bigdecimal (3.1.9-java) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) binding_of_caller (1.0.1) debug_inspector (>= 1.2.0) bootsnap (1.18.4) @@ -273,7 +268,6 @@ GEM minitest (5.25.5) msgpack (1.8.0) msgpack (1.8.0-java) - mutex_m (0.3.0) nenv (0.3.0) net-imap (0.5.6) date @@ -355,20 +349,20 @@ GEM rack (>= 1.3) rackup (2.2.1) rack (>= 3) - rails (7.1.5.1) - actioncable (= 7.1.5.1) - actionmailbox (= 7.1.5.1) - actionmailer (= 7.1.5.1) - actionpack (= 7.1.5.1) - actiontext (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activemodel (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + rails (8.0.1) + actioncable (= 8.0.1) + actionmailbox (= 8.0.1) + actionmailer (= 8.0.1) + actionpack (= 8.0.1) + actiontext (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activemodel (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) bundler (>= 1.15.0) - railties (= 7.1.5.1) + railties (= 8.0.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -376,13 +370,13 @@ GEM rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - rails-i18n (7.0.10) + rails-i18n (8.0.1) i18n (>= 0.7, < 2) - railties (>= 6.0.0, < 8) - railties (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) - irb + railties (>= 8.0.0, < 9) + railties (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -432,7 +426,6 @@ GEM nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) rotp (6.3.0) - rouge (4.5.1) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -552,8 +545,10 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uniform_notifier (1.16.0) - validates_timeliness (7.1.0) - activemodel (>= 7.0.0, < 8) + uri (1.0.2) + useragent (0.16.11) + validates_timeliness (8.0.0) + activemodel (>= 8.0.0, < 9) timeliness (>= 0.3.10, < 1) vcr (6.3.1) base64 @@ -626,8 +621,8 @@ DEPENDENCIES rack-attack (~> 6.7) rack-cors (~> 2.0, >= 2.0.2) rack-mini-profiler (~> 3.3, >= 3.3.1) - rails (~> 7.1.5, >= 7.1.5.1) - rails-i18n (~> 7.0, >= 7.0.10) + rails (~> 8.0, >= 8.0.1) + rails-i18n (~> 8.0, >= 8.0.0) rb-readline (~> 0.5, >= 0.5.5) redis (~> 5.4) roo (~> 2.10, >= 2.10.1) @@ -654,7 +649,7 @@ DEPENDENCIES terminal-notifier-guard (~> 1.7) timecop (~> 0.9, >= 0.9.10) tzinfo-data - validates_timeliness (~> 7.1.0) + validates_timeliness (~> 8.0.0) vcr (~> 6.3, >= 6.3.1) vpim (~> 24.2, >= 24.2.20) webmock (~> 3.25, >= 3.25.1) diff --git a/app/models/debit/mandate.rb b/app/models/debit/mandate.rb index 66170b2c..f35545fc 100644 --- a/app/models/debit/mandate.rb +++ b/app/models/debit/mandate.rb @@ -20,15 +20,18 @@ class Mandate < ApplicationRecord private - def unique_on_time_interval? - return true unless Debit::Mandate.where.not(id:).where(user_id:) - .exists?([':start_date BETWEEN start_date AND end_date OR - :end_date BETWEEN start_date AND end_date OR - start_date BETWEEN :start_date AND :end_date OR - end_date BETWEEN :start_date AND :end_date OR - (start_date < :start_date AND end_date IS NULL) OR - (start_date > :start_date AND :end_date IS NULL)', - { start_date:, end_date: }]) + def unique_on_time_interval? # rubocop:disable Metrics/MethodLength + return true unless Debit::Mandate.where.not(id:) + .where(user_id:) + .exists?([<<-SQL.squish, { start_date: start_date, end_date: end_date }]) + + CAST(:start_date AS date) BETWEEN start_date AND end_date OR + CAST(:end_date AS date) BETWEEN start_date AND end_date OR + start_date BETWEEN CAST(:start_date AS date) AND CAST(:end_date AS date) OR + end_date BETWEEN CAST(:start_date AS date) AND CAST(:end_date AS date) OR + (start_date < CAST(:start_date AS date) AND end_date IS NULL) OR + (start_date > CAST(:start_date AS date) AND CAST(:end_date AS date) IS NULL) + SQL errors.add(:mandate, 'is not unique on time interval') false diff --git a/app/models/import/user.rb b/app/models/import/user.rb index 4639cbe7..2a5d366f 100644 --- a/app/models/import/user.rb +++ b/app/models/import/user.rb @@ -1,6 +1,7 @@ module Import class User extend ActiveRecord::Translation + include ActiveModel::Model include SpreadsheetHelper attr_reader :errors, :imported_users diff --git a/app/models/membership.rb b/app/models/membership.rb index 8f58d645..e700310a 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -19,15 +19,18 @@ class Membership < ApplicationRecord private - def unique_on_time_interval? - return true unless Membership.where.not(id:).where(group_id:, user_id:) - .exists?([':start_date BETWEEN start_date AND end_date OR - :end_date BETWEEN start_date AND end_date OR - start_date BETWEEN :start_date AND :end_date OR - end_date BETWEEN :start_date AND :end_date OR - (start_date < :start_date AND end_date IS NULL) OR - (start_date > :start_date AND :end_date IS NULL)', - { start_date:, end_date: }]) + def unique_on_time_interval? # rubocop:disable Metrics/MethodLength + return true unless Membership.where.not(id:) + .where(group_id:, user_id:) + .exists?([<<-SQL.squish, { start_date: start_date, end_date: end_date }]) + + CAST(:start_date AS date) BETWEEN start_date AND end_date OR + CAST(:end_date AS date) BETWEEN start_date AND end_date OR + start_date BETWEEN CAST(:start_date AS date) AND CAST(:end_date AS date) OR + end_date BETWEEN CAST(:start_date AS date) AND CAST(:end_date AS date) OR + (start_date < CAST(:start_date AS date) AND end_date IS NULL) OR + (start_date > CAST(:start_date AS date) AND CAST(:end_date AS date) IS NULL) + SQL errors.add(:membership, 'is not unique on time interval') false diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 00000000..9c405df7 --- /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/rubocop b/bin/rubocop new file mode 100755 index 00000000..b3ed7c5e --- /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 451efe2e..fdf87f95 100755 --- a/bin/setup +++ b/bin/setup @@ -30,4 +30,8 @@ FileUtils.chdir APP_ROOT do puts "\n== Restarting application server ==" system! 'bin/rails restart' + + # puts "\n== Configuring puma-dev ==" + # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}" + # system "curl -Is https://#{APP_NAME}.test/up | head -n 1" end diff --git a/config/application.rb b/config/application.rb index 43326abe..5125cdef 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,5 @@ require_relative 'boot' +# Pick the frameworks you want: require 'rails' require 'active_model/railtie' require 'active_job/railtie' @@ -7,7 +8,10 @@ require 'action_controller/railtie' require 'action_mailer/railtie' require 'action_mailbox/engine' -# require "action_view/railtie" +# require 'action_text/engine' +# require 'action_view/railtie' +# require 'action_cable/engine' +# require 'rails/test_unit/railtie' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -18,7 +22,6 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.1 - config.add_autoload_paths_to_load_path = false # 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. diff --git a/config/environments/development.rb b/config/environments/development.rb index 582614c3..41e3f479 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,16 +14,14 @@ # 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. if Rails.root.join('tmp', 'caching-dev.txt').exist? 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 @@ -36,8 +34,13 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false + # Refer the Ember/UI of the Alpha website + config.action_mailer.default_url_options = { scheme: 'http', host: 'localhost', port: 4200 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -60,11 +63,14 @@ # 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 - # Raise error when a before_action's only/except options reference missing actions + # 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! + # 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 @@ -74,9 +80,6 @@ config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } config.action_mailer.asset_host = 'http://localhost:4200/api' - # Refer the Ember/UI of the Alpha website - config.action_mailer.default_url_options = { scheme: 'http', host: 'localhost', port: 4200 } - # Allow access to the api via ngrok config.hosts << ENV['NGROK_HOST'] if ENV['NGROK_HOST'] diff --git a/config/environments/production.rb b/config/environments/production.rb index cdd2f258..50b072e9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -12,7 +14,6 @@ # 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 ENV["RAILS_MASTER_KEY"], config/master.key, or an environment # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). @@ -39,11 +40,13 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + # Log to STDOUT by default config.logger = ActiveSupport::Logger.new($stdout) .tap { |logger| logger.formatter = Logger::Formatter.new } .then { |logger| ActiveSupport::TaggedLogging.new(logger) } - config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [:request_id] @@ -51,7 +54,7 @@ # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". - config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'debug') # Use a different cache store in production. config.cache_store = :redis_cache_store, { url: Rails.application.config_for(:cable)['url'] } @@ -60,6 +63,8 @@ config.active_job.queue_adapter = :sidekiq # config.active_job.queue_name_prefix = "amber_production" + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. @@ -70,12 +75,15 @@ # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.report_deprecations = :notify + # Don't log any deprecations. + config.active_support.report_deprecations = false # 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 diff --git a/config/environments/test.rb b/config/environments/test.rb index 07cc690e..e58d57cd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +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 @@ -6,26 +8,25 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - config.cache_classes = false + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # 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. + # 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 = false # 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}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = :none + # 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 @@ -33,6 +34,8 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -40,6 +43,10 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { scheme: 'http', host: 'testhost', port: 1337 } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -50,17 +57,15 @@ config.active_support.disallowed_deprecation_warnings = [] # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # 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 + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true # Configure url to test actionmailer urls - config.action_mailer.default_url_options = { scheme: 'http', host: 'testhost', port: 1337 } - config.active_job.queue_adapter = :test config.middleware.delete Rack::Attack config.x.mail_domains = %w[test.csvalpha.nl] diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 00000000..36e5e357 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,70 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 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 `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. +# +# Example: +# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2025-01-01'::date") #=> Date +# +# This query used to return a `String`. +#++ +# Rails.application.config.active_record.postgresql_adapter_decode_dates = true + +### +# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are +# deploying to a memory constrained environment you may want to set this to `false`. +#++ +# Rails.application.config.yjit = true diff --git a/config/puma.rb b/config/puma.rb index db29bd98..61566d04 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,41 +1,37 @@ -# 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. -# -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 +# 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. -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. # -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 +# 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' } - -# Ensure that the pidfile path exists -Pathname(pidfile).dirname.mkpath - -# 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', 5) +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 + +# 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'] + +# Specifies the `environment` that Puma will run in. +environment ENV.fetch('RAILS_ENV') { 'development' } diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 09578e0f..c233739f 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -1,5 +1,3 @@ -version: '3' - services: db: image: postgres:14.7 diff --git a/spec/requests/v1/stored_mails_controller/index_spec.rb b/spec/requests/v1/stored_mails_controller/index_spec.rb index 7c1edbc5..83ed54c5 100644 --- a/spec/requests/v1/stored_mails_controller/index_spec.rb +++ b/spec/requests/v1/stored_mails_controller/index_spec.rb @@ -7,6 +7,10 @@ let(:records) { create_list(:stored_mail, 3) } let(:record_permission) { 'stored_mail.read' } + before { Bullet.enable = false } + + after { Bullet.enable = true } + it_behaves_like 'an indexable model' describe 'when user is moderator' do @@ -22,8 +26,11 @@ before do create(:stored_mail) create_list(:stored_mail, 2, mail_alias:) + Bullet.enable = false end + after { Bullet.enable = true } + it_behaves_like '200 OK' it { expect(json['data'].count).to eq 2 } end diff --git a/spec/requests/v1/users_controller/destroy_spec.rb b/spec/requests/v1/users_controller/destroy_spec.rb index 392d270b..6d814867 100644 --- a/spec/requests/v1/users_controller/destroy_spec.rb +++ b/spec/requests/v1/users_controller/destroy_spec.rb @@ -7,6 +7,6 @@ subject(:request) { delete(record_url) } - it { expect { request }.to raise_error(ActionController::RoutingError) } + it_behaves_like '404 Not Found' end end