2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-01-21 08:38:45 +00:00
|
|
|
require 'rails_helper'
|
2019-01-22 16:35:01 +00:00
|
|
|
require 'models/application_model_examples'
|
2019-01-28 06:04:05 +00:00
|
|
|
require 'models/concerns/can_be_imported_examples'
|
2020-02-20 13:34:03 +00:00
|
|
|
require 'models/concerns/has_collection_update_examples'
|
2021-04-12 09:49:26 +00:00
|
|
|
require 'models/concerns/has_xss_sanitized_note_examples'
|
2019-01-21 08:38:45 +00:00
|
|
|
|
|
|
|
RSpec.describe Ticket::Priority, type: :model do
|
2019-01-24 10:13:04 +00:00
|
|
|
it_behaves_like 'ApplicationModel'
|
2019-01-28 06:04:05 +00:00
|
|
|
it_behaves_like 'CanBeImported'
|
2020-02-20 13:34:03 +00:00
|
|
|
it_behaves_like 'HasCollectionUpdate', collection_factory: :ticket_priority
|
2021-04-12 09:49:26 +00:00
|
|
|
it_behaves_like 'HasXssSanitizedNote', model_factory: :ticket_priority
|
2019-01-22 16:35:01 +00:00
|
|
|
|
2019-01-21 08:38:45 +00:00
|
|
|
describe 'Default state' do
|
|
|
|
describe 'of whole table:' do
|
|
|
|
it 'has exactly one default record' do
|
2019-09-16 15:04:17 +00:00
|
|
|
expect(described_class.where(default_create: true)).to be_one
|
2019-01-21 08:38:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'attributes' do
|
|
|
|
describe '#default_create' do
|
|
|
|
it 'cannot be true for more than one record at a time' do
|
|
|
|
expect { create(:'ticket/priority', default_create: true) }
|
2019-09-16 15:04:17 +00:00
|
|
|
.to change { described_class.find_by(default_create: true).id }
|
|
|
|
.and change { described_class.where(default_create: true).count }.by(0)
|
2019-01-21 08:38:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot be false for all records' do
|
|
|
|
create(:'ticket/priority', default_create: true)
|
|
|
|
|
2019-09-16 15:04:17 +00:00
|
|
|
expect { described_class.find_by(default_create: true).destroy }
|
|
|
|
.to change { described_class.find_by(default_create: true).id }
|
|
|
|
.and change { described_class.where(default_create: true).count }.by(0)
|
2019-01-21 08:38:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not automatically set to the last-created record' do
|
|
|
|
expect { create(:'ticket/priority') }
|
2019-09-16 15:04:17 +00:00
|
|
|
.not_to change { described_class.find_by(default_create: true).id }
|
2019-01-21 08:38:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|