@@ -1,143 +1,160 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
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 TimeEntryTest < ActiveSupport::TestCase |
|
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, |
|
22 | :members, :roles, :member_roles, :auth_sources, | |
23 | :trackers, :issue_statuses, |
|
23 | :trackers, :issue_statuses, | |
24 | :projects_trackers, |
|
24 | :projects_trackers, | |
25 | :journals, :journal_details, |
|
25 | :journals, :journal_details, | |
26 | :issue_categories, :enumerations, |
|
26 | :issue_categories, :enumerations, | |
27 | :groups_users, |
|
27 | :groups_users, | |
28 | :enabled_modules, |
|
28 | :enabled_modules, | |
29 | :workflows |
|
29 | :workflows | |
30 |
|
30 | |||
31 | def test_hours_format |
|
31 | def test_hours_format | |
32 | assertions = { "2" => 2.0, |
|
32 | assertions = { "2" => 2.0, | |
33 | "21.1" => 21.1, |
|
33 | "21.1" => 21.1, | |
34 | "2,1" => 2.1, |
|
34 | "2,1" => 2.1, | |
35 | "1,5h" => 1.5, |
|
35 | "1,5h" => 1.5, | |
36 | "7:12" => 7.2, |
|
36 | "7:12" => 7.2, | |
37 | "10h" => 10.0, |
|
37 | "10h" => 10.0, | |
38 | "10 h" => 10.0, |
|
38 | "10 h" => 10.0, | |
39 | "45m" => 0.75, |
|
39 | "45m" => 0.75, | |
40 | "45 m" => 0.75, |
|
40 | "45 m" => 0.75, | |
41 | "3h15" => 3.25, |
|
41 | "3h15" => 3.25, | |
42 | "3h 15" => 3.25, |
|
42 | "3h 15" => 3.25, | |
43 | "3 h 15" => 3.25, |
|
43 | "3 h 15" => 3.25, | |
44 | "3 h 15m" => 3.25, |
|
44 | "3 h 15m" => 3.25, | |
45 | "3 h 15 m" => 3.25, |
|
45 | "3 h 15 m" => 3.25, | |
46 | "3 hours" => 3.0, |
|
46 | "3 hours" => 3.0, | |
47 | "12min" => 0.2, |
|
47 | "12min" => 0.2, | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | assertions.each do |k, v| |
|
50 | assertions.each do |k, v| | |
51 | t = TimeEntry.new(:hours => k) |
|
51 | t = TimeEntry.new(:hours => k) | |
52 | assert_equal v, t.hours, "Converting #{k} failed:" |
|
52 | assert_equal v, t.hours, "Converting #{k} failed:" | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_hours_should_default_to_nil |
|
56 | def test_hours_should_default_to_nil | |
57 | assert_nil TimeEntry.new.hours |
|
57 | assert_nil TimeEntry.new.hours | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_spent_on_with_blank |
|
60 | def test_spent_on_with_blank | |
61 | c = TimeEntry.new |
|
61 | c = TimeEntry.new | |
62 | c.spent_on = '' |
|
62 | c.spent_on = '' | |
63 | assert_nil c.spent_on |
|
63 | assert_nil c.spent_on | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_spent_on_with_nil |
|
66 | def test_spent_on_with_nil | |
67 | c = TimeEntry.new |
|
67 | c = TimeEntry.new | |
68 | c.spent_on = nil |
|
68 | c.spent_on = nil | |
69 | assert_nil c.spent_on |
|
69 | assert_nil c.spent_on | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_spent_on_with_string |
|
72 | def test_spent_on_with_string | |
73 | c = TimeEntry.new |
|
73 | c = TimeEntry.new | |
74 | c.spent_on = "2011-01-14" |
|
74 | c.spent_on = "2011-01-14" | |
75 | assert_equal Date.parse("2011-01-14"), c.spent_on |
|
75 | assert_equal Date.parse("2011-01-14"), c.spent_on | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_spent_on_with_invalid_string |
|
78 | def test_spent_on_with_invalid_string | |
79 | c = TimeEntry.new |
|
79 | c = TimeEntry.new | |
80 | c.spent_on = "foo" |
|
80 | c.spent_on = "foo" | |
81 | assert_nil c.spent_on |
|
81 | assert_nil c.spent_on | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_spent_on_with_date |
|
84 | def test_spent_on_with_date | |
85 | c = TimeEntry.new |
|
85 | c = TimeEntry.new | |
86 | c.spent_on = Date.today |
|
86 | c.spent_on = Date.today | |
87 | assert_equal Date.today, c.spent_on |
|
87 | assert_equal Date.today, c.spent_on | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_spent_on_with_time |
|
90 | def test_spent_on_with_time | |
91 | c = TimeEntry.new |
|
91 | c = TimeEntry.new | |
92 | c.spent_on = Time.now |
|
92 | c.spent_on = Time.now | |
93 | assert_equal Date.today, c.spent_on |
|
93 | assert_equal Date.today, c.spent_on | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
|
96 | def test_validate_time_entry | |||
|
97 | anon = User.anonymous | |||
|
98 | project = Project.find(1) | |||
|
99 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1, | |||
|
100 | :priority => IssuePriority.all.first, :subject => 'test_create', | |||
|
101 | :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |||
|
102 | assert issue.save | |||
|
103 | activity = TimeEntryActivity.find_by_name('Design') | |||
|
104 | te = TimeEntry.create(:spent_on => '2010-01-01', | |||
|
105 | :hours => 100000, | |||
|
106 | :issue => issue, | |||
|
107 | :project => project, | |||
|
108 | :user => anon, | |||
|
109 | :activity => activity) | |||
|
110 | assert_equal 1, te.errors.count | |||
|
111 | end | |||
|
112 | ||||
96 | context "#earilest_date_for_project" do |
|
113 | context "#earilest_date_for_project" do | |
97 | setup do |
|
114 | setup do | |
98 | User.current = nil |
|
115 | User.current = nil | |
99 | @public_project = Project.generate!(:is_public => true) |
|
116 | @public_project = Project.generate!(:is_public => true) | |
100 | @issue = Issue.generate_for_project!(@public_project) |
|
117 | @issue = Issue.generate_for_project!(@public_project) | |
101 | TimeEntry.generate!(:spent_on => '2010-01-01', |
|
118 | TimeEntry.generate!(:spent_on => '2010-01-01', | |
102 | :issue => @issue, |
|
119 | :issue => @issue, | |
103 | :project => @public_project) |
|
120 | :project => @public_project) | |
104 | end |
|
121 | end | |
105 |
|
122 | |||
106 | context "without a project" do |
|
123 | context "without a project" do | |
107 | should "return the lowest spent_on value that is visible to the current user" do |
|
124 | should "return the lowest spent_on value that is visible to the current user" do | |
108 | assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s |
|
125 | assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s | |
109 | end |
|
126 | end | |
110 | end |
|
127 | end | |
111 |
|
128 | |||
112 | context "with a project" do |
|
129 | context "with a project" do | |
113 | should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do |
|
130 | should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do | |
114 | assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s |
|
131 | assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s | |
115 | end |
|
132 | end | |
116 | end |
|
133 | end | |
117 |
|
134 | |||
118 | end |
|
135 | end | |
119 |
|
136 | |||
120 | context "#latest_date_for_project" do |
|
137 | context "#latest_date_for_project" do | |
121 | setup do |
|
138 | setup do | |
122 | User.current = nil |
|
139 | User.current = nil | |
123 | @public_project = Project.generate!(:is_public => true) |
|
140 | @public_project = Project.generate!(:is_public => true) | |
124 | @issue = Issue.generate_for_project!(@public_project) |
|
141 | @issue = Issue.generate_for_project!(@public_project) | |
125 | TimeEntry.generate!(:spent_on => '2010-01-01', |
|
142 | TimeEntry.generate!(:spent_on => '2010-01-01', | |
126 | :issue => @issue, |
|
143 | :issue => @issue, | |
127 | :project => @public_project) |
|
144 | :project => @public_project) | |
128 | end |
|
145 | end | |
129 |
|
146 | |||
130 | context "without a project" do |
|
147 | context "without a project" do | |
131 | should "return the highest spent_on value that is visible to the current user" do |
|
148 | should "return the highest spent_on value that is visible to the current user" do | |
132 | assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s |
|
149 | assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s | |
133 | end |
|
150 | end | |
134 | end |
|
151 | end | |
135 |
|
152 | |||
136 | context "with a project" do |
|
153 | context "with a project" do | |
137 | should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do |
|
154 | should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do | |
138 | project = Project.find(1) |
|
155 | project = Project.find(1) | |
139 | assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s |
|
156 | assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s | |
140 | end |
|
157 | end | |
141 | end |
|
158 | end | |
142 | end |
|
159 | end | |
143 | end |
|
160 | end |
General Comments 0
You need to be logged in to leave comments.
Login now