From f816fe1f046929c65d7d2c72b4c8726eb958ffdd Mon Sep 17 00:00:00 2001 From: Danilo Date: Sun, 21 Jul 2024 23:44:45 -0300 Subject: [PATCH 1/5] WP Aplicando JOB ao cadastro de sindico Co-authored-by: Lucas Lima --- app/controllers/tenants_controller.rb | 4 ++- app/jobs/active_superintendent_job.rb | 5 +++ app/jobs/desactive_superintendet_job.rb | 5 +++ ...0722002636_add_status_to_superintendent.rb | 5 +++ db/schema.rb | 3 +- spec/jobs/update_superintendent_spec.rb | 8 +++++ .../manager_register_superintendent_spec.rb | 36 ++++++++++++++++--- 7 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 app/jobs/active_superintendent_job.rb create mode 100644 app/jobs/desactive_superintendet_job.rb create mode 100644 db/migrate/20240722002636_add_status_to_superintendent.rb create mode 100644 spec/jobs/update_superintendent_spec.rb diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb index 77f72b91..e5aad118 100644 --- a/app/controllers/tenants_controller.rb +++ b/app/controllers/tenants_controller.rb @@ -8,7 +8,7 @@ def new; end def create return unless update_resident_for_valid_unit - @resident.mail_not_confirmed! && send_email if @resident.residence_registration_pending? + return @resident.mail_not_confirmed! && send_email if @resident.residence_registration_pending? redirect_to @resident, notice: t('notices.tenant.updated') end @@ -29,6 +29,8 @@ def send_email random_password = SecureRandom.alphanumeric 8 @resident.update password: random_password @resident.send_invitation random_password + + redirect_to @resident, notice: t('notices.tenant.send_email') end def update_resident_for_valid_unit diff --git a/app/jobs/active_superintendent_job.rb b/app/jobs/active_superintendent_job.rb new file mode 100644 index 00000000..94f16667 --- /dev/null +++ b/app/jobs/active_superintendent_job.rb @@ -0,0 +1,5 @@ +class ActiveSuperIntendentJob < ApplicationJob + queue_as :default + + def perform(superintendent); end +end diff --git a/app/jobs/desactive_superintendet_job.rb b/app/jobs/desactive_superintendet_job.rb new file mode 100644 index 00000000..788e2211 --- /dev/null +++ b/app/jobs/desactive_superintendet_job.rb @@ -0,0 +1,5 @@ +class DesactiveSuperIntendentJob < ApplicationJob + queue_as :default + + def perform(superintendent); end +end diff --git a/db/migrate/20240722002636_add_status_to_superintendent.rb b/db/migrate/20240722002636_add_status_to_superintendent.rb new file mode 100644 index 00000000..9028b8f6 --- /dev/null +++ b/db/migrate/20240722002636_add_status_to_superintendent.rb @@ -0,0 +1,5 @@ +class AddStatusToSuperintendent < ActiveRecord::Migration[7.1] + def change + add_column :superintendents, :status, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 2956d541..424ecf29 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_18_231004) do +ActiveRecord::Schema[7.1].define(version: 2024_07_22_002636) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -172,6 +172,7 @@ t.datetime "updated_at", null: false t.integer "condo_id", null: false t.integer "tenant_id", null: false + t.integer "status" t.index ["condo_id"], name: "index_superintendents_on_condo_id" t.index ["tenant_id"], name: "index_superintendents_on_tenant_id" end diff --git a/spec/jobs/update_superintendent_spec.rb b/spec/jobs/update_superintendent_spec.rb new file mode 100644 index 00000000..c7089192 --- /dev/null +++ b/spec/jobs/update_superintendent_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' + +RSpec.describe UpdateSuperintendentJob, type: :job do + it '' do + superintendent = create :superintendent + UpdateSuperintendentJob.perfom(superintendent) + end +end diff --git a/spec/system/superintendent/manager_register_superintendent_spec.rb b/spec/system/superintendent/manager_register_superintendent_spec.rb index e4499ec3..049c3fe9 100644 --- a/spec/system/superintendent/manager_register_superintendent_spec.rb +++ b/spec/system/superintendent/manager_register_superintendent_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' describe 'Manager register superintendent' do - it 'Successfully' do + it 'Successfully to act now' do condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, full_name: 'Alvus Dumbledore', condo:) manager = create :manager - date = Time.zone.today + travel_to '2024-07-21'.to_date login_as manager, scope: :manager visit root_path @@ -17,8 +17,36 @@ within '#condoSelectPopupForSuperintendent' do click_on 'Condomínio X' end - fill_in 'Data de ínicio', with: date - fill_in 'Data de conclusão', with: date >> 12 + + fill_in 'Data de ínicio', with: '2024-07-21'.to_date + fill_in 'Data de conclusão', with: '2025-07-25'.to_date + select 'Alvus Dumbledore', from: 'Morador' + click_on 'Enviar' + + expect(page).to have_content 'Mandato de síndico cadastro com sucesso!' + expect(current_path).to eq condo_superintendent_path(condo, Superintendent.last) + expect(Superintendent.last.tenant).to eq resident + end + + it 'Successfully to act on 2024-07-25' do + condo = create :condo, name: 'Condomínio X' + resident = create(:resident, :with_residence, full_name: 'Alvus Dumbledore', condo:) + manager = create :manager + travel_to '2024-07-21'.to_date + + login_as manager, scope: :manager + visit root_path + within 'nav' do + click_on id: 'side-menu' + click_on 'Gerenciar Usuários' + click_on 'Cadastrar Síndico' + end + within '#condoSelectPopupForSuperintendent' do + click_on 'Condomínio X' + end + + fill_in 'Data de ínicio', with: '2024-07-25'.to_date + fill_in 'Data de conclusão', with: '2025-07-28'.to_date select 'Alvus Dumbledore', from: 'Morador' click_on 'Enviar' From eb6b980887580b5f2db1fcf82427a260cb7b5384 Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 22 Jul 2024 11:18:41 -0300 Subject: [PATCH 2/5] Implementa Job no cadastro de sindico Co-authored-by: Lucas Lima --- README.md | 2 +- app/controllers/superintendents_controller.rb | 30 +++--- app/jobs/active_superintendent_job.rb | 8 +- app/jobs/desactive_superintendent_job.rb | 9 ++ app/jobs/desactive_superintendet_job.rb | 5 - app/models/condo.rb | 6 +- app/models/superintendent.rb | 19 +++- app/views/condos/show.html.erb | 4 +- app/views/superintendents/edit.html.erb | 3 - app/views/superintendents/show.html.erb | 6 +- .../locales/models/superintendent.pt-BR.yml | 3 +- config/routes.rb | 2 +- spec/jobs/active_superintendent_spec.rb | 39 ++++++++ spec/jobs/desactive_superintendent_spec.rb | 39 ++++++++ spec/jobs/update_superintendent_spec.rb | 8 -- spec/models/condo_spec.rb | 25 +++++ spec/models/superintendent_spec.rb | 28 ++++++ .../manager_closed_superintendent_spec.rb | 41 ++++++++ .../manager_edit_superintendent_spec.rb | 95 ------------------- .../manager_delete_superintendent_spec.rb | 24 +++++ .../manager_edit_superintendent_spec.rb | 54 ----------- .../manager_register_superintendent_spec.rb | 53 +++++++++-- .../user_sees_superintendent_details_spec.rb | 5 +- 23 files changed, 305 insertions(+), 203 deletions(-) create mode 100644 app/jobs/desactive_superintendent_job.rb delete mode 100644 app/jobs/desactive_superintendet_job.rb delete mode 100644 app/views/superintendents/edit.html.erb create mode 100644 spec/jobs/active_superintendent_spec.rb create mode 100644 spec/jobs/desactive_superintendent_spec.rb delete mode 100644 spec/jobs/update_superintendent_spec.rb create mode 100644 spec/requests/manager_closed_superintendent_spec.rb delete mode 100644 spec/requests/manager_edit_superintendent_spec.rb create mode 100644 spec/system/superintendent/manager_delete_superintendent_spec.rb delete mode 100644 spec/system/superintendent/manager_edit_superintendent_spec.rb diff --git a/README.md b/README.md index 9bb61c46..748bb99a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] [![Status][status-shield]][status-url] - + diff --git a/app/controllers/superintendents_controller.rb b/app/controllers/superintendents_controller.rb index 12e2872e..043b5865 100644 --- a/app/controllers/superintendents_controller.rb +++ b/app/controllers/superintendents_controller.rb @@ -1,11 +1,12 @@ class SuperintendentsController < ApplicationController - before_action :authenticate_manager!, only: %i[new create edit update] - before_action :set_condo, only: %i[show new create edit update] - before_action :set_superintendent, only: %i[show edit update] - before_action :set_breadcrumbs_condo, only: %i[new create edit update] + before_action :authenticate_manager!, only: %i[new create ] + before_action :set_condo, only: %i[show new create destroy] + before_action :set_superintendent, only: %i[show destroy] + before_action :set_breadcrumbs_condo, only: %i[new create ] before_action :set_breadcrumbs_for_register, only: %i[new create] - before_action :set_breadcrumbs_for_edit, only: %i[edit update] - before_action -> { authorize_user(@condo) }, only: %i[show new create edit update] + before_action :set_breadcrumbs_for_edit, only: %i[] + before_action -> { authorize_condo_manager(@condo) }, only: %i[destroy] + before_action -> { authorize_user(@condo) }, only: %i[show new create ] def show @tenant = @superintendent.tenant @@ -23,12 +24,8 @@ def new @tenants = @condo.tenants end - def edit - @tenants = @condo.tenants - end - def create - @superintendent = Superintendent.new(superintendent_params.merge!(condo: @condo)) + @superintendent = Superintendent.new(superintendent_params.merge!({ status: :pending, condo: @condo })) unless @superintendent.save @tenants = @condo.tenants @@ -39,14 +36,9 @@ def create redirect_to condo_superintendent_path(@condo, @superintendent), notice: t('notices.superintendent.created') end - def update - unless @superintendent.update(superintendent_params) - @tenants = @condo.tenants - flash.now[:alert] = t('alerts.superintendent.not_updated') - return render 'new', status: :unprocessable_entity - end - - redirect_to condo_superintendent_path(@condo, @superintendent), notice: t('notices.superintendent.updated') + def destroy + @superintendent.closed! + redirect_to @condo, notice: t('notices.superintendent.closed') end private diff --git a/app/jobs/active_superintendent_job.rb b/app/jobs/active_superintendent_job.rb index 94f16667..ff1fa52d 100644 --- a/app/jobs/active_superintendent_job.rb +++ b/app/jobs/active_superintendent_job.rb @@ -1,5 +1,9 @@ -class ActiveSuperIntendentJob < ApplicationJob +class ActiveSuperintendentJob < ApplicationJob queue_as :default - def perform(superintendent); end + def perform(superintendent) + return unless superintendent.pending? && superintendent.start_date == Date.current + + superintendent.in_action! + end end diff --git a/app/jobs/desactive_superintendent_job.rb b/app/jobs/desactive_superintendent_job.rb new file mode 100644 index 00000000..306e1768 --- /dev/null +++ b/app/jobs/desactive_superintendent_job.rb @@ -0,0 +1,9 @@ +class DesactiveSuperintendentJob < ApplicationJob + queue_as :default + + def perform(superintendent) + return unless superintendent.in_action? && superintendent.end_date == Date.current + + superintendent.closed! + end +end diff --git a/app/jobs/desactive_superintendet_job.rb b/app/jobs/desactive_superintendet_job.rb deleted file mode 100644 index 788e2211..00000000 --- a/app/jobs/desactive_superintendet_job.rb +++ /dev/null @@ -1,5 +0,0 @@ -class DesactiveSuperIntendentJob < ApplicationJob - queue_as :default - - def perform(superintendent); end -end diff --git a/app/models/condo.rb b/app/models/condo.rb index f15e32a5..c69fad88 100644 --- a/app/models/condo.rb +++ b/app/models/condo.rb @@ -12,7 +12,7 @@ class Condo < ApplicationRecord has_many :units, through: :floors has_many :owners, through: :units has_many :tenants, through: :units - has_one :superintendent, dependent: :destroy + has_many :superintendents, dependent: :destroy delegate :city, to: :address delegate :state, to: :address @@ -23,6 +23,10 @@ class Condo < ApplicationRecord accepts_nested_attributes_for :address + def superintendent + superintendents.not_closed[0] + end + def residents (tenants + owners).uniq end diff --git a/app/models/superintendent.rb b/app/models/superintendent.rb index de5df43f..71c7f665 100644 --- a/app/models/superintendent.rb +++ b/app/models/superintendent.rb @@ -4,7 +4,24 @@ class Superintendent < ApplicationRecord validates :start_date, :end_date, presence: true - validate :start_date_must_be_valid, :end_date_must_be_valid + validate :start_date_must_be_valid, :end_date_must_be_valid, on: :create + + enum status: { pending: 0, in_action: 1, closed: 2 } + + after_create :action_now_or_after? + after_create :program_deactivation + + private + + def action_now_or_after? + return in_action! if start_date == Date.current + + ActiveSuperintendentJob.set(wait_until: start_date.to_datetime).perform_later self + end + + def program_deactivation + DesactiveSuperintendentJob.set(wait_until: end_date.to_datetime).perform_later self + end def start_date_must_be_valid errors.add :start_date, 'deve ser atual ou futura' if start_date&.past? diff --git a/app/views/condos/show.html.erb b/app/views/condos/show.html.erb index a714e3eb..7a506270 100644 --- a/app/views/condos/show.html.erb +++ b/app/views/condos/show.html.erb @@ -5,7 +5,9 @@

CNPJ: <%= @condo.registration_number %>

Síndico: <% if @condo.superintendent%> - <%= link_to @condo.superintendent.tenant.full_name, condo_superintendent_path(@condo, @condo.superintendent) %> + <%= link_to condo_superintendent_path(@condo, @condo.superintendent) do %> + <%= "#{@condo.superintendent.tenant.full_name} (#{@condo.superintendent.start_date} - #{@condo.superintendent.end_date})"%> + <% end %> <% else %> Não há um síndico ativo <% end %> diff --git a/app/views/superintendents/edit.html.erb b/app/views/superintendents/edit.html.erb deleted file mode 100644 index db6a6847..00000000 --- a/app/views/superintendents/edit.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

Editar Mandato de Síndico para <%= @condo.name %>

- -<%= render 'form' %> \ No newline at end of file diff --git a/app/views/superintendents/show.html.erb b/app/views/superintendents/show.html.erb index 0aa94203..63f5150b 100644 --- a/app/views/superintendents/show.html.erb +++ b/app/views/superintendents/show.html.erb @@ -19,7 +19,7 @@

Torre: <%= @tenant.residence.tower.name %>

Unidade: <%= @tenant.residence.short_identifier %>

-

Ínicio do mandato: <%= I18n.l(@superintendent.start_date) %>

+

Início do mandato: <%= I18n.l(@superintendent.start_date) %>

Fim do mandato: <%= I18n.l(@superintendent.end_date) %>

@@ -27,8 +27,8 @@ <% if manager_signed_in? %>
- <%= button_to 'Editar Síndico', edit_condo_superintendent_path(@condo, @superintendent), method: :get, class:'btn btn-dark rounded-pill px-4 mt-3' %> -
+ <%= button_to 'Encerrar Gestão', condo_superintendent_path(@condo, @superintendent), method: :delete, class:'btn btn-dark rounded-pill px-4 mt-3' %> + <% end %> diff --git a/config/locales/models/superintendent.pt-BR.yml b/config/locales/models/superintendent.pt-BR.yml index 39faca1e..7c202590 100644 --- a/config/locales/models/superintendent.pt-BR.yml +++ b/config/locales/models/superintendent.pt-BR.yml @@ -3,6 +3,7 @@ pt-BR: superintendent: created: 'Mandato de síndico cadastro com sucesso!' updated: 'Mandato de síndico atualizado com sucesso!' + closed: 'Mandato de síndico encerrado com sucesso!' alerts: superintendent: not_created: 'Não foi possível cadastrar o mandato.' @@ -15,7 +16,7 @@ pt-BR: other: 'Síndicos' attributes: superintendent: - start_date: 'Data de ínicio' + start_date: 'Data de início' end_date: 'Data de conclusão' tenant_id: 'Morador' tenant: 'Morador' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b738a878..030578f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,7 @@ resources :common_areas, only: [:new, :create] resources :unit_types, only: [:new, :create] resources :visitor_entries, only: [:index, :new, :create] - resources :superintendents, only: [:show, :new, :create, :edit, :update] + resources :superintendents, only: [:show, :new, :create, :destroy] resources :announcements, only: [:index, :new, :create] resources :visitors do diff --git a/spec/jobs/active_superintendent_spec.rb b/spec/jobs/active_superintendent_spec.rb new file mode 100644 index 00000000..78264255 --- /dev/null +++ b/spec/jobs/active_superintendent_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe ActiveSuperintendentJob, type: :job do + context 'must be activate the superintendent' do + it 'in two days' do + travel_to '2024-07-22'.to_date + superintendent = create :superintendent, :pending, start_date: '2024-07-24'.to_date, + end_date: '2024-08-25'.to_date + + travel_to '2024-07-24'.to_date + ActiveSuperintendentJob.perform_now(superintendent) + expect(superintendent.in_action?).to eq true + end + + it 'does not update if the accused is on another day' do + travel_to '2024-07-22'.to_date + superintendent = create :superintendent, :pending, start_date: '2024-07-24'.to_date, + end_date: '2024-08-25'.to_date + + travel_to '2024-07-23'.to_date + ActiveSuperintendentJob.perform_now(superintendent) + expect(superintendent.in_action?).to eq false + end + + it 'and the status needs to be pending to update' do + travel_to '2024-07-20'.to_date + superintendent_action = create :superintendent, :in_action, start_date: '2024-07-23'.to_date, + end_date: '2024-08-25'.to_date + superintendent_closed = create :superintendent, :closed, start_date: '2024-07-22'.to_date, + end_date: '2024-08-23'.to_date + + travel_to '2024-07-24'.to_date + ActiveSuperintendentJob.perform_now(superintendent_action) + ActiveSuperintendentJob.perform_now(superintendent_closed) + expect(superintendent_action.in_action?).to eq true + expect(superintendent_closed.closed?).to eq true + end + end +end diff --git a/spec/jobs/desactive_superintendent_spec.rb b/spec/jobs/desactive_superintendent_spec.rb new file mode 100644 index 00000000..104bb49e --- /dev/null +++ b/spec/jobs/desactive_superintendent_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe DesactiveSuperintendentJob, type: :job do + context 'must be activate the superintendent' do + it 'in two days' do + travel_to '2024-07-22'.to_date + superintendent = create :superintendent, :in_action, start_date: '2024-07-22'.to_date, + end_date: '2024-07-24'.to_date + + travel_to '2024-07-24'.to_date + DesactiveSuperintendentJob.perform_now(superintendent) + expect(superintendent.closed?).to eq true + end + + it 'does not update if the accused is on another day' do + travel_to '2024-07-22'.to_date + superintendent = create :superintendent, :in_action, start_date: '2024-07-22'.to_date, + end_date: '2024-07-24'.to_date + + travel_to '2024-07-23'.to_date + DesactiveSuperintendentJob.perform_now(superintendent) + expect(superintendent.closed?).to eq false + end + + it 'and the status needs to be in_action to update' do + travel_to '2024-07-20'.to_date + superintendent_action = create :superintendent, :pending, start_date: '2024-07-23'.to_date, + end_date: '2024-07-24'.to_date + superintendent_closed = create :superintendent, :closed, start_date: '2024-07-22'.to_date, + end_date: '2024-07-24'.to_date + + travel_to '2024-07-24'.to_date + DesactiveSuperintendentJob.perform_now(superintendent_action) + DesactiveSuperintendentJob.perform_now(superintendent_closed) + expect(superintendent_action.pending?).to eq true + expect(superintendent_closed.closed?).to eq true + end + end +end diff --git a/spec/jobs/update_superintendent_spec.rb b/spec/jobs/update_superintendent_spec.rb deleted file mode 100644 index c7089192..00000000 --- a/spec/jobs/update_superintendent_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'rails_helper' - -RSpec.describe UpdateSuperintendentJob, type: :job do - it '' do - superintendent = create :superintendent - UpdateSuperintendentJob.perfom(superintendent) - end -end diff --git a/spec/models/condo_spec.rb b/spec/models/condo_spec.rb index 4155d8ab..1cb9cdf9 100644 --- a/spec/models/condo_spec.rb +++ b/spec/models/condo_spec.rb @@ -108,4 +108,29 @@ expect(condo.residents).not_to include not_resident end end + + describe 'superintendent' do + it 'need to display only the superintendt in action or pending (action)' do + condo = create :condo + travel_to '2024-07-22'.to_date + + create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') + superintendent_in_action = create(:superintendent, condo:, start_date: '2024-07-22', end_date: '2024-07-25') + create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') + + expect(condo.superintendent).to eq superintendent_in_action + end + + it 'need to display only the superintendt in action or pending (pending)' do + condo = create :condo + travel_to '2024-07-22'.to_date + + create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') + superintendent_pending = create(:superintendent, :pending, condo:, start_date: '2024-07-23', + end_date: '2024-07-25') + create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') + + expect(condo.superintendent).to eq superintendent_pending + end + end end diff --git a/spec/models/superintendent_spec.rb b/spec/models/superintendent_spec.rb index 594f6319..fad1418d 100644 --- a/spec/models/superintendent_spec.rb +++ b/spec/models/superintendent_spec.rb @@ -26,4 +26,32 @@ expect(superintendent.errors).to include :end_date end end + + describe '#after_create' do + it 'superintendent action now' do + travel_to '2024-07-22'.to_date + superintendent = create :superintendent, :pending, start_date: '2024-07-22', end_date: '2024-07-25' + + expect(superintendent.in_action?).to eq true + end + + it 'program active superintendent' do + travel_to '2024-07-22'.to_date + active_superintendent_job_spy = spy 'ActiveSuperintendentJob' + stub_const 'ActiveSuperintendentJob', active_superintendent_job_spy + superintendent = create :superintendent, :pending, start_date: '2024-07-23', end_date: '2024-07-25' + + expect(superintendent.pending?).to eq true + expect(active_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-23'.to_datetime }) + end + + it 'program desactive superintendent' do + travel_to '2024-07-22'.to_date + desactive_superintendent_job_spy = spy 'DesactiveSuperintendentJob' + stub_const 'DesactiveSuperintendentJob', desactive_superintendent_job_spy + create :superintendent, start_date: '2024-07-22', end_date: '2024-07-25' + + expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-25'.to_datetime }) + end + end end diff --git a/spec/requests/manager_closed_superintendent_spec.rb b/spec/requests/manager_closed_superintendent_spec.rb new file mode 100644 index 00000000..bfc14ab2 --- /dev/null +++ b/spec/requests/manager_closed_superintendent_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +describe 'Manager closed superintendent' do + context 'delete /condos/:condo_id/superintendents/new' do + it 'must be authenticated to closed an superintendent' do + condo = create :condo + superintendent = create :superintendent + + delete condo_superintendent_path(condo, superintendent) + + expect(response).to redirect_to root_path + expect(Superintendent.last).not_to eq nil + end + + it 'must be authenticated as condo manager to register a superintendent' do + manager = create :manager, is_super: false + condo = create :condo + superintendent = create :superintendent + + login_as manager, scope: :manager + + delete condo_superintendent_path(condo, superintendent) + + expect(response).to redirect_to root_path + expect(Superintendent.last).not_to eq nil + end + + it 'must be authenticated as manager' do + resident = create :resident + condo = create :condo + superintendent = create :superintendent + + login_as resident, scope: :resident + + delete condo_superintendent_path(condo, superintendent) + + expect(response).to redirect_to root_path + expect(Superintendent.last).not_to eq nil + end + end +end diff --git a/spec/requests/manager_edit_superintendent_spec.rb b/spec/requests/manager_edit_superintendent_spec.rb deleted file mode 100644 index 6763b4c9..00000000 --- a/spec/requests/manager_edit_superintendent_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'rails_helper' - -describe 'Manager edits superintendent' do - context 'GET /condos/:condo_id/superintendents/new' do - it 'must be authenticated to edit an superintendent' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - get edit_condo_superintendent_path(condo, superintendent) - - expect(response).to redirect_to new_manager_session_path - end - - it 'must be authenticated as condo manager to edit a superintendent' do - manager = create :manager, is_super: false - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - login_as manager, scope: :manager - - get edit_condo_superintendent_path(condo, superintendent) - - expect(response).to redirect_to root_path - end - - it 'must be authenticated as manager' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - login_as resident, scope: :resident - - get edit_condo_superintendent_path(condo, superintendent) - - expect(response).to redirect_to root_path - end - end - - context 'PATCH /condos/:condo_id/superintendents' do - it 'must be authenticated to edit an superintendent' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - resident2 = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - params = { superintendent: { tenant_id: resident2.id }, condo_id: condo.id } - - patch(condo_superintendent_path(condo, superintendent), params:) - - expect(response).to redirect_to new_manager_session_path - expect(Superintendent.last.tenant).not_to eq resident2 - end - - it 'must be authenticated as condo manager to edit a superintendent' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - resident2 = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - manager = create :manager, is_super: false - login_as manager, scope: :manager - - params = { superintendent: { tenant_id: resident2.id }, condo_id: condo.id } - - patch(condo_superintendent_path(condo, superintendent), params:) - - expect(response).to redirect_to root_path - expect(Superintendent.last.tenant).not_to eq resident2 - end - - it 'must be authenticated as manager' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, condo:) - resident2 = create(:resident, :with_residence, condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, - end_date: Date.current >> 2) - - login_as resident, scope: :resident - - params = { superintendent: { tenant_id: resident2.id }, condo_id: condo.id } - - patch(condo_superintendent_path(condo, superintendent), params:) - - expect(response).to redirect_to root_path - expect(Superintendent.last.tenant).not_to eq resident2 - end - end -end diff --git a/spec/system/superintendent/manager_delete_superintendent_spec.rb b/spec/system/superintendent/manager_delete_superintendent_spec.rb new file mode 100644 index 00000000..9b58dae9 --- /dev/null +++ b/spec/system/superintendent/manager_delete_superintendent_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +describe 'Manager delete superintendent' do + it 'from condo details page' do + condo = create :condo, name: 'Condomínio X' + travel_to '2024-07-21'.to_date + tower = create(:tower, condo:) + unit11 = tower.floors.first.units.first + resident = create :resident, full_name: 'Dona Alvara', residence: unit11, email: 'alvara@email.com' + create(:superintendent, condo:, tenant: resident, start_date: '2024-07-21'.to_date, + end_date: '2024-07-25'.to_date) + manager = create :manager + + login_as manager, scope: :manager + visit condo_path condo + click_on 'Dona Alvara' + + click_on 'Encerrar Gestão' + + expect(page).to have_content 'Mandato de síndico encerrado com sucesso!' + expect(current_path).to eq condo_path condo + expect(Superintendent.last.closed?).to eq true + end +end diff --git a/spec/system/superintendent/manager_edit_superintendent_spec.rb b/spec/system/superintendent/manager_edit_superintendent_spec.rb deleted file mode 100644 index f91d3ec1..00000000 --- a/spec/system/superintendent/manager_edit_superintendent_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'rails_helper' - -describe 'Manager edit superintendent' do - it 'successfully' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, full_name: 'Dona Alvara', condo:) - resident2 = create(:resident, :with_residence, full_name: 'Havana Silva', email: 'email@email.com', condo:) - travel_to '2024-07-21'.to_date - superintendent = create(:superintendent, tenant: resident, condo:, start_date: '2024-07-21'.to_date, - end_date: '2024-07-25'.to_date) - - manager = create :manager - - resident.user_image.attach(io: Rails.root.join('spec/support/images/resident_photo.jpg').open, - filename: 'resident_photo.jpg') - - login_as manager, scope: :manager - visit condo_path condo - click_on 'Dona Alvara' - click_on 'Editar Síndico' - fill_in 'Data de conclusão', with: '2024-07-25'.to_date - select 'Havana Silva', from: 'Morador' - click_on 'Enviar' - - superintendent.reload - expect(page).to have_content 'Mandato de síndico atualizado com sucesso!' - expect(current_path).to eq condo_superintendent_path(condo, Superintendent.last) - expect(superintendent.end_date).to eq '2024-07-25'.to_date - expect(superintendent.tenant).to eq resident2 - expect(resident.superintendent).to eq nil - end - - it 'with missing params' do - condo = create :condo, name: 'Condomínio X' - resident = create(:resident, :with_residence, full_name: 'Dona Alvara', condo:) - travel_to '2024-07-21'.to_date - create(:superintendent, tenant: resident, condo:, start_date: '2024-07-21'.to_date, - end_date: '2024-07-25'.to_date) - manager = create :manager - - resident.user_image.attach(io: Rails.root.join('spec/support/images/resident_photo.jpg').open, - filename: 'resident_photo.jpg') - - login_as manager, scope: :manager - visit condo_path condo - click_on 'Dona Alvara' - click_on 'Editar Síndico' - fill_in 'Data de conclusão', with: '' - click_on 'Enviar' - - expect(page).to have_content 'Não foi possível atualizar o mandato.' - expect(Superintendent.last.end_date).to eq '2024-07-25'.to_date - end -end diff --git a/spec/system/superintendent/manager_register_superintendent_spec.rb b/spec/system/superintendent/manager_register_superintendent_spec.rb index 59ec938b..db8ca861 100644 --- a/spec/system/superintendent/manager_register_superintendent_spec.rb +++ b/spec/system/superintendent/manager_register_superintendent_spec.rb @@ -7,6 +7,9 @@ manager = create :manager travel_to '2024-07-21'.to_date + desactive_superintendent_job_spy = spy 'DesactiveSuperintendentJob' + stub_const 'DesactiveSuperintendentJob', desactive_superintendent_job_spy + login_as manager, scope: :manager visit root_path within 'nav' do @@ -18,7 +21,7 @@ click_on 'Condomínio X' end - fill_in 'Data de ínicio', with: '2024-07-21'.to_date + fill_in 'Data de início', with: '2024-07-21'.to_date fill_in 'Data de conclusão', with: '2025-07-25'.to_date select 'Alvus Dumbledore', from: 'Morador' click_on 'Enviar' @@ -26,6 +29,8 @@ expect(page).to have_content 'Mandato de síndico cadastro com sucesso!' expect(current_path).to eq condo_superintendent_path(condo, Superintendent.last) expect(Superintendent.last.tenant).to eq resident + expect(Superintendent.last.in_action?).to eq true + expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2025-07-25'.to_datetime }) end it 'Successfully to act on 2024-07-25' do @@ -34,6 +39,12 @@ manager = create :manager travel_to '2024-07-21'.to_date + active_superintendent_job_spy = spy 'ActiveSuperintendentJob' + stub_const 'ActiveSuperintendentJob', active_superintendent_job_spy + + desactive_superintendent_job_spy = spy 'DesactiveSuperintendentJob' + stub_const 'DesactiveSuperintendentJob', desactive_superintendent_job_spy + login_as manager, scope: :manager visit root_path within 'nav' do @@ -44,14 +55,17 @@ within '#condoSelectPopupForSuperintendent' do click_on 'Condomínio X' end - fill_in 'Data de ínicio', with: '2024-07-21'.to_date + fill_in 'Data de início', with: '2024-07-25'.to_date fill_in 'Data de conclusão', with: '2025-07-21'.to_date select 'Alvus Dumbledore', from: 'Morador' click_on 'Enviar' expect(page).to have_content 'Mandato de síndico cadastro com sucesso!' expect(current_path).to eq condo_superintendent_path(condo, Superintendent.last) + expect(active_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-25'.to_datetime }) + expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2025-07-21'.to_datetime }) expect(Superintendent.last.tenant).to eq resident + expect(Superintendent.last.pending?).to eq true end it 'with blank fields' do @@ -69,20 +83,47 @@ within '#condoSelectPopupForSuperintendent' do click_on 'Condomínio X' end - fill_in 'Data de ínicio', with: '' + fill_in 'Data de início', with: '' fill_in 'Data de conclusão', with: '' click_on 'Enviar' expect(page).to have_content 'Não foi possível cadastrar o mandato.' - expect(page).to have_content 'Data de ínicio não pode ficar em branco' + expect(page).to have_content 'Data de início não pode ficar em branco' expect(page).to have_content 'Data de conclusão não pode ficar em branco' expect(page).to have_content 'Morador é obrigatório' expect(Superintendent.count).to eq 0 end - it 'and condo has superintedent' do + it 'and condo has superintedent active' do + condo = create :condo, name: 'Condomínio X' + superintendent = create(:superintendent, :in_action, condo:) + resident = superintendent.tenant + manager = create :manager + + resident.user_image.attach(io: Rails.root.join('spec/support/images/resident_photo.jpg').open, + filename: 'resident_photo.jpg') + + login_as manager, scope: :manager + + visit root_path + within 'nav' do + click_on id: 'side-menu' + click_on 'Gerenciar Usuários' + click_on 'Cadastrar Síndico' + end + within '#condoSelectPopupForSuperintendent' do + click_on 'Condomínio X' + end + + expect(current_path).to eq condo_superintendent_path(condo, superintendent) + expect(page).to have_content 'Esse condomínio já possui um síndico cadastrado!' + end + + it 'and condo has superintedent in pending' do condo = create :condo, name: 'Condomínio X' - superintendent = create(:superintendent, condo:) + travel_to '2024-07-21'.to_date + + superintendent = create(:superintendent, :pending, condo:, start_date: '2024-07-22'.to_date, end_date: '2024-07-25'.to_date) resident = superintendent.tenant manager = create :manager diff --git a/spec/system/superintendent/user_sees_superintendent_details_spec.rb b/spec/system/superintendent/user_sees_superintendent_details_spec.rb index 4f82b212..37da2921 100644 --- a/spec/system/superintendent/user_sees_superintendent_details_spec.rb +++ b/spec/system/superintendent/user_sees_superintendent_details_spec.rb @@ -30,7 +30,8 @@ expect(page).to have_content I18n.l('2024-07-21'.to_date) expect(page).to have_content I18n.l('2024-07-25'.to_date) end - expect(page).to have_button 'Editar Síndico' + + expect(page).to have_button 'Encerrar Gestão' end it 'and is not a condo manager' do @@ -76,7 +77,7 @@ expect(page).to have_content I18n.l('2024-07-25'.to_date) end - expect(page).not_to have_button 'Editar Síndico' + expect(page).not_to have_button 'Encerrar Gestão' end it 'and is not a condo resident' do From d6e1e612a12cd0f1a55119daa6dca151092308c0 Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 22 Jul 2024 11:32:33 -0300 Subject: [PATCH 3/5] Corrige erros do rubocop --- app/controllers/superintendents_controller.rb | 10 +++++----- spec/models/condo_spec.rb | 6 +++--- .../manager_register_superintendent_spec.rb | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/superintendents_controller.rb b/app/controllers/superintendents_controller.rb index 043b5865..aabae850 100644 --- a/app/controllers/superintendents_controller.rb +++ b/app/controllers/superintendents_controller.rb @@ -1,12 +1,12 @@ class SuperintendentsController < ApplicationController - before_action :authenticate_manager!, only: %i[new create ] - before_action :set_condo, only: %i[show new create destroy] - before_action :set_superintendent, only: %i[show destroy] - before_action :set_breadcrumbs_condo, only: %i[new create ] + before_action :authenticate_manager!, only: %i[new create] + before_action :set_condo, only: %i[show new create destroy] + before_action :set_superintendent, only: %i[show destroy] + before_action :set_breadcrumbs_condo, only: %i[new create] before_action :set_breadcrumbs_for_register, only: %i[new create] before_action :set_breadcrumbs_for_edit, only: %i[] before_action -> { authorize_condo_manager(@condo) }, only: %i[destroy] - before_action -> { authorize_user(@condo) }, only: %i[show new create ] + before_action -> { authorize_user(@condo) }, only: %i[show new create] def show @tenant = @superintendent.tenant diff --git a/spec/models/condo_spec.rb b/spec/models/condo_spec.rb index 1cb9cdf9..9d672fae 100644 --- a/spec/models/condo_spec.rb +++ b/spec/models/condo_spec.rb @@ -110,7 +110,7 @@ end describe 'superintendent' do - it 'need to display only the superintendt in action or pending (action)' do + it 'need to display only the superintendt in action or pending (action)' do condo = create :condo travel_to '2024-07-22'.to_date @@ -121,12 +121,12 @@ expect(condo.superintendent).to eq superintendent_in_action end - it 'need to display only the superintendt in action or pending (pending)' do + it 'need to display only the superintendt in action or pending (pending)' do condo = create :condo travel_to '2024-07-22'.to_date create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') - superintendent_pending = create(:superintendent, :pending, condo:, start_date: '2024-07-23', + superintendent_pending = create(:superintendent, :pending, condo:, start_date: '2024-07-23', end_date: '2024-07-25') create(:superintendent, :closed, condo:, start_date: '2024-07-24', end_date: '2024-07-25') diff --git a/spec/system/superintendent/manager_register_superintendent_spec.rb b/spec/system/superintendent/manager_register_superintendent_spec.rb index db8ca861..c4ca715e 100644 --- a/spec/system/superintendent/manager_register_superintendent_spec.rb +++ b/spec/system/superintendent/manager_register_superintendent_spec.rb @@ -123,7 +123,8 @@ condo = create :condo, name: 'Condomínio X' travel_to '2024-07-21'.to_date - superintendent = create(:superintendent, :pending, condo:, start_date: '2024-07-22'.to_date, end_date: '2024-07-25'.to_date) + superintendent = create(:superintendent, :pending, condo:, start_date: '2024-07-22'.to_date, + end_date: '2024-07-25'.to_date) resident = superintendent.tenant manager = create :manager From 7757c0487240c3bc6ad6cd3567b7656cf549051d Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 22 Jul 2024 12:29:30 -0300 Subject: [PATCH 4/5] Merge com a main --- app/models/superintendent.rb | 15 +++++----- app/views/condos/show.html.erb | 2 +- spec/jobs/active_superintendent_spec.rb | 12 ++++---- spec/jobs/desactive_superintendent_spec.rb | 14 +++++----- spec/models/condo_spec.rb | 4 +-- spec/models/superintendent_spec.rb | 28 +++++++++++-------- .../manager_closed_superintendent_spec.rb | 2 +- .../manager_register_superintendent_spec.rb | 2 +- 8 files changed, 43 insertions(+), 36 deletions(-) diff --git a/app/models/superintendent.rb b/app/models/superintendent.rb index 71c7f665..6461f75b 100644 --- a/app/models/superintendent.rb +++ b/app/models/superintendent.rb @@ -8,21 +8,22 @@ class Superintendent < ApplicationRecord enum status: { pending: 0, in_action: 1, closed: 2 } - after_create :action_now_or_after? - after_create :program_deactivation + after_create :program_activate_and_desactiation? + + def condo_presentation + "#{tenant.full_name} (#{start_date} - #{end_date})" + end private - def action_now_or_after? + def program_activate_and_desactiation? + DesactiveSuperintendentJob.set(wait_until: end_date.to_datetime).perform_later self + return in_action! if start_date == Date.current ActiveSuperintendentJob.set(wait_until: start_date.to_datetime).perform_later self end - def program_deactivation - DesactiveSuperintendentJob.set(wait_until: end_date.to_datetime).perform_later self - end - def start_date_must_be_valid errors.add :start_date, 'deve ser atual ou futura' if start_date&.past? end diff --git a/app/views/condos/show.html.erb b/app/views/condos/show.html.erb index 7a506270..081db7fd 100644 --- a/app/views/condos/show.html.erb +++ b/app/views/condos/show.html.erb @@ -6,7 +6,7 @@

Síndico: <% if @condo.superintendent%> <%= link_to condo_superintendent_path(@condo, @condo.superintendent) do %> - <%= "#{@condo.superintendent.tenant.full_name} (#{@condo.superintendent.start_date} - #{@condo.superintendent.end_date})"%> + <%= @condo.superintendent.condo_presentation%> <% end %> <% else %> Não há um síndico ativo diff --git a/spec/jobs/active_superintendent_spec.rb b/spec/jobs/active_superintendent_spec.rb index 78264255..5db8a599 100644 --- a/spec/jobs/active_superintendent_spec.rb +++ b/spec/jobs/active_superintendent_spec.rb @@ -3,33 +3,33 @@ RSpec.describe ActiveSuperintendentJob, type: :job do context 'must be activate the superintendent' do it 'in two days' do - travel_to '2024-07-22'.to_date + travel_to '2024-07-22' superintendent = create :superintendent, :pending, start_date: '2024-07-24'.to_date, end_date: '2024-08-25'.to_date - travel_to '2024-07-24'.to_date + travel_to '2024-07-24' ActiveSuperintendentJob.perform_now(superintendent) expect(superintendent.in_action?).to eq true end it 'does not update if the accused is on another day' do - travel_to '2024-07-22'.to_date + travel_to '2024-07-22' superintendent = create :superintendent, :pending, start_date: '2024-07-24'.to_date, end_date: '2024-08-25'.to_date - travel_to '2024-07-23'.to_date + travel_to '2024-07-23' ActiveSuperintendentJob.perform_now(superintendent) expect(superintendent.in_action?).to eq false end it 'and the status needs to be pending to update' do - travel_to '2024-07-20'.to_date + travel_to '2024-07-20' superintendent_action = create :superintendent, :in_action, start_date: '2024-07-23'.to_date, end_date: '2024-08-25'.to_date superintendent_closed = create :superintendent, :closed, start_date: '2024-07-22'.to_date, end_date: '2024-08-23'.to_date - travel_to '2024-07-24'.to_date + travel_to '2024-07-24' ActiveSuperintendentJob.perform_now(superintendent_action) ActiveSuperintendentJob.perform_now(superintendent_closed) expect(superintendent_action.in_action?).to eq true diff --git a/spec/jobs/desactive_superintendent_spec.rb b/spec/jobs/desactive_superintendent_spec.rb index 104bb49e..cf6dc285 100644 --- a/spec/jobs/desactive_superintendent_spec.rb +++ b/spec/jobs/desactive_superintendent_spec.rb @@ -1,35 +1,35 @@ require 'rails_helper' RSpec.describe DesactiveSuperintendentJob, type: :job do - context 'must be activate the superintendent' do + context 'must be desactivate the superintendent' do it 'in two days' do - travel_to '2024-07-22'.to_date + travel_to '2024-07-22' superintendent = create :superintendent, :in_action, start_date: '2024-07-22'.to_date, end_date: '2024-07-24'.to_date - travel_to '2024-07-24'.to_date + travel_to '2024-07-24' DesactiveSuperintendentJob.perform_now(superintendent) expect(superintendent.closed?).to eq true end it 'does not update if the accused is on another day' do - travel_to '2024-07-22'.to_date + travel_to '2024-07-22' superintendent = create :superintendent, :in_action, start_date: '2024-07-22'.to_date, end_date: '2024-07-24'.to_date - travel_to '2024-07-23'.to_date + travel_to '2024-07-23' DesactiveSuperintendentJob.perform_now(superintendent) expect(superintendent.closed?).to eq false end it 'and the status needs to be in_action to update' do - travel_to '2024-07-20'.to_date + travel_to '2024-07-20' superintendent_action = create :superintendent, :pending, start_date: '2024-07-23'.to_date, end_date: '2024-07-24'.to_date superintendent_closed = create :superintendent, :closed, start_date: '2024-07-22'.to_date, end_date: '2024-07-24'.to_date - travel_to '2024-07-24'.to_date + travel_to '2024-07-24' DesactiveSuperintendentJob.perform_now(superintendent_action) DesactiveSuperintendentJob.perform_now(superintendent_closed) expect(superintendent_action.pending?).to eq true diff --git a/spec/models/condo_spec.rb b/spec/models/condo_spec.rb index 9d672fae..47d6259a 100644 --- a/spec/models/condo_spec.rb +++ b/spec/models/condo_spec.rb @@ -110,7 +110,7 @@ end describe 'superintendent' do - it 'need to display only the superintendt in action or pending (action)' do + it 'need to display only the superintendent in action or pending (action)' do condo = create :condo travel_to '2024-07-22'.to_date @@ -121,7 +121,7 @@ expect(condo.superintendent).to eq superintendent_in_action end - it 'need to display only the superintendt in action or pending (pending)' do + it 'need to display only the superintendent in action or pending (pending)' do condo = create :condo travel_to '2024-07-22'.to_date diff --git a/spec/models/superintendent_spec.rb b/spec/models/superintendent_spec.rb index fad1418d..dcc67122 100644 --- a/spec/models/superintendent_spec.rb +++ b/spec/models/superintendent_spec.rb @@ -27,30 +27,36 @@ end end + it '#condo_presentation' do + travel_to '2024-07-22' + condo = create :condo, name: 'Condominio X' + resident = create(:resident, :with_residence, condo:, full_name: 'Adroaldo') + superintendent = create(:superintendent, :pending, tenant: resident, + condo:, start_date: '2024-07-22', + end_date: '2024-07-25') + + expect(superintendent.condo_presentation).to eq 'Adroaldo (2024-07-22 - 2024-07-25)' + end + describe '#after_create' do it 'superintendent action now' do - travel_to '2024-07-22'.to_date + travel_to '2024-07-22' superintendent = create :superintendent, :pending, start_date: '2024-07-22', end_date: '2024-07-25' expect(superintendent.in_action?).to eq true end - it 'program active superintendent' do - travel_to '2024-07-22'.to_date + it 'program_activate_and_desactiation' do + travel_to '2024-07-22' active_superintendent_job_spy = spy 'ActiveSuperintendentJob' stub_const 'ActiveSuperintendentJob', active_superintendent_job_spy superintendent = create :superintendent, :pending, start_date: '2024-07-23', end_date: '2024-07-25' - - expect(superintendent.pending?).to eq true - expect(active_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-23'.to_datetime }) - end - - it 'program desactive superintendent' do - travel_to '2024-07-22'.to_date desactive_superintendent_job_spy = spy 'DesactiveSuperintendentJob' stub_const 'DesactiveSuperintendentJob', desactive_superintendent_job_spy create :superintendent, start_date: '2024-07-22', end_date: '2024-07-25' - + + expect(superintendent.pending?).to eq true + expect(active_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-23'.to_datetime }) expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-25'.to_datetime }) end end diff --git a/spec/requests/manager_closed_superintendent_spec.rb b/spec/requests/manager_closed_superintendent_spec.rb index bfc14ab2..8cb395e7 100644 --- a/spec/requests/manager_closed_superintendent_spec.rb +++ b/spec/requests/manager_closed_superintendent_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'Manager closed superintendent' do - context 'delete /condos/:condo_id/superintendents/new' do + context 'DELETE /condos/:condo_id/superintendents/:id' do it 'must be authenticated to closed an superintendent' do condo = create :condo superintendent = create :superintendent diff --git a/spec/system/superintendent/manager_register_superintendent_spec.rb b/spec/system/superintendent/manager_register_superintendent_spec.rb index c4ca715e..dafecc8b 100644 --- a/spec/system/superintendent/manager_register_superintendent_spec.rb +++ b/spec/system/superintendent/manager_register_superintendent_spec.rb @@ -33,7 +33,7 @@ expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2025-07-25'.to_datetime }) end - it 'Successfully to act on 2024-07-25' do + it 'successfully to act on future' do condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, full_name: 'Alvus Dumbledore', condo:) manager = create :manager From 5d16998781ffb3f10bdaf45edf3b3a63d04fa9df Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 22 Jul 2024 12:31:22 -0300 Subject: [PATCH 5/5] Corrige erros do rubocop --- spec/models/superintendent_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/superintendent_spec.rb b/spec/models/superintendent_spec.rb index dcc67122..82b590ff 100644 --- a/spec/models/superintendent_spec.rb +++ b/spec/models/superintendent_spec.rb @@ -54,7 +54,7 @@ desactive_superintendent_job_spy = spy 'DesactiveSuperintendentJob' stub_const 'DesactiveSuperintendentJob', desactive_superintendent_job_spy create :superintendent, start_date: '2024-07-22', end_date: '2024-07-25' - + expect(superintendent.pending?).to eq true expect(active_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-23'.to_datetime }) expect(desactive_superintendent_job_spy).to have_received(:set).with({ wait_until: '2024-07-25'.to_datetime })