Commit 175d2048 authored by Mark Chao's avatar Mark Chao

Prevent query of calculating milestone dates when fixed dates are not used

parent 5bec56da
......@@ -123,12 +123,12 @@ module EE
# Earliest start date from issues' milestones
def start_date_from_milestones
epic_issues.joins(issue: :milestone).minimum('milestones.start_date')
start_date_is_fixed? ? epic_issues.joins(issue: :milestone).minimum('milestones.start_date') : start_date
end
# Latest end date from issues' milestones
def due_date_from_milestones
epic_issues.joins(issue: :milestone).maximum('milestones.due_date')
due_date_is_fixed? ? epic_issues.joins(issue: :milestone).maximum('milestones.due_date') : due_date
end
def to_reference(from = nil, full: false)
......
......@@ -98,7 +98,8 @@ describe Epic do
end
describe '#start_date_from_milestones' do
subject { create(:epic) }
context 'fixed date' do
subject { create(:epic, :use_fixed_dates) }
let(:date) { Date.new(2017, 3, 4) }
before do
......@@ -124,8 +125,19 @@ describe Epic do
end
end
context 'milestone date' do
subject { create(:epic, start_date: date) }
let(:date) { Date.new(2017, 3, 4) }
it 'returns start_date' do
expect(subject.start_date_from_milestones).to eq(date)
end
end
end
describe '#due_date_from_milestones' do
subject { create(:epic) }
context 'fixed date' do
subject { create(:epic, :use_fixed_dates) }
let(:date) { Date.new(2017, 3, 4) }
before do
......@@ -151,6 +163,16 @@ describe Epic do
end
end
context 'milestone date' do
subject { create(:epic, due_date: date) }
let(:date) { Date.new(2017, 3, 4) }
it 'returns due_date' do
expect(subject.due_date_from_milestones).to eq(date)
end
end
end
describe '#update_dates' do
context 'fixed date is set' do
subject { create(:epic, :use_fixed_dates, start_date: nil, end_date: nil) }
......
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