Mercurial > hg > soundsoftware-site
comparison .svn/pristine/3c/3cbd1a22df619e52f4440d56f4eefc4b5f35d719.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class TimeEntryTest < ActiveSupport::TestCase | |
21 fixtures :issues, :projects, :users, :time_entries, | |
22 :members, :roles, :member_roles, | |
23 :trackers, :issue_statuses, | |
24 :projects_trackers, | |
25 :journals, :journal_details, | |
26 :issue_categories, :enumerations, | |
27 :groups_users, | |
28 :enabled_modules, | |
29 :workflows | |
30 | |
31 def test_hours_format | |
32 assertions = { "2" => 2.0, | |
33 "21.1" => 21.1, | |
34 "2,1" => 2.1, | |
35 "1,5h" => 1.5, | |
36 "7:12" => 7.2, | |
37 "10h" => 10.0, | |
38 "10 h" => 10.0, | |
39 "45m" => 0.75, | |
40 "45 m" => 0.75, | |
41 "3h15" => 3.25, | |
42 "3h 15" => 3.25, | |
43 "3 h 15" => 3.25, | |
44 "3 h 15m" => 3.25, | |
45 "3 h 15 m" => 3.25, | |
46 "3 hours" => 3.0, | |
47 "12min" => 0.2, | |
48 "12 Min" => 0.2, | |
49 } | |
50 | |
51 assertions.each do |k, v| | |
52 t = TimeEntry.new(:hours => k) | |
53 assert_equal v, t.hours, "Converting #{k} failed:" | |
54 end | |
55 end | |
56 | |
57 def test_hours_should_default_to_nil | |
58 assert_nil TimeEntry.new.hours | |
59 end | |
60 | |
61 def test_spent_on_with_blank | |
62 c = TimeEntry.new | |
63 c.spent_on = '' | |
64 assert_nil c.spent_on | |
65 end | |
66 | |
67 def test_spent_on_with_nil | |
68 c = TimeEntry.new | |
69 c.spent_on = nil | |
70 assert_nil c.spent_on | |
71 end | |
72 | |
73 def test_spent_on_with_string | |
74 c = TimeEntry.new | |
75 c.spent_on = "2011-01-14" | |
76 assert_equal Date.parse("2011-01-14"), c.spent_on | |
77 end | |
78 | |
79 def test_spent_on_with_invalid_string | |
80 c = TimeEntry.new | |
81 c.spent_on = "foo" | |
82 assert_nil c.spent_on | |
83 end | |
84 | |
85 def test_spent_on_with_date | |
86 c = TimeEntry.new | |
87 c.spent_on = Date.today | |
88 assert_equal Date.today, c.spent_on | |
89 end | |
90 | |
91 def test_spent_on_with_time | |
92 c = TimeEntry.new | |
93 c.spent_on = Time.now | |
94 assert_equal Date.today, c.spent_on | |
95 end | |
96 | |
97 def test_validate_time_entry | |
98 anon = User.anonymous | |
99 project = Project.find(1) | |
100 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1, | |
101 :priority => IssuePriority.all.first, :subject => 'test_create', | |
102 :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |
103 assert issue.save | |
104 activity = TimeEntryActivity.find_by_name('Design') | |
105 te = TimeEntry.create(:spent_on => '2010-01-01', | |
106 :hours => 100000, | |
107 :issue => issue, | |
108 :project => project, | |
109 :user => anon, | |
110 :activity => activity) | |
111 assert_equal 1, te.errors.count | |
112 end | |
113 | |
114 def test_set_project_if_nil | |
115 anon = User.anonymous | |
116 project = Project.find(1) | |
117 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1, | |
118 :priority => IssuePriority.all.first, :subject => 'test_create', | |
119 :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |
120 assert issue.save | |
121 activity = TimeEntryActivity.find_by_name('Design') | |
122 te = TimeEntry.create(:spent_on => '2010-01-01', | |
123 :hours => 10, | |
124 :issue => issue, | |
125 :user => anon, | |
126 :activity => activity) | |
127 assert_equal project.id, te.project.id | |
128 end | |
129 end |