Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fast_destroy_all.rb « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8079b6d86416614021d3c2416acdde1d4f58664 (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
36
37
38
shared_examples_for 'fast destroyable' do
  describe 'Forbid #destroy and #destroy_all' do
    it 'does not delete database rows and associted external data' do
      expect(external_data_counter).to be > 0
      expect(subjects.count).to be > 0

      expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`')
      expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') # rubocop: disable DestroyAll

      expect(subjects.count).to be > 0
      expect(external_data_counter).to be > 0
    end
  end

  describe '.fast_destroy_all' do
    it 'deletes database rows and associted external data' do
      expect(external_data_counter).to be > 0
      expect(subjects.count).to be > 0

      expect { subjects.fast_destroy_all }.not_to raise_error

      expect(subjects.count).to eq(0)
      expect(external_data_counter).to eq(0)
    end
  end

  describe '.use_fast_destroy' do
    it 'performs cascading delete with fast_destroy_all' do
      expect(external_data_counter).to be > 0
      expect(subjects.count).to be > 0

      expect { parent.destroy }.not_to raise_error

      expect(subjects.count).to eq(0)
      expect(external_data_counter).to eq(0)
    end
  end
end