priority_spec.rb 1.6 KB

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