@@ -1,135 +1,143 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class TimeEntryTest < ActiveSupport::TestCase |
|
21 | fixtures :issues, :projects, :users, :time_entries | |
|
21 | fixtures :issues, :projects, :users, :time_entries, | |
|
22 | :members, :roles, :member_roles, :auth_sources, | |
|
23 | :trackers, :issue_statuses, | |
|
24 | :projects_trackers, | |
|
25 | :journals, :journal_details, | |
|
26 | :issue_categories, :enumerations, | |
|
27 | :groups_users, | |
|
28 | :enabled_modules, | |
|
29 | :workflows | |
|
22 | 30 | |
|
23 | 31 | def test_hours_format |
|
24 | 32 | assertions = { "2" => 2.0, |
|
25 | 33 | "21.1" => 21.1, |
|
26 | 34 | "2,1" => 2.1, |
|
27 | 35 | "1,5h" => 1.5, |
|
28 | 36 | "7:12" => 7.2, |
|
29 | 37 | "10h" => 10.0, |
|
30 | 38 | "10 h" => 10.0, |
|
31 | 39 | "45m" => 0.75, |
|
32 | 40 | "45 m" => 0.75, |
|
33 | 41 | "3h15" => 3.25, |
|
34 | 42 | "3h 15" => 3.25, |
|
35 | 43 | "3 h 15" => 3.25, |
|
36 | 44 | "3 h 15m" => 3.25, |
|
37 | 45 | "3 h 15 m" => 3.25, |
|
38 | 46 | "3 hours" => 3.0, |
|
39 | 47 | "12min" => 0.2, |
|
40 | 48 | } |
|
41 | 49 | |
|
42 | 50 | assertions.each do |k, v| |
|
43 | 51 | t = TimeEntry.new(:hours => k) |
|
44 | 52 | assert_equal v, t.hours, "Converting #{k} failed:" |
|
45 | 53 | end |
|
46 | 54 | end |
|
47 | 55 | |
|
48 | 56 | def test_hours_should_default_to_nil |
|
49 | 57 | assert_nil TimeEntry.new.hours |
|
50 | 58 | end |
|
51 | 59 | |
|
52 | 60 | def test_spent_on_with_blank |
|
53 | 61 | c = TimeEntry.new |
|
54 | 62 | c.spent_on = '' |
|
55 | 63 | assert_nil c.spent_on |
|
56 | 64 | end |
|
57 | 65 | |
|
58 | 66 | def test_spent_on_with_nil |
|
59 | 67 | c = TimeEntry.new |
|
60 | 68 | c.spent_on = nil |
|
61 | 69 | assert_nil c.spent_on |
|
62 | 70 | end |
|
63 | 71 | |
|
64 | 72 | def test_spent_on_with_string |
|
65 | 73 | c = TimeEntry.new |
|
66 | 74 | c.spent_on = "2011-01-14" |
|
67 | 75 | assert_equal Date.parse("2011-01-14"), c.spent_on |
|
68 | 76 | end |
|
69 | 77 | |
|
70 | 78 | def test_spent_on_with_invalid_string |
|
71 | 79 | c = TimeEntry.new |
|
72 | 80 | c.spent_on = "foo" |
|
73 | 81 | assert_nil c.spent_on |
|
74 | 82 | end |
|
75 | 83 | |
|
76 | 84 | def test_spent_on_with_date |
|
77 | 85 | c = TimeEntry.new |
|
78 | 86 | c.spent_on = Date.today |
|
79 | 87 | assert_equal Date.today, c.spent_on |
|
80 | 88 | end |
|
81 | 89 | |
|
82 | 90 | def test_spent_on_with_time |
|
83 | 91 | c = TimeEntry.new |
|
84 | 92 | c.spent_on = Time.now |
|
85 | 93 | assert_equal Date.today, c.spent_on |
|
86 | 94 | end |
|
87 | 95 | |
|
88 | 96 | context "#earilest_date_for_project" do |
|
89 | 97 | setup do |
|
90 | 98 | User.current = nil |
|
91 | 99 | @public_project = Project.generate!(:is_public => true) |
|
92 | 100 | @issue = Issue.generate_for_project!(@public_project) |
|
93 | 101 | TimeEntry.generate!(:spent_on => '2010-01-01', |
|
94 | 102 | :issue => @issue, |
|
95 | 103 | :project => @public_project) |
|
96 | 104 | end |
|
97 | 105 | |
|
98 | 106 | context "without a project" do |
|
99 | 107 | should "return the lowest spent_on value that is visible to the current user" do |
|
100 | 108 | assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s |
|
101 | 109 | end |
|
102 | 110 | end |
|
103 | 111 | |
|
104 | 112 | context "with a project" do |
|
105 | 113 | should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do |
|
106 | 114 | assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s |
|
107 | 115 | end |
|
108 | 116 | end |
|
109 | 117 | |
|
110 | 118 | end |
|
111 | 119 | |
|
112 | 120 | context "#latest_date_for_project" do |
|
113 | 121 | setup do |
|
114 | 122 | User.current = nil |
|
115 | 123 | @public_project = Project.generate!(:is_public => true) |
|
116 | 124 | @issue = Issue.generate_for_project!(@public_project) |
|
117 | 125 | TimeEntry.generate!(:spent_on => '2010-01-01', |
|
118 | 126 | :issue => @issue, |
|
119 | 127 | :project => @public_project) |
|
120 | 128 | end |
|
121 | 129 | |
|
122 | 130 | context "without a project" do |
|
123 | 131 | should "return the highest spent_on value that is visible to the current user" do |
|
124 | 132 | assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s |
|
125 | 133 | end |
|
126 | 134 | end |
|
127 | 135 | |
|
128 | 136 | context "with a project" do |
|
129 | 137 | should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do |
|
130 | 138 | project = Project.find(1) |
|
131 | 139 | assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s |
|
132 | 140 | end |
|
133 | 141 | end |
|
134 | 142 | end |
|
135 | 143 | end |
General Comments 0
You need to be logged in to leave comments.
Login now