From 871248ef7ed3f74d61fbdf91154e9df488fc22cd Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Tue, 3 May 2022 16:22:51 -0400 Subject: [PATCH 1/8] init repo --- .idea/.gitignore | 8 ++ .idea/desafio-dev.iml | 15 +++ .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 7 ++ billing/.gitattributes | 7 ++ billing/.gitignore | 31 +++++++ billing/.ruby-version | 1 + billing/Gemfile | 72 ++++++++++++++ billing/README.md | 24 +++++ billing/Rakefile | 6 ++ billing/app/assets/config/manifest.js | 2 + billing/app/assets/images/.keep | 0 .../app/assets/stylesheets/application.css | 15 +++ .../app/channels/application_cable/channel.rb | 4 + .../channels/application_cable/connection.rb | 4 + .../app/controllers/application_controller.rb | 2 + billing/app/controllers/concerns/.keep | 0 billing/app/helpers/application_helper.rb | 2 + billing/app/jobs/application_job.rb | 7 ++ billing/app/mailers/application_mailer.rb | 4 + billing/app/models/application_record.rb | 3 + billing/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 15 +++ billing/app/views/layouts/mailer.html.erb | 13 +++ billing/app/views/layouts/mailer.text.erb | 1 + billing/bin/rails | 4 + billing/bin/rake | 4 + billing/bin/setup | 33 +++++++ billing/config.ru | 6 ++ billing/config/application.rb | 22 +++++ billing/config/boot.rb | 4 + billing/config/cable.yml | 10 ++ billing/config/credentials.yml.enc | 1 + billing/config/database.yml | 86 +++++++++++++++++ billing/config/environment.rb | 5 + billing/config/environments/development.rb | 70 ++++++++++++++ billing/config/environments/production.rb | 93 +++++++++++++++++++ billing/config/environments/test.rb | 60 ++++++++++++ billing/config/initializers/assets.rb | 12 +++ .../initializers/content_security_policy.rb | 26 ++++++ .../initializers/filter_parameter_logging.rb | 8 ++ billing/config/initializers/inflections.rb | 16 ++++ .../config/initializers/permissions_policy.rb | 11 +++ billing/config/locales/en.yml | 33 +++++++ billing/config/puma.rb | 43 +++++++++ billing/config/routes.rb | 6 ++ billing/config/storage.yml | 34 +++++++ billing/db/seeds.rb | 7 ++ billing/lib/assets/.keep | 0 billing/lib/tasks/.keep | 0 billing/log/.keep | 0 billing/public/404.html | 67 +++++++++++++ billing/public/422.html | 67 +++++++++++++ billing/public/500.html | 66 +++++++++++++ .../public/apple-touch-icon-precomposed.png | 0 billing/public/apple-touch-icon.png | 0 billing/public/favicon.ico | 0 billing/public/robots.txt | 1 + billing/storage/.keep | 0 billing/test/application_system_test_case.rb | 5 + .../application_cable/connection_test.rb | 11 +++ billing/test/controllers/.keep | 0 billing/test/fixtures/files/.keep | 0 billing/test/helpers/.keep | 0 billing/test/integration/.keep | 0 billing/test/mailers/.keep | 0 billing/test/models/.keep | 0 billing/test/system/.keep | 0 billing/test/test_helper.rb | 13 +++ billing/tmp/.keep | 0 billing/tmp/pids/.keep | 0 billing/tmp/storage/.keep | 0 billing/vendor/.keep | 0 74 files changed, 1079 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/desafio-dev.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 billing/.gitattributes create mode 100644 billing/.gitignore create mode 100644 billing/.ruby-version create mode 100644 billing/Gemfile create mode 100644 billing/README.md create mode 100644 billing/Rakefile create mode 100644 billing/app/assets/config/manifest.js create mode 100644 billing/app/assets/images/.keep create mode 100644 billing/app/assets/stylesheets/application.css create mode 100644 billing/app/channels/application_cable/channel.rb create mode 100644 billing/app/channels/application_cable/connection.rb create mode 100644 billing/app/controllers/application_controller.rb create mode 100644 billing/app/controllers/concerns/.keep create mode 100644 billing/app/helpers/application_helper.rb create mode 100644 billing/app/jobs/application_job.rb create mode 100644 billing/app/mailers/application_mailer.rb create mode 100644 billing/app/models/application_record.rb create mode 100644 billing/app/models/concerns/.keep create mode 100644 billing/app/views/layouts/application.html.erb create mode 100644 billing/app/views/layouts/mailer.html.erb create mode 100644 billing/app/views/layouts/mailer.text.erb create mode 100755 billing/bin/rails create mode 100755 billing/bin/rake create mode 100755 billing/bin/setup create mode 100644 billing/config.ru create mode 100644 billing/config/application.rb create mode 100644 billing/config/boot.rb create mode 100644 billing/config/cable.yml create mode 100644 billing/config/credentials.yml.enc create mode 100644 billing/config/database.yml create mode 100644 billing/config/environment.rb create mode 100644 billing/config/environments/development.rb create mode 100644 billing/config/environments/production.rb create mode 100644 billing/config/environments/test.rb create mode 100644 billing/config/initializers/assets.rb create mode 100644 billing/config/initializers/content_security_policy.rb create mode 100644 billing/config/initializers/filter_parameter_logging.rb create mode 100644 billing/config/initializers/inflections.rb create mode 100644 billing/config/initializers/permissions_policy.rb create mode 100644 billing/config/locales/en.yml create mode 100644 billing/config/puma.rb create mode 100644 billing/config/routes.rb create mode 100644 billing/config/storage.yml create mode 100644 billing/db/seeds.rb create mode 100644 billing/lib/assets/.keep create mode 100644 billing/lib/tasks/.keep create mode 100644 billing/log/.keep create mode 100644 billing/public/404.html create mode 100644 billing/public/422.html create mode 100644 billing/public/500.html create mode 100644 billing/public/apple-touch-icon-precomposed.png create mode 100644 billing/public/apple-touch-icon.png create mode 100644 billing/public/favicon.ico create mode 100644 billing/public/robots.txt create mode 100644 billing/storage/.keep create mode 100644 billing/test/application_system_test_case.rb create mode 100644 billing/test/channels/application_cable/connection_test.rb create mode 100644 billing/test/controllers/.keep create mode 100644 billing/test/fixtures/files/.keep create mode 100644 billing/test/helpers/.keep create mode 100644 billing/test/integration/.keep create mode 100644 billing/test/mailers/.keep create mode 100644 billing/test/models/.keep create mode 100644 billing/test/system/.keep create mode 100644 billing/test/test_helper.rb create mode 100644 billing/tmp/.keep create mode 100644 billing/tmp/pids/.keep create mode 100644 billing/tmp/storage/.keep create mode 100644 billing/vendor/.keep diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..13566b81b0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/desafio-dev.iml b/.idea/desafio-dev.iml new file mode 100644 index 0000000000..6e7c09c280 --- /dev/null +++ b/.idea/desafio-dev.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..75f7d7b91d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..e790241d40 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..cabddbfef4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/billing/.gitattributes b/billing/.gitattributes new file mode 100644 index 0000000000..31eeee0b6a --- /dev/null +++ b/billing/.gitattributes @@ -0,0 +1,7 @@ +# 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 diff --git a/billing/.gitignore b/billing/.gitignore new file mode 100644 index 0000000000..e16dc71d2b --- /dev/null +++ b/billing/.gitignore @@ -0,0 +1,31 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore uploaded files in development. +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/billing/.ruby-version b/billing/.ruby-version new file mode 100644 index 0000000000..2a49746976 --- /dev/null +++ b/billing/.ruby-version @@ -0,0 +1 @@ +ruby-3.1.1 diff --git a/billing/Gemfile b/billing/Gemfile new file mode 100644 index 0000000000..4ac5e99088 --- /dev/null +++ b/billing/Gemfile @@ -0,0 +1,72 @@ +source "https://rubygems.org" +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby "3.1.1" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 7.0.2", ">= 7.0.2.4" + +# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] +gem "sprockets-rails" + +# Use postgresql as the database for Active Record +gem "pg", "~> 1.1" + +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", "~> 5.0" + +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" + +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" + +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" + +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" + +# Use Redis adapter to run Action Cable in production +# gem "redis", "~> 4.0" + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +# Use Sass to process CSS +# gem "sassc-rails" + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri mingw x64_mingw ] +end + +group :development do + # Use console on exceptions pages [https://github.com/rails/web-console] + gem "web-console" + + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] + # gem "rack-mini-profiler" + + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem "spring" +end + +group :test do + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end diff --git a/billing/README.md b/billing/README.md new file mode 100644 index 0000000000..7db80e4ca1 --- /dev/null +++ b/billing/README.md @@ -0,0 +1,24 @@ +# README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... diff --git a/billing/Rakefile b/billing/Rakefile new file mode 100644 index 0000000000..9a5ea7383a --- /dev/null +++ b/billing/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/billing/app/assets/config/manifest.js b/billing/app/assets/config/manifest.js new file mode 100644 index 0000000000..591819335f --- /dev/null +++ b/billing/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/billing/app/assets/images/.keep b/billing/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/assets/stylesheets/application.css b/billing/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..288b9ab718 --- /dev/null +++ b/billing/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/billing/app/channels/application_cable/channel.rb b/billing/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /dev/null +++ b/billing/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/billing/app/channels/application_cable/connection.rb b/billing/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000..0ff5442f47 --- /dev/null +++ b/billing/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/billing/app/controllers/application_controller.rb b/billing/app/controllers/application_controller.rb new file mode 100644 index 0000000000..09705d12ab --- /dev/null +++ b/billing/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/billing/app/controllers/concerns/.keep b/billing/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/helpers/application_helper.rb b/billing/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/billing/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/billing/app/jobs/application_job.rb b/billing/app/jobs/application_job.rb new file mode 100644 index 0000000000..d394c3d106 --- /dev/null +++ b/billing/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/billing/app/mailers/application_mailer.rb b/billing/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..3c34c8148f --- /dev/null +++ b/billing/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/billing/app/models/application_record.rb b/billing/app/models/application_record.rb new file mode 100644 index 0000000000..b63caeb8a5 --- /dev/null +++ b/billing/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/billing/app/models/concerns/.keep b/billing/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/views/layouts/application.html.erb b/billing/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..7025e20c69 --- /dev/null +++ b/billing/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ + + + + Billing + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + + + + <%= yield %> + + diff --git a/billing/app/views/layouts/mailer.html.erb b/billing/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/billing/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/billing/app/views/layouts/mailer.text.erb b/billing/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/billing/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/billing/bin/rails b/billing/bin/rails new file mode 100755 index 0000000000..efc0377492 --- /dev/null +++ b/billing/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/billing/bin/rake b/billing/bin/rake new file mode 100755 index 0000000000..4fbf10b960 --- /dev/null +++ b/billing/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/billing/bin/setup b/billing/bin/setup new file mode 100755 index 0000000000..ec47b79b3b --- /dev/null +++ b/billing/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) || abort("\n== Command #{args} failed ==") +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/billing/config.ru b/billing/config.ru new file mode 100644 index 0000000000..4a3c09a688 --- /dev/null +++ b/billing/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/billing/config/application.rb b/billing/config/application.rb new file mode 100644 index 0000000000..409ce6c9da --- /dev/null +++ b/billing/config/application.rb @@ -0,0 +1,22 @@ +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 Billing + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.0 + + # 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") + end +end diff --git a/billing/config/boot.rb b/billing/config/boot.rb new file mode 100644 index 0000000000..988a5ddc46 --- /dev/null +++ b/billing/config/boot.rb @@ -0,0 +1,4 @@ +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/billing/config/cable.yml b/billing/config/cable.yml new file mode 100644 index 0000000000..b48aee3b3c --- /dev/null +++ b/billing/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: billing_production diff --git a/billing/config/credentials.yml.enc b/billing/config/credentials.yml.enc new file mode 100644 index 0000000000..b2537169dd --- /dev/null +++ b/billing/config/credentials.yml.enc @@ -0,0 +1 @@ +NncYRlzhay4q8xDhIUA21ReCvawELEsbyV8B4RSO86c70lx9yM9iejD8GOd1xPZe8raHoZRszxUNZ2uD3DwGYXq3ZFIJ4EKf6sGA9a93HQaAhIloneoZtgMA+yBhgeLhCdYKs+e/4xItqU9RHYEBVA5wDYq3SIPmW+HqTDAT3KEI6Wlryrnmw+3bkQHhaiYNxJd64FoRKGqFfLd6iIEWekYcwDBedCZ+yShyDuXX5AS467e9OUym5GjNGBTXnGTVmLq7xrxlln4OWCpiMl2PjtPCFiKMKZPK9YVwktzG+foqk1RH9u2uNm4GbH2ex/FWAjbHe4QDm2skFY5X+rMqxT0aL/1NLiY51+D1h+Tztp8WtANkO7kRnnI8kqML/BwMYS6N9OR8VRAdZZKeHU3weje+ncWMDTPvC7rM--WheY72HjdgGrNYNG--5Ujd5hwwlFdEMqTAtwrsXA== \ No newline at end of file diff --git a/billing/config/database.yml b/billing/config/database.yml new file mode 100644 index 0000000000..abdc1ce3d0 --- /dev/null +++ b/billing/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 macOS with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/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 } %> + +development: + <<: *default + database: billing_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user running Rails. + #username: billing + + # The password associated with the postgres 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: billing_test + +# 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: billing_production + username: billing + password: <%= ENV["BILLING_DATABASE_PASSWORD"] %> diff --git a/billing/config/environment.rb b/billing/config/environment.rb new file mode 100644 index 0000000000..cac5315775 --- /dev/null +++ b/billing/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/billing/config/environments/development.rb b/billing/config/environments/development.rb new file mode 100644 index 0000000000..8500f459a8 --- /dev/null +++ b/billing/config/environments/development.rb @@ -0,0 +1,70 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # 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.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + 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 + + # Suppress logger output for asset requests. + config.assets.quiet = 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 +end diff --git a/billing/config/environments/production.rb b/billing/config/environments/production.rb new file mode 100644 index 0000000000..cbfb75c8d3 --- /dev/null +++ b/billing/config/environments/production.rb @@ -0,0 +1,93 @@ +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.cache_classes = true + + # 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 + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = 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.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # 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 = "billing_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 + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/billing/config/environments/test.rb b/billing/config/environments/test.rb new file mode 100644 index 0000000000..6ea4d1e706 --- /dev/null +++ b/billing/config/environments/test.rb @@ -0,0 +1,60 @@ +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. + + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = true + + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + 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 + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # 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 +end diff --git a/billing/config/initializers/assets.rb b/billing/config/initializers/assets.rb new file mode 100644 index 0000000000..2eeef966fe --- /dev/null +++ b/billing/config/initializers/assets.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/billing/config/initializers/content_security_policy.rb b/billing/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..3621f97f8e --- /dev/null +++ b/billing/config/initializers/content_security_policy.rb @@ -0,0 +1,26 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src) +# +# # Report CSP violations to a specified URI. See: +# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# # config.content_security_policy_report_only = true +# end diff --git a/billing/config/initializers/filter_parameter_logging.rb b/billing/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..adc6568ce8 --- /dev/null +++ b/billing/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 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/billing/config/initializers/inflections.rb b/billing/config/initializers/inflections.rb new file mode 100644 index 0000000000..3860f659ea --- /dev/null +++ b/billing/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/billing/config/initializers/permissions_policy.rb b/billing/config/initializers/permissions_policy.rb new file mode 100644 index 0000000000..00f64d71b0 --- /dev/null +++ b/billing/config/initializers/permissions_policy.rb @@ -0,0 +1,11 @@ +# Define an application-wide HTTP permissions policy. For further +# information see https://developers.google.com/web/updates/2018/06/feature-policy +# +# Rails.application.config.permissions_policy do |f| +# f.camera :none +# f.gyroscope :none +# f.microphone :none +# f.usb :none +# f.fullscreen :self +# f.payment :self, "https://secure.example.com" +# end diff --git a/billing/config/locales/en.yml b/billing/config/locales/en.yml new file mode 100644 index 0000000000..8ca56fc74f --- /dev/null +++ b/billing/config/locales/en.yml @@ -0,0 +1,33 @@ +# 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. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# "true": "foo" +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/billing/config/puma.rb b/billing/config/puma.rb new file mode 100644 index 0000000000..daaf036999 --- /dev/null +++ b/billing/config/puma.rb @@ -0,0 +1,43 @@ +# 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 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" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/billing/config/routes.rb b/billing/config/routes.rb new file mode 100644 index 0000000000..262ffd5472 --- /dev/null +++ b/billing/config/routes.rb @@ -0,0 +1,6 @@ +Rails.application.routes.draw do + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Defines the root path route ("/") + # root "articles#index" +end diff --git a/billing/config/storage.yml b/billing/config/storage.yml new file mode 100644 index 0000000000..4942ab6694 --- /dev/null +++ b/billing/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/billing/db/seeds.rb b/billing/db/seeds.rb new file mode 100644 index 0000000000..bc25fce306 --- /dev/null +++ b/billing/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: "Luke", movie: movies.first) diff --git a/billing/lib/assets/.keep b/billing/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/lib/tasks/.keep b/billing/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/log/.keep b/billing/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/404.html b/billing/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /dev/null +++ b/billing/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/422.html b/billing/public/422.html new file mode 100644 index 0000000000..c08eac0d1d --- /dev/null +++ b/billing/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/500.html b/billing/public/500.html new file mode 100644 index 0000000000..78a030af22 --- /dev/null +++ b/billing/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/apple-touch-icon-precomposed.png b/billing/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/apple-touch-icon.png b/billing/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/favicon.ico b/billing/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/robots.txt b/billing/public/robots.txt new file mode 100644 index 0000000000..c19f78ab68 --- /dev/null +++ b/billing/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/billing/storage/.keep b/billing/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/application_system_test_case.rb b/billing/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/billing/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/billing/test/channels/application_cable/connection_test.rb b/billing/test/channels/application_cable/connection_test.rb new file mode 100644 index 0000000000..800405f15e --- /dev/null +++ b/billing/test/channels/application_cable/connection_test.rb @@ -0,0 +1,11 @@ +require "test_helper" + +class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase + # test "connects with cookies" do + # cookies.signed[:user_id] = 42 + # + # connect + # + # assert_equal connection.user_id, "42" + # end +end diff --git a/billing/test/controllers/.keep b/billing/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/fixtures/files/.keep b/billing/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/helpers/.keep b/billing/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/integration/.keep b/billing/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/mailers/.keep b/billing/test/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/models/.keep b/billing/test/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/system/.keep b/billing/test/system/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/test/test_helper.rb b/billing/test/test_helper.rb new file mode 100644 index 0000000000..d713e377c9 --- /dev/null +++ b/billing/test/test_helper.rb @@ -0,0 +1,13 @@ +ENV["RAILS_ENV"] ||= "test" +require_relative "../config/environment" +require "rails/test_help" + +class ActiveSupport::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 diff --git a/billing/tmp/.keep b/billing/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/tmp/pids/.keep b/billing/tmp/pids/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/tmp/storage/.keep b/billing/tmp/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/vendor/.keep b/billing/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2 From 06c09e40e1a65f3575fde559162458f2fbdf56e6 Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Tue, 3 May 2022 16:52:19 -0400 Subject: [PATCH 2/8] config Docker --- billing/Dockerfile | 31 ++++++++++++++++++ billing/README.md | 65 +++++++++++++++++++++++++------------- billing/docker-compose.yml | 26 +++++++++++++++ billing/start.sh | 5 +++ 4 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 billing/Dockerfile create mode 100644 billing/docker-compose.yml create mode 100644 billing/start.sh diff --git a/billing/Dockerfile b/billing/Dockerfile new file mode 100644 index 0000000000..e8d061b1c1 --- /dev/null +++ b/billing/Dockerfile @@ -0,0 +1,31 @@ +FROM ruby:3.1.1 + +# add nodejs and yarn dependencies for the frontend +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \ +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +# Instala nossas dependencias +RUN apt-get update && apt-get install -qq -y --no-install-recommends \ +nodejs yarn build-essential libpq-dev imagemagick git-all nano + +# Instalar bundler +RUN gem install bundler + +# Seta nosso path +ENV INSTALL_PATH /billing + +# Cria nosso diretório +RUN mkdir -p $INSTALL_PATH + +# Seta o nosso path como o diretório principal +WORKDIR $INSTALL_PATH + +# Copia o nosso Gemfile para dentro do container +COPY Gemfile ./ + +# Seta o path para as Gems +ENV BUNDLE_PATH /gems + +# Copia nosso código para dentro do container +COPY . . \ No newline at end of file diff --git a/billing/README.md b/billing/README.md index 7db80e4ca1..318d7e5e44 100644 --- a/billing/README.md +++ b/billing/README.md @@ -1,24 +1,45 @@ # README -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... +💻 **Stack** + +- Ruby 3.1.1 + +- Rails 7.0.2 + +- Host machine dependencies + - [Docker (CE)](https://docs.docker.com/engine/installation/) + - [Docker Compose](https://docs.docker.com/compose/install/) + +🚀 **To start the Rails app, run:** + +- ⚠️ Is it your first time? ⚠️ + + - Create a external volume to share gems across containers: + ```bash + docker-compose build + ``` + Note: If your docker commands only work using sudo before, run the following command in the console to fix it: + - ```bash + sudo groupadd docker + ``` + - ```bash + sudo usermod -aG docker $USER + ``` + - ```bash + sudo service docker restart + ``` + +🛠 **Useful commands:** + +- Start Rails console: + ```bash + docker-compose up + ``` +- Execute migration: + ```bash + docker-compose run --rm app bundle exec rails db:create db:migrate + ``` +- Execute Webpack: + ```bash + docker-compose run --rm app bundle exec rails webpacker:install + ``` diff --git a/billing/docker-compose.yml b/billing/docker-compose.yml new file mode 100644 index 0000000000..7451ebd941 --- /dev/null +++ b/billing/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.8" + +services: + db: + image: "postgres:12.2" + environment: + - POSTGRES_PASSWORD=postgres + volumes: + - postgres:/var/lib/postgresql/data + + app: + build: . + command: bash start.sh + ports: + - "3000:3000" + environment: + - DB_PASSWORD=postgres + volumes: + - .:/billing + - gems:/gems + depends_on: + - db + +volumes: + postgres: + gems: \ No newline at end of file diff --git a/billing/start.sh b/billing/start.sh new file mode 100644 index 0000000000..53952ba72c --- /dev/null +++ b/billing/start.sh @@ -0,0 +1,5 @@ +# Instala as Gems +bundle check || bundle install + +# Roda nosso servidor +bundle exec puma -C config/puma.rb \ No newline at end of file From 3b4e7552e003dd29411c46a53605c1417cf9d5f7 Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Tue, 3 May 2022 16:53:34 -0400 Subject: [PATCH 3/8] add readme --- billing/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/billing/README.md b/billing/README.md index 318d7e5e44..84c9ad9542 100644 --- a/billing/README.md +++ b/billing/README.md @@ -1,5 +1,4 @@ # README - 💻 **Stack** - Ruby 3.1.1 @@ -28,7 +27,6 @@ - ```bash sudo service docker restart ``` - 🛠 **Useful commands:** - Start Rails console: @@ -42,4 +40,4 @@ - Execute Webpack: ```bash docker-compose run --rm app bundle exec rails webpacker:install - ``` + ``` \ No newline at end of file From 268c5923f4de6870d2a0d76cbb644853162751af Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Tue, 3 May 2022 17:21:51 -0400 Subject: [PATCH 4/8] add Rspec --- .idea/codeStyles/codeStyleConfig.xml | 5 + billing/.rspec | 1 + billing/Gemfile | 6 + billing/Gemfile.lock | 272 ++++++++++++++++++ billing/README.md | 27 +- billing/config/database.yml | 71 +---- billing/db/schema.rb | 17 ++ billing/spec/rails_helper.rb | 66 +++++ billing/spec/spec_helper.rb | 94 ++++++ billing/spec/support/factory_bot.rb | 3 + billing/spec/support/shoulda_matchers.rb | 6 + billing/test/application_system_test_case.rb | 5 - .../application_cable/connection_test.rb | 11 - billing/test/controllers/.keep | 0 billing/test/fixtures/files/.keep | 0 billing/test/helpers/.keep | 0 billing/test/integration/.keep | 0 billing/test/mailers/.keep | 0 billing/test/models/.keep | 0 billing/test/system/.keep | 0 billing/test/test_helper.rb | 13 - 21 files changed, 498 insertions(+), 99 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 billing/.rspec create mode 100644 billing/Gemfile.lock create mode 100644 billing/db/schema.rb create mode 100644 billing/spec/rails_helper.rb create mode 100644 billing/spec/spec_helper.rb create mode 100644 billing/spec/support/factory_bot.rb create mode 100644 billing/spec/support/shoulda_matchers.rb delete mode 100644 billing/test/application_system_test_case.rb delete mode 100644 billing/test/channels/application_cable/connection_test.rb delete mode 100644 billing/test/controllers/.keep delete mode 100644 billing/test/fixtures/files/.keep delete mode 100644 billing/test/helpers/.keep delete mode 100644 billing/test/integration/.keep delete mode 100644 billing/test/mailers/.keep delete mode 100644 billing/test/models/.keep delete mode 100644 billing/test/system/.keep delete mode 100644 billing/test/test_helper.rb diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000000..a55e7a179b --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/billing/.rspec b/billing/.rspec new file mode 100644 index 0000000000..c99d2e7396 --- /dev/null +++ b/billing/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/billing/Gemfile b/billing/Gemfile index 4ac5e99088..d912aae194 100644 --- a/billing/Gemfile +++ b/billing/Gemfile @@ -51,6 +51,12 @@ gem "bootsnap", require: false group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri mingw x64_mingw ] + gem 'factory_bot_rails' + gem 'faker' + gem 'rspec-rails', '~> 4.0.1' + gem 'shoulda-matchers', '~> 4.0' + gem 'ffaker' + gem 'pry' end group :development do diff --git a/billing/Gemfile.lock b/billing/Gemfile.lock new file mode 100644 index 0000000000..aeff77a5e5 --- /dev/null +++ b/billing/Gemfile.lock @@ -0,0 +1,272 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.2.4) + actionpack (= 7.0.2.4) + activesupport (= 7.0.2.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.2.4) + actionpack (= 7.0.2.4) + activejob (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.2.4) + actionpack (= 7.0.2.4) + actionview (= 7.0.2.4) + activejob (= 7.0.2.4) + activesupport (= 7.0.2.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.2.4) + actionview (= 7.0.2.4) + activesupport (= 7.0.2.4) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.2.4) + actionpack (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.2.4) + activesupport (= 7.0.2.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.2.4) + activesupport (= 7.0.2.4) + globalid (>= 0.3.6) + activemodel (7.0.2.4) + activesupport (= 7.0.2.4) + activerecord (7.0.2.4) + activemodel (= 7.0.2.4) + activesupport (= 7.0.2.4) + activestorage (7.0.2.4) + actionpack (= 7.0.2.4) + activejob (= 7.0.2.4) + activerecord (= 7.0.2.4) + activesupport (= 7.0.2.4) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.2.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) + bindex (0.8.1) + bootsnap (1.11.1) + msgpack (~> 1.2) + builder (3.2.4) + capybara (3.36.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + childprocess (4.1.0) + coderay (1.1.3) + concurrent-ruby (1.1.10) + crass (1.0.6) + debug (1.5.0) + irb (>= 1.3.6) + reline (>= 0.2.7) + diff-lcs (1.5.0) + digest (3.1.0) + erubi (1.10.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 (2.20.0) + i18n (>= 1.8.11, < 2) + ffaker (2.21.0) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.10.0) + concurrent-ruby (~> 1.0) + importmap-rails (1.0.3) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.5.11) + irb (1.4.1) + reline (>= 0.3.0) + jbuilder (2.11.5) + actionview (>= 5.0.0) + activesupport (>= 5.0.0) + loofah (2.17.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + matrix (0.4.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.15.0) + msgpack (1.5.1) + net-imap (0.2.3) + digest + net-protocol + strscan + net-pop (0.1.1) + digest + net-protocol + timeout + net-protocol (0.1.3) + timeout + net-smtp (0.3.1) + digest + net-protocol + timeout + nio4r (2.5.8) + nokogiri (1.13.4-x86_64-linux) + racc (~> 1.4) + pg (1.3.5) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (4.0.7) + puma (5.6.4) + nio4r (~> 2.0) + racc (1.6.0) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (7.0.2.4) + actioncable (= 7.0.2.4) + actionmailbox (= 7.0.2.4) + actionmailer (= 7.0.2.4) + actionpack (= 7.0.2.4) + actiontext (= 7.0.2.4) + actionview (= 7.0.2.4) + activejob (= 7.0.2.4) + activemodel (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + bundler (>= 1.15.0) + railties (= 7.0.2.4) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.2) + loofah (~> 2.3) + railties (7.0.2.4) + actionpack (= 7.0.2.4) + activesupport (= 7.0.2.4) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.0.6) + regexp_parser (2.3.1) + reline (0.3.1) + io-console (~> 0.5) + rexml (3.2.5) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-rails (4.0.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.11.0) + rubyzip (2.3.2) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2) + shoulda-matchers (4.5.1) + activesupport (>= 4.2.0) + sprockets (4.0.3) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + stimulus-rails (1.0.4) + railties (>= 6.0.0) + strscan (3.0.1) + thor (1.2.1) + timeout (0.2.0) + turbo-rails (1.0.1) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + web-console (4.2.0) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + webdrivers (5.0.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.5.4) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + bootsnap + capybara + debug + factory_bot_rails + faker + ffaker + importmap-rails + jbuilder + pg (~> 1.1) + pry + puma (~> 5.0) + rails (~> 7.0.2, >= 7.0.2.4) + rspec-rails (~> 4.0.1) + selenium-webdriver + shoulda-matchers (~> 4.0) + sprockets-rails + stimulus-rails + turbo-rails + tzinfo-data + web-console + webdrivers + +RUBY VERSION + ruby 3.1.1p18 + +BUNDLED WITH + 2.3.12 diff --git a/billing/README.md b/billing/README.md index 84c9ad9542..acdbb33fd8 100644 --- a/billing/README.md +++ b/billing/README.md @@ -27,17 +27,40 @@ - ```bash sudo service docker restart ``` + - Load all needed gems into `gems_ops` external volume: + ```bash + docker-compose run --rm app bundle install + ``` +- Starting all stack (_add `-d` flag to run in background_): + + - Follow the `Starting all stack` section + ```bash + docker-compose up + ``` 🛠 **Useful commands:** - Start Rails console: ```bash - docker-compose up + docker-compose run --rm app bundle exec rails c ``` +- Execute create DB: + ```bash + docker-compose run --rm app bundle exec rails db:create + ``` - Execute migration: ```bash - docker-compose run --rm app bundle exec rails db:create db:migrate + docker-compose run --rm app bundle exec rails db:migrate ``` - Execute Webpack: ```bash docker-compose run --rm app bundle exec rails webpacker:install + ``` +- Access database console: + ```bash + docker-compose run --rm app bundle exec rails dbconsole + ``` +- Test a specific file + + ```bash + docker-compose run --rm app bundle exec rspec ./spec/services/name_file.rb' ``` \ No newline at end of file diff --git a/billing/config/database.yml b/billing/config/database.yml index abdc1ce3d0..6eaabe88d5 100644 --- a/billing/config/database.yml +++ b/billing/config/database.yml @@ -1,84 +1,19 @@ -# 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 macOS with MacPorts: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/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 } %> + host: db + user: postgres + password: <%= ENV['DB_PASSWORD'] %> development: <<: *default database: billing_development - # The specified database role being used to connect to postgres. - # To create additional roles in postgres see `$ createuser --help`. - # When left blank, postgres will use the default role. This is - # the same name as the operating system user running Rails. - #username: billing - - # The password associated with the postgres 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: billing_test -# 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: billing_production diff --git a/billing/db/schema.rb b/billing/db/schema.rb new file mode 100644 index 0000000000..b783f98666 --- /dev/null +++ b/billing/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.0].define(version: 0) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + +end diff --git a/billing/spec/rails_helper.rb b/billing/spec/rails_helper.rb new file mode 100644 index 0000000000..7f186c967c --- /dev/null +++ b/billing/spec/rails_helper.rb @@ -0,0 +1,66 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../config/environment', __dir__) +# 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! + +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# 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. +# +# Dir[Rails.root.join('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 + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/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://relishapp.com/rspec/rspec-rails/docs + 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/billing/spec/spec_helper.rb b/billing/spec/spec_helper.rb new file mode 100644 index 0000000000..a0d4080592 --- /dev/null +++ b/billing/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://relishapp.com/rspec/rspec-core/docs/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/billing/spec/support/factory_bot.rb b/billing/spec/support/factory_bot.rb new file mode 100644 index 0000000000..329748fc9d --- /dev/null +++ b/billing/spec/support/factory_bot.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods +end \ No newline at end of file diff --git a/billing/spec/support/shoulda_matchers.rb b/billing/spec/support/shoulda_matchers.rb new file mode 100644 index 0000000000..1c55e783af --- /dev/null +++ b/billing/spec/support/shoulda_matchers.rb @@ -0,0 +1,6 @@ +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end \ No newline at end of file diff --git a/billing/test/application_system_test_case.rb b/billing/test/application_system_test_case.rb deleted file mode 100644 index d19212abd5..0000000000 --- a/billing/test/application_system_test_case.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/billing/test/channels/application_cable/connection_test.rb b/billing/test/channels/application_cable/connection_test.rb deleted file mode 100644 index 800405f15e..0000000000 --- a/billing/test/channels/application_cable/connection_test.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "test_helper" - -class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase - # test "connects with cookies" do - # cookies.signed[:user_id] = 42 - # - # connect - # - # assert_equal connection.user_id, "42" - # end -end diff --git a/billing/test/controllers/.keep b/billing/test/controllers/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/fixtures/files/.keep b/billing/test/fixtures/files/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/helpers/.keep b/billing/test/helpers/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/integration/.keep b/billing/test/integration/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/mailers/.keep b/billing/test/mailers/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/models/.keep b/billing/test/models/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/system/.keep b/billing/test/system/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/billing/test/test_helper.rb b/billing/test/test_helper.rb deleted file mode 100644 index d713e377c9..0000000000 --- a/billing/test/test_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" - -class ActiveSupport::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 From 6bfd0ad4e375f0388bea4defc50ddf4368e34bcc Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Wed, 4 May 2022 17:23:20 -0400 Subject: [PATCH 5/8] feat: create models --- billing/app/models/customer.rb | 16 +++++++++++++++ billing/app/models/provider.rb | 15 ++++++++++++++ billing/app/models/transaction.rb | 19 ++++++++++++++++++ .../20220504205720_create_customers.rb | 9 +++++++++ .../20220504205941_create_providers.rb | 10 ++++++++++ .../20220504210141_create_transactions.rb | 20 +++++++++++++++++++ billing/spec/factories/customers.rb | 5 +++++ billing/spec/factories/providers.rb | 6 ++++++ billing/spec/factories/transactions.rb | 7 +++++++ billing/spec/models/customer_spec.rb | 5 +++++ billing/spec/models/provider_spec.rb | 5 +++++ billing/spec/models/transaction_spec.rb | 5 +++++ 12 files changed, 122 insertions(+) create mode 100644 billing/app/models/customer.rb create mode 100644 billing/app/models/provider.rb create mode 100644 billing/app/models/transaction.rb create mode 100644 billing/db/migrate/20220504205720_create_customers.rb create mode 100644 billing/db/migrate/20220504205941_create_providers.rb create mode 100644 billing/db/migrate/20220504210141_create_transactions.rb create mode 100644 billing/spec/factories/customers.rb create mode 100644 billing/spec/factories/providers.rb create mode 100644 billing/spec/factories/transactions.rb create mode 100644 billing/spec/models/customer_spec.rb create mode 100644 billing/spec/models/provider_spec.rb create mode 100644 billing/spec/models/transaction_spec.rb diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb new file mode 100644 index 0000000000..be8646866b --- /dev/null +++ b/billing/app/models/customer.rb @@ -0,0 +1,16 @@ +class Customer < ApplicationRecord + validate :cpf_valid, on: %i[create update] + validates :cpf, presence: true, uniqueness: true + + def cpf_valid + return errors.add(:base, "CPF #{self.cpf} invalid") unless CPF.valid?(self.cpf) + end + + private + + def record_exists? + return false unless Customer.find_by_cpf(self.cpf).present? + + true + end +end diff --git a/billing/app/models/provider.rb b/billing/app/models/provider.rb new file mode 100644 index 0000000000..626c779b92 --- /dev/null +++ b/billing/app/models/provider.rb @@ -0,0 +1,15 @@ +class Provider < ApplicationRecord + validate :name_provider_valid, on: %i[create] + + def name_provider_valid + return errors.add(:base, "Nome da Loja #{self.name_provider} já cadastrado") if name_provider_exists? + end + + private + + def name_provider_exists? + return false unless Provider.where('lower(name_provider) LIKE ?', "%#{self.name_provider.downcase}%").present? + + true + end +end diff --git a/billing/app/models/transaction.rb b/billing/app/models/transaction.rb new file mode 100644 index 0000000000..0dbc4bc569 --- /dev/null +++ b/billing/app/models/transaction.rb @@ -0,0 +1,19 @@ +class Transaction < ApplicationRecord + before_save :set_transaction_nature_and_signal + + TRANSACTION_TYPES_DEBITS = %w[boleto financiamento aluguel].freeze + + validates :transaction_type, presence: true + belongs_to :customer + belongs_to :provider + + enum transaction_type: i%[debit credit ticket financing receivable sales ted doc rent] + + + def set_transaction_nature_and_signal + signal = !TRANSACTION_TYPES_DEBITS.include?(self.transaction_type) + nature = signal ? 'Entrada' : 'Saída' + self.signal = signal + self.nature = nature + end +end diff --git a/billing/db/migrate/20220504205720_create_customers.rb b/billing/db/migrate/20220504205720_create_customers.rb new file mode 100644 index 0000000000..f6f6993011 --- /dev/null +++ b/billing/db/migrate/20220504205720_create_customers.rb @@ -0,0 +1,9 @@ +class CreateCustomers < ActiveRecord::Migration[7.0] + def change + create_table :customers do |t| + t.string :cpf + + t.timestamps + end + end +end diff --git a/billing/db/migrate/20220504205941_create_providers.rb b/billing/db/migrate/20220504205941_create_providers.rb new file mode 100644 index 0000000000..5b77e32a56 --- /dev/null +++ b/billing/db/migrate/20220504205941_create_providers.rb @@ -0,0 +1,10 @@ +class CreateProviders < ActiveRecord::Migration[7.0] + def change + create_table :providers do |t| + t.string :name_owner + t.string :name_provider + + t.timestamps + end + end +end diff --git a/billing/db/migrate/20220504210141_create_transactions.rb b/billing/db/migrate/20220504210141_create_transactions.rb new file mode 100644 index 0000000000..29f655d70c --- /dev/null +++ b/billing/db/migrate/20220504210141_create_transactions.rb @@ -0,0 +1,20 @@ +class CreateTransactions < ActiveRecord::Migration[7.0] + def change + create_table :transactions do |t| + t.references :customers, foreign_key: true + t.references :providers, foreign_key: true + + t.integer :transaction_type + t.string :nature + t.boolean :signal + t.float :value + t.date :transaction_date + t.string :hour + t.string :card_number + t.bigint :customer_id + t.bigint :provider_id + + t.timestamps + end + end +end diff --git a/billing/spec/factories/customers.rb b/billing/spec/factories/customers.rb new file mode 100644 index 0000000000..e2b0fd5c86 --- /dev/null +++ b/billing/spec/factories/customers.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :customer do + cpf { "MyString" } + end +end diff --git a/billing/spec/factories/providers.rb b/billing/spec/factories/providers.rb new file mode 100644 index 0000000000..49bb7e1b06 --- /dev/null +++ b/billing/spec/factories/providers.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :provider do + name_owner { "MyString" } + name_provider { "MyString" } + end +end diff --git a/billing/spec/factories/transactions.rb b/billing/spec/factories/transactions.rb new file mode 100644 index 0000000000..7be305b099 --- /dev/null +++ b/billing/spec/factories/transactions.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :transaction do + transaction_type { 1 } + nature { "MyString" } + signal { false } + end +end diff --git a/billing/spec/models/customer_spec.rb b/billing/spec/models/customer_spec.rb new file mode 100644 index 0000000000..3399b1f561 --- /dev/null +++ b/billing/spec/models/customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Customer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/billing/spec/models/provider_spec.rb b/billing/spec/models/provider_spec.rb new file mode 100644 index 0000000000..5e672c7776 --- /dev/null +++ b/billing/spec/models/provider_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Provider, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/billing/spec/models/transaction_spec.rb b/billing/spec/models/transaction_spec.rb new file mode 100644 index 0000000000..572759a7ed --- /dev/null +++ b/billing/spec/models/transaction_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Transaction, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 58bd81efb5808f23a38d463cb0118f5b9f6d01fa Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Wed, 4 May 2022 18:52:50 -0400 Subject: [PATCH 6/8] test: models --- billing/Gemfile | 4 ++ billing/Gemfile.lock | 6 +++ billing/app/models/transaction.rb | 4 +- billing/db/schema.rb | 35 ++++++++++++- billing/spec/factories/customers.rb | 6 ++- billing/spec/factories/providers.rb | 8 ++- billing/spec/factories/transactions.rb | 8 +-- billing/spec/models/customer_spec.rb | 36 +++++++++++++- billing/spec/models/provider_spec.rb | 18 ++++++- billing/spec/models/transaction_spec.rb | 65 ++++++++++++++++++++++++- 10 files changed, 178 insertions(+), 12 deletions(-) diff --git a/billing/Gemfile b/billing/Gemfile index d912aae194..ff205db96e 100644 --- a/billing/Gemfile +++ b/billing/Gemfile @@ -42,6 +42,9 @@ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false +#validate CPF +gem 'cpf_cnpj' + # Use Sass to process CSS # gem "sassc-rails" @@ -57,6 +60,7 @@ group :development, :test do gem 'shoulda-matchers', '~> 4.0' gem 'ffaker' gem 'pry' + gem 'cpf_faker' end group :development do diff --git a/billing/Gemfile.lock b/billing/Gemfile.lock index aeff77a5e5..05e4204631 100644 --- a/billing/Gemfile.lock +++ b/billing/Gemfile.lock @@ -82,8 +82,12 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (4.1.0) + clipboard (1.3.6) coderay (1.1.3) concurrent-ruby (1.1.10) + cpf_cnpj (0.5.0) + cpf_faker (1.3.0) + clipboard crass (1.0.6) debug (1.5.0) irb (>= 1.3.6) @@ -245,6 +249,8 @@ PLATFORMS DEPENDENCIES bootsnap capybara + cpf_cnpj + cpf_faker debug factory_bot_rails faker diff --git a/billing/app/models/transaction.rb b/billing/app/models/transaction.rb index 0dbc4bc569..bb6b8e405b 100644 --- a/billing/app/models/transaction.rb +++ b/billing/app/models/transaction.rb @@ -7,12 +7,12 @@ class Transaction < ApplicationRecord belongs_to :customer belongs_to :provider - enum transaction_type: i%[debit credit ticket financing receivable sales ted doc rent] + enum transaction_type: %i[debit credit ticket financing receivable sales ted doc rent] def set_transaction_nature_and_signal signal = !TRANSACTION_TYPES_DEBITS.include?(self.transaction_type) - nature = signal ? 'Entrada' : 'Saída' + nature = signal ? 'Entrada' : 'Saída'/ self.signal = signal self.nature = nature end diff --git a/billing/db/schema.rb b/billing/db/schema.rb index b783f98666..3feabfe13b 100644 --- a/billing/db/schema.rb +++ b/billing/db/schema.rb @@ -10,8 +10,41 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 0) do +ActiveRecord::Schema[7.0].define(version: 2022_05_04_210141) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "customers", force: :cascade do |t| + t.string "cpf" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "providers", force: :cascade do |t| + t.string "name_owner" + t.string "name_provider" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "transactions", force: :cascade do |t| + t.bigint "customers_id" + t.bigint "providers_id" + t.integer "transaction_type" + t.string "nature" + t.boolean "signal" + t.float "value" + t.date "transaction_date" + t.string "hour" + t.string "card_number" + t.bigint "customer_id" + t.bigint "provider_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["customers_id"], name: "index_transactions_on_customers_id" + t.index ["providers_id"], name: "index_transactions_on_providers_id" + end + + add_foreign_key "transactions", "customers", column: "customers_id" + add_foreign_key "transactions", "providers", column: "providers_id" end diff --git a/billing/spec/factories/customers.rb b/billing/spec/factories/customers.rb index e2b0fd5c86..b0ae4b0228 100644 --- a/billing/spec/factories/customers.rb +++ b/billing/spec/factories/customers.rb @@ -1,5 +1,9 @@ FactoryBot.define do factory :customer do - cpf { "MyString" } + cpf { Faker::CPF.numeric.to_s } + + trait :invalid do + cpf { '123456' } + end end end diff --git a/billing/spec/factories/providers.rb b/billing/spec/factories/providers.rb index 49bb7e1b06..36867167fc 100644 --- a/billing/spec/factories/providers.rb +++ b/billing/spec/factories/providers.rb @@ -1,6 +1,10 @@ FactoryBot.define do factory :provider do - name_owner { "MyString" } - name_provider { "MyString" } + name_owner { Faker::Name.name } + name_provider { Faker::Name.first_name } + + trait :invalid do + name_provider { nil } + end end end diff --git a/billing/spec/factories/transactions.rb b/billing/spec/factories/transactions.rb index 7be305b099..070a572c10 100644 --- a/billing/spec/factories/transactions.rb +++ b/billing/spec/factories/transactions.rb @@ -1,7 +1,9 @@ FactoryBot.define do factory :transaction do - transaction_type { 1 } - nature { "MyString" } - signal { false } + transaction_type { 'credit' } + value { 249.0 } + transaction_date { '2022-05-03' } + hour { '17:00:51' } + card_number { '9876****1234' } end end diff --git a/billing/spec/models/customer_spec.rb b/billing/spec/models/customer_spec.rb index 3399b1f561..1dea6abc26 100644 --- a/billing/spec/models/customer_spec.rb +++ b/billing/spec/models/customer_spec.rb @@ -1,5 +1,39 @@ require 'rails_helper' RSpec.describe Customer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + context 'when create a new Customer with valid CPF' do + subject(:customer) { build :customer } + + describe 'validation' do + it { should be_valid } + end + end + + context 'when create a new Customer with invalid CPF' do + subject(:customer) { build :customer , :invalid } + describe 'validation' do + it { should_not be_valid } + end + end + + context 'when try create a Customer but it already exists and' do + let(:cpf) { Faker::CPF.numeric.to_s } + subject(:customer) { create :customer, cpf: cpf } + subject(:customer2) { build :customer, cpf: cpf } + + it 'fails' do + expect(customer).to be_valid + expect(customer2.save).to eq(false) + expect { customer2.save! }.to raise_error + end + end + + context 'when try update a Customer with a invalid CPF and' do + subject(:customer) { create :customer } + + it 'fails' do + expect(customer.update(cpf: '123456789')).to eq(false) + expect { customer.update!(cpf: '123456789') }.to raise_error + end + end end diff --git a/billing/spec/models/provider_spec.rb b/billing/spec/models/provider_spec.rb index 5e672c7776..62d44a2052 100644 --- a/billing/spec/models/provider_spec.rb +++ b/billing/spec/models/provider_spec.rb @@ -1,5 +1,21 @@ require 'rails_helper' RSpec.describe Provider, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + context 'when create a new Provider with valid name provider and' do + it 'create with successful' do + expect(Provider.create(name_provider: 'Teste')).to be_valid + end + end + + context 'when try create a Provider but it already exists and' do + let(:cpf) { Faker::CPF.numeric.to_s } + let(:provider) { Provider.create(name_provider: 'Teste') } + let(:provider2) { Provider.create(name_provider: 'Teste') } + + it 'fails' do + expect(provider).to be_valid + expect(provider2.save).to eq(false) + expect { provider2.save! }.to raise_error + end + end end diff --git a/billing/spec/models/transaction_spec.rb b/billing/spec/models/transaction_spec.rb index 572759a7ed..855b7613d2 100644 --- a/billing/spec/models/transaction_spec.rb +++ b/billing/spec/models/transaction_spec.rb @@ -1,5 +1,68 @@ require 'rails_helper' RSpec.describe Transaction, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + + let!(:customer) {Customer.create(cpf: Faker::CPF.numeric.to_s) } + let!(:provider) { Provider.create(name_provider: 'Teste') } + + context 'when create a new Transaction with valid data and' do + let(:transaction) do + Transaction.create( + provider_id: provider.id, + customer_id: customer.id, + transaction_type: 'credit', + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'create with successful' do + expect(transaction).to be_valid + expect(transaction.provider_id).to eq(provider.id) + expect(transaction.customer_id).to eq(customer.id) + expect(transaction.transaction_type).to eq('credit') + expect(transaction.value).to eq(192.0) + expect(transaction.transaction_date.class).to eq(Date) + expect(transaction.hour).to eq('17:27:12') + expect(transaction.card_number).to eq('6777****1313') + end + end + + context 'when try create a Transaction without Provider and' do + let(:transaction) do + Transaction.create( + customer_id: customer.id, + transaction_type: 'credit', + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'fails' do + expect(transaction).to be_invalid + expect { transaction.save! }.to raise_error(StandardError) + end + end + + context 'when try create a Transaction without Customer' do + let(:transaction) do + Transaction.create( + provider_id: provider.id, + transaction_type: :credit, + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'when exist fails in transaction' do + expect(transaction).to be_invalid + expect { transaction.save! }.to raise_error(StandardError) + end + end end From c82e62bbe71a533616a36d2df769fc017dc65959 Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Wed, 4 May 2022 21:45:00 -0400 Subject: [PATCH 7/8] feat: controllers --- .idea/modules/billing.iml | 114 ++++++++++++++++++ billing/app/controllers/imports_controller.rb | 28 +++++ .../controllers/transactions_controller.rb | 37 ++++++ billing/config/routes.rb | 9 +- billing/db/seeds.rb | 2 +- .../controllers/importers_controller_spec.rb | 34 ++++++ .../transactions_controller_spec.rb | 46 +++++++ 7 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 .idea/modules/billing.iml create mode 100644 billing/app/controllers/imports_controller.rb create mode 100644 billing/app/controllers/transactions_controller.rb create mode 100644 billing/spec/controllers/importers_controller_spec.rb create mode 100644 billing/spec/controllers/transactions_controller_spec.rb diff --git a/.idea/modules/billing.iml b/.idea/modules/billing.iml new file mode 100644 index 0000000000..ddb090beaf --- /dev/null +++ b/.idea/modules/billing.iml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/billing/app/controllers/imports_controller.rb b/billing/app/controllers/imports_controller.rb new file mode 100644 index 0000000000..367fe1082a --- /dev/null +++ b/billing/app/controllers/imports_controller.rb @@ -0,0 +1,28 @@ +class ImportsController < ApplicationController + before_action :importer_params + + def import_file + key_file = params.keys.reject { |x| ['action', 'controller'].include?(x) }&.first + path = params[key_file]&.path + + return default_error unless path.present? + + importer = Importer.new(path) + + if importer.import_and_create_data + render json: { success: true, message: 'Upload and creation data make with successful!' } + else + default_error + end + end + + private + + def default_error + render json: { success: false, message: 'Something is wrong!' } + end + + def valid_params + params.permit(:files) + end +end \ No newline at end of file diff --git a/billing/app/controllers/transactions_controller.rb b/billing/app/controllers/transactions_controller.rb new file mode 100644 index 0000000000..7b0df7a4e7 --- /dev/null +++ b/billing/app/controllers/transactions_controller.rb @@ -0,0 +1,37 @@ +class TransactionsController < ApplicationController + before_action :transactions_params + + def index + transactions = [] + @providers = Provider.all + + @providers.each do |provider| + transactions_by_provider = Transaction.where(provider_id: provider.id) + provider_name = capitalize_name(provider.name_provider) + provider_owner = capitalize_name(provider.name_owner) + total_balance = transactions_by_provider.map(&:value).sum + + transactions << { + provider_name: provider_name, + provider_owner: provider_owner, + total_balance: "R$#{total_balance.to_s}" + } + end + + render json: { success: true, transactions: transactions } + end + + private + + def capitalize_name(name) + name.split(' ')&.map { |x| x.capitalize }.join(' ') + end + + def default_error + render json: { success: false, message: 'Something is wrong!' } + end + + def transactions_params + params.permit(:id) + end +end \ No newline at end of file diff --git a/billing/config/routes.rb b/billing/config/routes.rb index 262ffd5472..1f8d41a9de 100644 --- a/billing/config/routes.rb +++ b/billing/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html - - # Defines the root path route ("/") - # root "articles#index" + resources :importer, only: [:index] do + collection { post :import_file, via: :options } + end + + resources :transactions, only: [:index] end diff --git a/billing/db/seeds.rb b/billing/db/seeds.rb index bc25fce306..2ecb15835d 100644 --- a/billing/db/seeds.rb +++ b/billing/db/seeds.rb @@ -4,4 +4,4 @@ # Examples: # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) -# Character.create(name: "Luke", movie: movies.first) +# Character.create(name: " Luke", movie: movies.first) diff --git a/billing/spec/controllers/importers_controller_spec.rb b/billing/spec/controllers/importers_controller_spec.rb new file mode 100644 index 0000000000..49e0d8b2cd --- /dev/null +++ b/billing/spec/controllers/importers_controller_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe 'ImporterController', type: :request do + context 'when try make a post with txt file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return successful' do + post '/importer/import_file', params: { file: file } + json_response = JSON.parse(@response.body) + + expect(@response.code).to eq('200') + expect(json_response).to eq({ + 'success' => true, + 'message' => 'Upload and creation data make with successful!' + }) + end + end + + context 'when try make a post with another extension file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return fails' do + post '/importer/import_file', params: { file: file } + json_response = JSON.parse(@response.body) + + expect(json_response).to eq({ + 'success' => false, + 'message' => 'Something is wrong!' + }) + end + end +end \ No newline at end of file diff --git a/billing/spec/controllers/transactions_controller_spec.rb b/billing/spec/controllers/transactions_controller_spec.rb new file mode 100644 index 0000000000..bd7e99e309 --- /dev/null +++ b/billing/spec/controllers/transactions_controller_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +RSpec.describe 'TransactionsController', type: :request do + context 'when make request GET and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let(:data) do + [ + { "provider_name"=>"Bar Do João", "provider_owner"=>"João Macedo", "total_balance"=>"R$406.0" }, + { "provider_name"=>"Loja Do Ó - Matriz", "provider_owner"=>"Maria Josefina", "total_balance"=>"R$434.0" }, + { "provider_name"=>"Mercado Da Avenida", "provider_owner"=>"Marcos Pereira", "total_balance"=>"R$2335.2" }, + { "provider_name"=>"Mercearia 3 Irmãos", "provider_owner"=>"José Costa", "total_balance"=>"R$7023.0" }, + { "provider_name"=>"Loja Do Ó - Filial", "provider_owner"=>"Maria Josefina", "total_balance"=>"R$152.32" } + ] + end + + before do + Importer.new(path).import_and_create_data + end + + it 'return successful with array with transactions' do + get '/transactions' + json_response = JSON.parse(@response.body) + + expect(@response.code).to eq('200') + expect(json_response).to eq({ + 'success' => true, + 'transactions' => data + }) + end + end + + context 'when make request GET and havent anyone register and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return successful with empty array' do + get '/transactions' + json_response = JSON.parse(@response.body) + + expect(json_response).to eq({ + 'success' => true, + 'transactions' => [] + }) + end + end +end From 8fcaf036ac858dce525280e19b2a5e2dadfb8b62 Mon Sep 17 00:00:00 2001 From: Ueverton-oliveira Date: Wed, 4 May 2022 22:13:29 -0400 Subject: [PATCH 8/8] feat: importer service --- billing/app/services/importer.rb | 61 +++++++++++++++++++ billing/spec/fixtures/files/file_example.txt | 21 +++++++ billing/spec/fixtures/files/rails.png | Bin 0 -> 23061 bytes billing/spec/rails_helper.rb | 41 +------------ billing/spec/services/importer_spec.rb | 27 ++++++++ 5 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 billing/app/services/importer.rb create mode 100644 billing/spec/fixtures/files/file_example.txt create mode 100644 billing/spec/fixtures/files/rails.png create mode 100644 billing/spec/services/importer_spec.rb diff --git a/billing/app/services/importer.rb b/billing/app/services/importer.rb new file mode 100644 index 0000000000..ddf4e55e08 --- /dev/null +++ b/billing/app/services/importer.rb @@ -0,0 +1,61 @@ +class Importer + attr_reader :read_file, :open_file + + def initialize(file) + @open_file = File.open(file) + @read_file = @open_file&.readlines + end + + def import_and_create_data + return false unless is_valid_extension?(open_file) + + read_file.each do |line| + data = convert_line_to_hash(line) + provider = find_or_create_provider(data['provider']) + customer = find_or_create_customer(data['customer']) + data_transaction = data['transaction'].merge({ customer_id: customer.reload.id, provider_id: provider.reload.id }) + + Transaction.create(data_transaction) + end + + true + end + + private + + def is_valid_extension?(file) + return true if File.extname(file).match(/txt|csv/) + false + end + + def find_or_create_provider(provider) + object = Provider.where(name_provider: provider[:name_provider]) + + return object if object.present? + Provider.create!(provider) + end + + def find_or_create_customer(customer) + object = Customer.where(cpf: customer[:cpf]) + + return object if object.present? + Customer.create!(customer) + end + + def convert_line_to_hash(line) + type = line[0, 1].strip + date = Date.parse(line[1, 8].strip).strftime("%d/%m/%Y") + value = (line[9, 10].strip.to_f) / 100 + cpf = line[19, 11].strip + card = line[30, 12].strip + hour = line[42, 6].strip.scan(/[0-9]{2}/).join(':') + name_owner = line[48, 14].strip + name_provider = line[62, 19].strip + + { + 'transaction' => { type_transaction: type.to_i, date_transaction: date, value: value, hour: hour, number_card: card }, + 'customer' => { cpf: cpf }, + 'provider' => { name_owner: name_owner, name_provider: name_provider} + } + end +end \ No newline at end of file diff --git a/billing/spec/fixtures/files/file_example.txt b/billing/spec/fixtures/files/file_example.txt new file mode 100644 index 0000000000..0a81268be2 --- /dev/null +++ b/billing/spec/fixtures/files/file_example.txt @@ -0,0 +1,21 @@ +3201903010000014200096206760174753****3153153453JOÃO MACEDO BAR DO JOÃO +5201903010000013200556418150633123****7687145607MARIA JOSEFINALOJA DO Ó - MATRIZ +3201903010000012200845152540736777****1313172712MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000011200096206760173648****0099234234JOÃO MACEDO BAR DO JOÃO +1201903010000015200096206760171234****7890233000JOÃO MACEDO BAR DO JOÃO +2201903010000010700845152540738723****9987123333MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000050200845152540738473****1231231233MARCOS PEREIRAMERCADO DA AVENIDA +3201903010000060200232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +1201903010000020000556418150631234****3324090002MARIA JOSEFINALOJA DO Ó - MATRIZ +5201903010000080200845152540733123****7687145607MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000010200232702980568473****1231231233JOSÉ COSTA MERCEARIA 3 IRMÃOS +3201903010000610200232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +4201903010000015232556418150631234****6678100000MARIA JOSEFINALOJA DO Ó - FILIAL +8201903010000010203845152540732344****1222123222MARCOS PEREIRAMERCADO DA AVENIDA +3201903010000010300232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +9201903010000010200556418150636228****9090000000MARIA JOSEFINALOJA DO Ó - MATRIZ +4201906010000050617845152540731234****2231100000MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000010900232702980568723****9987123333JOSÉ COSTA MERCEARIA 3 IRMÃOS +8201903010000000200845152540732344****1222123222MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000000500232702980567677****8778141808JOSÉ COSTA MERCEARIA 3 IRMÃOS +3201903010000019200845152540736777****1313172712MARCOS PEREIRAMERCADO DA AVENIDA \ No newline at end of file diff --git a/billing/spec/fixtures/files/rails.png b/billing/spec/fixtures/files/rails.png new file mode 100644 index 0000000000000000000000000000000000000000..9e5b7f139a36e8a780aa5f98dea3098d11733b6d GIT binary patch literal 23061 zcmW(+1zeL~8+}KN(WAQ?X^`#?rCYi~0SRds-Q7ru(g;XOkC2cSX^@fz>8@}8Z@+Et z2EXmzJvW|n&U0>zrn(X~1~~=*0N5(Z^4b6ZLc9b45HR9m;$CitxS-g}yp{ogZ%LRB zmZ*sLwARYnuK~c1831760C0!+6Kod%ym$a$-vR(cvjKp_Ew4>W9PtmZm70<~;)=N4 z%C!e0E@+-AuNBbN(XdG9DdpB`ngGBEO+{Wt*Jts_)VqUHuk*PeXTi+n_?lU$6CVkb zIw?jEiJfPPE-$wrDb(nx5f?jVGps|39cmDl7p3nECpJbx-)s4Mb!7X~H+b~$U*k%9 z;C7~~q>z}$_ULHN!sFxk@wHgDERWi0kWUZH1IYnt61j*%8Vx20a029@8vrF;N(vwW z%J!3xr2(GG3E$Dr#PjbNdOscn>WuG~)qtC6l>txCJYXRKYXbC<41ppL-|4tD^#?_G z?8k9Ka2=`)H!Ka5hq$I)_?{~=&}=_~;JoMCupE@$dfNCiRP9T=%9WWga`mC56m1|~ zeJNi%R)E|1Q56^k5KZ;~FlX9{JEnvz9xTWRY~2v5|A+b2b`p#y{?&;*v!|?QDH0MK z1XXXswQz(dskbcc8|Y9$0r`=w`gRfZa=!p1Q@J2bYvdVkP4e=B$ynMi#nef*YsY)x zWuFyVrSxiE%Ul)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iyO6X6G`stH!ayzNK>AEva#fh5XxT1B3Dm*1YW8gWHRYB z7-HWdG!l9IWaU87s(y3%dO3`4PUlbgO~&P=6SR4@z2^CW)fpG{ze6M}0^keFva2d^ z`4x{`;rf{yK9MoSC>c6;>A*(=j!eS=?_wxmYOtGuu+%#j+o)V!dv7~1Q;JK0_j(DC z9l+a`R(O$1zfYSF&`9G=gJ%}2A+SiA3`bWE6#*Uw$>@C4Tr8ShgCv&L=EVh6MN%P* z6Utm@d67Y(;aOUzOnB&Q9N~FwnG1_yS zRSP$-rg5|-AyN}7q(jxsl<`bcisSim#pYX0NK3d;vdxqOI>!b|Y7SDY1yDJ$AU>1Y z#X+S6HP>~Ui}EF;JVRtkL*_3yPHEYxHreB??!NX@s`-IqvHRls^iE_cwXcex7IS zmx=_hE`9d&{L~#)Yx4AVtB;NZr)UZ$%2ebW}VF zFsevExj)LVq{3_@p3++d{{ZEEsZTX&H6x zX#xpc|I5nqr&PAm4qyWANA*!rkqG8>)m~BWo}0Zln`nj!zcO9nzZQZ(Tkj|Ldg}x1 zAW7h}@b>+0nLzzuNZ`-D#D0iz5Up%DoYhN2$GIH^*DBKX2%djk2vOHF3r zVt)13jv#ULM1w2l}3L||>)N3x#>o?KiV0_^oTNGCqXN2A{ z19%4vAwto2ys8C=a6|Dp8&2`S4w6c;c(CamKL=Ys#~b!Oj-(F>cbh; e @@ -33,34 +16,12 @@ exit 1 end RSpec.configure do |config| - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/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://relishapp.com/rspec/rspec-rails/docs 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/billing/spec/services/importer_spec.rb b/billing/spec/services/importer_spec.rb new file mode 100644 index 0000000000..2e96e578ac --- /dev/null +++ b/billing/spec/services/importer_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe Importer do + context 'when call the service with file txt and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let(:importer) { Importer.new(path) } + + it 'return successful' do + expect(importer.import_and_create_data).to eq(true) + expect(Customer.last).to be_present + expect(Provider.last).to be_present + expect(Transaction.last).to be_present + end + end + + context 'when call the service with another extension file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let(:importer) { Importer.new(path) } + + it 'return fails' do + expect(importer.import_and_create_data).to eq(false) + expect(Customer.last).to be(nil) + expect(Provider.last).to be(nil) + expect(Transaction.last).to be(nil) + end + end +end \ No newline at end of file