diff --git a/config/application.rb b/config/application.rb index ca9fbce..75236f0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -32,8 +32,7 @@ class Application < Rails::Application # # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. - # - config.time_zone = "America/Sao_Paulo" + config.time_zone = 'America/Sao_Paulo' config.api = config_for(:api) # config.eager_load_paths << Rails.root.join("extras") diff --git a/spec/factories/superintendents.rb b/spec/factories/superintendents.rb index 80b3332..de35db0 100644 --- a/spec/factories/superintendents.rb +++ b/spec/factories/superintendents.rb @@ -2,7 +2,7 @@ factory :superintendent do condo { build :condo } tenant { create(:resident, :with_residence, condo:) } - start_date { Time.zone.today } - end_date { Time.zone.today >> 6 } + start_date { Date.current } + end_date { Date.current >> 6 } end end diff --git a/spec/models/superintendent_spec.rb b/spec/models/superintendent_spec.rb index 316b594..594f631 100644 --- a/spec/models/superintendent_spec.rb +++ b/spec/models/superintendent_spec.rb @@ -20,7 +20,7 @@ end it 'end date greater than to start_date' do - superintendent = build :superintendent, start_date: Time.zone.today, end_date: Time.zone.today + superintendent = build :superintendent, start_date: Date.current, end_date: Date.current expect(superintendent).not_to be_valid expect(superintendent.errors).to include :end_date diff --git a/spec/requests/manager_confirms_visitor_spec.rb b/spec/requests/manager_confirms_visitor_spec.rb index 703abe8..fb7761b 100644 --- a/spec/requests/manager_confirms_visitor_spec.rb +++ b/spec/requests/manager_confirms_visitor_spec.rb @@ -37,7 +37,7 @@ it 'successfully only if associated with the condo' do manager = create :manager, is_super: false - visitor = create :visitor, visit_date: Time.zone.today + visitor = create :visitor, visit_date: Date.current manager.condos << visitor.condo login_as manager, scope: :manager @@ -63,7 +63,7 @@ context 'visit_date ' do it 'cannot be past' do manager = create :manager - visitor = create :visitor, visit_date: Time.zone.today + visitor = create :visitor, visit_date: Date.current login_as manager, scope: :manager travel_to 1.day.from_now do diff --git a/spec/requests/manager_edit_superintendent_spec.rb b/spec/requests/manager_edit_superintendent_spec.rb index d59bffc..bc0425d 100644 --- a/spec/requests/manager_edit_superintendent_spec.rb +++ b/spec/requests/manager_edit_superintendent_spec.rb @@ -5,8 +5,8 @@ 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: Time.zone.today, - end_date: Time.zone.today >> 2) + superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, + end_date: Date.current >> 2) get edit_condo_superintendent_path(condo, superintendent) @@ -17,8 +17,8 @@ condo_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: Time.zone.today, - end_date: Time.zone.today >> 2) + superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, + end_date: Date.current >> 2) login_as condo_manager, scope: :manager @@ -30,8 +30,8 @@ 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: Time.zone.today, - end_date: Time.zone.today >> 2) + superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, + end_date: Date.current >> 2) login_as resident, scope: :resident @@ -46,8 +46,8 @@ condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, condo:) resident2 = create(:resident, :with_residence, email: 'Adrolado@email.com', condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Time.zone.today, - end_date: Time.zone.today >> 2) + 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 } @@ -61,8 +61,8 @@ condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, condo:) resident2 = create(:resident, :with_residence, email: 'Adrolado@email.com', condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Time.zone.today, - end_date: Time.zone.today >> 2) + superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, + end_date: Date.current >> 2) condo_manager = create :manager, is_super: false login_as condo_manager, scope: :manager @@ -79,8 +79,8 @@ condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, condo:) resident2 = create(:resident, :with_residence, email: 'Adrolado@email.com', condo:) - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Time.zone.today, - end_date: Time.zone.today >> 2) + superintendent = create(:superintendent, condo:, tenant: resident, start_date: Date.current, + end_date: Date.current >> 2) login_as resident, scope: :resident diff --git a/spec/requests/manager_registers_superintendent_spec.rb b/spec/requests/manager_registers_superintendent_spec.rb index 876d175..e984e5f 100644 --- a/spec/requests/manager_registers_superintendent_spec.rb +++ b/spec/requests/manager_registers_superintendent_spec.rb @@ -38,7 +38,7 @@ condo = create :condo resident = create(:resident, :with_residence, condo:) - params = { superintendent: { start_date: Time.zone.today, end_date: Time.zone.today >> 2, + params = { superintendent: { start_date: Date.current, end_date: Date.current >> 2, tenant_id: resident.id }, condo_id: condo.id } post(condo_superintendents_path(condo), params:) @@ -54,7 +54,7 @@ login_as condo_manager, scope: :manager - params = { superintendent: { start_date: Time.zone.today, end_date: Time.zone.today >> 2, + params = { superintendent: { start_date: Date.current, end_date: Date.current >> 2, tenant_id: resident.id }, condo_id: condo.id } post(condo_superintendents_path(condo), params:) @@ -69,7 +69,7 @@ login_as resident, scope: :resident - params = { superintendent: { start_date: Time.zone.today, end_date: Time.zone.today >> 2, + params = { superintendent: { start_date: Date.current, end_date: Date.current >> 2, tenant_id: resident.id }, condo_id: condo.id } post(condo_superintendents_path(condo), params:) diff --git a/spec/system/superintendent/manager_edit_superintendent_spec.rb b/spec/system/superintendent/manager_edit_superintendent_spec.rb index 8c66ac4..f91d3ec 100644 --- a/spec/system/superintendent/manager_edit_superintendent_spec.rb +++ b/spec/system/superintendent/manager_edit_superintendent_spec.rb @@ -1,11 +1,13 @@ require 'rails_helper' describe 'Manager edit superintendent' do - it 'succesfully' 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:) - superintendent = create(:superintendent, tenant: resident, 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 @@ -16,14 +18,14 @@ visit condo_path condo click_on 'Dona Alvara' click_on 'Editar Síndico' - fill_in 'Data de conclusão', with: Time.zone.today >> 30 + 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 Time.zone.today >> 30 + expect(superintendent.end_date).to eq '2024-07-25'.to_date expect(superintendent.tenant).to eq resident2 expect(resident.superintendent).to eq nil end @@ -31,7 +33,9 @@ it 'with missing params' do condo = create :condo, name: 'Condomínio X' resident = create(:resident, :with_residence, full_name: 'Dona Alvara', condo:) - create(:superintendent, tenant: resident, condo:, start_date: Time.zone.today, end_date: Time.zone.today >> 2) + 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, @@ -45,6 +49,6 @@ click_on 'Enviar' expect(page).to have_content 'Não foi possível atualizar o mandato.' - expect(Superintendent.last.end_date).to eq Time.zone.today >> 2 + 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 e4499ec..8c34949 100644 --- a/spec/system/superintendent/manager_register_superintendent_spec.rb +++ b/spec/system/superintendent/manager_register_superintendent_spec.rb @@ -5,7 +5,7 @@ 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,8 @@ 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-21'.to_date select 'Alvus Dumbledore', from: 'Morador' click_on 'Enviar' diff --git a/spec/system/superintendent/user_sees_superintendent_details_spec.rb b/spec/system/superintendent/user_sees_superintendent_details_spec.rb index f95d884..4f82b21 100644 --- a/spec/system/superintendent/user_sees_superintendent_details_spec.rb +++ b/spec/system/superintendent/user_sees_superintendent_details_spec.rb @@ -7,8 +7,9 @@ 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: Time.zone.today, - end_date: Time.zone.today >> 2) + 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, @@ -26,8 +27,8 @@ expect(page).to have_content 'Condomínio X' expect(page).to have_content 'Torre A' expect(page).to have_content 'Unidade: 11' - expect(page).to have_content I18n.l Time.zone.today - expect(page).to have_content I18n.l(Time.zone.today >> 2) + 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' end @@ -52,8 +53,9 @@ tower = create(:tower, condo:) unit11 = tower.floors.first.units.first resident = create :resident, full_name: 'Dona Alvara', residence: unit11, email: 'alvara@email.com' - superintendent = create(:superintendent, condo:, tenant: resident, start_date: Time.zone.today, - end_date: Time.zone.today >> 2) + 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) resident.user_image.attach(io: Rails.root.join('spec/support/images/resident_photo.jpg').open, filename: 'resident_photo.jpg') @@ -70,8 +72,8 @@ expect(page).to have_content 'Condomínio X' expect(page).to have_content 'Torre A' expect(page).to have_content 'Unidade: 11' - expect(page).to have_content I18n.l Time.zone.today - expect(page).to have_content I18n.l(Time.zone.today >> 2) + 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).not_to have_button 'Editar Síndico' diff --git a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb index b2ea2e6..110d24a 100644 --- a/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb +++ b/spec/system/visitor/manager_view_condo_full_visitors_list_spec.rb @@ -10,14 +10,14 @@ second_resident = create :resident, full_name: 'Maria Silveira', residence: tower.floors[0].units[1] first_visitor = create :visitor, condo: first_condo, resident: first_resident, - visit_date: Time.zone.today, + visit_date: Date.current, full_name: 'João da Silva', identity_number: '12467' second_visitor = create :visitor, condo: first_condo, resident: first_resident, category: :employee, recurrence: :weekly, - visit_date: Time.zone.today, + visit_date: Date.current, full_name: 'Maria Oliveira', identity_number: '45977' third_visitor = create :visitor, condo: first_condo, @@ -26,7 +26,7 @@ full_name: 'Marcos Lima', identity_number: '12345' fourth_visitor = create :visitor, condo: second_condo, - visit_date: Time.zone.today, + visit_date: Date.current, full_name: 'Juliana Ferreira' login_as manager, scope: :manager @@ -41,7 +41,7 @@ expect(page).to have_content 'Visitante' expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) + expect(page).to have_content I18n.l(Date.current) end within("#visitor-#{second_visitor.id}") do expect(page).to have_content 'Maria Oliveira' @@ -49,7 +49,7 @@ expect(page).to have_content 'Funcionário' expect(page).to have_content 'Torre A - 11' expect(page).to have_content 'Alberto Silveira' - expect(page).to have_content I18n.l(Time.zone.today) + expect(page).to have_content I18n.l(Date.current) expect(page).to have_content 'Semanal' end within("#visitor-#{third_visitor.id}") do diff --git a/spec/system/visitor/manager_view_condo_visitors_list_spec.rb b/spec/system/visitor/manager_view_condo_visitors_list_spec.rb index ae98db8..9b71ae5 100644 --- a/spec/system/visitor/manager_view_condo_visitors_list_spec.rb +++ b/spec/system/visitor/manager_view_condo_visitors_list_spec.rb @@ -8,19 +8,19 @@ first_condo = create :condo second_condo = create :condo first_visitor = create :visitor, condo: first_condo, resident:, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + visit_date: Date.current, full_name: 'João da Silva', identity_number: '12467' second_visitor = create :visitor, condo: first_condo, resident:, - visit_date: Time.zone.today, full_name: 'Maria Oliveira', identity_number: '45977' + visit_date: Date.current, full_name: 'Maria Oliveira', identity_number: '45977' third_visitor = create :visitor, condo: first_condo, visit_date: 1.day.from_now, full_name: 'Marcos Lima' fourth_visitor = create :visitor, condo: second_condo, - visit_date: Time.zone.today, full_name: 'Juliana Ferreira' + visit_date: Date.current, full_name: 'Juliana Ferreira' login_as manager, scope: :manager visit condo_path first_condo click_on 'Agenda de visitantes/funcionários' - expect(page).to have_content I18n.l(Time.zone.today, format: :long) + expect(page).to have_content I18n.l(Date.current, format: :long) within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'Alberto Silveira' expect(page).to have_content 'João da Silva' @@ -50,7 +50,7 @@ second_visitor = create :visitor, condo: first_condo, resident:, visit_date: 1.day.from_now, full_name: 'Maria Oliveira', identity_number: '45977' third_visitor = create :visitor, condo: first_condo, resident:, - visit_date: Time.zone.today, full_name: 'Marcos Lima' + visit_date: Date.current, full_name: 'Marcos Lima' fourth_visitor = create :visitor, condo: second_condo, visit_date: 1.day.from_now, full_name: 'Juliana Ferreira' @@ -58,7 +58,7 @@ visit find_condo_visitors_path first_condo click_on 'Dia Seguinte' - expect(page).to have_content I18n.l(Time.zone.today + 1.day, format: :long) + expect(page).to have_content I18n.l(Date.current + 1.day, format: :long) within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'Alberto Silveira' expect(page).to have_content 'João da Silva' @@ -84,19 +84,19 @@ first_condo = create :condo second_condo = create :condo first_visitor = create :visitor, condo: first_condo, resident:, - visit_date: Time.zone.today, full_name: 'João da Silva', identity_number: '12467' + visit_date: Date.current, full_name: 'João da Silva', identity_number: '12467' second_visitor = create :visitor, condo: first_condo, resident:, - visit_date: Time.zone.today, full_name: 'Maria Oliveira', identity_number: '45977' + visit_date: Date.current, full_name: 'Maria Oliveira', identity_number: '45977' third_visitor = create :visitor, condo: first_condo, resident:, visit_date: 1.day.from_now, full_name: 'Marcos Lima' fourth_visitor = create :visitor, condo: second_condo, - visit_date: Time.zone.today, full_name: 'Juliana Ferreira' + visit_date: Date.current, full_name: 'Juliana Ferreira' login_as manager, scope: :manager visit find_condo_visitors_path(first_condo, date: 1.day.from_now) click_on 'Dia Anterior' - expect(page).to have_content I18n.l(Time.zone.today, format: :long) + expect(page).to have_content I18n.l(Date.current, format: :long) within("#visitor-#{first_visitor.id}") do expect(page).to have_content 'Alberto Silveira' expect(page).to have_content 'João da Silva' @@ -125,7 +125,7 @@ expect(page).to have_content 'Não é possível acessar uma data passada' expect(current_path).to eq find_condo_visitors_path(condo) - expect(page).to have_content I18n.l(Time.zone.today, format: :long) + expect(page).to have_content I18n.l(Date.current, format: :long) end it 'must be authenticated' do @@ -163,7 +163,7 @@ manager = create :manager condo = create :condo resident = create(:resident, :with_residence, condo:) - visitor = create :visitor, condo:, resident:, visit_date: Time.zone.today, full_name: 'João Almeida' + visitor = create :visitor, condo:, resident:, visit_date: Date.current, full_name: 'João Almeida' login_as manager, scope: :manager visit find_condo_visitors_path condo diff --git a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb index 0d9b446..84b798c 100644 --- a/spec/system/visitor/resident_sees_own_visitors_list_spec.rb +++ b/spec/system/visitor/resident_sees_own_visitors_list_spec.rb @@ -97,11 +97,11 @@ second_resident_visitor = create :visitor, resident: second_resident, full_name: 'Fernando Dias' first_visitor = create :visitor, resident:, full_name: 'João Ferreira', - visit_date: Time.zone.today, + visit_date: Date.current, category: :visitor second_visitor = create :visitor, resident:, full_name: 'Maria Almeida', - visit_date: Time.zone.today, + visit_date: Date.current, category: :employee, recurrence: :daily third_visitor = create :visitor, resident:, full_name: 'João Almeida', diff --git a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb index 03447a4..3f90900 100644 --- a/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb +++ b/spec/system/visitor_entry/manager_see_visitor_entries_spec.rb @@ -96,21 +96,27 @@ it 'with visit date filter' do manager = create :manager condo = create :condo - travel_to 1.day.ago do + travel_to '04/07/2024' do create :visitor_entry, condo:, full_name: 'Nome Visitante Ontem' end - create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' - create :visitor_entry, condo:, full_name: 'Nome Último Visitante' - login_as manager, scope: :manager - visit condo_visitor_entries_path condo - fill_in 'Data da Visita', with: Time.zone.today - click_on 'Pesquisar' + travel_to '05/07/2024' do + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante' + end - expect(page).to have_content '2 entradas de visitante encontrada' - within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Último Visitante' } - within('.table > tbody > tr:nth-child(2)') { expect(page).to have_content 'Nome Primeiro Visitante' } - expect(page).not_to have_content 'Nome Visitante Ontem' + travel_to '05/07/2024 00:30' do + create :visitor_entry, condo:, full_name: 'Nome Último Visitante' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Data da Visita', with: '2024-07-05' + click_on 'Pesquisar' + + expect(page).to have_content '2 entradas de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Último Visitante' } + within('.table > tbody > tr:nth-child(2)') { expect(page).to have_content 'Nome Primeiro Visitante' } + expect(page).not_to have_content 'Nome Visitante Ontem' + end end it 'with identity number filter' do @@ -130,23 +136,25 @@ end it 'with all filters' do - manager = create :manager - condo = create :condo - create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante', identity_number: '145697' - create :visitor_entry, condo:, full_name: 'Nome Segundo Visitante', identity_number: '789354' - create :visitor_entry, condo:, full_name: 'Nome Terceiro Visitante', identity_number: '78935447' - - login_as manager, scope: :manager - visit condo_visitor_entries_path condo - fill_in 'Nome Completo', with: 'Segundo' - fill_in 'RG', with: '789354' - fill_in 'Data da Visita', with: Time.zone.today - click_on 'Pesquisar' - - expect(page).to have_content '1 entrada de visitante encontrada' - within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Segundo Visitante' } - expect(page).not_to have_content 'Nome Primeiro Visitante' - expect(page).not_to have_content 'Nome Terceiro Visitante' + travel_to '05/07/2024' do + manager = create :manager + condo = create :condo + create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante', identity_number: '145697' + create :visitor_entry, condo:, full_name: 'Nome Segundo Visitante', identity_number: '789354' + create :visitor_entry, condo:, full_name: 'Nome Terceiro Visitante', identity_number: '78935447' + + login_as manager, scope: :manager + visit condo_visitor_entries_path condo + fill_in 'Nome Completo', with: 'Segundo' + fill_in 'RG', with: '789354' + fill_in 'Data da Visita', with: '2024-07-05' + click_on 'Pesquisar' + + expect(page).to have_content '1 entrada de visitante encontrada' + within('.table > tbody > tr:nth-child(1)') { expect(page).to have_content 'Nome Segundo Visitante' } + expect(page).not_to have_content 'Nome Primeiro Visitante' + expect(page).not_to have_content 'Nome Terceiro Visitante' + end end it 'with no filters' do