Title of a list is either the label name, or Backlog, or Done

parent b07c5f23
......@@ -7,4 +7,10 @@ class List < ActiveRecord::Base
validates :board, :list_type, presence: true
validates :label, :position, presence: true, if: :label?
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :label?
delegate :name, to: :label, allow_nil: true, prefix: true
def title
label? ? label_name : list_type.humanize
end
end
......@@ -6,6 +6,10 @@ describe List do
it { is_expected.to belong_to(:label) }
end
describe 'delegate methods' do
it { is_expected.to delegate_method(:name).to(:label).with_prefix }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:board) }
it { is_expected.to validate_presence_of(:label) }
......@@ -27,4 +31,24 @@ describe List do
it { is_expected.not_to validate_presence_of(:position) }
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
it 'returns Backlog when list_type is set to backlog' do
subject.list_type = :backlog
expect(subject.title).to eq 'Backlog'
end
it 'returns Done when list_type is set to done' do
subject.list_type = :done
expect(subject.title).to eq 'Done'
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment