Skip to content

Commit

Permalink
Implementa o job_spy nos testes de sistema para garantir o funcioname…
Browse files Browse the repository at this point in the history
…nto do Job

Co-authored-by: thalyta lima <[email protected]>
  • Loading branch information
RyanOxon and thalytalima211 committed Jul 18, 2024
1 parent 390723c commit a84ae9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/visitors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def new
def create
@visitor = Visitor.new(visitor_params)
unless @visitor.save
set_visit_date_job
flash.now[:alert] = t('alerts.visitor.not_created')
return render :new, status: :unprocessable_entity
end
set_visit_date_job
redirect_to resident_visitors_path(@resident), notice: I18n.t('notice.visitor.created')
end

Expand Down
12 changes: 12 additions & 0 deletions spec/system/visitor/resident_registers_a_new_visitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
condo = create :condo
tower = create(:tower, condo:)
resident = create :resident, residence: tower.floors[0].units[0]
update_visit_date_job_spy = spy(UpdateVisitDateJob)
stub_const('UpdateVisitDateJob', update_visit_date_job_spy)

login_as resident, scope: :resident
visit condo_path condo
Expand All @@ -21,12 +23,15 @@
expect(page).to have_content 'Visitante'
expect(page).to have_content '12311'
expect(page).to have_content I18n.l(1.month.from_now.to_date)
expect(update_visit_date_job_spy).not_to have_received(:perform_later).with(Visitor.last)
end

it 'as an employee' do
condo = create :condo
tower = create(:tower, condo:)
resident = create :resident, residence: tower.floors[0].units[0]
update_visit_date_job_spy = spy(UpdateVisitDateJob)
stub_const('UpdateVisitDateJob', update_visit_date_job_spy)

login_as resident, scope: :resident
visit condo_path condo
Expand All @@ -46,6 +51,7 @@
expect(page).to have_content I18n.l(1.month.from_now.to_date)
expect(page).to have_content 'Semanalmente'
end
expect(update_visit_date_job_spy).to have_received(:perform_later).with(Visitor.last)
end

it 'only if as a tenant' do
Expand All @@ -62,6 +68,8 @@
condo = create :condo
tower = create(:tower, condo:)
resident = create :resident, residence: tower.floors[0].units[0]
update_visit_date_job_spy = spy(UpdateVisitDateJob)
stub_const('UpdateVisitDateJob', update_visit_date_job_spy)

login_as resident, scope: :resident
visit new_resident_visitor_path resident
Expand All @@ -75,12 +83,15 @@
expect(page).to have_content 'Nome Completo não pode ficar em branco'
expect(page).to have_content 'RG não pode ficar em branco'
expect(page).to have_content 'Data da Visita não pode ficar em branco'
expect(update_visit_date_job_spy).not_to have_received(:perform_later).with(Visitor.last)
end

it 'date must be future' do
condo = create :condo
tower = create(:tower, condo:)
resident = create :resident, residence: tower.floors[0].units[0]
update_visit_date_job_spy = spy(UpdateVisitDateJob)
stub_const('UpdateVisitDateJob', update_visit_date_job_spy)

login_as resident, scope: :resident
visit new_resident_visitor_path resident
Expand All @@ -92,6 +103,7 @@
expect(page).to have_content 'Erro ao registrar visitante'
expect(current_path).to eq new_resident_visitor_path resident
expect(page).to have_content 'Data da Visita deve ser futura'
expect(update_visit_date_job_spy).not_to have_received(:perform_later).with(Visitor.last)
end

context 'identity number' do
Expand Down

0 comments on commit a84ae9f

Please sign in to comment.