Skip to content

Commit

Permalink
Merge pull request #133 from TreinaDev/corrige-bugs-timezone
Browse files Browse the repository at this point in the history
Corrige bugs de timezone
  • Loading branch information
ruliancruz authored Jul 22, 2024
2 parents 27933f6 + 78e1dbc commit 38e1446
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 86 deletions.
3 changes: 1 addition & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/superintendents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/models/superintendent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/manager_confirms_visitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions spec/requests/manager_edit_superintendent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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

Expand All @@ -46,8 +46,8 @@
condo = create :condo, name: 'Condomínio X'
resident = create(:resident, :with_residence, condo:)
resident2 = create(:resident, :with_residence, email: '[email protected]', 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 }

Expand All @@ -61,8 +61,8 @@
condo = create :condo, name: 'Condomínio X'
resident = create(:resident, :with_residence, condo:)
resident2 = create(:resident, :with_residence, email: '[email protected]', 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
Expand All @@ -79,8 +79,8 @@
condo = create :condo, name: 'Condomínio X'
resident = create(:resident, :with_residence, condo:)
resident2 = create(:resident, :with_residence, email: '[email protected]', 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

Expand Down
6 changes: 3 additions & 3 deletions spec/requests/manager_registers_superintendent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand All @@ -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:)
Expand All @@ -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:)
Expand Down
16 changes: 10 additions & 6 deletions spec/system/superintendent/manager_edit_superintendent_spec.rb
Original file line number Diff line number Diff line change
@@ -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 protected]', 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

Expand All @@ -16,22 +18,24 @@
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

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,
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
tower = create(:tower, condo:)
unit11 = tower.floors.first.units.first
resident = create :resident, full_name: 'Dona Alvara', residence: unit11, email: '[email protected]'
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,
Expand All @@ -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
Expand All @@ -52,8 +53,9 @@
tower = create(:tower, condo:)
unit11 = tower.floors.first.units.first
resident = create :resident, full_name: 'Dona Alvara', residence: unit11, email: '[email protected]'
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')

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -41,15 +41,15 @@
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'
expect(page).to have_content '45977'
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
Expand Down
24 changes: 12 additions & 12 deletions spec/system/visitor/manager_view_condo_visitors_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -50,15 +50,15 @@
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'

login_as manager, scope: :manager
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'
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/system/visitor/resident_sees_own_visitors_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 38e1446

Please sign in to comment.