priority_spec.rb 1.5 KB

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