Returns Milestone::Upcoming for boards with this milestone

parent 3e9820dd
class Board < ActiveRecord::Base
belongs_to :project
belongs_to :milestone
has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all
belongs_to :milestone
validates :name, :project, presence: true
def done_list
lists.merge(List.done).take
end
def milestone
if milestone_id === Milestone::Upcoming.id
Milestone::Upcoming
else
super
end
end
end
......@@ -3,6 +3,8 @@ require 'rails_helper'
describe Board do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:milestone) }
it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
end
......@@ -10,4 +12,27 @@ describe Board do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:project) }
end
describe 'milestone' do
subject { described_class.new }
it 'returns Milestone::Upcoming for upcoming milestone id' do
subject.milestone_id = Milestone::Upcoming.id
expect(subject.milestone).to eq Milestone::Upcoming
end
it 'returns milestone for valid milestone id' do
milestone = create(:milestone)
subject.milestone_id = milestone.id
expect(subject.milestone).to eq milestone
end
it 'returns nil for invalid milestone id' do
subject.milestone_id = -1
expect(subject.milestone).to be_nil
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