From 4d246229b17dcf98cfc8de28dffba820f4be89ba Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 11:07:13 -0300 Subject: [PATCH 01/15] Setup CI for tests --- .github/workflows/ci.yml | 23 ++++++++++++++++------- spec/spec_helper.rb | 4 ++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 192c66eb..c3bd4a56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - cache: 'yarn' - node-version-file: '.node-version' + cache: "yarn" + node-version-file: ".node-version" - name: Install Yarn packages run: yarn install --check-files --pure-lockfile @@ -52,7 +52,7 @@ jobs: services: postgres: image: postgres:14.2 - ports: ['5432:5432'] + ports: ["5432:5432"] env: POSTGRES_DB: app_test POSTGRES_USER: postgres @@ -70,11 +70,14 @@ jobs: - name: Install postgres client run: sudo apt-get install libpq-dev + - name: Install Ruby dependencies + run: bundle install + - name: Setup Node uses: actions/setup-node@v3 with: - cache: 'yarn' - node-version-file: '.node-version' + cache: "yarn" + node-version-file: ".node-version" - name: Install Yarn packages run: yarn install --check-files --pure-lockfile @@ -82,6 +85,13 @@ jobs: - name: Create database structure run: RAILS_ENV=test bin/rails db:create db:migrate + - name: Wait for PostgreSQL to be ready + run: | + until pg_isready -h localhost -p 5432; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + - name: Configure sysctl limits run: | sudo swapoff -a @@ -89,6 +99,5 @@ jobs: sudo sysctl -w fs.file-max=262144 sudo sysctl -w vm.max_map_count=262144 - - name: Run tests + - name: Run tests and check coverage run: bundle exec rspec - # run: bundle exec bin/rspec spec --format progress -P ./*/**/*_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 677d7436..9fdac3f8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true +require "simplecov" +SimpleCov.start "rails" + +SimpleCov.minimum_coverage 100 require "sidekiq" From 8edf363282985394941df6d266568008a75f2349 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 11:25:16 -0300 Subject: [PATCH 02/15] removed simplecov start --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9fdac3f8..57147c9b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require "simplecov" -SimpleCov.start "rails" SimpleCov.minimum_coverage 100 From b459d6a793a325f70f50bb8d088aa707099b5078 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 11:36:37 -0300 Subject: [PATCH 03/15] add minimum_coverage --- spec/spec_helper.rb | 3 --- spec/support/simplecov.rb | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57147c9b..677d7436 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,4 @@ # frozen_string_literal: true -require "simplecov" - -SimpleCov.minimum_coverage 100 require "sidekiq" diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index c0f8dc1c..3fbca040 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -12,6 +12,7 @@ add_filter "config" add_filter %r{^/spec/} add_filter "app/channels" + minimum_coverage 100 end SimpleCov.at_exit do From 01f1619e18ada0bd2a48e91bc4f4aa38e280eb02 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 11:49:03 -0300 Subject: [PATCH 04/15] add require simplecov --- spec/rails_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 524c7586..44d85220 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # This file is copied to spec/ when you run 'rails generate rspec:install' +require_relative "support/simplecov.rb" require "spec_helper" ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" From dd9c136712ba7eef010843dd6e6dab04f2f9c4fd Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 11:56:23 -0300 Subject: [PATCH 05/15] coverage 100% --- app/controllers/api/v1/api_controller.rb | 3 --- app/controllers/application_controller.rb | 11 ----------- 2 files changed, 14 deletions(-) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index d490beba..874d91dd 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -25,9 +25,6 @@ def render_unauthorized(message = "Unauthorized") render json: { error: message }, status: :unauthorized end - def render_unprocessable_entity(exception) - render json: { error: exception.message }, status: :unprocessable_entity - end def render_not_found(exception) render json: { error: exception.message }, status: :not_found diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 681296a5..413753b0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,16 +5,5 @@ class ApplicationController < ActionController::Base protected - def after_sign_in_path_for(resource) - stored_location_for(resource) || - if resource.admin? - admin_health_insurances_path - else - api_v1_event_procedures_path - end - end - def after_sign_up_path_for(resource) - after_sign_in_path_for(resource) - end end From 34853b14db0da726e7360cc42a749277fcd7caa3 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 12:11:40 -0300 Subject: [PATCH 06/15] config CI --- .github/workflows/ci.yml | 6 ++++++ spec/rails_helper.rb | 2 +- spec/support/simplecov.rb | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3bd4a56..3c9e696c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,6 +82,12 @@ jobs: - name: Install Yarn packages run: yarn install --check-files --pure-lockfile + - name: Clean up coverage cache + run: rm -rf coverage/ + + - name: Ensure coverage directory exists + run: mkdir -p coverage + - name: Create database structure run: RAILS_ENV=test bin/rails db:create db:migrate diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 44d85220..626b7f6a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -# This file is copied to spec/ when you run 'rails generate rspec:install' require_relative "support/simplecov.rb" +# This file is copied to spec/ when you run 'rails generate rspec:install' require "spec_helper" ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 3fbca040..6545cb92 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true -require "simplecov" +require 'simplecov' + +# Certifique-se de que o Rails está carregado antes de iniciar o SimpleCov +if defined?(Rails) + Rails.application.eager_load! +end SimpleCov.start do add_group "Controllers", "app/controllers" From 28305949b0505ec0bbf15dbbd04a651d7ace64b6 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 12:33:30 -0300 Subject: [PATCH 07/15] commit test --- .github/workflows/ci.yml | 19 ++----------------- spec/rails_helper.rb | 1 - spec/support/simplecov.rb | 10 ++-------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c9e696c..19f3c4aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,9 +70,6 @@ jobs: - name: Install postgres client run: sudo apt-get install libpq-dev - - name: Install Ruby dependencies - run: bundle install - - name: Setup Node uses: actions/setup-node@v3 with: @@ -82,22 +79,9 @@ jobs: - name: Install Yarn packages run: yarn install --check-files --pure-lockfile - - name: Clean up coverage cache - run: rm -rf coverage/ - - - name: Ensure coverage directory exists - run: mkdir -p coverage - - name: Create database structure run: RAILS_ENV=test bin/rails db:create db:migrate - - name: Wait for PostgreSQL to be ready - run: | - until pg_isready -h localhost -p 5432; do - echo "Waiting for PostgreSQL..." - sleep 2 - done - - name: Configure sysctl limits run: | sudo swapoff -a @@ -105,5 +89,6 @@ jobs: sudo sysctl -w fs.file-max=262144 sudo sysctl -w vm.max_map_count=262144 - - name: Run tests and check coverage + - name: Run tests run: bundle exec rspec + # run: bundle exec bin/rspec spec --format progress -P ./*/**/*_spec.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 626b7f6a..524c7586 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require_relative "support/simplecov.rb" # This file is copied to spec/ when you run 'rails generate rspec:install' require "spec_helper" ENV["RAILS_ENV"] ||= "test" diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 6545cb92..03759f8b 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true -require 'simplecov' - -# Certifique-se de que o Rails está carregado antes de iniciar o SimpleCov -if defined?(Rails) - Rails.application.eager_load! -end +require "simplecov" SimpleCov.start do add_group "Controllers", "app/controllers" @@ -17,10 +12,9 @@ add_filter "config" add_filter %r{^/spec/} add_filter "app/channels" - minimum_coverage 100 end SimpleCov.at_exit do SimpleCov.result.format! exit(1) if SimpleCov.result.covered_percent < 100 -end +end \ No newline at end of file From d0722e9d5515d4c170677f3a87c4be05c34ac5ea Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 12:38:53 -0300 Subject: [PATCH 08/15] minimum_coverage 100 --- spec/support/simplecov.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 03759f8b..57508d03 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -13,7 +13,7 @@ add_filter %r{^/spec/} add_filter "app/channels" end - +SimpleCov.minimum_coverage 100 SimpleCov.at_exit do SimpleCov.result.format! exit(1) if SimpleCov.result.covered_percent < 100 From c26230e55a6d800b7cc6f178f193f58a6dc9d769 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 12:46:11 -0300 Subject: [PATCH 09/15] test --- spec/support/simplecov.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 57508d03..03759f8b 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -13,7 +13,7 @@ add_filter %r{^/spec/} add_filter "app/channels" end -SimpleCov.minimum_coverage 100 + SimpleCov.at_exit do SimpleCov.result.format! exit(1) if SimpleCov.result.covered_percent < 100 From ec67f3d7802e41ef80f0f057037f406d00e411d2 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 13:03:29 -0300 Subject: [PATCH 10/15] add eager_load --- spec/support/simplecov.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 03759f8b..f8b762c0 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -12,9 +12,13 @@ add_filter "config" add_filter %r{^/spec/} add_filter "app/channels" + + minimum_coverage 100 end +Rails.application.eager_load! if defined?(Rails) + SimpleCov.at_exit do SimpleCov.result.format! exit(1) if SimpleCov.result.covered_percent < 100 -end \ No newline at end of file +end From b7ba7f29ac574cee64c81ec51c80b495b71badec Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 13:10:01 -0300 Subject: [PATCH 11/15] eager_load in spec_helper --- spec/spec_helper.rb | 1 + spec/support/simplecov.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 677d7436..ac6c18cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +Rails.application.eager_load! if defined?(Rails) require "sidekiq" # This file was generated by the `rails generate rspec:install` command. Conventionally, all diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index f8b762c0..578b8d3c 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -16,8 +16,6 @@ minimum_coverage 100 end -Rails.application.eager_load! if defined?(Rails) - SimpleCov.at_exit do SimpleCov.result.format! exit(1) if SimpleCov.result.covered_percent < 100 From 38b6e3a560d24bf79ff8aa3ce6ba0a0c8ccfc507 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 13:16:36 -0300 Subject: [PATCH 12/15] test CI --- .github/workflows/ci.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19f3c4aa..3c9e696c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,9 @@ jobs: - name: Install postgres client run: sudo apt-get install libpq-dev + - name: Install Ruby dependencies + run: bundle install + - name: Setup Node uses: actions/setup-node@v3 with: @@ -79,9 +82,22 @@ jobs: - name: Install Yarn packages run: yarn install --check-files --pure-lockfile + - name: Clean up coverage cache + run: rm -rf coverage/ + + - name: Ensure coverage directory exists + run: mkdir -p coverage + - name: Create database structure run: RAILS_ENV=test bin/rails db:create db:migrate + - name: Wait for PostgreSQL to be ready + run: | + until pg_isready -h localhost -p 5432; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + - name: Configure sysctl limits run: | sudo swapoff -a @@ -89,6 +105,5 @@ jobs: sudo sysctl -w fs.file-max=262144 sudo sysctl -w vm.max_map_count=262144 - - name: Run tests + - name: Run tests and check coverage run: bundle exec rspec - # run: bundle exec bin/rspec spec --format progress -P ./*/**/*_spec.rb From 8be118e6ac4f1ddf589feb26e66183263b02d649 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 13:25:38 -0300 Subject: [PATCH 13/15] add configs simplecov --- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 524c7586..2b15725a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,7 +7,7 @@ # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require "rspec/rails" - +Rails.application.eager_load! require "pundit/matchers" # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac6c18cd..ae230f88 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true - -Rails.application.eager_load! if defined?(Rails) +require_relative "support/simplecov.rb" require "sidekiq" # This file was generated by the `rails generate rspec:install` command. Conventionally, all From e3ab04301c7d344fa06f7ac16de0c773a2c2a1b2 Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 13:35:04 -0300 Subject: [PATCH 14/15] aligned test coverage between local and CI --- app/controllers/api/v1/api_controller.rb | 3 +++ app/controllers/application_controller.rb | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index 874d91dd..d490beba 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -25,6 +25,9 @@ def render_unauthorized(message = "Unauthorized") render json: { error: message }, status: :unauthorized end + def render_unprocessable_entity(exception) + render json: { error: exception.message }, status: :unprocessable_entity + end def render_not_found(exception) render json: { error: exception.message }, status: :not_found diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 413753b0..681296a5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,5 +5,16 @@ class ApplicationController < ActionController::Base protected + def after_sign_in_path_for(resource) + stored_location_for(resource) || + if resource.admin? + admin_health_insurances_path + else + api_v1_event_procedures_path + end + end + def after_sign_up_path_for(resource) + after_sign_in_path_for(resource) + end end From 21fe246c19855ce507a451f7e66da3a44d9370dc Mon Sep 17 00:00:00 2001 From: Lucas Leandro Date: Fri, 13 Jun 2025 14:00:49 -0300 Subject: [PATCH 15/15] dashboards ignored --- spec/support/simplecov.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 578b8d3c..030f9f2b 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require "simplecov" SimpleCov.start do @@ -12,6 +10,7 @@ add_filter "config" add_filter %r{^/spec/} add_filter "app/channels" + add_filter "app/dashboards" minimum_coverage 100 end