diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-07-31 20:45:56 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 12:58:57 -0300 |
commit | 252e93c9e664e595ea9b4987f14ca8fb21a0e307 (patch) | |
tree | 2d62339b792ac429520e1fe037b09650b2fc6925 | |
parent | b07c5f23b8761ae87d29ded1a69b14ae6393443a (diff) | |
download | gitlab-ce-252e93c9e664e595ea9b4987f14ca8fb21a0e307.tar.gz |
Title of a list is either the label name, or Backlog, or Done
-rw-r--r-- | app/models/list.rb | 6 | ||||
-rw-r--r-- | spec/models/list_spec.rb | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/app/models/list.rb b/app/models/list.rb index 38cf2050527..b4fdab7893a 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 60b46f06195..689011454d3 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 |