drop_removed_state_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe DropRemovedState, :aggregate_failures, db_strategy: :reset, type: :db_migration do
  4. context 'when removed state is absent' do
  5. it 'does not change anything' do
  6. expect { migrate }.not_to change(Ticket::State, :count)
  7. end
  8. end
  9. context 'when removed state is present' do
  10. let!(:state_type) { create(:ticket_state_type, name: 'removed') }
  11. let!(:state) { create(:ticket_state, name: 'removed', state_type:) }
  12. context 'without tickets present' do
  13. before { migrate }
  14. it 'drops removed state and type' do
  15. expect { state.reload }.to raise_error(ActiveRecord::RecordNotFound)
  16. expect { state_type.reload }.to raise_error(ActiveRecord::RecordNotFound)
  17. end
  18. end
  19. context 'with tickets present' do
  20. let!(:ticket) { create(:ticket, state:) }
  21. before { migrate }
  22. it 'keeps the ticket, the removed state and type' do
  23. expect(state.reload).to be_persisted
  24. expect(state_type.reload).to be_persisted
  25. expect(ticket.reload).to be_persisted
  26. end
  27. end
  28. end
  29. end