##// END OF EJS Templates
remove trailing white-spaces from test/unit/time_entry_test.rb....
Toshi MARUYAMA -
r6632:cf733e7db7b6
parent child
Show More
@@ -1,135 +1,135
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
1 # Redmine - project management software
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 21 fixtures :issues, :projects, :users, :time_entries
22 22
23 23 def test_hours_format
24 24 assertions = { "2" => 2.0,
25 25 "21.1" => 21.1,
26 26 "2,1" => 2.1,
27 27 "1,5h" => 1.5,
28 28 "7:12" => 7.2,
29 29 "10h" => 10.0,
30 30 "10 h" => 10.0,
31 31 "45m" => 0.75,
32 32 "45 m" => 0.75,
33 33 "3h15" => 3.25,
34 34 "3h 15" => 3.25,
35 35 "3 h 15" => 3.25,
36 36 "3 h 15m" => 3.25,
37 37 "3 h 15 m" => 3.25,
38 38 "3 hours" => 3.0,
39 39 "12min" => 0.2,
40 40 }
41
41
42 42 assertions.each do |k, v|
43 43 t = TimeEntry.new(:hours => k)
44 44 assert_equal v, t.hours, "Converting #{k} failed:"
45 45 end
46 46 end
47
47
48 48 def test_hours_should_default_to_nil
49 49 assert_nil TimeEntry.new.hours
50 50 end
51
51
52 52 def test_spent_on_with_blank
53 53 c = TimeEntry.new
54 54 c.spent_on = ''
55 55 assert_nil c.spent_on
56 56 end
57
57
58 58 def test_spent_on_with_nil
59 59 c = TimeEntry.new
60 60 c.spent_on = nil
61 61 assert_nil c.spent_on
62 62 end
63
63
64 64 def test_spent_on_with_string
65 65 c = TimeEntry.new
66 66 c.spent_on = "2011-01-14"
67 67 assert_equal Date.parse("2011-01-14"), c.spent_on
68 68 end
69
69
70 70 def test_spent_on_with_invalid_string
71 71 c = TimeEntry.new
72 72 c.spent_on = "foo"
73 73 assert_nil c.spent_on
74 74 end
75
75
76 76 def test_spent_on_with_date
77 77 c = TimeEntry.new
78 78 c.spent_on = Date.today
79 79 assert_equal Date.today, c.spent_on
80 80 end
81
81
82 82 def test_spent_on_with_time
83 83 c = TimeEntry.new
84 84 c.spent_on = Time.now
85 85 assert_equal Date.today, c.spent_on
86 86 end
87 87
88 88 context "#earilest_date_for_project" do
89 89 setup do
90 90 User.current = nil
91 91 @public_project = Project.generate!(:is_public => true)
92 92 @issue = Issue.generate_for_project!(@public_project)
93 93 TimeEntry.generate!(:spent_on => '2010-01-01',
94 94 :issue => @issue,
95 95 :project => @public_project)
96 96 end
97
97
98 98 context "without a project" do
99 99 should "return the lowest spent_on value that is visible to the current user" do
100 100 assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s
101 101 end
102 102 end
103 103
104 104 context "with a project" do
105 105 should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do
106 106 assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s
107 107 end
108 108 end
109
109
110 110 end
111 111
112 112 context "#latest_date_for_project" do
113 113 setup do
114 114 User.current = nil
115 115 @public_project = Project.generate!(:is_public => true)
116 116 @issue = Issue.generate_for_project!(@public_project)
117 117 TimeEntry.generate!(:spent_on => '2010-01-01',
118 118 :issue => @issue,
119 119 :project => @public_project)
120 120 end
121 121
122 122 context "without a project" do
123 123 should "return the highest spent_on value that is visible to the current user" do
124 124 assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s
125 125 end
126 126 end
127 127
128 128 context "with a project" do
129 129 should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do
130 130 project = Project.find(1)
131 131 assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s
132 132 end
133 133 end
134 end
134 end
135 135 end
General Comments 0
You need to be logged in to leave comments. Login now