Commit d789295a authored by Felipe Artur's avatar Felipe Artur

Set closed and reopened issues without closed_at to milestone start date

parent 465b4ec5
class Burndown
attr_accessor :start_date, :due_date, :end_date, :issues_count, :issues_weight
attr_accessor :start_date, :due_date, :end_date, :issues_count, :issues_weight, :has_data
def initialize(milestone)
@milestone = milestone
......@@ -7,6 +7,7 @@ class Burndown
@due_date = @milestone.due_date
@end_date = @milestone.due_date
@end_date = Date.today if @end_date.present? && @end_date > Date.today
@has_data = issues_with_closed_at.pluck(:closed_at).compact.any?
@issues_count, @issues_weight = milestone.issues.reorder(nil).pluck('COUNT(*), COALESCE(SUM(weight), 0)').first
end
......@@ -51,7 +52,11 @@ class Burndown
def closed_and_reopened_issues_by(date)
current_date = date.to_date
closed = issues_with_closed_at.select { |issue| issue.closed_at.to_date == current_date }
closed =
issues_with_closed_at.select do |issue|
(issue.closed_at&.to_date || @start_date) == current_date
end
reopened = closed.select { |issue| issue.state == 'reopened' }
[closed, reopened]
......@@ -59,8 +64,8 @@ class Burndown
def issues_with_closed_at
@issues_with_closed_at ||=
@milestone.issues.select('closed_at, weight, state').
where('closed_at IS NOT NULL').
order('closed_at ASC')
@milestone.issues.select("closed_at, weight, state").
where("state IN ('reopened', 'closed')").
order("closed_at ASC")
end
end
---
title: Set closed and reopened issues without closed_at to milestone start date
merge_request:
author:
......@@ -57,6 +57,32 @@ describe Burndown, models: true do
expect(JSON.parse(subject).last[0]).to eq(Time.now.strftime("%Y-%m-%d"))
end
it "it sets attribute has_data to true" do
burndown = described_class.new(milestone)
expect(burndown.has_data).to be_truthy
end
context "when closed and reopened issues does not have closed_at" do
before { milestone.issues.update_all(closed_at: nil) }
it "it considers closed_at as milestone start date" do
expect(subject).to eq([
["2017-03-01", 15, 30],
["2017-03-02", 27, 54],
["2017-03-03", 27, 54],
["2017-03-04", 27, 54],
["2017-03-05", 27, 54]
].to_json)
end
it "it sets attribute has_data to false" do
burndown = described_class.new(milestone)
expect(burndown.has_data).to be_falsy
end
end
# Creates, closes and reopens issues only for odd days numbers
def build_sample
milestone.start_date.upto(milestone.due_date) do |date|
......
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