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'
|
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'
|
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
|