Mercurial > hg > soundsoftware-site
comparison test/unit/version_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | bb32da3bea34 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 | 19 |
20 class VersionTest < ActiveSupport::TestCase | 20 class VersionTest < ActiveSupport::TestCase |
21 fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions | 21 fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions, :projects_trackers |
22 | 22 |
23 def setup | 23 def setup |
24 end | 24 end |
25 | 25 |
26 def test_create | 26 def test_create |
30 assert_equal 'none', v.sharing | 30 assert_equal 'none', v.sharing |
31 end | 31 end |
32 | 32 |
33 def test_invalid_effective_date_validation | 33 def test_invalid_effective_date_validation |
34 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01') | 34 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01') |
35 assert !v.save | 35 assert !v.valid? |
36 assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date) | 36 v.effective_date = '2012-11-33' |
37 assert !v.valid? | |
38 v.effective_date = '2012-31-11' | |
39 assert !v.valid? | |
40 v.effective_date = 'ABC' | |
41 assert !v.valid? | |
42 assert_include I18n.translate('activerecord.errors.messages.not_a_date'), | |
43 v.errors[:effective_date] | |
37 end | 44 end |
38 | 45 |
39 def test_progress_should_be_0_with_no_assigned_issues | 46 def test_progress_should_be_0_with_no_assigned_issues |
40 project = Project.find(1) | 47 project = Project.find(1) |
41 v = Version.create!(:project => project, :name => 'Progress') | 48 v = Version.create!(:project => project, :name => 'Progress') |
104 add_issue(v, :estimated_hours => 40, :done_ratio => 10) | 111 add_issue(v, :estimated_hours => 40, :done_ratio => 10) |
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 | 112 assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent |
106 assert_progress_equal 25.0/100.0*100, v.closed_pourcent | 113 assert_progress_equal 25.0/100.0*100, v.closed_pourcent |
107 end | 114 end |
108 | 115 |
116 def test_should_sort_scheduled_then_unscheduled_versions | |
117 Version.delete_all | |
118 v4 = Version.create!(:project_id => 1, :name => 'v4') | |
119 v3 = Version.create!(:project_id => 1, :name => 'v2', :effective_date => '2012-07-14') | |
120 v2 = Version.create!(:project_id => 1, :name => 'v1') | |
121 v1 = Version.create!(:project_id => 1, :name => 'v3', :effective_date => '2012-08-02') | |
122 v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02') | |
123 | |
124 assert_equal [v5, v3, v1, v2, v4], [v1, v2, v3, v4, v5].sort | |
125 assert_equal [v5, v3, v1, v2, v4], Version.sorted.all | |
126 end | |
127 | |
128 def test_completed_should_be_false_when_due_today | |
129 version = Version.create!(:project_id => 1, :effective_date => Date.today, :name => 'Due today') | |
130 assert_equal false, version.completed? | |
131 end | |
132 | |
109 context "#behind_schedule?" do | 133 context "#behind_schedule?" do |
110 setup do | 134 setup do |
111 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | 135 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
112 @project = Project.generate!(:identifier => 'test0') | 136 @project = Project.create!(:name => 'test0', :identifier => 'test0') |
113 @project.trackers << Tracker.generate! | 137 @project.trackers << Tracker.create!(:name => 'track') |
114 | 138 |
115 @version = Version.generate!(:project => @project, :effective_date => nil) | 139 @version = Version.create!(:project => @project, :effective_date => nil, :name => 'version') |
116 end | 140 end |
117 | 141 |
118 should "be false if there are no issues assigned" do | 142 should "be false if there are no issues assigned" do |
119 @version.update_attribute(:effective_date, Date.yesterday) | 143 @version.update_attribute(:effective_date, Date.yesterday) |
120 assert_equal false, @version.behind_schedule? | 144 assert_equal false, @version.behind_schedule? |
124 assert_equal false, @version.behind_schedule? | 148 assert_equal false, @version.behind_schedule? |
125 end | 149 end |
126 | 150 |
127 should "be false if all of the issues are ahead of schedule" do | 151 should "be false if all of the issues are ahead of schedule" do |
128 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 152 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
129 @version.fixed_issues = [ | 153 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
130 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60), # 14 day span, 60% done, 50% time left | 154 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
131 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left | |
132 ] | |
133 assert_equal 60, @version.completed_pourcent | 155 assert_equal 60, @version.completed_pourcent |
134 assert_equal false, @version.behind_schedule? | 156 assert_equal false, @version.behind_schedule? |
135 end | 157 end |
136 | 158 |
137 should "be true if any of the issues are behind schedule" do | 159 should "be true if any of the issues are behind schedule" do |
138 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 160 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
139 @version.fixed_issues = [ | 161 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
140 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 60), # 14 day span, 60% done, 50% time left | 162 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left |
141 Issue.generate_for_project!(@project, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left | |
142 ] | |
143 assert_equal 40, @version.completed_pourcent | 163 assert_equal 40, @version.completed_pourcent |
144 assert_equal true, @version.behind_schedule? | 164 assert_equal true, @version.behind_schedule? |
145 end | 165 end |
146 | 166 |
147 should "be false if all of the issues are complete" do | 167 should "be false if all of the issues are complete" do |
148 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 168 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
149 @version.fixed_issues = [ | 169 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
150 Issue.generate_for_project!(@project, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)), # 7 day span | 170 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
151 Issue.generate_for_project!(@project, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span | |
152 ] | |
153 assert_equal 100, @version.completed_pourcent | 171 assert_equal 100, @version.completed_pourcent |
154 assert_equal false, @version.behind_schedule? | 172 assert_equal false, @version.behind_schedule? |
155 | |
156 end | 173 end |
157 end | 174 end |
158 | 175 |
159 context "#estimated_hours" do | 176 context "#estimated_hours" do |
160 setup do | 177 setup do |