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,56 +98,78 @@ describe Epic do
end
describe '#start_date_from_milestones' do
subject { create(:epic) }
let(:date) { Date.new(2017, 3, 4) }
context 'fixed date' do
subject { create(:epic, :use_fixed_dates) }
let(:date) { Date.new(2017, 3, 4) }
before do
milestone1 = create(
:milestone,
start_date: date,
due_date: date + 10.days
)
epic_issue1 = create(:epic_issue, epic: subject)
epic_issue1.issue.update(milestone: milestone1)
milestone2 = create(
:milestone,
start_date: date + 5.days,
due_date: date + 15.days
)
epic_issue2 = create(:epic_issue, epic: subject)
epic_issue2.issue.update(milestone: milestone2)
before do
milestone1 = create(
:milestone,
start_date: date,
due_date: date + 10.days
)
epic_issue1 = create(:epic_issue, epic: subject)
epic_issue1.issue.update(milestone: milestone1)
milestone2 = create(
:milestone,
start_date: date + 5.days,
due_date: date + 15.days
)
epic_issue2 = create(:epic_issue, epic: subject)
epic_issue2.issue.update(milestone: milestone2)
end
it 'returns earliest start date from issue milestones' do
expect(subject.start_date_from_milestones).to eq(date)
end
end
it 'returns earliest start date from issue milestones' do
expect(subject.start_date_from_milestones).to eq(date)
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) }
let(:date) { Date.new(2017, 3, 4) }
context 'fixed date' do
subject { create(:epic, :use_fixed_dates) }
let(:date) { Date.new(2017, 3, 4) }
before do
milestone1 = create(
:milestone,
start_date: date - 30.days,
due_date: date - 20.days
)
epic_issue1 = create(:epic_issue, epic: subject)
epic_issue1.issue.update(milestone: milestone1)
milestone2 = create(
:milestone,
start_date: date - 10.days,
due_date: date
)
epic_issue2 = create(:epic_issue, epic: subject)
epic_issue2.issue.update(milestone: milestone2)
before do
milestone1 = create(
:milestone,
start_date: date - 30.days,
due_date: date - 20.days
)
epic_issue1 = create(:epic_issue, epic: subject)
epic_issue1.issue.update(milestone: milestone1)
milestone2 = create(
:milestone,
start_date: date - 10.days,
due_date: date
)
epic_issue2 = create(:epic_issue, epic: subject)
epic_issue2.issue.update(milestone: milestone2)
end
it 'returns latest due date from issue milestones' do
expect(subject.due_date_from_milestones).to eq(date)
end
end
it 'returns latest due date from issue milestones' do
expect(subject.due_date_from_milestones).to eq(date)
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
......
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