diff --git a/app/models/list.rb b/app/models/list.rb index 38cf2050527ebefdfed5731a3c6a2ae9ef197d3c..b4fdab7893ab92004b58c6468e1f531109707b70 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -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 diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb index 60b46f061950dd4545c4e5226c35181cffb99128..689011454d30148620b470d0831f4c9731248993 100644 --- a/spec/models/list_spec.rb +++ b/spec/models/list_spec.rb @@ -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