annotate .svn/pristine/bb/bb10932a078b9ed11d9a91d216248a45a8481e6c.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class VersionTest < ActiveSupport::TestCase
Chris@909 21 fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions
Chris@909 22
Chris@909 23 def setup
Chris@909 24 end
Chris@909 25
Chris@909 26 def test_create
Chris@909 27 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '2011-03-25')
Chris@909 28 assert v.save
Chris@909 29 assert_equal 'open', v.status
Chris@909 30 assert_equal 'none', v.sharing
Chris@909 31 end
Chris@909 32
Chris@909 33 def test_invalid_effective_date_validation
Chris@909 34 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
Chris@909 35 assert !v.save
Chris@909 36 assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date)
Chris@909 37 end
Chris@909 38
Chris@909 39 def test_progress_should_be_0_with_no_assigned_issues
Chris@909 40 project = Project.find(1)
Chris@909 41 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 42 assert_equal 0, v.completed_pourcent
Chris@909 43 assert_equal 0, v.closed_pourcent
Chris@909 44 end
Chris@909 45
Chris@909 46 def test_progress_should_be_0_with_unbegun_assigned_issues
Chris@909 47 project = Project.find(1)
Chris@909 48 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 49 add_issue(v)
Chris@909 50 add_issue(v, :done_ratio => 0)
Chris@909 51 assert_progress_equal 0, v.completed_pourcent
Chris@909 52 assert_progress_equal 0, v.closed_pourcent
Chris@909 53 end
Chris@909 54
Chris@909 55 def test_progress_should_be_100_with_closed_assigned_issues
Chris@909 56 project = Project.find(1)
Chris@909 57 status = IssueStatus.find(:first, :conditions => {:is_closed => true})
Chris@909 58 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 59 add_issue(v, :status => status)
Chris@909 60 add_issue(v, :status => status, :done_ratio => 20)
Chris@909 61 add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25)
Chris@909 62 add_issue(v, :status => status, :estimated_hours => 15)
Chris@909 63 assert_progress_equal 100.0, v.completed_pourcent
Chris@909 64 assert_progress_equal 100.0, v.closed_pourcent
Chris@909 65 end
Chris@909 66
Chris@909 67 def test_progress_should_consider_done_ratio_of_open_assigned_issues
Chris@909 68 project = Project.find(1)
Chris@909 69 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 70 add_issue(v)
Chris@909 71 add_issue(v, :done_ratio => 20)
Chris@909 72 add_issue(v, :done_ratio => 70)
Chris@909 73 assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_pourcent
Chris@909 74 assert_progress_equal 0, v.closed_pourcent
Chris@909 75 end
Chris@909 76
Chris@909 77 def test_progress_should_consider_closed_issues_as_completed
Chris@909 78 project = Project.find(1)
Chris@909 79 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 80 add_issue(v)
Chris@909 81 add_issue(v, :done_ratio => 20)
Chris@909 82 add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
Chris@909 83 assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent
Chris@909 84 assert_progress_equal (100.0)/3, v.closed_pourcent
Chris@909 85 end
Chris@909 86
Chris@909 87 def test_progress_should_consider_estimated_hours_to_weigth_issues
Chris@909 88 project = Project.find(1)
Chris@909 89 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 90 add_issue(v, :estimated_hours => 10)
Chris@909 91 add_issue(v, :estimated_hours => 20, :done_ratio => 30)
Chris@909 92 add_issue(v, :estimated_hours => 40, :done_ratio => 10)
Chris@909 93 add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
Chris@909 94 assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent
Chris@909 95 assert_progress_equal 25.0/95.0*100, v.closed_pourcent
Chris@909 96 end
Chris@909 97
Chris@909 98 def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues
Chris@909 99 project = Project.find(1)
Chris@909 100 v = Version.create!(:project => project, :name => 'Progress')
Chris@909 101 add_issue(v, :done_ratio => 20)
Chris@909 102 add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
Chris@909 103 add_issue(v, :estimated_hours => 10, :done_ratio => 30)
Chris@909 104 add_issue(v, :estimated_hours => 40, :done_ratio => 10)
Chris@909 105 assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent
Chris@909 106 assert_progress_equal 25.0/100.0*100, v.closed_pourcent
Chris@909 107 end
Chris@909 108
Chris@909 109 context "#behind_schedule?" do
Chris@909 110 setup do
Chris@909 111 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
Chris@909 112 @project = Project.generate!(:identifier => 'test0')
Chris@909 113 @project.trackers << Tracker.generate!
Chris@909 114
Chris@909 115 @version = Version.generate!(:project => @project, :effective_date => nil)
Chris@909 116 end
Chris@909 117
Chris@909 118 should "be false if there are no issues assigned" do
Chris@909 119 @version.update_attribute(:effective_date, Date.yesterday)
Chris@909 120 assert_equal false, @version.behind_schedule?
Chris@909 121 end
Chris@909 122
Chris@909 123 should "be false if there is no effective_date" do
Chris@909 124 assert_equal false, @version.behind_schedule?
Chris@909 125 end
Chris@909 126
Chris@909 127 should "be false if all of the issues are ahead of schedule" do
Chris@909 128 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
Chris@909 129 @version.fixed_issues = [
Chris@909 130 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60), # 14 day span, 60% done, 50% time left
Chris@909 131 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
Chris@909 132 ]
Chris@909 133 assert_equal 60, @version.completed_pourcent
Chris@909 134 assert_equal false, @version.behind_schedule?
Chris@909 135 end
Chris@909 136
Chris@909 137 should "be true if any of the issues are behind schedule" do
Chris@909 138 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
Chris@909 139 @version.fixed_issues = [
Chris@909 140 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60), # 14 day span, 60% done, 50% time left
Chris@909 141 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
Chris@909 142 ]
Chris@909 143 assert_equal 40, @version.completed_pourcent
Chris@909 144 assert_equal true, @version.behind_schedule?
Chris@909 145 end
Chris@909 146
Chris@909 147 should "be false if all of the issues are complete" do
Chris@909 148 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
Chris@909 149 @version.fixed_issues = [
Chris@909 150 Issue.generate_for_project!(@project, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)), # 7 day span
Chris@909 151 Issue.generate_for_project!(@project, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
Chris@909 152 ]
Chris@909 153 assert_equal 100, @version.completed_pourcent
Chris@909 154 assert_equal false, @version.behind_schedule?
Chris@909 155
Chris@909 156 end
Chris@909 157 end
Chris@909 158
Chris@909 159 context "#estimated_hours" do
Chris@909 160 setup do
Chris@909 161 @version = Version.create!(:project_id => 1, :name => '#estimated_hours')
Chris@909 162 end
Chris@909 163
Chris@909 164 should "return 0 with no assigned issues" do
Chris@909 165 assert_equal 0, @version.estimated_hours
Chris@909 166 end
Chris@909 167
Chris@909 168 should "return 0 with no estimated hours" do
Chris@909 169 add_issue(@version)
Chris@909 170 assert_equal 0, @version.estimated_hours
Chris@909 171 end
Chris@909 172
Chris@909 173 should "return the sum of estimated hours" do
Chris@909 174 add_issue(@version, :estimated_hours => 2.5)
Chris@909 175 add_issue(@version, :estimated_hours => 5)
Chris@909 176 assert_equal 7.5, @version.estimated_hours
Chris@909 177 end
Chris@909 178
Chris@909 179 should "return the sum of leaves estimated hours" do
Chris@909 180 parent = add_issue(@version)
Chris@909 181 add_issue(@version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
Chris@909 182 add_issue(@version, :estimated_hours => 5, :parent_issue_id => parent.id)
Chris@909 183 assert_equal 7.5, @version.estimated_hours
Chris@909 184 end
Chris@909 185 end
Chris@909 186
Chris@909 187 test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
Chris@909 188 User.current = User.find(1) # Need the admin's permissions
Chris@909 189
Chris@909 190 @version = Version.find(7)
Chris@909 191 # Separate hierarchy
Chris@909 192 project_1_issue = Issue.find(1)
Chris@909 193 project_1_issue.fixed_version = @version
Chris@909 194 assert project_1_issue.save, project_1_issue.errors.full_messages.to_s
Chris@909 195
Chris@909 196 project_5_issue = Issue.find(6)
Chris@909 197 project_5_issue.fixed_version = @version
Chris@909 198 assert project_5_issue.save
Chris@909 199
Chris@909 200 # Project
Chris@909 201 project_2_issue = Issue.find(4)
Chris@909 202 project_2_issue.fixed_version = @version
Chris@909 203 assert project_2_issue.save
Chris@909 204
Chris@909 205 # Update the sharing
Chris@909 206 @version.sharing = 'none'
Chris@909 207 assert @version.save
Chris@909 208
Chris@909 209 # Project 1 now out of the shared scope
Chris@909 210 project_1_issue.reload
Chris@909 211 assert_equal nil, project_1_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
Chris@909 212
Chris@909 213 # Project 5 now out of the shared scope
Chris@909 214 project_5_issue.reload
Chris@909 215 assert_equal nil, project_5_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
Chris@909 216
Chris@909 217 # Project 2 issue remains
Chris@909 218 project_2_issue.reload
Chris@909 219 assert_equal @version, project_2_issue.fixed_version
Chris@909 220 end
Chris@909 221
Chris@909 222 private
Chris@909 223
Chris@909 224 def add_issue(version, attributes={})
Chris@909 225 Issue.create!({:project => version.project,
Chris@909 226 :fixed_version => version,
Chris@909 227 :subject => 'Test',
Chris@909 228 :author => User.find(:first),
Chris@909 229 :tracker => version.project.trackers.find(:first)}.merge(attributes))
Chris@909 230 end
Chris@909 231
Chris@909 232 def assert_progress_equal(expected_float, actual_float, message="")
Chris@909 233 assert_in_delta(expected_float, actual_float, 0.000001, message="")
Chris@909 234 end
Chris@909 235 end