priority_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/application_model_examples'
  4. require 'models/concerns/can_be_imported_examples'
  5. require 'models/concerns/has_collection_update_examples'
  6. require 'models/concerns/has_xss_sanitized_note_examples'
  7. RSpec.describe Ticket::Priority, type: :model do
  8. it_behaves_like 'ApplicationModel'
  9. it_behaves_like 'CanBeImported'
  10. it_behaves_like 'HasCollectionUpdate', collection_factory: :ticket_priority
  11. it_behaves_like 'HasXssSanitizedNote', model_factory: :ticket_priority
  12. describe 'Default state' do
  13. describe 'of whole table:' do
  14. it 'has exactly one default record' do
  15. expect(described_class.where(default_create: true)).to be_one
  16. end
  17. end
  18. end
  19. describe 'attributes' do
  20. describe '#default_create' do
  21. it 'cannot be true for more than one record at a time' do
  22. expect { create(:'ticket/priority', default_create: true) }
  23. .to change { described_class.find_by(default_create: true).id }
  24. .and not_change { described_class.where(default_create: true).count }
  25. end
  26. it 'cannot be false for all records' do
  27. create(:'ticket/priority', default_create: true)
  28. expect { described_class.find_by(default_create: true).destroy }
  29. .to change { described_class.find_by(default_create: true).id }
  30. .and not_change { described_class.where(default_create: true).count }
  31. end
  32. it 'is not automatically set to the last-created record' do
  33. expect { create(:'ticket/priority') }
  34. .not_to change { described_class.find_by(default_create: true).id }
  35. end
  36. end
  37. end
  38. end