summaryrefslogtreecommitdiff
path: root/spec/services/users/saved_replies/destroy_service_spec.rb
blob: cb97fac7b7c14061e63eff14c1f2a53ccea6fe1a (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Users::SavedReplies::DestroyService do
  describe '#execute' do
    let!(:saved_reply) { create(:saved_reply) }

    subject { described_class.new(saved_reply: saved_reply).execute }

    context 'when destroy fails' do
      before do
        allow(saved_reply).to receive(:destroy).and_return(false)
      end

      it 'does not remove Saved Reply from database' do
        expect { subject }.not_to change(::Users::SavedReply, :count)
      end

      it { is_expected.not_to be_success }
    end

    context 'when destroy succeeds' do
      it { is_expected.to be_success }

      it 'removes Saved Reply from database' do
        expect { subject }.to change(::Users::SavedReply, :count).by(-1)
      end

      it 'returns saved reply' do
        expect(subject[:saved_reply]).to eq(saved_reply)
      end
    end
  end
end