comparison .svn/pristine/8c/8c1d2e96303e1f62e53705f1a07477a847f9fb94.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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
30 def test_hours_format
31 assertions = { "2" => 2.0,
32 "21.1" => 21.1,
33 "2,1" => 2.1,
34 "1,5h" => 1.5,
35 "7:12" => 7.2,
36 "10h" => 10.0,
37 "10 h" => 10.0,
38 "45m" => 0.75,
39 "45 m" => 0.75,
40 "3h15" => 3.25,
41 "3h 15" => 3.25,
42 "3 h 15" => 3.25,
43 "3 h 15m" => 3.25,
44 "3 h 15 m" => 3.25,
45 "3 hours" => 3.0,
46 "12min" => 0.2,
47 "12 Min" => 0.2,
48 }
49
50 assertions.each do |k, v|
51 t = TimeEntry.new(:hours => k)
52 assert_equal v, t.hours, "Converting #{k} failed:"
53 end
54 end
55
56 def test_hours_should_default_to_nil
57 assert_nil TimeEntry.new.hours
58 end
59
60 def test_spent_on_with_blank
61 c = TimeEntry.new
62 c.spent_on = ''
63 assert_nil c.spent_on
64 end
65
66 def test_spent_on_with_nil
67 c = TimeEntry.new
68 c.spent_on = nil
69 assert_nil c.spent_on
70 end
71
72 def test_spent_on_with_string
73 c = TimeEntry.new
74 c.spent_on = "2011-01-14"
75 assert_equal Date.parse("2011-01-14"), c.spent_on
76 end
77
78 def test_spent_on_with_invalid_string
79 c = TimeEntry.new
80 c.spent_on = "foo"
81 assert_nil c.spent_on
82 end
83
84 def test_spent_on_with_date
85 c = TimeEntry.new
86 c.spent_on = Date.today
87 assert_equal Date.today, c.spent_on
88 end
89
90 def test_spent_on_with_time
91 c = TimeEntry.new
92 c.spent_on = Time.now
93 assert_equal Date.today, c.spent_on
94 end
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
113 def test_spent_on_with_2_digits_year_should_not_be_valid
114 entry = TimeEntry.new(:project => Project.find(1), :user => User.find(1), :activity => TimeEntryActivity.first, :hours => 1)
115 entry.spent_on = "09-02-04"
116 assert !entry.valid?
117 assert_include I18n.translate('activerecord.errors.messages.not_a_date'), entry.errors[:spent_on]
118 end
119
120 def test_set_project_if_nil
121 anon = User.anonymous
122 project = Project.find(1)
123 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
124 :priority => IssuePriority.all.first, :subject => 'test_create',
125 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
126 assert issue.save
127 activity = TimeEntryActivity.find_by_name('Design')
128 te = TimeEntry.create(:spent_on => '2010-01-01',
129 :hours => 10,
130 :issue => issue,
131 :user => anon,
132 :activity => activity)
133 assert_equal project.id, te.project.id
134 end
135 end