-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathrequest_destroy_service_spec.rb
More file actions
64 lines (51 loc) · 2.14 KB
/
request_destroy_service_spec.rb
File metadata and controls
64 lines (51 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
RSpec.describe RequestDestroyService, type: :service do
describe '#call' do
subject { described_class.new(request_id: request_id).call }
let(:request_id) { request.id }
let(:request) { create(:request) }
it 'should return an instance of itself' do
expect(subject).to be_a_kind_of(RequestDestroyService)
end
context 'when the request_id matches no request' do
let(:request_id) { 0 }
it 'should not be successful and have errors indicating request id is invalid' do
expect(subject.errors.full_messages).to eq(['request_id is invalid'])
end
end
context 'when the request is already cancelled' do
before do
request.discard!
end
it 'should not be successful and have errors' do
expect(subject.errors.full_messages).to eq(['request already cancelled'])
end
end
context 'when there are no validation errors' do
let(:fake_mailer) { double('fake_mailer', deliver_later: -> {}) }
before do
allow(RequestMailer).to receive(:request_cancel_partner_notification).with(request_id: request.id).and_return(fake_mailer)
end
it 'should update the discarded_at column on the request' do
expect { subject }.to change { request.reload.discarded? }.from(false).to(true)
end
it 'should update the status column on the request' do
expect { subject }.to change { request.reload.status_cancelled? }.from(false).to(true)
end
it 'should send a email notification to the partner' do
subject
expect(fake_mailer).to have_received(:deliver_later)
end
end
context "when the request's partner is deactivated" do
let!(:partner) { create(:partner, status: 'deactivated') }
let(:request) { create(:request, partner: partner) }
it 'should update the status column on the request' do
expect { subject }.to change { request.reload.status_cancelled? }.from(false).to(true)
end
it 'should not send a email notification to the partner' do
expect(RequestMailer).not_to receive(:request_cancel_partner_notification)
subject
end
end
end
end