From 9f839289efa5cfb2d580ada0758fe8b7d00b7211 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 20:07:50 -0300 Subject: [PATCH 01/72] Add Dockerfile for Ruby on Rails development --- Dockerfile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bd1333c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ruby:3.2.3-alpine3.19 + +LABEL maintainer="Fabiano Santos Florentino" +LABEL version="0.1" +LABEL description="Docker image for Ruby on Rails development" +LABEL appname="Black Pearl" + +ENV PATH="/usr/local/bundle/bin:${PATH}" +ENV RUBY_YJIT_ENABLE=1 + +COPY . /app + +WORKDIR /app + +RUN apk update && apk upgrade --no-cache \ + && apk add --no-cache libpq-dev build-base git bash tzdata gcompat postgresql \ + && gem install rails railties bundler \ + && bundle install --jobs 2 --no-cache \ + && bundle exec bootsnap precompile + +EXPOSE 3000 + +CMD ["bash", "-c", "bundle exec rails s -b 0.0.0.0 -p 3000"] From b50de1fc25913386091a5d1a48241af0fc6c8f7d Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 20:07:57 -0300 Subject: [PATCH 02/72] Add docker-compose.yml for Blackpearl service --- docker-compose.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1f3a982 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +version: '3.9' + +services: + blackpearl: + container_name: blackpearl + image: fabianoflorentino/blackpearl:0.1-linux-arm64 + hostname: blackpearl + build: + context: . + dockerfile: Dockerfile + ports: + - "9999:3000" + links: + - blackpearl-db + volumes: + - .:/app + env_file: .env + networks: + - dev + tty: true + stdin_open: true + + blackpearl-db: + container_name: blackpearl-db + image: postgres:latest + hostname: blackpearl-db + volumes: + - data:/var/lib/postgresql/data + env_file: .env + networks: + - dev + + # blackpearl-migration: + # container_name: blackpearl-migration + # image: fabianoflorentino/blackpearl:0.1-linux-arm64 + # hostname: blackpearl-migration + # volumes: + # - .:/app + # env_file: .env + # networks: + # - dev + # entrypoint: ["/bin/bash", "-c", "bin/migration"] + +volumes: + data: + name: blackpearl + driver: local + +networks: + dev: + name: blackpearl + driver: bridge From c60168d5a083deaebd37313aae0f5d48ba8602f8 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 20:09:09 -0300 Subject: [PATCH 03/72] Add Gemfile and Gemfile.lock --- Gemfile | 25 +++++ Gemfile.lock | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0733cc7 --- /dev/null +++ b/Gemfile @@ -0,0 +1,25 @@ +source 'https://rubygems.org' + +ruby '3.2.3' + +gem 'rails', '~> 7.1.3', '>= 7.1.3.2' + +gem 'bootsnap', require: false +gem 'jsonapi-serializer', '~> 2.2.0' +gem 'pg', '~> 1.1' +gem 'puma', '>= 5.0' +gem 'tzinfo-data', '~> 1.2024', '>= 1.2024.1' + +group :development, :test do + gem 'brakeman', '~> 6.0.1', require: false + gem 'debug' + gem 'factory_bot_rails', '~> 6.2.0' + gem 'faker', '~> 3.2.0' + gem 'rspec', '~> 3.13' + gem 'rspec-rails', '~> 6.1', '>= 6.1.1' + gem 'rubocop', '~> 1.61.0' + gem 'rubocop-performance', '~> 1.20.0' + gem 'rubocop-rails', '~> 2.23.1' + gem 'rubocop-rspec', '~> 2.27.0' + gem 'rubocop-shopify', '~> 2.15.1' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..b0cfe12 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,288 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) + 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.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) + globalid (>= 0.3.6) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) + timeout (>= 0.4.0) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) + marcel (~> 1.0) + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.6) + bootsnap (1.18.3) + msgpack (~> 1.2) + brakeman (6.0.1) + builder (3.2.4) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + crass (1.0.6) + date (3.3.4) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.1) + drb (2.2.1) + erubi (1.12.0) + factory_bot (6.2.1) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) + faker (3.2.3) + i18n (>= 1.8.11, < 2) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.11.2) + rdoc + reline (>= 0.4.2) + json (2.7.1) + jsonapi-serializer (2.2.0) + activesupport (>= 4.2) + language_server-protocol (3.17.0.3) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + minitest (5.22.2) + msgpack (1.7.2) + mutex_m (0.2.0) + net-imap (0.4.10) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.2-aarch64-linux) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc + pg (1.5.6) + psych (5.1.2) + stringio + puma (6.4.2) + nio4r (~> 2.0) + racc (1.7.3) + rack (3.0.9.1) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + bundler (>= 1.15.0) + railties (= 7.1.3.2) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.1.0) + rdoc (6.6.2) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.4.3) + io-console (~> 0.5) + rexml (3.2.6) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-rails (6.1.1) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) + rspec-support (3.13.1) + rubocop (1.61.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rspec (2.27.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-shopify (2.15.1) + rubocop (~> 1.51) + ruby-progressbar (1.13.0) + stringio (3.1.0) + thor (1.3.1) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + tzinfo-data (1.2024.1) + tzinfo (>= 1.0.0) + unicode-display_width (2.5.0) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.13) + +PLATFORMS + aarch64-linux + aarch64-linux-musl + +DEPENDENCIES + bootsnap + brakeman (~> 6.0.1) + debug + factory_bot_rails (~> 6.2.0) + faker (~> 3.2.0) + jsonapi-serializer (~> 2.2.0) + pg (~> 1.1) + puma (>= 5.0) + rails (~> 7.1.3, >= 7.1.3.2) + rspec (~> 3.13) + rspec-rails (~> 6.1, >= 6.1.1) + rubocop (~> 1.61.0) + rubocop-performance (~> 1.20.0) + rubocop-rails (~> 2.23.1) + rubocop-rspec (~> 2.27.0) + rubocop-shopify (~> 2.15.1) + tzinfo-data (~> 1.2024, >= 1.2024.1) + +RUBY VERSION + ruby 3.2.3p157 + +BUNDLED WITH + 2.5.6 From 22b5787a0d57167c7227e556819045093d4ad337 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 20:09:20 -0300 Subject: [PATCH 04/72] Add .pgpass and .env to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e3200e0..c40f393 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ build-iPhoneSimulator/ # Used by RuboCop. Remote config files pulled in from inherit_from directive. # .rubocop-https?--* +.pgpass +.env From 9cc10087ccafb970e78330b3d2748e3d0814577e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 21:35:54 -0300 Subject: [PATCH 05/72] Add initial project files and configurations --- .dockerignore | 31 +++ .gitattributes | 9 + .gitignore | 3 + .rubocop.yml | 3 + .ruby-version | 1 + Gemfile.lock | 3 + Rakefile | 6 + app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 2 + app/controllers/concerns/.keep | 0 app/jobs/application_job.rb | 7 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 109 ++++++++ bin/docker-entrypoint | 8 + bin/rails | 4 + bin/rake | 4 + bin/setup | 33 +++ config.ru | 6 + config/application.rb | 32 +++ config/boot.rb | 6 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 86 +++++++ config/environment.rb | 5 + config/environments/development.rb | 81 ++++++ config/environments/production.rb | 92 +++++++ config/environments/test.rb | 64 +++++ config/initializers/cors.rb | 16 ++ .../initializers/filter_parameter_logging.rb | 8 + config/initializers/inflections.rb | 16 ++ config/locales/en.yml | 31 +++ config/puma.rb | 37 +++ config/routes.rb | 12 + config/storage.yml | 34 +++ db/seeds.rb | 9 + lib/tasks/.keep | 0 log/.keep | 0 log/development.log | 232 ++++++++++++++++++ public/robots.txt | 1 + storage/.keep | 0 .../application_cable/connection_test.rb | 13 + test/controllers/.keep | 0 test/fixtures/files/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/test_helper.rb | 15 ++ vendor/.keep | 0 53 files changed, 1059 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .rubocop.yml create mode 100644 .ruby-version create mode 100644 Rakefile create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/docker-entrypoint create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/cors.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/storage.yml create mode 100644 db/seeds.rb create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 log/development.log create mode 100644 public/robots.txt create mode 100644 storage/.keep create mode 100644 test/channels/application_cable/connection_test.rb create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/test_helper.rb create mode 100644 vendor/.keep diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bb56daf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. + +# Ignore git directory. +/.git/ + +# Ignore bundler config. +/.bundle + +# Ignore all environment files (except templates). +/.env* +!/.env*.erb + +# Ignore all default key files. +/config/master.key +/config/credentials/*.key + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/.keep diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8dc4323 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/.gitignore b/.gitignore index c40f393..9e2e78a 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ build-iPhoneSimulator/ # .rubocop-https?--* .pgpass .env + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..b934698 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,3 @@ + +Metrics/BlockLength: + Enabled: false diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ab96aa9 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-3.2.3 diff --git a/Gemfile.lock b/Gemfile.lock index b0cfe12..a54d7c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,6 +136,8 @@ GEM nio4r (2.7.0) nokogiri (1.16.2-aarch64-linux) racc (~> 1.4) + nokogiri (1.16.2-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -261,6 +263,7 @@ GEM PLATFORMS aarch64-linux aarch64-linux-musl + x86_64-linux DEPENDENCIES bootsnap diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9a5ea73 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# 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" + +Rails.application.load_tasks diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..4ac8823 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..50da5fd --- /dev/null +++ b/bin/bundle @@ -0,0 +1,109 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + bundler_gem_version.approximate_recommendation + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint new file mode 100755 index 0000000..67ef493 --- /dev/null +++ b/bin/docker-entrypoint @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# If running the rails server then create or migrate existing database +if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then + ./bin/rails db:prepare +fi + +exec "${@}" diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4fbf10b --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..3cd5a9d --- /dev/null +++ b/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args, exception: true) +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..4a3c09a --- /dev/null +++ b/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..3303188 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,32 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module App + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.1 + + # 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. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..c04863f --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..f39dc04 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: app_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..4cd91ad --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +diTmIKTGK35vGHExryH65PptXkTE8ECV1gif32DYsSXNNHQ2pR+K2yWTUxj5p/L4ElJ6t6GqlhOno0a9YaRkhGEmbPnXnAOZrlcwQCfjptg5X1lCiWPlAt5cFAFxfavTXQ3gAXg0RJlTtrxF4M5lBRXxiA7riMZK6E4CGl0a5J/NnMPcAVRmqHdzF6vvdCf5YG4QmGK5uSKOm4I/YP/0h3Diqil2+ISzsn80SaREcsLk9+zoVNrL3ip1dNeSe8KQdt4mnMGPv5GG+hmWPtS6SEbhlzj9vitqXRTyHckXYYInQVaSIqTsAHBRcfprJEA0aebRs+lE5njjx++gn6hyxYf81FW1ntPAICC/6VNVkNLVCXenJ/NJrj+UbvjYPhNFg8GViHv5W9nrAaxNggKLjnyPNMb6--KkYo0c0em7EDJBgw--V4kKhla0Baf3Y/r10S0+jg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..5cc82fa --- /dev/null +++ b/config/database.yml @@ -0,0 +1,86 @@ +# PostgreSQL. Versions 9.3 and up are supported. +# +# Install the pg driver: +# gem install pg +# On macOS with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem "pg" +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # https://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + username: <%= ENV.fetch("POSTGRES_USER") %> + password: <%= ENV.fetch("POSTGRES_PASSWORD") %> + host: <%= ENV.fetch("POSTGRES_HOST") %> + port: <%= ENV.fetch("POSTGRES_PORT") %> + +development: + <<: *default + database: blackpearl + + # The specified database role being used to connect to PostgreSQL. + # To create additional roles in PostgreSQL see `$ createuser --help`. + # When left blank, PostgreSQL will use the default role. This is + # the same name as the operating system user running Rails. + #username: app + + # The password associated with the PostgreSQL role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: blackpearl + +# As with config/credentials.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# +production: + <<: *default + database: blackpearl diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..cac5315 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..d9f9d4a --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,81 @@ +# 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. + + config.hosts += [/.*\.localhost/, 'localhost'] + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + config.assume_ssl = false + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = false + + # 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.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # 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}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise 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 + + # 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 + + # 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 +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..7d108c0 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,92 @@ +# 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. + + # Code is not reloaded between requests. + 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. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # 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). + # config.require_master_key = true + + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + # config.public_file_server.enabled = false + + # 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 + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # 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. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Log to STDOUT by default + 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] + + # "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') + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # 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 = "app_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # 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 + + # 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 diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..adbb4a6 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,64 @@ +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 +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # 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}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # 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 + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + 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 + + # 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 diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb new file mode 100644 index 0000000..0c5dd99 --- /dev/null +++ b/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..c2d89e2 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# 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, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..3860f65 --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..6c349ae --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..7ed4157 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# 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. + +# 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 + +# Specifies that the worker count should equal the number of processors in production. +if ENV['RAILS_ENV'] == 'production' + require 'concurrent-ruby' + worker_count = Integer(ENV.fetch('WEB_CONCURRENCY') { Concurrent.physical_processor_count }) + workers worker_count if worker_count > 1 +end + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch('PORT', 3000) + +# Specifies the `environment` that Puma will run in. +environment ENV.fetch('RAILS_ENV', 'development') + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..7c16bc7 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +Rails.application.routes.draw do + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # Can be used by load balancers and uptime monitors to verify that the app is live. + get 'up' => 'rails/health#show', as: :rails_health_check + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000..4942ab6 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..4fbd6ed --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,9 @@ +# 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). +# +# Example: +# +# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| +# MovieGenre.find_or_create_by!(name: genre_name) +# end diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/development.log b/log/development.log new file mode 100644 index 0000000..e998026 --- /dev/null +++ b/log/development.log @@ -0,0 +1,232 @@ +Started GET "/up" for 172.26.0.1 at 2024-03-01 23:41:16 +0000 + +ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory + Is the server running locally and accepting connections on that socket? +): + +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' +activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' +activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' +activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' +activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' +activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' +railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' +activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' +rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' +activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' +rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' +railties (7.1.3.2) lib/rails/engine.rb:536:in `call' +puma (6.4.2) lib/puma/configuration.rb:272:in `call' +puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' +puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' +puma (6.4.2) lib/puma/request.rb:99:in `handle_request' +puma (6.4.2) lib/puma/server.rb:464:in `process_client' +puma (6.4.2) lib/puma/server.rb:245:in `block in run' +puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' +Started GET "/up" for 172.28.0.1 at 2024-03-02 00:04:02 +0000 + +ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory + Is the server running locally and accepting connections on that socket? +): + +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' +activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' +activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' +activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' +activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' +activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' +railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' +activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' +rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' +activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' +rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' +railties (7.1.3.2) lib/rails/engine.rb:536:in `call' +puma (6.4.2) lib/puma/configuration.rb:272:in `call' +puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' +puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' +puma (6.4.2) lib/puma/request.rb:99:in `handle_request' +puma (6.4.2) lib/puma/server.rb:464:in `process_client' +puma (6.4.2) lib/puma/server.rb:245:in `block in run' +puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' +Started GET "/up" for 172.28.0.1 at 2024-03-02 00:24:04 +0000 + +ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory + Is the server running locally and accepting connections on that socket? +): + +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' +activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' +activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' +activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' +activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' +activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' +activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' +activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' +activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' +activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' +activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' +actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' +railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' +activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' +activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' +railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' +rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' +activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' +actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' +rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' +actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' +railties (7.1.3.2) lib/rails/engine.rb:536:in `call' +puma (6.4.2) lib/puma/configuration.rb:272:in `call' +puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' +puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' +puma (6.4.2) lib/puma/request.rb:99:in `handle_request' +puma (6.4.2) lib/puma/server.rb:464:in `process_client' +puma (6.4.2) lib/puma/server.rb:245:in `block in run' +puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' +Started GET "/up" for 172.29.0.1 at 2024-03-02 00:25:32 +0000 +  (4.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY) +  (2.9ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL) + ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC +Processing by Rails::HealthController#show as */* + Rendering html template + Rendered html template (Duration: 0.1ms | Allocations: 8) +Completed 200 OK in 57ms (Views: 33.4ms | ActiveRecord: 0.0ms | Allocations: 4972) + + diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb new file mode 100644 index 0000000..6340bf9 --- /dev/null +++ b/test/channels/application_cable/connection_test.rb @@ -0,0 +1,13 @@ +require "test_helper" + +module ApplicationCable + class ConnectionTest < ActionCable::Connection::TestCase + # test "connects with cookies" do + # cookies.signed[:user_id] = 42 + # + # connect + # + # assert_equal connection.user_id, "42" + # end + end +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..0c22470 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require_relative "../config/environment" +require "rails/test_help" + +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... + end +end diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000..e69de29 From b34a1d4beddf7da23e9673e4107b907b50fab608 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 21:51:11 -0300 Subject: [PATCH 06/72] Ignore log files in .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9e2e78a..252e0e7 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ build-iPhoneSimulator/ # Ignore master key for decrypting credentials and more. /config/master.key +log/development.log +log/test.log From 17d5c05e6295306e052e6c0c681fcdeb792e3f38 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 21:51:22 -0300 Subject: [PATCH 07/72] Add db/schema.rb file --- db/schema.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/schema.rb diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..f913998 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,17 @@ +# 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.1].define(version: 0) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + +end From 2c6b765a24c2472cf79e2e9ffa8ed9008fa728b2 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 23:19:04 -0300 Subject: [PATCH 08/72] Add UpController to check app status --- app/controllers/up_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/controllers/up_controller.rb diff --git a/app/controllers/up_controller.rb b/app/controllers/up_controller.rb new file mode 100644 index 0000000..4de30b4 --- /dev/null +++ b/app/controllers/up_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# This controller is used to check if the app is up and running. +class UpController < ApplicationController + def index + render json: { status: 'up!' } + end +end From 6246f5ffa016a1264a3f46197fa7ae03e0aedf94 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 23:19:13 -0300 Subject: [PATCH 09/72] Refactor application.rb file to remove unnecessary code --- config/application.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index 3303188..f21fbde 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,12 +1,15 @@ -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. Bundler.require(*Rails.groups) module App + # The main application class. class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.1 @@ -14,7 +17,7 @@ class Application < Rails::Application # 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)) + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # @@ -28,5 +31,10 @@ class Application < Rails::Application # Middleware like session, flash, cookies can be added back manually. # Skip views, helpers and assets when generating a new resource. config.api_only = true + + initializer(:remove_action_mailbox_and_activestorage_routes, after: :add_routing_paths) do |app| + app.routes_reloader.paths.delete_if { |path| path =~ /activestorage/ } + app.routes_reloader.paths.delete_if { |path| path =~ /actionmailbox/ } + end end end From e1d7b5a14da16243474058ac5be5bc3980065710 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Fri, 1 Mar 2024 23:22:46 -0300 Subject: [PATCH 10/72] Update health check route in routes.rb --- config/routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 7c16bc7..bac6108 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,8 @@ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live. - get 'up' => 'rails/health#show', as: :rails_health_check + # get 'up' => 'rails/health#show', as: :rails_health_check + get 'up', to: 'up#index' # Defines the root path route ("/") # root "posts#index" From 1e445b52f170ae72aedd1d63548f36dfffc8d098 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:19:59 -0300 Subject: [PATCH 11/72] Add blackpearl-migration service to docker-compose.yml --- docker-compose.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1f3a982..9e42dbc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,16 +30,16 @@ services: networks: - dev - # blackpearl-migration: - # container_name: blackpearl-migration - # image: fabianoflorentino/blackpearl:0.1-linux-arm64 - # hostname: blackpearl-migration - # volumes: - # - .:/app - # env_file: .env - # networks: - # - dev - # entrypoint: ["/bin/bash", "-c", "bin/migration"] + blackpearl-migration: + container_name: blackpearl-migration + image: fabianoflorentino/blackpearl:0.1-linux-arm64 + hostname: blackpearl-migration + volumes: + - .:/app + env_file: .env + networks: + - dev + entrypoint: ["/bin/bash", "-c", "bin/migration"] volumes: data: From 2200992d2701de6af157c7032d52435bf3feb170 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:20:20 -0300 Subject: [PATCH 12/72] Add RSpec configuration files --- .rspec | 2 + spec/rails_helper.rb | 69 +++++++++++++++++++++++++++ spec/spec_helper.rb | 94 +++++++++++++++++++++++++++++++++++++ spec/support/factory_bot.rb | 7 +++ 4 files changed, 172 insertions(+) create mode 100644 .rspec create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/factory_bot.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..608bb18 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +require 'support/factory_bot' + +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +# Prevent database truncation if the environment is production +abort('The Rails environment is running in production mode!') if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + abort e.to_s.strip +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_paths = [ + Rails.root.join('spec/fixtures') + ] + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://rspec.info/features/6-0/rspec-rails + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..327b58e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb new file mode 100644 index 0000000..690bbe6 --- /dev/null +++ b/spec/support/factory_bot.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'factory_bot' + +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods +end From 22c913a1534fb63c1eeda432a4b19b43d4deece7 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:20:38 -0300 Subject: [PATCH 13/72] Add Customer model with validations --- app/models/customer.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/models/customer.rb diff --git a/app/models/customer.rb b/app/models/customer.rb new file mode 100644 index 0000000..6be7e84 --- /dev/null +++ b/app/models/customer.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# Path: app/models/customer.rb +class Customer < ApplicationRecord + validates :name, presence: true + validates :limit, presence: true + validates :balance, presence: true +end From 474ad293d206f5f0d7bbcbfeecb69d4390fd803d Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:20:45 -0300 Subject: [PATCH 14/72] Add migration script --- bin/migration | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 bin/migration diff --git a/bin/migration b/bin/migration new file mode 100755 index 0000000..2aaf714 --- /dev/null +++ b/bin/migration @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +bundle exec rails db:migrate From 31316a6e27587ab7d2e003555bcdcfdc67c3ac21 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:21:12 -0300 Subject: [PATCH 15/72] Add customers table to schema.rb --- db/schema.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index f913998..a389119 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,8 +10,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 0) do +ActiveRecord::Schema[7.1].define(version: 20_240_302_015_845) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension 'plpgsql' + create_table 'customers', force: :cascade do |t| + t.string 'name' + t.integer 'limit', default: 0 + t.integer 'balance', default: 0 + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['balance'], name: 'index_customers_on_balance' + end end From 0c8012189dc59ee6c46f7cede771b00404b5e275 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:21:23 -0300 Subject: [PATCH 16/72] Add customer factory to spec/factories/customers.rb --- spec/factories/customers.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/factories/customers.rb diff --git a/spec/factories/customers.rb b/spec/factories/customers.rb new file mode 100644 index 0000000..54b04b0 --- /dev/null +++ b/spec/factories/customers.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :customer do + name { 'MyString' } + limit { 1 } + balance { 1 } + end +end From 487469492fc69f4d85c2d9a0df31a50f93c036ac Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:22:13 -0300 Subject: [PATCH 17/72] Add customer model tests --- spec/models/customer_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/models/customer_spec.rb diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb new file mode 100644 index 0000000..ae7e466 --- /dev/null +++ b/spec/models/customer_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Customer, type: :model do + it 'is valid with valid attributes' do + customer = Customer.new(name: 'John', limit: 1000, balance: 0) + expect(customer).to be_valid + end + + it 'is not valid without a name' do + customer = Customer.new(name: nil, limit: 1000, balance: 0) + expect(customer).to_not be_valid + end + + it 'is not valid without a limit' do + customer = Customer.new(name: 'John', limit: nil, balance: 0) + expect(customer).to_not be_valid + end + + it 'is not valid without a balance' do + customer = Customer.new(name: 'John', limit: 1000, balance: nil) + expect(customer).to_not be_valid + end +end From 59fe8a98a5a90440c3d90c9842614db73aa8d6cd Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:22:24 -0300 Subject: [PATCH 18/72] Add migration to create customers table --- db/migrate/20240302015304_create_customers.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/migrate/20240302015304_create_customers.rb diff --git a/db/migrate/20240302015304_create_customers.rb b/db/migrate/20240302015304_create_customers.rb new file mode 100644 index 0000000..74e3753 --- /dev/null +++ b/db/migrate/20240302015304_create_customers.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# CreateCustomers class +# This class is responsible for creating the customers table +# This table will store the customers' name, limit and balance +# This table will be used to store the customers' data +class CreateCustomers < ActiveRecord::Migration[7.1] + def change + create_table :customers do |t| + t.string :name + t.integer :limit, default: 0 + t.integer :balance, default: 0 + + t.timestamps + end + end +end From 401c5ba13055396133426cf78bee14bc75e76f0b Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:22:30 -0300 Subject: [PATCH 19/72] Add index for balance column in customers table --- .../20240302015845_add_index_balance_to_customer.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20240302015845_add_index_balance_to_customer.rb diff --git a/db/migrate/20240302015845_add_index_balance_to_customer.rb b/db/migrate/20240302015845_add_index_balance_to_customer.rb new file mode 100644 index 0000000..2d0c7e0 --- /dev/null +++ b/db/migrate/20240302015845_add_index_balance_to_customer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# AddIndexBalanceToCustomer class +class AddIndexBalanceToCustomer < ActiveRecord::Migration[7.1] + def up + add_index :customers, :balance + end + + def down + remove_index :customers, :balance + end +end From 7ad6f8e7ee873b75e6237cb68f12436e00bac14a Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:31:09 -0300 Subject: [PATCH 20/72] Add initial SQL script to truncate customer table --- db/init.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/init.sql diff --git a/db/init.sql b/db/init.sql new file mode 100644 index 0000000..b2b7395 --- /dev/null +++ b/db/init.sql @@ -0,0 +1 @@ +TRUNCATE CUSTOMER; From aae3dc465e946dd2b153d08701f0fb76250f0208 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:36:34 -0300 Subject: [PATCH 21/72] Update .gitignore to ignore all log files --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 252e0e7..ab5124d 100644 --- a/.gitignore +++ b/.gitignore @@ -59,5 +59,4 @@ build-iPhoneSimulator/ # Ignore master key for decrypting credentials and more. /config/master.key -log/development.log -log/test.log +/log/*.log From 3a3c1b4a8bbd7f90dc710b23736bde13dab6a7de Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 00:37:57 -0300 Subject: [PATCH 22/72] Add frozen_string_literal to ApplicationRecord --- app/models/application_record.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b63caeb..9112d93 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# ApplicationRecord is the base class for all models in the application. class ApplicationRecord < ActiveRecord::Base primary_abstract_class end From 2ad3d82523f49ca54e80e6a61ff23684967f5cde Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:38:24 -0300 Subject: [PATCH 23/72] Add CustomersController with index and show actions --- app/controllers/customers_controller.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/controllers/customers_controller.rb diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb new file mode 100644 index 0000000..2a2515d --- /dev/null +++ b/app/controllers/customers_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# CustomersController +class CustomersController < ApplicationController + def index + render json: { customers: }, status: :ok + end + + def show + render json: { customer: }, status: :ok + end + + private + + def customers + @customers ||= Customer.all + end + + def customer + @customer ||= Customer.find(params[:id]) + end +end From c159a385207a26e4835782bbe0a5fbf4ec14ad62 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:38:39 -0300 Subject: [PATCH 24/72] Add resource route for customers and transactions --- config/routes.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index bac6108..0cfecc0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,4 +10,9 @@ # Defines the root path route ("/") # root "posts#index" + + # Define a resource route for customers + resources :customers, only: %i[index show] do + resources :transactions, only: %i[create] + end end From ef4d60b8227d1ddd13764ff8882d3cdbf3980bb5 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:39:01 -0300 Subject: [PATCH 25/72] Add migration files for creating transactions and adding reference to customer --- db/migrate/20240302151936_create_transactions.rb | 14 ++++++++++++++ ...02152546_add_ref_customer_id_to_transactions.rb | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 db/migrate/20240302151936_create_transactions.rb create mode 100644 db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb diff --git a/db/migrate/20240302151936_create_transactions.rb b/db/migrate/20240302151936_create_transactions.rb new file mode 100644 index 0000000..d27cb4f --- /dev/null +++ b/db/migrate/20240302151936_create_transactions.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Transaction model which is used to interact with the database. +class CreateTransactions < ActiveRecord::Migration[7.1] + def change + create_table :transactions do |t| + t.integer :amount, null: false, default: 0 + t.string :type, null: false + t.text :desciption, null: false, limit: 10 + + t.timestamps + end + end +end diff --git a/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb b/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb new file mode 100644 index 0000000..0e99b51 --- /dev/null +++ b/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Transaction model which is used to interact with the database. +class AddRefCustomerIdToTransactions < ActiveRecord::Migration[7.1] + def up + add_reference :transactions, :customer, null: false, foreign_key: true + end + + def down + remove_reference :transactions, :customer + end +end From d15e99a1542c63ed6f19ab5ba29db29b8715cf66 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:41:13 -0300 Subject: [PATCH 26/72] Add empty keep files to tmp directory --- tmp/.keep | 0 tmp/pids/.keep | 0 tmp/storage/.keep | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tmp/.keep create mode 100644 tmp/pids/.keep create mode 100644 tmp/storage/.keep diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/pids/.keep b/tmp/pids/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/storage/.keep b/tmp/storage/.keep new file mode 100644 index 0000000..e69de29 From 98be68e64a4707af69a123ee717ec8ceb7690076 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:42:32 -0300 Subject: [PATCH 27/72] Delete log/development.log --- log/development.log | 232 -------------------------------------------- 1 file changed, 232 deletions(-) delete mode 100644 log/development.log diff --git a/log/development.log b/log/development.log deleted file mode 100644 index e998026..0000000 --- a/log/development.log +++ /dev/null @@ -1,232 +0,0 @@ -Started GET "/up" for 172.26.0.1 at 2024-03-01 23:41:16 +0000 - -ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory - Is the server running locally and accepting connections on that socket? -): - -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' -activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' -activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' -activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' -activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' -activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' -railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' -activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' -rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' -activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' -rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' -railties (7.1.3.2) lib/rails/engine.rb:536:in `call' -puma (6.4.2) lib/puma/configuration.rb:272:in `call' -puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' -puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' -puma (6.4.2) lib/puma/request.rb:99:in `handle_request' -puma (6.4.2) lib/puma/server.rb:464:in `process_client' -puma (6.4.2) lib/puma/server.rb:245:in `block in run' -puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' -Started GET "/up" for 172.28.0.1 at 2024-03-02 00:04:02 +0000 - -ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory - Is the server running locally and accepting connections on that socket? -): - -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' -activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' -activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' -activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' -activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' -activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' -railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' -activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' -rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' -activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' -rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' -railties (7.1.3.2) lib/rails/engine.rb:536:in `call' -puma (6.4.2) lib/puma/configuration.rb:272:in `call' -puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' -puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' -puma (6.4.2) lib/puma/request.rb:99:in `handle_request' -puma (6.4.2) lib/puma/server.rb:464:in `process_client' -puma (6.4.2) lib/puma/server.rb:245:in `block in run' -puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' -Started GET "/up" for 172.28.0.1 at 2024-03-02 00:24:04 +0000 - -ActiveRecord::ConnectionNotEstablished (connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory - Is the server running locally and accepting connections on that socket? -): - -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:80:in `rescue in new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:68:in `new_client' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:980:in `connect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:992:in `reconnect' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:685:in `block in reconnect!' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:684:in `reconnect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:788:in `verify!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:795:in `connect!' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1001:in `block in with_raw_connection' -activesupport (7.1.3.2) lib/active_support/concurrency/null_lock.rb:9:in `synchronize' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:1113:in `valid_raw_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:616:in `get_database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:374:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:70:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/schema_cache.rb:200:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract_adapter.rb:871:in `database_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb:644:in `check_version' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:678:in `new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:723:in `checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:702:in `try_to_checkout_new_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:654:in `acquire_connection' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `checkout' -activerecord (7.1.3.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `connection' -activerecord (7.1.3.2) lib/active_record/migration/pending_migration_connection.rb:8:in `establish_temporary_connection' -activerecord (7.1.3.2) lib/active_record/migration.rb:774:in `block in pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `each' -activerecord (7.1.3.2) lib/active_record/migration.rb:773:in `pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:752:in `check_pending_migrations' -activerecord (7.1.3.2) lib/active_record/migration.rb:644:in `block (2 levels) in call' -activesupport (7.1.3.2) lib/active_support/file_update_checker.rb:85:in `execute' -activerecord (7.1.3.2) lib/active_record/migration.rb:649:in `block in call' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `synchronize' -activerecord (7.1.3.2) lib/active_record/migration.rb:641:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' -activesupport (7.1.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks' -actionpack (7.1.3.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' -railties (7.1.3.2) lib/rails/rack/logger.rb:37:in `call_app' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `block in call' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `block in tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:39:in `tagged' -activesupport (7.1.3.2) lib/active_support/tagged_logging.rb:135:in `tagged' -activesupport (7.1.3.2) lib/active_support/broadcast_logger.rb:240:in `method_missing' -railties (7.1.3.2) lib/rails/rack/logger.rb:24:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/request_id.rb:28:in `call' -rack (3.0.9.1) lib/rack/runtime.rb:24:in `call' -activesupport (7.1.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events' -actionpack (7.1.3.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/static.rb:25:in `call' -rack (3.0.9.1) lib/rack/sendfile.rb:114:in `call' -actionpack (7.1.3.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call' -railties (7.1.3.2) lib/rails/engine.rb:536:in `call' -puma (6.4.2) lib/puma/configuration.rb:272:in `call' -puma (6.4.2) lib/puma/request.rb:100:in `block in handle_request' -puma (6.4.2) lib/puma/thread_pool.rb:378:in `with_force_shutdown' -puma (6.4.2) lib/puma/request.rb:99:in `handle_request' -puma (6.4.2) lib/puma/server.rb:464:in `process_client' -puma (6.4.2) lib/puma/server.rb:245:in `block in run' -puma (6.4.2) lib/puma/thread_pool.rb:155:in `block in spawn_thread' -Started GET "/up" for 172.29.0.1 at 2024-03-02 00:25:32 +0000 -  (4.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY) -  (2.9ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL) - ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC -Processing by Rails::HealthController#show as */* - Rendering html template - Rendered html template (Duration: 0.1ms | Allocations: 8) -Completed 200 OK in 57ms (Views: 33.4ms | ActiveRecord: 0.0ms | Allocations: 4972) - - From a57513bb7b01f85512d3e9624bb019fc8bcbf4b3 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:57:47 -0300 Subject: [PATCH 28/72] Add index to amount column in transactions table --- ...0240302155627_add_index_amount_to_transactions.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20240302155627_add_index_amount_to_transactions.rb diff --git a/db/migrate/20240302155627_add_index_amount_to_transactions.rb b/db/migrate/20240302155627_add_index_amount_to_transactions.rb new file mode 100644 index 0000000..0f64b45 --- /dev/null +++ b/db/migrate/20240302155627_add_index_amount_to_transactions.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Added index to the amount column in the transactions table +class AddIndexAmountToTransactions < ActiveRecord::Migration[7.1] + def up + add_index :transactions, :amount + end + + def down + remove_index :transactions, :amount + end +end From 4157ab59ddeda8ef91c7b8a0316a4290e591dfc2 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 12:58:17 -0300 Subject: [PATCH 29/72] Add transactions table to schema.rb --- db/schema.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index a389119..4bcda42 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # 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. @@ -10,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_302_015_845) do +ActiveRecord::Schema[7.1].define(version: 20_240_302_155_627) do # These are extensions that must be enabled in order to support this database enable_extension 'plpgsql' @@ -22,4 +24,17 @@ t.datetime 'updated_at', null: false t.index ['balance'], name: 'index_customers_on_balance' end + + create_table 'transactions', force: :cascade do |t| + t.integer 'amount', default: 0, null: false + t.string 'type', null: false + t.text 'desciption', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.bigint 'customer_id', null: false + t.index ['amount'], name: 'index_transactions_on_amount' + t.index ['customer_id'], name: 'index_transactions_on_customer_id' + end + + add_foreign_key 'transactions', 'customers' end From 8204a139b21d06d6627d3414d14e7176bd16f15b Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 14:56:28 -0300 Subject: [PATCH 30/72] Add dependency on blackpearl-db in docker-compose.yml --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 9e42dbc..8e5f965 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,6 +37,8 @@ services: volumes: - .:/app env_file: .env + depends_on: + - blackpearl-db networks: - dev entrypoint: ["/bin/bash", "-c", "bin/migration"] From 4bb2eda5c6964ab59e24f86cfc9985f8655ab446 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 14:56:39 -0300 Subject: [PATCH 31/72] Add shoulda-matchers gem --- Gemfile | 3 +++ Gemfile.lock | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Gemfile b/Gemfile index 0733cc7..7cec9ee 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' ruby '3.2.3' @@ -22,4 +24,5 @@ group :development, :test do gem 'rubocop-rails', '~> 2.23.1' gem 'rubocop-rspec', '~> 2.27.0' gem 'rubocop-shopify', '~> 2.15.1' + gem 'shoulda-matchers', '~> 5.3' end diff --git a/Gemfile.lock b/Gemfile.lock index a54d7c5..55000a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -246,6 +246,8 @@ GEM rubocop-shopify (2.15.1) rubocop (~> 1.51) ruby-progressbar (1.13.0) + shoulda-matchers (5.3.0) + activesupport (>= 5.2.0) stringio (3.1.0) thor (1.3.1) timeout (0.4.1) @@ -282,6 +284,7 @@ DEPENDENCIES rubocop-rails (~> 2.23.1) rubocop-rspec (~> 2.27.0) rubocop-shopify (~> 2.15.1) + shoulda-matchers (~> 5.3) tzinfo-data (~> 1.2024, >= 1.2024.1) RUBY VERSION From 829cf7d7a724c22183d5a64a7ddb938abe85616c Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 14:57:54 -0300 Subject: [PATCH 32/72] Fix typo in transaction table column name --- db/migrate/20240302151936_create_transactions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20240302151936_create_transactions.rb b/db/migrate/20240302151936_create_transactions.rb index d27cb4f..d053823 100644 --- a/db/migrate/20240302151936_create_transactions.rb +++ b/db/migrate/20240302151936_create_transactions.rb @@ -6,7 +6,7 @@ def change create_table :transactions do |t| t.integer :amount, null: false, default: 0 t.string :type, null: false - t.text :desciption, null: false, limit: 10 + t.text :description, null: false, limit: 10 t.timestamps end From 1ba720266adfa8cfa9047dfa89343e0a477fc7a9 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 14:58:05 -0300 Subject: [PATCH 33/72] Add Shoulda Matchers configuration to rails_helper.rb --- spec/rails_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 608bb18..ffd4c77 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -33,6 +33,7 @@ rescue ActiveRecord::PendingMigrationError => e abort e.to_s.strip end + RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_paths = [ @@ -66,4 +67,11 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + Shoulda::Matchers.configure do |c| + c.integrate do |with| + with.test_framework :rspec + with.library :rails + end + end end From 0b4a66296d2e9d7beb8ceb3ac8ee50b91490ba75 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:57:00 -0300 Subject: [PATCH 34/72] Add has_many association and update validations for Customer model --- app/models/customer.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 6be7e84..f6f3320 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,7 +2,9 @@ # Path: app/models/customer.rb class Customer < ApplicationRecord + has_many :transactions + validates :name, presence: true - validates :limit, presence: true - validates :balance, presence: true + validates :limit, presence: true, numericality: { greater_than: 0 } + validates :balance, presence: true, numericality: true end From a666ea7b67e67270d226906946095e3614b9d88e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:57:10 -0300 Subject: [PATCH 35/72] Add Transaction model with validations --- app/models/transaction.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/models/transaction.rb diff --git a/app/models/transaction.rb b/app/models/transaction.rb new file mode 100644 index 0000000..83460f1 --- /dev/null +++ b/app/models/transaction.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Transaction model which is used to interact with the database. +class Transaction < ApplicationRecord + belongs_to :customer + + validates :amount, presence: true, numericality: { greater_than: 0 } + validates :type, presence: true, inclusion: { in: %w[c d] } + validates :description, presence: true, length: { maximum: 10 } +end From 896c9667bfc9795a77414d0f8f4623700fe36c45 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:58:03 -0300 Subject: [PATCH 36/72] Update customer factory to use Faker and SecureRandom --- spec/factories/customers.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/factories/customers.rb b/spec/factories/customers.rb index 54b04b0..3ca18be 100644 --- a/spec/factories/customers.rb +++ b/spec/factories/customers.rb @@ -1,7 +1,10 @@ +# frozen_string_literal: true + +# customer FactoryBot.define do factory :customer do - name { 'MyString' } - limit { 1 } - balance { 1 } + name { Faker::Name.name } + limit { SecureRandom.random_number(10_000) } + balance { SecureRandom.random_number(10_000) } end end From 206ac0a6602f5a4dc24be28ecafa8e7b86c26011 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:58:12 -0300 Subject: [PATCH 37/72] Add transaction factory to spec/factories/transactions.rb --- spec/factories/transactions.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 spec/factories/transactions.rb diff --git a/spec/factories/transactions.rb b/spec/factories/transactions.rb new file mode 100644 index 0000000..fdcf5f7 --- /dev/null +++ b/spec/factories/transactions.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# transaction +FactoryBot.define do + factory :transaction do + amount { SecureRandom.random_number(100) } + type { %w[c d].sample } + desciption { 'transaction' } + end +end From ce5b66f165928bee2199f597fe7874950cad5826 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:58:20 -0300 Subject: [PATCH 38/72] Add validation tests for Customer model --- spec/models/customer_spec.rb | 39 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index ae7e466..94b6fd4 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -3,23 +3,38 @@ require 'rails_helper' RSpec.describe Customer, type: :model do - it 'is valid with valid attributes' do - customer = Customer.new(name: 'John', limit: 1000, balance: 0) - expect(customer).to be_valid + let(:customer) { Customer.new } + + it { should have_many(:transactions) } + it { should validate_presence_of(:name) } + it { should validate_presence_of(:limit) } + it { should validate_presence_of(:balance) } + + it 'should validate the presence of the name' do + customer.name = nil + + customer.valid? + expect(customer.errors[:name]).to include("can't be blank") end - it 'is not valid without a name' do - customer = Customer.new(name: nil, limit: 1000, balance: 0) - expect(customer).to_not be_valid + it 'should validate the presence of the limit' do + customer.limit = -1 + + customer.valid? + expect(customer.errors[:limit]).to include('must be greater than 0') end - it 'is not valid without a limit' do - customer = Customer.new(name: 'John', limit: nil, balance: 0) - expect(customer).to_not be_valid + it 'should validate the presence of the limit' do + customer.limit = 'string' + + customer.valid? + expect(customer.errors[:limit]).to include('is not a number') end - it 'is not valid without a balance' do - customer = Customer.new(name: 'John', limit: 1000, balance: nil) - expect(customer).to_not be_valid + it 'should validate the presence of the balance' do + customer.balance = 'string' + + customer.valid? + expect(customer.errors[:balance]).to include('is not a number') end end From 955ee0329c859432d0ac1e7d869221860e2f6c1e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 15:58:33 -0300 Subject: [PATCH 39/72] Add Transaction model tests --- spec/models/transaction_spec.rb | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/models/transaction_spec.rb diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb new file mode 100644 index 0000000..8207bea --- /dev/null +++ b/spec/models/transaction_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Transaction, type: :model do + let(:transaction) { Transaction.new } + + it { should belong_to(:customer) } + it { should validate_presence_of(:amount) } + it { should validate_numericality_of(:amount).is_greater_than(0) } + it { should validate_presence_of(:type) } + it { should validate_inclusion_of(:type).in_array(%w[c d]) } + it { should validate_presence_of(:description) } + + it 'should validate the presence of the customer' do + transaction.valid? + expect(transaction.errors[:customer]).to include('must exist') + end + + it 'should validate the presence of the amount' do + transaction.valid? + expect(transaction.errors[:amount]).to include('must be greater than 0') + end + + it 'should validate the presence of the type' do + transaction.valid? + expect(transaction.errors[:type]).to include('is not included in the list') + end + + it 'should validate the presence of the description' do + transaction.valid? + expect(transaction.errors[:description]).to include("can't be blank") + end + + it 'should validate the description length' do + transaction.description = 'a' * 11 + + transaction.valid? + expect(transaction.errors[:description]).to include('is too long (maximum is 10 characters)') + end +end From 9d411c8752075ac878fb1fa3bf193aebfc8c4fb5 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:06:36 -0300 Subject: [PATCH 40/72] Update config.ru to use single quotes and add frozen_string_literal directive --- config.ru | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 54d681779e1c37b1b710456ebcf191141f68aa7e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:06:45 -0300 Subject: [PATCH 41/72] Add RuboCop extensions and disable Metrics/BlockLength rule --- .rubocop.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index b934698..59cb41c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,10 @@ +--- + +require: + - rubocop-rails + - rubocop-performance + - rubocop-rspec + - rubocop-factory_bot Metrics/BlockLength: Enabled: false From 85339114f4afedc2b0174595b514515a8350ca20 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:06:54 -0300 Subject: [PATCH 42/72] Update Rakefile to use single quotes and add frozen_string_literal directive --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From fe11bda1077f4e4830064c0e4b9d9f3f80d5dcbf Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:07:04 -0300 Subject: [PATCH 43/72] Add frozen_string_literal: true to channel.rb --- app/channels/application_cable/channel.rb | 2 ++ 1 file changed, 2 insertions(+) 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 From 4b7947a4be73bce88e38820a8bb5541037288432 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:07:12 -0300 Subject: [PATCH 44/72] Add frozen_string_literal directive to connection.rb --- app/channels/application_cable/connection.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end From b6baa9eff373baa69e0916e783aec66198c61d2d Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:08:18 -0300 Subject: [PATCH 45/72] Add frozen_string_literal directive to ApplicationController --- app/controllers/application_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4ac8823..13c271f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::API end From bda786a6f68c423cbd1bbb90194c0687fece6578 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:08:49 -0300 Subject: [PATCH 46/72] Add frozen string literal comment to files --- app/jobs/application_job.rb | 2 ++ app/mailers/application_mailer.rb | 6 ++++-- config/environment.rb | 4 +++- config/environments/test.rb | 8 +++++--- config/initializers/cors.rb | 1 + 5 files changed, 15 insertions(+), 6 deletions(-) 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/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/test.rb b/config/environments/test.rb index adbb4a6..f1d2fb5 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,12 +17,12 @@ # 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.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 0c5dd99..ce5b71a 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. From 72600d834d9bd0a865dc98e23c0f981b30e15ab9 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:09:21 -0300 Subject: [PATCH 47/72] Update filter_parameter_logging.rb to include additional sensitive parameters --- config/initializers/filter_parameter_logging.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c2d89e2..c416e6a 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, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] From 7c3c2e446bc15ed6caebf94cc5b76656052a6251 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:09:57 -0300 Subject: [PATCH 48/72] Add frozen_string_literal: true to files --- config/initializers/inflections.rb | 1 + db/seeds.rb | 1 + spec/spec_helper.rb | 94 +++++++++---------- .../application_cable/connection_test.rb | 4 +- test/test_helper.rb | 8 +- 5 files changed, 57 insertions(+), 51 deletions(-) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f65..6c78420 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed..07b11e8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# 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). diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 327b58e..409c64b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -44,51 +46,49 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb index 6340bf9..4aee9b3 100644 --- a/test/channels/application_cable/connection_test.rb +++ b/test/channels/application_cable/connection_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' module ApplicationCable class ConnectionTest < ActionCable::Connection::TestCase diff --git a/test/test_helper.rb b/test/test_helper.rb index 0c22470..0c92e8e 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 From 9f3a6ce7845af4301777d7c2210f8ebeab98c847 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:10:18 -0300 Subject: [PATCH 49/72] Refactor customer_spec.rb to use is_expected syntax --- spec/models/customer_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 94b6fd4..7670f0b 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -3,35 +3,35 @@ require 'rails_helper' RSpec.describe Customer, type: :model do - let(:customer) { Customer.new } + let(:customer) { described_class.new } - it { should have_many(:transactions) } - it { should validate_presence_of(:name) } - it { should validate_presence_of(:limit) } - it { should validate_presence_of(:balance) } + it { is_expected.to have_many(:transactions) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_presence_of(:limit) } + it { is_expected.to validate_presence_of(:balance) } - it 'should validate the presence of the name' do + it 'validates the presence of the name' do customer.name = nil customer.valid? expect(customer.errors[:name]).to include("can't be blank") end - it 'should validate the presence of the limit' do + it 'validates limit is greater than 0' do customer.limit = -1 customer.valid? expect(customer.errors[:limit]).to include('must be greater than 0') end - it 'should validate the presence of the limit' do + it 'validates limit is not a string' do customer.limit = 'string' customer.valid? expect(customer.errors[:limit]).to include('is not a number') end - it 'should validate the presence of the balance' do + it 'validates balance is not a string' do customer.balance = 'string' customer.valid? From 7de41d12c54da3af2b572d0b0c2fa83221d41d7e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:10:25 -0300 Subject: [PATCH 50/72] Refactor transaction_spec.rb to use is_expected.to syntax --- spec/models/transaction_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb index 8207bea..af633ad 100644 --- a/spec/models/transaction_spec.rb +++ b/spec/models/transaction_spec.rb @@ -3,36 +3,36 @@ require 'rails_helper' RSpec.describe Transaction, type: :model do - let(:transaction) { Transaction.new } + let(:transaction) { described_class.new } - it { should belong_to(:customer) } - it { should validate_presence_of(:amount) } - it { should validate_numericality_of(:amount).is_greater_than(0) } - it { should validate_presence_of(:type) } - it { should validate_inclusion_of(:type).in_array(%w[c d]) } - it { should validate_presence_of(:description) } + it { is_expected.to belong_to(:customer) } + it { is_expected.to validate_presence_of(:amount) } + it { is_expected.to validate_numericality_of(:amount).is_greater_than(0) } + it { is_expected.to validate_presence_of(:type) } + it { is_expected.to validate_inclusion_of(:type).in_array(%w[c d]) } + it { is_expected.to validate_presence_of(:description) } - it 'should validate the presence of the customer' do + it 'validates the presence of the customer' do transaction.valid? expect(transaction.errors[:customer]).to include('must exist') end - it 'should validate the presence of the amount' do + it 'validates the presence of the amount' do transaction.valid? expect(transaction.errors[:amount]).to include('must be greater than 0') end - it 'should validate the presence of the type' do + it 'validates the presence of the type' do transaction.valid? expect(transaction.errors[:type]).to include('is not included in the list') end - it 'should validate the presence of the description' do + it 'validates the presence of the description' do transaction.valid? expect(transaction.errors[:description]).to include("can't be blank") end - it 'should validate the description length' do + it 'validates the description length' do transaction.description = 'a' * 11 transaction.valid? From a6c9eed5a47d70c5254a3a428566222caf4d1bee Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:24:56 -0300 Subject: [PATCH 51/72] Add ApplicationMailer class --- app/mailers/application_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index d84cb6e..529126a 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# ApplicationMailer class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' From 800ee8bf69e72c241705d8c9b317590ac431a205 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:25:01 -0300 Subject: [PATCH 52/72] Update has_many association in Customer model --- app/models/customer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index f6f3320..5248109 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,7 +2,7 @@ # Path: app/models/customer.rb class Customer < ApplicationRecord - has_many :transactions + has_many :transactions, dependent: :destroy validates :name, presence: true validates :limit, presence: true, numericality: { greater_than: 0 } From 05ee9f236306de219a338b2f4461a9f24edb52e0 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:29:51 -0300 Subject: [PATCH 53/72] Enable NewCops in .rubocop.yml --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 59cb41c..e1ded92 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ --- +AllCops: + NewCops: enable + require: - rubocop-rails - rubocop-performance From 76f17458137983b302147179f84a4e33f3f72e62 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:30:00 -0300 Subject: [PATCH 54/72] Update schema.rb with new version and table definitions --- db/schema.rb | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 4bcda42..0a00506 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # 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. @@ -12,29 +10,29 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_302_155_627) do +ActiveRecord::Schema[7.1].define(version: 2024_03_02_155627) do # These are extensions that must be enabled in order to support this database - enable_extension 'plpgsql' + enable_extension "plpgsql" - create_table 'customers', force: :cascade do |t| - t.string 'name' - t.integer 'limit', default: 0 - t.integer 'balance', default: 0 - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['balance'], name: 'index_customers_on_balance' + create_table "customers", force: :cascade do |t| + t.string "name" + t.integer "limit", default: 0 + t.integer "balance", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["balance"], name: "index_customers_on_balance" end - create_table 'transactions', force: :cascade do |t| - t.integer 'amount', default: 0, null: false - t.string 'type', null: false - t.text 'desciption', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.bigint 'customer_id', null: false - t.index ['amount'], name: 'index_transactions_on_amount' - t.index ['customer_id'], name: 'index_transactions_on_customer_id' + create_table "transactions", force: :cascade do |t| + t.integer "amount", default: 0, null: false + t.string "type", null: false + t.text "description", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "customer_id", default: 1, null: false + t.index ["amount"], name: "index_transactions_on_amount" + t.index ["customer_id"], name: "index_transactions_on_customer_id" end - add_foreign_key 'transactions', 'customers' + add_foreign_key "transactions", "customers" end From b8413936c04712e84dbd2464ed8eecd9c7f8e45b Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:30:06 -0300 Subject: [PATCH 55/72] Add default value for customer reference in transactions table --- .../20240302152546_add_ref_customer_id_to_transactions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb b/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb index 0e99b51..78f4b1b 100644 --- a/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb +++ b/db/migrate/20240302152546_add_ref_customer_id_to_transactions.rb @@ -3,7 +3,7 @@ # Transaction model which is used to interact with the database. class AddRefCustomerIdToTransactions < ActiveRecord::Migration[7.1] def up - add_reference :transactions, :customer, null: false, foreign_key: true + add_reference :transactions, :customer, null: false, default: 1, foreign_key: true end def down From c6c48c8893a9f34b9cb9daed877f40be8fe126fd Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:30:40 -0300 Subject: [PATCH 56/72] Refactor routes_reloader paths in application.rb --- config/application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/application.rb b/config/application.rb index f21fbde..36ea8e3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -33,8 +33,8 @@ class Application < Rails::Application config.api_only = true initializer(:remove_action_mailbox_and_activestorage_routes, after: :add_routing_paths) do |app| - app.routes_reloader.paths.delete_if { |path| path =~ /activestorage/ } - app.routes_reloader.paths.delete_if { |path| path =~ /actionmailbox/ } + app.routes_reloader.paths.delete_if { |path| path.include?('activestorage') } + app.routes_reloader.paths.delete_if { |path| path.include?('actionmailbox') } end end end From 16e6738ae12fb155012257cebd356263edf2b83b Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:30:50 -0300 Subject: [PATCH 57/72] Update logger formatter in production environment --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 7d108c0..f7d6ee1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -48,7 +48,7 @@ # Log to STDOUT by default config.logger = ActiveSupport::Logger.new($stdout) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .tap { |logger| logger.formatter = Logger::Formatter.new } .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. From fdcc478acbd0885fc14b3e9b69d0aa846843e3e4 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:31:10 -0300 Subject: [PATCH 58/72] Refactor model specs --- spec/models/customer_spec.rb | 2 +- spec/models/transaction_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 7670f0b..00848f6 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe Customer, type: :model do +RSpec.describe Customer do let(:customer) { described_class.new } it { is_expected.to have_many(:transactions) } diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb index af633ad..eb72dba 100644 --- a/spec/models/transaction_spec.rb +++ b/spec/models/transaction_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe Transaction, type: :model do +RSpec.describe Transaction do let(:transaction) { described_class.new } it { is_expected.to belong_to(:customer) } From f3a81151eaf38ffb853ef4834fd540aca061fb2d Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sat, 2 Mar 2024 16:33:22 -0300 Subject: [PATCH 59/72] Fix validation for customer presence --- spec/models/transaction_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb index eb72dba..7778d36 100644 --- a/spec/models/transaction_spec.rb +++ b/spec/models/transaction_spec.rb @@ -13,6 +13,8 @@ it { is_expected.to validate_presence_of(:description) } it 'validates the presence of the customer' do + transaction.customer_id = nil + transaction.valid? expect(transaction.errors[:customer]).to include('must exist') end From 4777f04fe32d370817b037e71c460faabc1e7ae7 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 11:08:03 -0300 Subject: [PATCH 60/72] Add www.example.com to allowed hosts in development environment --- config/environments/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index d9f9d4a..d19adb3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -5,7 +5,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - config.hosts += [/.*\.localhost/, 'localhost'] + config.hosts += [/.*\.localhost/, 'localhost', 'www.example.com'] # Assume all access to the app is happening through a SSL-terminating reverse proxy. # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. From 1957b7f3dcbf16ab49a4fc8ef8d138b20ef03712 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 11:08:09 -0300 Subject: [PATCH 61/72] Disable Metrics/BlockLength and RSpec/MultipleExpectations in .rubocop.yml --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index e1ded92..4d10653 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,6 @@ require: Metrics/BlockLength: Enabled: false + +RSpec/MultipleExpectations: + Enabled: false From beb915f8fa402575819407904f7761614afe2b02 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 11:41:35 -0300 Subject: [PATCH 62/72] Disable RSpec/ExampleLength cop in .rubocop.yml --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 4d10653..8736762 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,3 +14,6 @@ Metrics/BlockLength: RSpec/MultipleExpectations: Enabled: false + +RSpec/ExampleLength: + Enabled: false From d721e1046df005f302a13607c4170507f22fd511 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 11:47:14 -0300 Subject: [PATCH 63/72] Add customer request specs --- spec/requests/customers_spec.rb | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/requests/customers_spec.rb diff --git a/spec/requests/customers_spec.rb b/spec/requests/customers_spec.rb new file mode 100644 index 0000000..57d3d9b --- /dev/null +++ b/spec/requests/customers_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'GET - /customers' do + let(:url) { '/customers' } + + context 'when there are customers' do + it 'returns a list of customers' do + customers = create_list(:customer, 10) + + get(url) + + response_body = response.parsed_body['customers'] + + expect(response).to have_http_status(:ok) + expect(response_body.count).to eq(10) + expect(response_body.first.keys).to match_array(customers.first.attributes.keys) + end + + it 'returns a single customer' do + customer = create(:customer) + + get("#{url}/#{customer.id}") + + response_body = response.parsed_body['customer'] + + expect(response).to have_http_status(:ok) + expect(response_body.keys).to match_array(customer.attributes.keys) + end + + it 'returns attributes for a single customer' do + customer = create(:customer) + + get("#{url}/#{customer.id}") + + response_body = response.parsed_body['customer'] + + expect(response_body.keys).to match_array(customer.attributes.keys) + expect(response_body['id']).to eq(customer.id) + expect(response_body['name']).to eq(customer.name) + expect(response_body['limit']).to eq(customer.limit) + expect(response_body['balance']).to eq(customer.balance) + end + end + + context 'when there are no customers' do + it 'returns an empty list' do + get(url) + + expect(response).to have_http_status(:ok) + expect(response.body).to eq('{"customers":[]}') + end + + it 'returns a 404' do + get("#{url}/1") + + expect(response).to have_http_status(:not_found) + end + end + + context 'when there is an error' do + it 'returns a 500' do + allow(Customer).to receive(:all).and_raise(StandardError) + + get(url) + + expect(response).to have_http_status(:internal_server_error) + end + end +end From 02ec2c7be7390917f2db1a3d5816488baad8e306 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 12:28:06 -0300 Subject: [PATCH 64/72] Add unit test workflow configuration --- .github/workflows/unit_tests.yml | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/unit_tests.yml diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..d782030 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,64 @@ +--- +name: Unit Tests + +on: + push: + branches: + - main + - development + pull_request: + branches: + - main + - development + +jobs: + rspec: + name: Unit Tests with RSepc + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + env: + RAILS_ENV: development + RAILS_MAX_THREADS: 2 + WEB_CONCURRENCY: 2 + PGPASSFILE: /app/.pgpass + POSTGRES_PASSWORD: ephermeral_exists_during_tests + POSTGRES_USER: admin + POSTGRES_DB: blackpearl + POSTGRES_PORT: '5432' + POSTGRES_MAX_CONNECTIONS: '30' + POSTGRES_RANDOM_PAGE_COST: '1.1' + POSTGRES_EFFECTIVE_IO_CONCURRENCY: '30' + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: admin + POSTGRES_PASSWORD: ephermeral_exists_during_tests + POSTGRES_DB: blackpearl + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 3 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Dependences + run: | + sudo apt-get update -y + sudo apt-get install -y libpq-dev postgresql-client build-essential libssl-dev + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.0 + + - name: Bundle Install + run: bundle install + + - name: Database Setup + run: bundle exec rails db:migrate + + - name: Run RSpec + run: bundle exec rspec From 72f8054e97ed414b621cb4daa6f6c426e7e62527 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 12:29:54 -0300 Subject: [PATCH 65/72] Update Ruby version to 3.2.3 --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index d782030..10bf729 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -52,7 +52,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.0 + ruby-version: 3.2.3 - name: Bundle Install run: bundle install From 6f10d05564168206c6106e98fc004e5a3d95b20e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 12:32:01 -0300 Subject: [PATCH 66/72] Add POSTGRES_HOST environment variable to unit_tests.yml --- .github/workflows/unit_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 10bf729..c67db8d 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -34,6 +34,7 @@ jobs: postgres: image: postgres:latest env: + POSTGRES_HOST: postgres POSTGRES_USER: admin POSTGRES_PASSWORD: ephermeral_exists_during_tests POSTGRES_DB: blackpearl From f18917d735c41f1be5871a4e1b9d8005aacb0bae Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 12:34:46 -0300 Subject: [PATCH 67/72] Add POSTGRES_HOST to unit tests workflow --- .github/workflows/unit_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index c67db8d..a7d2bfd 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -25,6 +25,7 @@ jobs: PGPASSFILE: /app/.pgpass POSTGRES_PASSWORD: ephermeral_exists_during_tests POSTGRES_USER: admin + POSTGRES_HOST: postgres POSTGRES_DB: blackpearl POSTGRES_PORT: '5432' POSTGRES_MAX_CONNECTIONS: '30' From 20faf50ca3b01a60c74a2c684813bcab65ef2c5c Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 13:01:09 -0300 Subject: [PATCH 68/72] Update unit_tests.yml and database.yml --- .github/workflows/unit_tests.yml | 18 ++++++++++-------- config/database.yml | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index a7d2bfd..a5925e6 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -22,23 +22,23 @@ jobs: RAILS_ENV: development RAILS_MAX_THREADS: 2 WEB_CONCURRENCY: 2 - PGPASSFILE: /app/.pgpass - POSTGRES_PASSWORD: ephermeral_exists_during_tests - POSTGRES_USER: admin POSTGRES_HOST: postgres - POSTGRES_DB: blackpearl POSTGRES_PORT: '5432' - POSTGRES_MAX_CONNECTIONS: '30' - POSTGRES_RANDOM_PAGE_COST: '1.1' - POSTGRES_EFFECTIVE_IO_CONCURRENCY: '30' + POSTGRES_USER: admin + POSTGRES_PASSWORD: ephermeral_exists_during_tests + POSTGRES_DB: blackpearl services: postgres: image: postgres:latest env: POSTGRES_HOST: postgres + POSTGRES_PORT: '5432' POSTGRES_USER: admin POSTGRES_PASSWORD: ephermeral_exists_during_tests POSTGRES_DB: blackpearl + POSTGRES_MAX_CONNECTIONS: '30' + POSTGRES_RANDOM_PAGE_COST: '1.1' + POSTGRES_EFFECTIVE_IO_CONCURRENCY: '30' ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 3 @@ -60,7 +60,9 @@ jobs: run: bundle install - name: Database Setup - run: bundle exec rails db:migrate + run: | + bundle exec rails db:setup + bundle exec rails db:migrate - name: Run RSpec run: bundle exec rspec diff --git a/config/database.yml b/config/database.yml index 5cc82fa..0509cbe 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,8 +20,8 @@ default: &default pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: <%= ENV.fetch("POSTGRES_USER") %> password: <%= ENV.fetch("POSTGRES_PASSWORD") %> - host: <%= ENV.fetch("POSTGRES_HOST") %> - port: <%= ENV.fetch("POSTGRES_PORT") %> + host: <%= ENV.fetch("POSTGRES_HOST", 'postgres') %> + port: <%= ENV.fetch("POSTGRES_PORT", 5432) %> development: <<: *default From 4732b33996dca37a25fb59ffd6c3ebdfbc6ebfa5 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 13:05:10 -0300 Subject: [PATCH 69/72] Update database configuration to use localhost as the PostgreSQL host --- .github/workflows/unit_tests.yml | 5 ++--- config/database.yml | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index a5925e6..9784264 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -22,7 +22,7 @@ jobs: RAILS_ENV: development RAILS_MAX_THREADS: 2 WEB_CONCURRENCY: 2 - POSTGRES_HOST: postgres + POSTGRES_HOST: localhost POSTGRES_PORT: '5432' POSTGRES_USER: admin POSTGRES_PASSWORD: ephermeral_exists_during_tests @@ -31,7 +31,7 @@ jobs: postgres: image: postgres:latest env: - POSTGRES_HOST: postgres + POSTGRES_HOST: localhost POSTGRES_PORT: '5432' POSTGRES_USER: admin POSTGRES_PASSWORD: ephermeral_exists_during_tests @@ -61,7 +61,6 @@ jobs: - name: Database Setup run: | - bundle exec rails db:setup bundle exec rails db:migrate - name: Run RSpec diff --git a/config/database.yml b/config/database.yml index 0509cbe..5cc82fa 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,8 +20,8 @@ default: &default pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: <%= ENV.fetch("POSTGRES_USER") %> password: <%= ENV.fetch("POSTGRES_PASSWORD") %> - host: <%= ENV.fetch("POSTGRES_HOST", 'postgres') %> - port: <%= ENV.fetch("POSTGRES_PORT", 5432) %> + host: <%= ENV.fetch("POSTGRES_HOST") %> + port: <%= ENV.fetch("POSTGRES_PORT") %> development: <<: *default From b918df56b5e9788ac3a40f79986d13352accb614 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 13:15:19 -0300 Subject: [PATCH 70/72] Update unit_tests.yml to use secrets for PostgreSQL credentials --- .github/workflows/unit_tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 9784264..819c669 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -24,18 +24,18 @@ jobs: WEB_CONCURRENCY: 2 POSTGRES_HOST: localhost POSTGRES_PORT: '5432' - POSTGRES_USER: admin - POSTGRES_PASSWORD: ephermeral_exists_during_tests - POSTGRES_DB: blackpearl + POSTGRES_USER: "{{ secrets.POSTGRES_USER }}" + POSTGRES_PASSWORD: "{{ secrets.POSTGRES_PASSWORD }}" + POSTGRES_DB: "{{ secrets.POSTGRES_DB }}" services: postgres: image: postgres:latest env: POSTGRES_HOST: localhost POSTGRES_PORT: '5432' - POSTGRES_USER: admin - POSTGRES_PASSWORD: ephermeral_exists_during_tests - POSTGRES_DB: blackpearl + POSTGRES_USER: "{{ secrets.POSTGRES_USER }}" + POSTGRES_PASSWORD: "{{ secrets.POSTGRES_PASSWORD }}" + POSTGRES_DB: "{{ secrets.POSTGRES_DB }}" POSTGRES_MAX_CONNECTIONS: '30' POSTGRES_RANDOM_PAGE_COST: '1.1' POSTGRES_EFFECTIVE_IO_CONCURRENCY: '30' From f182440078236deb773a498cc78e2c6b9773765e Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 13:18:54 -0300 Subject: [PATCH 71/72] Update secrets in unit_tests.yml --- .github/workflows/unit_tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 819c669..866e7bf 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -24,18 +24,18 @@ jobs: WEB_CONCURRENCY: 2 POSTGRES_HOST: localhost POSTGRES_PORT: '5432' - POSTGRES_USER: "{{ secrets.POSTGRES_USER }}" - POSTGRES_PASSWORD: "{{ secrets.POSTGRES_PASSWORD }}" - POSTGRES_DB: "{{ secrets.POSTGRES_DB }}" + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + POSTGRES_DB: ${{ secrets.POSTGRES_DB }} services: postgres: image: postgres:latest env: POSTGRES_HOST: localhost POSTGRES_PORT: '5432' - POSTGRES_USER: "{{ secrets.POSTGRES_USER }}" - POSTGRES_PASSWORD: "{{ secrets.POSTGRES_PASSWORD }}" - POSTGRES_DB: "{{ secrets.POSTGRES_DB }}" + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + POSTGRES_DB: ${{ secrets.POSTGRES_DB }} POSTGRES_MAX_CONNECTIONS: '30' POSTGRES_RANDOM_PAGE_COST: '1.1' POSTGRES_EFFECTIVE_IO_CONCURRENCY: '30' From af44d26386820a9c26e8ca3d30286758c590b913 Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Sun, 3 Mar 2024 13:29:35 -0300 Subject: [PATCH 72/72] Add Brakeman and RSpec workflows --- .github/workflows/brakeman.yml | 46 +++++++++++++++++++ .../workflows/{unit_tests.yml => rspec.yml} | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/brakeman.yml rename .github/workflows/{unit_tests.yml => rspec.yml} (99%) diff --git a/.github/workflows/brakeman.yml b/.github/workflows/brakeman.yml new file mode 100644 index 0000000..883f2e0 --- /dev/null +++ b/.github/workflows/brakeman.yml @@ -0,0 +1,46 @@ +--- + +name: Brakeman + +on: + push: + branches: + - main + - development + pull_request: + branches: + - main + - development + +jobs: + brakeman: + name: Brakeman Security Scan + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Dependences + run: | + sudo apt-get update -y + sudo apt-get install -y libpq-dev postgresql-client build-essential libssl-dev + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.3 + + - name: Bundle Install + run: bundle install + + - name: Brakeman Security Scan + run: brakeman -z -o brakeman-output.json + + - name: Upload Brakeman Report + uses: actions/upload-artifact@v2 + with: + name: brakeman-report + path: brakeman-output.json diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/rspec.yml similarity index 99% rename from .github/workflows/unit_tests.yml rename to .github/workflows/rspec.yml index 866e7bf..ce9c7bc 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/rspec.yml @@ -1,5 +1,5 @@ --- -name: Unit Tests +name: RSpec on: push: