]> source.dussan.org Git - redmine.git/commitdiff
Fixes calculation of version estimated hours with subtasks (#5265).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 11 Apr 2010 13:20:02 +0000 (13:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 11 Apr 2010 13:20:02 +0000 (13:20 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3633 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/version.rb
test/unit/version_test.rb

index bc0e17e22fdd2d8e342ffefe863897d8d5d5da73..f9b48fb1117347a78a2e22934d765554ccab1a79 100644 (file)
@@ -52,8 +52,9 @@ class Version < ActiveRecord::Base
   end
   
   # Returns the total estimated time for this version
+  # (sum of leaves estimated_hours)
   def estimated_hours
-    @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
+    @estimated_hours ||= fixed_issues.leaves.sum(:estimated_hours).to_f
   end
   
   # Returns the total reported time for this version
index dcc1edbc839a692ab8483379ee6b6a5424de0fe6..1abb4a2729680a124c55595a2c3a9e6df87eca8c 100644 (file)
@@ -104,6 +104,34 @@ class VersionTest < ActiveSupport::TestCase
     assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent
     assert_progress_equal 25.0/100.0*100, v.closed_pourcent
   end
+  
+  context "#estimated_hours" do
+    setup do
+      @version = Version.create!(:project_id => 1, :name => '#estimated_hours')
+    end
+    
+    should "return 0 with no assigned issues" do
+      assert_equal 0, @version.estimated_hours
+    end
+    
+    should "return 0 with no estimated hours" do
+      add_issue(@version)
+      assert_equal 0, @version.estimated_hours
+    end
+    
+    should "return the sum of estimated hours" do
+      add_issue(@version, :estimated_hours => 2.5)
+      add_issue(@version, :estimated_hours => 5)
+      assert_equal 7.5, @version.estimated_hours
+    end
+    
+    should "return the sum of leaves estimated hours" do
+      parent = add_issue(@version)
+      add_issue(@version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
+      add_issue(@version, :estimated_hours => 5, :parent_issue_id => parent.id)
+      assert_equal 7.5, @version.estimated_hours
+    end
+  end
 
   test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
     User.current = User.find(1) # Need the admin's permissions