annotate .svn/pristine/85/85fed445bc4e23817aeef540aae47e00666a5c48.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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