debian-mirror-gitlab/spec/models/list_spec.rb

81 lines
2.1 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'rails_helper'
describe List do
describe 'relationships' do
it { is_expected.to belong_to(:board) }
it { is_expected.to belong_to(:label) }
end
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-08-17 22:00:37 +05:30
context 'when list_type is set to closed' do
subject { described_class.new(list_type: :closed) }
2016-09-13 17:45:13 +05:30
it { is_expected.not_to validate_presence_of(:label) }
it { is_expected.not_to validate_presence_of(:position) }
end
end
describe '#destroy' do
it 'can be destroyed when when list_type is set to label' do
subject = create(:list)
expect(subject.destroy).to be_truthy
end
2017-08-17 22:00:37 +05:30
it 'can not be destroyed when when list_type is set to closed' do
subject = create(:closed_list)
2016-09-13 17:45:13 +05:30
expect(subject.destroy).to be_falsey
end
end
describe '#destroyable?' do
2017-08-17 22:00:37 +05:30
it 'returns true when list_type is set to label' do
2016-09-13 17:45:13 +05:30
subject.list_type = :label
expect(subject).to be_destroyable
end
2017-08-17 22:00:37 +05:30
it 'returns false when list_type is set to closed' do
subject.list_type = :closed
2016-09-13 17:45:13 +05:30
expect(subject).not_to be_destroyable
end
end
describe '#movable?' do
2017-08-17 22:00:37 +05:30
it 'returns true when list_type is set to label' do
2016-09-13 17:45:13 +05:30
subject.list_type = :label
expect(subject).to be_movable
end
2017-08-17 22:00:37 +05:30
it 'returns false when list_type is set to closed' do
subject.list_type = :closed
2016-09-13 17:45:13 +05:30
expect(subject).not_to be_movable
end
end
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-08-17 22:00:37 +05:30
it 'returns Closed when list_type is set to closed' do
subject.list_type = :closed
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
expect(subject.title).to eq 'Closed'
2016-09-13 17:45:13 +05:30
end
end
end