diff --git a/.rubocop.yml b/.rubocop.yml index f9d86d4..5a92dcf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,24 @@ -# Omakase Ruby styling for Rails -inherit_gem: { rubocop-rails-omakase: rubocop.yml } - -# Overwrite or add rules to create your own house style -# -# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` -# Layout/SpaceInsideArrayLiteralBrackets: -# Enabled: false +inherit_from: .rubocop_todo.yml + +require: + - rubocop-capybara + - rubocop-rails + +AllCops: + TargetRubyVersion: 3.3 + NewCops: enable + Exclude: + - bin/* + - db/schema.rb + +Style/Documentation: + Enabled: false + +Metrics/BlockLength: + Exclude: + - config/environments/* + +Metrics/MethodLength: + Max: 35 + Exclude: + - db/migrate/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..8d0811c --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,7 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-07-19 12:31:30 UTC using RuboCop version 1.64.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. diff --git a/Gemfile b/Gemfile index 7dffb60..090b9b1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,55 +1,57 @@ -source "https://rubygems.org" +# frozen_string_literal: true -ruby file: ".ruby-version" +source 'https://rubygems.org' -gem "rails", "~> 7.1" +ruby file: '.ruby-version' + +gem 'rails', '~> 7.1' # Drivers -gem "sqlite3", "~> 1.4" -gem "redis", ">= 4.0.1" +gem 'redis', '>= 4.0.1' +gem 'sqlite3', '~> 1.4' # Deployment -gem "puma", ">= 5.0" +gem 'puma', '>= 5.0' # Jobs -gem "resque", "~> 2.6.0" -gem "resque-pool", "~> 0.7.1" +gem 'resque', '~> 2.6.0' +gem 'resque-pool', '~> 0.7.1' # Front-end -gem "propshaft" -gem "importmap-rails" -gem "turbo-rails" -gem "stimulus-rails" -gem "bootstrap", "~> 5.1" -gem "sassc-rails" -gem "simple_form", "~> 5.3" +gem 'bootstrap', '~> 5.1' +gem 'importmap-rails' +gem 'simple_form', '~> 5.3' +gem 'stimulus-rails' +gem 'turbo-rails' # Other -gem "sprockets-rails" -gem "useragent", github: "basecamp/useragent" -gem "jbuilder" -gem "redcarpet", "~> 3.6" -gem "rouge", "~> 4.2" -gem "bcrypt", "~> 3.1.7" -gem "image_processing", "~> 1.2" -gem "rqrcode" -gem "thruster" -gem "front_matter_parser" -gem "rails-i18n", "~> 7.0.0" +gem 'bcrypt', '~> 3.1.7' +gem 'front_matter_parser' +gem 'image_processing', '~> 1.2' +gem 'jbuilder' +gem 'rails-i18n', '~> 7.0.0' +gem 'redcarpet', '~> 3.6' +gem 'rouge', '~> 4.2' +gem 'rqrcode' +gem 'sassc-rails' +gem 'sprockets-rails' +gem 'thruster' +gem 'useragent', github: 'basecamp/useragent' group :development, :test do - gem "debug" - gem "faker", require: false - gem "brakeman", require: false - gem "rubocop-rails-omakase", require: false + gem 'brakeman', require: false + gem 'debug' + gem 'faker', require: false + gem 'rubocop-capybara', require: false + gem 'rubocop-rails', require: false end group :development do - gem "web-console" - gem "htmlbeautifier" + gem 'htmlbeautifier' + gem 'web-console' end group :test do - gem "capybara" - gem "selenium-webdriver" + gem 'capybara' + gem 'selenium-webdriver' end diff --git a/Gemfile.lock b/Gemfile.lock index 04af754..e654a7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,11 +186,6 @@ GEM ast (~> 2.4.1) racc popper_js (2.11.8) - propshaft (0.8.0) - actionpack (>= 7.0.0) - activesupport (>= 7.0.0) - rack - railties (>= 7.0.0) psych (5.1.2) stringio public_suffix (5.0.5) @@ -282,22 +277,13 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.3) parser (>= 3.3.1.0) - rubocop-minitest (0.35.0) - rubocop (>= 1.61, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-performance (1.21.0) - rubocop (>= 1.48.1, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) rubocop-rails (2.25.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails-omakase (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) @@ -391,7 +377,6 @@ DEPENDENCIES image_processing (~> 1.2) importmap-rails jbuilder - propshaft puma (>= 5.0) rails (~> 7.1) rails-i18n (~> 7.0.0) @@ -401,7 +386,8 @@ DEPENDENCIES resque-pool (~> 0.7.1) rouge (~> 4.2) rqrcode - rubocop-rails-omakase + rubocop-capybara + rubocop-rails sassc-rails selenium-webdriver simple_form (~> 5.3) diff --git a/Rakefile b/Rakefile index 9a5ea73..488c551 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 41f414c..8349c0f 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -12,4 +12,28 @@ $theme-colors: map-merge($theme-colors, $custom-colors); @import "bootstrap"; // simple_form helpers -@import "simple_form-bootstrap/simple_form-bootstrap"; \ No newline at end of file +@import "simple_form-bootstrap/simple_form-bootstrap"; + +.dot-ok { + height: 10px; + width: 10px; + background-color: green; + border-radius: 50%; + display: inline-block; +} + +.dot-warning { + height: 10px; + width: 10px; + background-color: orange; + border-radius: 50%; + display: inline-block; +} + +.dot-error { + height: 10px; + width: 10px; + background-color: red; + border-radius: 50%; + display: inline-block; +} \ No newline at end of file diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d95db2..9c1acb3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. allow_browser versions: :modern diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 95f2992..ad544d1 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true + class HomeController < ApplicationController def index + @members = Member.all end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d..bef3959 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3c34c81..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" - layout "mailer" + default from: 'from@example.com' + layout 'mailer' end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..71fbba5 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/medical_certificate.rb b/app/models/medical_certificate.rb new file mode 100644 index 0000000..deaf20f --- /dev/null +++ b/app/models/medical_certificate.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class MedicalCertificate < ApplicationRecord + has_one_attached :certificate + + enum :kind, %i[regular competitive] + + validates :kind, :certificate, :expires_at, presence: true +end diff --git a/app/models/member.rb b/app/models/member.rb new file mode 100644 index 0000000..402fdbb --- /dev/null +++ b/app/models/member.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Member < ApplicationRecord + has_many :payments, dependent: :destroy + has_many :memberships, dependent: :destroy + + validates :name, :surname, :born_at, :born_in, :citizenship, :address, :postal_code, presence: true + + def status + %w[ok warning error].sample + end +end diff --git a/app/models/membership.rb b/app/models/membership.rb new file mode 100644 index 0000000..3db3f3a --- /dev/null +++ b/app/models/membership.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Membership < ApplicationRecord + belongs_to :member +end diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 0000000..de0bf39 --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Payment < ApplicationRecord + belongs_to :member + + validates :amount, presence: true +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 9118d6c..b3c742e 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1 +1,17 @@ -asdasd \ No newline at end of file + +
+ <% @members.each do |member| %> +
+ <%= member.name %> +
+ <% end %> +
\ No newline at end of file diff --git a/config.ru b/config.ru index 4a3c09a..6dc8321 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/config/application.rb b/config/application.rb index e8332f6..12c2cef 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,8 @@ -require_relative "boot" +# frozen_string_literal: true -require "rails/all" +require_relative 'boot' + +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/boot.rb b/config/boot.rb index 2820116..30e594e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +# frozen_string_literal: true -require "bundler/setup" # Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index cac5315..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 6af3ffe..95d7d40 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -19,12 +21,12 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + 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 diff --git a/config/environments/production.rb b/config/environments/production.rb index ed5a046..eca302d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,7 @@ -require "active_support/core_ext/integer/time" -require "active_support/core_ext/numeric/bytes" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' +require 'active_support/core_ext/numeric/bytes' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -30,24 +32,24 @@ config.active_storage.service = :local # 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.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Info include generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). Use "debug" # for everything. - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Cache in memory for now config.cache_store = :redis_cache_store # Assets are cacheable config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.year.to_i}" + 'Cache-Control' => "public, max-age=#{1.year.to_i}" } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -55,8 +57,8 @@ config.i18n.fallbacks = true # Always be SSL'ing (unless told not to) - config.assume_ssl = ENV["DISABLE_SSL"].blank? - config.force_ssl = ENV["DISABLE_SSL"].blank? + config.assume_ssl = ENV['DISABLE_SSL'].blank? + config.force_ssl = ENV['DISABLE_SSL'].blank? # Don't log any deprecations. config.active_support.report_deprecations = false diff --git a/config/environments/test.rb b/config/environments/test.rb index 75f22c6..fc2eb5c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# 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 @@ -15,10 +17,10 @@ # 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? + config.eager_load = ENV['CI'].present? # Configure public file server for tests with Cache-Control for performance. - 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 @@ -60,5 +62,5 @@ config.action_controller.raise_on_missing_callback_actions = true # Load test helpers - config.autoload_paths += %w[ test/test_helpers ] + config.autoload_paths += %w[test/test_helpers] end diff --git a/config/importmap.rb b/config/importmap.rb index 8124b68..b37a292 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # Pin npm packages by running ./bin/importmap -pin "application" -pin "@hotwired/turbo-rails", to: "turbo.min.js" -pin "@hotwired/stimulus", to: "stimulus.min.js" -pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" -pin_all_from "app/javascript/controllers", under: "controllers" +pin 'application' +pin '@hotwired/turbo-rails', to: 'turbo.min.js' +pin '@hotwired/stimulus', to: 'stimulus.min.js' +pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js' +pin_all_from 'app/javascript/controllers', under: 'controllers' -pin "bootstrap", to: "bootstrap.min.js", preload: true -pin "popper", to: "popper.js", preload: true +pin 'bootstrap', to: 'bootstrap.min.js', preload: true +pin 'popper', to: 'popper.js', preload: true diff --git a/config/initializers/active_storage.rb b/config/initializers/active_storage.rb index 675541b..0e69b4c 100644 --- a/config/initializers/active_storage.rb +++ b/config/initializers/active_storage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ActiveSupport.on_load(:active_storage_blob) do ActiveStorage::DiskController.after_action only: :show do expires_in 1.year, public: true diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 97653ea..46430b8 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # 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" +Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index b3076b3..35ab3fd 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/config/initializers/enable_yjit.rb b/config/initializers/enable_yjit.rb index 8a44221..8d19d5a 100644 --- a/config/initializers/enable_yjit.rb +++ b/config/initializers/enable_yjit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Automatically enable YJIT as of Ruby 3.3, as it brings very # sizeable performance improvements. diff --git a/config/initializers/extensions.rb b/config/initializers/extensions.rb index 455b96d..caf04fa 100644 --- a/config/initializers/extensions.rb +++ b/config/initializers/extensions.rb @@ -1 +1,3 @@ -Dir["#{Rails.root}/lib/rails_ext/*"].each { |path| require "rails_ext/#{File.basename(path)}" } +# frozen_string_literal: true + +Dir[Rails.root.join('lib/rails_ext/*').to_s].each { |path| require "rails_ext/#{File.basename(path)}" } diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c010b83..5a36c53 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this 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 += [ - :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw email secret token _key crypt salt certificate otp ssn ] diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 7db3b95..e8d0b2a 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide HTTP permissions policy. For further diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index d268784..8d5f9bc 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Uncomment this and change the path if necessary to include your own # components. @@ -13,8 +14,11 @@ # wrapper, change the order or even add your own to the # stack. The options given below are used to wrap the # whole input. - config.wrappers :default, class: :input, - hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b| + config.wrappers :default, + class: :input, + hint_class: :field_with_hint, + error_class: :field_with_errors, + valid_class: :field_without_errors do |b| ## Extensions enabled by default # Any of these extensions can be disabled for a # given input by passing: `f.input EXTENSION_NAME => false`. diff --git a/config/initializers/sqlite3.rb b/config/initializers/sqlite3.rb index f34bc1d..c83163a 100644 --- a/config/initializers/sqlite3.rb +++ b/config/initializers/sqlite3.rb @@ -1,17 +1,20 @@ +# frozen_string_literal: true + module SQLite3Configuration private - def configure_connection - super - if @config[:retries] - retries = self.class.type_cast_config_to_integer(@config[:retries]) - raw_connection.busy_handler do |count| - (count <= retries).tap { |result| sleep count * 0.001 if result } - end - end + def configure_connection + super + + return unless @config[:retries] + + retries = self.class.type_cast_config_to_integer(@config[:retries]) + raw_connection.busy_handler do |count| + (count <= retries).tap { |result| sleep count * 0.001 if result } end + end end ActiveSupport.on_load :active_record do - ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend SQLite3Configuration + ActiveSupport.on_load(:active_record_sqlite3adapter) { prepend SQLite3Configuration } end diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 3861cc4..d161b45 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,2 +1,4 @@ -Rails.application.config.app_version = ENV.fetch("APP_VERSION", "0") -Rails.application.config.git_revision = ENV["GIT_REVISION"] +# frozen_string_literal: true + +Rails.application.config.app_version = ENV.fetch('APP_VERSION', '0') +Rails.application.config.git_revision = ENV.fetch('GIT_REVISION', nil) diff --git a/config/puma.rb b/config/puma.rb index 022ebc8..2ea6962 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,18 +1,20 @@ -threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +# frozen_string_literal: true + +threads_count = ENV.fetch('RAILS_MAX_THREADS', 3) threads threads_count, threads_count -rails_env = ENV.fetch("RAILS_ENV", "development") +rails_env = ENV.fetch('RAILS_ENV', 'development') environment rails_env case rails_env -when "production" - workers_count = Integer(ENV.fetch("WEB_CONCURRENCY") { (Concurrent.processor_count * 0.666).ceil }) +when 'production' + workers_count = Integer(ENV.fetch('WEB_CONCURRENCY') { (Concurrent.processor_count * 0.666).ceil }) workers workers_count if workers_count > 1 preload_app! -when "development" +when 'development' worker_timeout 3600 # Don't let worker die during debugger session end -port ENV.fetch("PORT", 3000) +port ENV.fetch('PORT', 3000) plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb index 9b8dbe5..96d91b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - root to: "home#index" + root to: 'home#index' - get "up" => "rails/health#show", as: :rails_health_check + get 'up' => 'rails/health#show', as: :rails_health_check end diff --git a/db/migrate/20240718060253_create_medical_certificates.rb b/db/migrate/20240718060253_create_medical_certificates.rb new file mode 100644 index 0000000..46c6acd --- /dev/null +++ b/db/migrate/20240718060253_create_medical_certificates.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class CreateMedicalCertificates < ActiveRecord::Migration[7.2] + def change + create_table :medical_certificates do |t| + t.integer :kind, null: false + t.date :expires_at, null: false + + t.timestamps + end + end +end diff --git a/db/migrate/20240718060338_create_memberships.rb b/db/migrate/20240718060338_create_memberships.rb new file mode 100644 index 0000000..15028ff --- /dev/null +++ b/db/migrate/20240718060338_create_memberships.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreateMemberships < ActiveRecord::Migration[7.2] + def change + create_table :memberships do |t| + t.belongs_to :member + + t.timestamps + end + end +end diff --git a/db/migrate/20240718060353_create_payments.rb b/db/migrate/20240718060353_create_payments.rb new file mode 100644 index 0000000..243381c --- /dev/null +++ b/db/migrate/20240718060353_create_payments.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class CreatePayments < ActiveRecord::Migration[7.2] + def change + create_table :payments do |t| + t.belongs_to :member + t.integer :amount, null: false + + t.timestamps + end + end +end diff --git a/db/migrate/20240718060539_create_member.rb b/db/migrate/20240718060539_create_member.rb new file mode 100644 index 0000000..6e96e49 --- /dev/null +++ b/db/migrate/20240718060539_create_member.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class CreateMember < ActiveRecord::Migration[7.2] + def change + create_table :members do |t| + t.string :name, null: false + t.string :surname, null: false + t.date :born_at, null: false + t.string :born_in, null: false + t.string :tax_code + t.string :citizenship, null: false + t.string :address, null: false + t.string :postal_code, null: false + t.string :province + t.string :telephone + t.string :email + + t.text :notes + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..eefba89 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,52 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.2].define(version: 2024_07_18_060539) do + create_table "medical_certificates", force: :cascade do |t| + t.integer "kind", null: false + t.date "expires_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "members", force: :cascade do |t| + t.string "name", null: false + t.string "surname", null: false + t.date "born_at", null: false + t.string "born_in", null: false + t.string "tax_code" + t.string "citizenship", null: false + t.string "address", null: false + t.string "postal_code", null: false + t.string "province" + t.string "telephone" + t.string "email" + t.text "notes" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "memberships", force: :cascade do |t| + t.integer "member_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["member_id"], name: "index_memberships_on_member_id" + end + + create_table "payments", force: :cascade do |t| + t.integer "member_id" + t.integer "amount", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["member_id"], name: "index_payments_on_member_id" + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed..a72d4ef 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should ensure the existence of records required to run the application in every environment (production, # development, test). The code here should be idempotent so that it can be executed at any point in every environment. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). @@ -7,3 +9,19 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end + +require 'faker' + +Faker::Config.locale = 'it' + +10.times do + Member.create( + name: Faker::Name.first_name, + surname: Faker::Name.last_name, + born_at: Faker::Date.between(from: '2015-12-31', to: '2000-01-01'), + born_in: Faker::Address.city, + citizenship: Faker::Address.country, + address: Faker::Address.full_address, + postal_code: Faker::Address.postcode + ) +end diff --git a/script/admin/prepare-backup b/script/admin/prepare-backup index e4e6d0a..f65c378 100755 --- a/script/admin/prepare-backup +++ b/script/admin/prepare-backup @@ -1,11 +1,13 @@ #!/usr/bin/env ruby -require File.expand_path("../../config/environment", File.dirname(__FILE__)) +# frozen_string_literal: true + +require File.expand_path('../../config/environment', File.dirname(__FILE__)) class Backup class << self def create dest = SQLite3::Database.new(backup_filename) - backup = SQLite3::Backup.new(dest, "main", User.connection.raw_connection, "main") + backup = SQLite3::Backup.new(dest, 'main', User.connection.raw_connection, 'main') backup.step(-1) backup.finish @@ -13,14 +15,15 @@ class Backup end private - def backup_filename - Rails.root.join("storage", "backups").tap(&:mkpath).join(primary_database_filename) - end - def primary_database_filename - path = Rails.application.config.database_configuration[Rails.env]["primary"]["database"] - File.basename(path) - end + def backup_filename + Rails.root.join('storage/backups').tap(&:mkpath).join(primary_database_filename) + end + + def primary_database_filename + path = Rails.application.config.database_configuration[Rails.env]['primary']['database'] + File.basename(path) + end end end diff --git a/script/admin/reset-password b/script/admin/reset-password index 908a023..8ff7aaa 100755 --- a/script/admin/reset-password +++ b/script/admin/reset-password @@ -1,13 +1,15 @@ #!/usr/bin/env ruby -require File.expand_path("../../config/environment", File.dirname(__FILE__)) +# frozen_string_literal: true -abort "Usage: #{$0} " unless ARGV.length == 2 +require File.expand_path('../../config/environment', File.dirname(__FILE__)) + +abort "Usage: #{$PROGRAM_NAME} " unless ARGV.length == 2 email_address, password = ARGV -if user = User.find_by(email_address: email_address) - user.update!(password: password) - puts "Password has been reset" +if (user = User.find_by(email_address:)) + user.update!(password:) + puts 'Password has been reset' else - puts "User not found" - exit -1 + puts 'User not found' + exit(-1) end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index c3f0fa4..46f6c6b 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,7 +1,7 @@ -require "test_helper" +# frozen_string_literal: true -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - include SystemTestHelper +require 'test_helper' - driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] end diff --git a/test/models/medical_certificate_test.rb b/test/models/medical_certificate_test.rb new file mode 100644 index 0000000..bde9779 --- /dev/null +++ b/test/models/medical_certificate_test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'test_helper' + +class MedicalCertificateTest < ActiveSupport::TestCase + test 'valudates presence' do + mc = MedicalCertificate.create + + assert(mc.errors.key?('kind')) + assert(mc.errors.key?('certificate')) + assert(mc.errors.key?('expires_at')) + end +end diff --git a/test/models/member_test.rb b/test/models/member_test.rb new file mode 100644 index 0000000..0089690 --- /dev/null +++ b/test/models/member_test.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'test_helper' + +class MemberTest < ActiveSupport::TestCase + test 'valudates presence' do + member = Member.create + + assert(member.errors.key?('name')) + assert(member.errors.key?('surname')) + assert(member.errors.key?('born_at')) + assert(member.errors.key?('born_in')) + assert(member.errors.key?('citizenship')) + assert(member.errors.key?('address')) + assert(member.errors.key?('postal_code')) + end +end diff --git a/test/models/membership_test.rb b/test/models/membership_test.rb new file mode 100644 index 0000000..973eb9c --- /dev/null +++ b/test/models/membership_test.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'test_helper' + +class MembershipTest < ActiveSupport::TestCase + test 'valudates presence' do + membership = Membership.create + + assert(membership.errors.key?('member')) + end +end diff --git a/test/models/payment_test.rb b/test/models/payment_test.rb new file mode 100644 index 0000000..751801f --- /dev/null +++ b/test/models/payment_test.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'test_helper' + +class PaymentTest < ActiveSupport::TestCase + test 'valudates presence' do + payment = Payment.create + + assert(payment.errors.key?('member')) + assert(payment.errors.key?('amount')) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 37e5e0a..3e74cf5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,8 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" +# frozen_string_literal: true + +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' module ActiveSupport class TestCase @@ -9,7 +11,5 @@ class TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all - - include SessionTestHelper end end diff --git a/test/test_helpers/session_test_helper.rb b/test/test_helpers/session_test_helper.rb deleted file mode 100644 index 15e9858..0000000 --- a/test/test_helpers/session_test_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -module SessionTestHelper - def parsed_cookies - ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash) - end - - def sign_in(user) - user = users(user) unless user.is_a? User - post session_url, params: { email_address: user.email_address, password: "secret123456" } - assert cookies[:session_token].present? - end - - def sign_out - delete session_url - assert_not cookies[:session_token].present? - end -end diff --git a/test/test_helpers/system_test_helper.rb b/test/test_helpers/system_test_helper.rb deleted file mode 100644 index e0d0838..0000000 --- a/test/test_helpers/system_test_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -module SystemTestHelper - include ActionView::Helpers::JavaScriptHelper - - def sign_in(email_address, password = "secret123456") - visit new_session_url - - fill_in "email_address", with: email_address - fill_in "password", with: password - - click_on "log_in" - assert_selector "h2", text: "Handbook" - end - - def fill_house_editor(name, content) - execute_script <<~JS - const editor = document.querySelector("[name='#{name}']") - editor.value = "#{escape_javascript(content)}" - JS - end -end