2016-07-27 15:32:32 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe List do
|
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:board) }
|
|
|
|
it { is_expected.to belong_to(:label) }
|
2016-07-31 19:45:56 -04:00
|
|
|
end
|
|
|
|
|
2016-07-27 15:32:32 -04:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:board) }
|
|
|
|
it { is_expected.to validate_presence_of(:label) }
|
|
|
|
it { is_expected.to validate_presence_of(:list_type) }
|
|
|
|
it { is_expected.to validate_presence_of(:position) }
|
|
|
|
it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) }
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
context 'when list_type is set to closed' do
|
|
|
|
subject { described_class.new(list_type: :closed) }
|
2016-07-27 15:32:32 -04:00
|
|
|
|
2016-07-28 18:26:16 -04:00
|
|
|
it { is_expected.not_to validate_presence_of(:label) }
|
|
|
|
it { is_expected.not_to validate_presence_of(:position) }
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-31 19:48:00 -04:00
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'can be destroyed when when list_type is set to label' do
|
2016-07-31 20:55:03 -04:00
|
|
|
subject = create(:list)
|
2016-07-31 19:48:00 -04:00
|
|
|
|
|
|
|
expect(subject.destroy).to be_truthy
|
|
|
|
end
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
it 'can not be destroyed when when list_type is set to closed' do
|
|
|
|
subject = create(:closed_list)
|
2016-07-31 19:48:00 -04:00
|
|
|
|
|
|
|
expect(subject.destroy).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 10:31:21 -04:00
|
|
|
describe '#destroyable?' do
|
2017-01-27 00:23:07 -05:00
|
|
|
it 'returns true when list_type is set to label' do
|
2016-08-16 10:31:21 -04:00
|
|
|
subject.list_type = :label
|
|
|
|
|
|
|
|
expect(subject).to be_destroyable
|
|
|
|
end
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
it 'returns false when list_type is set to closed' do
|
|
|
|
subject.list_type = :closed
|
2016-08-16 10:31:21 -04:00
|
|
|
|
|
|
|
expect(subject).not_to be_destroyable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 13:38:43 -04:00
|
|
|
describe '#movable?' do
|
2017-01-27 00:23:07 -05:00
|
|
|
it 'returns true when list_type is set to label' do
|
2016-08-16 13:38:43 -04:00
|
|
|
subject.list_type = :label
|
|
|
|
|
|
|
|
expect(subject).to be_movable
|
|
|
|
end
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
it 'returns false when list_type is set to closed' do
|
|
|
|
subject.list_type = :closed
|
2016-08-16 13:38:43 -04:00
|
|
|
|
|
|
|
expect(subject).not_to be_movable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-31 19:45:56 -04:00
|
|
|
describe '#title' do
|
|
|
|
it 'returns label name when list_type is set to label' do
|
|
|
|
subject.list_type = :label
|
|
|
|
subject.label = Label.new(name: 'Development')
|
|
|
|
|
|
|
|
expect(subject.title).to eq 'Development'
|
|
|
|
end
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
it 'returns Closed when list_type is set to closed' do
|
|
|
|
subject.list_type = :closed
|
2016-07-31 19:45:56 -04:00
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
expect(subject.title).to eq 'Closed'
|
2016-07-31 19:45:56 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|