Skip to content

Commit

Permalink
Close milestones when all tickets are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
kneath committed May 2, 2009
1 parent b69e857 commit d3ea123
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/burndown/lighthouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def self.get_milestones(remote_project_id, account, token)
end

def self.get_milestone(remote_milestone_id, remote_project_id, account, token)
puts "http://#{account}.#{lighthouse_host}/projects/#{remote_project_id}/milestone/#{remote_milestone_id}.xml"
get "http://#{account}.#{lighthouse_host}/projects/#{remote_project_id}/milestone/#{remote_milestone_id}.xml", :headers => default_headers(token)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/burndown/milestone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def sync_with_lighthouse
results = Lighthouse.get_milestone(self.remote_id, self.project.remote_id, self.project.token.account, self.project.token.token)
return false unless milestone = results["milestone"]
self.update_attributes(:name => milestone["title"], :due_on => milestone["due_on"], :tickets_count => milestone["tickets_count"], :open_tickets_count => milestone["open_tickets_count"])
if !self.active?
self.update_attributes(:closed_at => Time.now)
return true
end

results = Lighthouse.get_milestone_tickets(self.name, self.project.remote_id, self.project.token.account, self.project.token.token)
ticket_ids = results["tickets"] ? results["tickets"].collect{ |t| t["number"] }.join(",") : ""
Expand Down
35 changes: 25 additions & 10 deletions test/unit/miilestone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ class MiilestoneTest < Test::Unit::TestCase
end

context "lighthouse syncing" do
before(:all) do
@existing = Milestone.generate(:remote_id => 42, :tickets_count => 20, :open_tickets_count => 10, :name => "ExistingMilestone", :due_on => DateTime.new(2006, 06, 06), :project_id => @activated_project.id)
end

before(:each) do
@existing = Milestone.generate(:remote_id => 42, :tickets_count => 20, :open_tickets_count => 10, :name => "ExistingMilestone", :due_on => DateTime.new(2006, 06, 06), :project_id => @activated_project.id)

@milestone_update_hash = {
"title" => "ExistingMilestoneUpdated",
"id" => "42",
"tickets_count" => "30",
"open_tickets_count" => "5",
"due_on" => "2007-07-07T20:00:00Z"
}
stub(Lighthouse).get_milestone{
{
"milestone" => {
"title" => "ExistingMilestoneUpdated",
"id" => "42",
"tickets_count" => "30",
"open_tickets_count" => "5",
"due_on" => "2007-07-07T20:00:00Z"
}
"milestone" => @milestone_update_hash
}
}
end
Expand All @@ -108,6 +108,21 @@ class MiilestoneTest < Test::Unit::TestCase
@existing.tickets_count.should == 30
@existing.due_on.strftime("%m/%d/%y").should == "07/07/07"
end

it "closes the milstone if all open tickets have been closed and the due date is past" do
stub(Lighthouse).get_milestone{
{ "milestone" => @milestone_update_hash.merge({"open_tickets_count" => 0}) }
}
@existing.should be_active
@existing.closed_at.should be_nil

@existing.sync_with_lighthouse

@existing.should_not be_active
@existing.closed_at.should_not be_nil
end

it "reopenes the milestone if there are open tickets"
end

end

0 comments on commit d3ea123

Please sign in to comment.