Skip to content

Commit 7f5b420

Browse files
authored
Merge pull request #5233 from zanetagebka/5231-cancel-requests-deactivated-partners
feat: Allow to cancel request when partner is deactivated
2 parents cbe828e + 1aa0549 commit 7f5b420

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

app/services/request_destroy_service.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def call
1414
request.status = :discarded
1515
request.save!
1616

17-
RequestMailer.request_cancel_partner_notification(request_id: request.id).deliver_later
17+
unless request.partner.deactivated?
18+
RequestMailer.request_cancel_partner_notification(request_id: request.id).deliver_later
19+
end
1820

1921
self
2022
end
@@ -28,8 +30,6 @@ def valid?
2830
errors.add(:base, 'request_id is invalid')
2931
elsif request.discarded_at.present?
3032
errors.add(:base, 'request already discarded')
31-
elsif request.partner.deactivated?
32-
errors.add(:base, 'partner is deactivated')
3333
end
3434

3535
errors.none?

app/views/requests/cancelation/new.html.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
<div class="box w-1/2">
3131
<%= simple_form_for :cancelation, url: request_cancelation_path(organization: @organization, request_id: @request.id), method: :post do |f| %>
3232
<div class='flex flex-col'>
33-
<%= f.input :reason, label: "Cancelation reason" %>
34-
<span class='font-light text-md text-yellow-600'>This will be included in the email notification we send to the partner</span>
33+
<%= f.input :reason, label: "Cancellation reason" %>
34+
<div class='font-light text-md text-yellow-600'>This will be included in the email notification we send to the partner</div>
35+
<div class="font-light text-sm text-red">Note: cancellation emails will not be sent to deactivated partners</div>
3536
</div>
3637

37-
<div class='flex flex-row justify-end'>
38+
<div class='flex flex-row justify-end pt-2'>
3839
<%= f.submit 'Yes. Cancel Request', class: 'btn btn-primary' %>
3940
</div>
4041
<% end %>

spec/services/request_destroy_service_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@
5050
let!(:partner) { create(:partner, status: 'deactivated') }
5151
let(:request) { create(:request, partner: partner) }
5252

53-
it 'should have errors' do
54-
expect(subject.errors.full_messages).to eq(['partner is deactivated'])
53+
it 'should update the status column on the request' do
54+
expect { subject }.to change { request.reload.status_discarded? }.from(false).to(true)
55+
end
56+
57+
it 'should not send a email notification to the partner' do
58+
expect(RequestMailer).not_to receive(:request_cancel_partner_notification)
59+
subject
5560
end
5661
end
5762
end

spec/system/request_system_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255

256256
it 'should set the request as canceled/discarded and contain the reason' do
257257
click_on 'Cancel'
258-
fill_in 'Cancelation reason *', with: reason
258+
fill_in 'Cancellation reason *', with: reason
259259
click_on 'Yes. Cancel Request'
260260

261261
expect(page).to have_content("Request #{request.id} has been removed")

0 commit comments

Comments
 (0)