@@ -1,79 +1,79 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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 | class TimeEntry < ActiveRecord::Base |
|
19 | 19 | # could have used polymorphic association |
|
20 | 20 | # project association here allows easy loading of time entries at project level with one database trip |
|
21 | 21 | belongs_to :project |
|
22 | 22 | belongs_to :issue |
|
23 | 23 | belongs_to :user |
|
24 | 24 | belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id |
|
25 | 25 | |
|
26 | 26 | attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek |
|
27 | 27 | |
|
28 | 28 | acts_as_customizable |
|
29 | 29 | acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"}, |
|
30 | 30 | :url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}}, |
|
31 | 31 | :author => :user, |
|
32 | 32 | :description => :comments |
|
33 | 33 | |
|
34 | 34 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
35 | validates_numericality_of :hours, :allow_nil => true | |
|
35 | validates_numericality_of :hours, :allow_nil => true, :message => :activerecord_error_invalid | |
|
36 | 36 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
37 | 37 | |
|
38 | 38 | def after_initialize |
|
39 | 39 | if new_record? && self.activity.nil? |
|
40 | 40 | if default_activity = Enumeration.default('ACTI') |
|
41 | 41 | self.activity_id = default_activity.id |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def before_validation |
|
47 | 47 | self.project = issue.project if issue && project.nil? |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def validate |
|
51 | 51 | errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000) |
|
52 | 52 | errors.add :project_id, :activerecord_error_invalid if project.nil? |
|
53 | 53 | errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def hours=(h) |
|
57 | write_attribute :hours, (h.is_a?(String) ? h.to_hours : h) | |
|
57 | write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h) | |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | # tyear, tmonth, tweek assigned where setting spent_on attributes |
|
61 | 61 | # these attributes make time aggregations easier |
|
62 | 62 | def spent_on=(date) |
|
63 | 63 | super |
|
64 | 64 | self.tyear = spent_on ? spent_on.year : nil |
|
65 | 65 | self.tmonth = spent_on ? spent_on.month : nil |
|
66 | 66 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | # Returns true if the time entry can be edited by usr, otherwise false |
|
70 | 70 | def editable_by?(usr) |
|
71 | 71 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def self.visible_by(usr) |
|
75 | 75 | with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do |
|
76 | 76 | yield |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | end |
@@ -1,40 +1,42 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2008 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 | module Redmine #:nodoc: |
|
19 | 19 | module CoreExtensions #:nodoc: |
|
20 | 20 | module String #:nodoc: |
|
21 | 21 | # Custom string conversions |
|
22 | 22 | module Conversions |
|
23 | 23 | # Parses hours format and returns a float |
|
24 | 24 | def to_hours |
|
25 | 25 | s = self.dup |
|
26 | 26 | s.strip! |
|
27 |
|
|
|
27 | if s =~ %r{^(\d+([.,]\d+)?)h?$} | |
|
28 | s = $1 | |
|
29 | else | |
|
28 | 30 | # 2:30 => 2.5 |
|
29 | 31 | s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 } |
|
30 | 32 | # 2h30, 2h, 30m => 2.5, 2, 0.5 |
|
31 | 33 | s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] } |
|
32 | 34 | end |
|
33 | 35 | # 2,5 => 2.5 |
|
34 | 36 | s.gsub!(',', '.') |
|
35 | 37 | begin; Kernel.Float(s); rescue; nil; end |
|
36 | 38 | end |
|
37 | 39 | end |
|
38 | 40 | end |
|
39 | 41 | end |
|
40 | 42 | end |
@@ -1,759 +1,777 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'issues_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class IssuesController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class IssuesControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, |
|
26 | 26 | :users, |
|
27 | 27 | :roles, |
|
28 | 28 | :members, |
|
29 | 29 | :issues, |
|
30 | 30 | :issue_statuses, |
|
31 | 31 | :versions, |
|
32 | 32 | :trackers, |
|
33 | 33 | :projects_trackers, |
|
34 | 34 | :issue_categories, |
|
35 | 35 | :enabled_modules, |
|
36 | 36 | :enumerations, |
|
37 | 37 | :attachments, |
|
38 | 38 | :workflows, |
|
39 | 39 | :custom_fields, |
|
40 | 40 | :custom_values, |
|
41 | 41 | :custom_fields_trackers, |
|
42 | 42 | :time_entries, |
|
43 | 43 | :journals, |
|
44 | 44 | :journal_details |
|
45 | 45 | |
|
46 | 46 | def setup |
|
47 | 47 | @controller = IssuesController.new |
|
48 | 48 | @request = ActionController::TestRequest.new |
|
49 | 49 | @response = ActionController::TestResponse.new |
|
50 | 50 | User.current = nil |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_index |
|
54 | 54 | get :index |
|
55 | 55 | assert_response :success |
|
56 | 56 | assert_template 'index.rhtml' |
|
57 | 57 | assert_not_nil assigns(:issues) |
|
58 | 58 | assert_nil assigns(:project) |
|
59 | 59 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
60 | 60 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
61 | 61 | # private projects hidden |
|
62 | 62 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
63 | 63 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_index_should_not_list_issues_when_module_disabled |
|
67 | 67 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
68 | 68 | get :index |
|
69 | 69 | assert_response :success |
|
70 | 70 | assert_template 'index.rhtml' |
|
71 | 71 | assert_not_nil assigns(:issues) |
|
72 | 72 | assert_nil assigns(:project) |
|
73 | 73 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
74 | 74 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def test_index_with_project |
|
78 | 78 | Setting.display_subprojects_issues = 0 |
|
79 | 79 | get :index, :project_id => 1 |
|
80 | 80 | assert_response :success |
|
81 | 81 | assert_template 'index.rhtml' |
|
82 | 82 | assert_not_nil assigns(:issues) |
|
83 | 83 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
84 | 84 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | def test_index_with_project_and_subprojects |
|
88 | 88 | Setting.display_subprojects_issues = 1 |
|
89 | 89 | get :index, :project_id => 1 |
|
90 | 90 | assert_response :success |
|
91 | 91 | assert_template 'index.rhtml' |
|
92 | 92 | assert_not_nil assigns(:issues) |
|
93 | 93 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
94 | 94 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
95 | 95 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
99 | 99 | @request.session[:user_id] = 2 |
|
100 | 100 | Setting.display_subprojects_issues = 1 |
|
101 | 101 | get :index, :project_id => 1 |
|
102 | 102 | assert_response :success |
|
103 | 103 | assert_template 'index.rhtml' |
|
104 | 104 | assert_not_nil assigns(:issues) |
|
105 | 105 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
106 | 106 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
107 | 107 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def test_index_with_project_and_filter |
|
111 | 111 | get :index, :project_id => 1, :set_filter => 1 |
|
112 | 112 | assert_response :success |
|
113 | 113 | assert_template 'index.rhtml' |
|
114 | 114 | assert_not_nil assigns(:issues) |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_index_csv_with_project |
|
118 | 118 | get :index, :format => 'csv' |
|
119 | 119 | assert_response :success |
|
120 | 120 | assert_not_nil assigns(:issues) |
|
121 | 121 | assert_equal 'text/csv', @response.content_type |
|
122 | 122 | |
|
123 | 123 | get :index, :project_id => 1, :format => 'csv' |
|
124 | 124 | assert_response :success |
|
125 | 125 | assert_not_nil assigns(:issues) |
|
126 | 126 | assert_equal 'text/csv', @response.content_type |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def test_index_pdf |
|
130 | 130 | get :index, :format => 'pdf' |
|
131 | 131 | assert_response :success |
|
132 | 132 | assert_not_nil assigns(:issues) |
|
133 | 133 | assert_equal 'application/pdf', @response.content_type |
|
134 | 134 | |
|
135 | 135 | get :index, :project_id => 1, :format => 'pdf' |
|
136 | 136 | assert_response :success |
|
137 | 137 | assert_not_nil assigns(:issues) |
|
138 | 138 | assert_equal 'application/pdf', @response.content_type |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | def test_index_sort |
|
142 | 142 | get :index, :sort_key => 'tracker' |
|
143 | 143 | assert_response :success |
|
144 | 144 | |
|
145 | 145 | sort_params = @request.session['issuesindex_sort'] |
|
146 | 146 | assert sort_params.is_a?(Hash) |
|
147 | 147 | assert_equal 'tracker', sort_params[:key] |
|
148 | 148 | assert_equal 'ASC', sort_params[:order] |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_gantt |
|
152 | 152 | get :gantt, :project_id => 1 |
|
153 | 153 | assert_response :success |
|
154 | 154 | assert_template 'gantt.rhtml' |
|
155 | 155 | assert_not_nil assigns(:gantt) |
|
156 | 156 | events = assigns(:gantt).events |
|
157 | 157 | assert_not_nil events |
|
158 | 158 | # Issue with start and due dates |
|
159 | 159 | i = Issue.find(1) |
|
160 | 160 | assert_not_nil i.due_date |
|
161 | 161 | assert events.include?(Issue.find(1)) |
|
162 | 162 | # Issue with without due date but targeted to a version with date |
|
163 | 163 | i = Issue.find(2) |
|
164 | 164 | assert_nil i.due_date |
|
165 | 165 | assert events.include?(i) |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | def test_cross_project_gantt |
|
169 | 169 | get :gantt |
|
170 | 170 | assert_response :success |
|
171 | 171 | assert_template 'gantt.rhtml' |
|
172 | 172 | assert_not_nil assigns(:gantt) |
|
173 | 173 | events = assigns(:gantt).events |
|
174 | 174 | assert_not_nil events |
|
175 | 175 | end |
|
176 | 176 | |
|
177 | 177 | def test_gantt_export_to_pdf |
|
178 | 178 | get :gantt, :project_id => 1, :format => 'pdf' |
|
179 | 179 | assert_response :success |
|
180 | 180 | assert_equal 'application/pdf', @response.content_type |
|
181 | 181 | assert @response.body.starts_with?('%PDF') |
|
182 | 182 | assert_not_nil assigns(:gantt) |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | def test_cross_project_gantt_export_to_pdf |
|
186 | 186 | get :gantt, :format => 'pdf' |
|
187 | 187 | assert_response :success |
|
188 | 188 | assert_equal 'application/pdf', @response.content_type |
|
189 | 189 | assert @response.body.starts_with?('%PDF') |
|
190 | 190 | assert_not_nil assigns(:gantt) |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | if Object.const_defined?(:Magick) |
|
194 | 194 | def test_gantt_image |
|
195 | 195 | get :gantt, :project_id => 1, :format => 'png' |
|
196 | 196 | assert_response :success |
|
197 | 197 | assert_equal 'image/png', @response.content_type |
|
198 | 198 | end |
|
199 | 199 | else |
|
200 | 200 | puts "RMagick not installed. Skipping tests !!!" |
|
201 | 201 | end |
|
202 | 202 | |
|
203 | 203 | def test_calendar |
|
204 | 204 | get :calendar, :project_id => 1 |
|
205 | 205 | assert_response :success |
|
206 | 206 | assert_template 'calendar' |
|
207 | 207 | assert_not_nil assigns(:calendar) |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def test_cross_project_calendar |
|
211 | 211 | get :calendar |
|
212 | 212 | assert_response :success |
|
213 | 213 | assert_template 'calendar' |
|
214 | 214 | assert_not_nil assigns(:calendar) |
|
215 | 215 | end |
|
216 | 216 | |
|
217 | 217 | def test_changes |
|
218 | 218 | get :changes, :project_id => 1 |
|
219 | 219 | assert_response :success |
|
220 | 220 | assert_not_nil assigns(:journals) |
|
221 | 221 | assert_equal 'application/atom+xml', @response.content_type |
|
222 | 222 | end |
|
223 | 223 | |
|
224 | 224 | def test_show_by_anonymous |
|
225 | 225 | get :show, :id => 1 |
|
226 | 226 | assert_response :success |
|
227 | 227 | assert_template 'show.rhtml' |
|
228 | 228 | assert_not_nil assigns(:issue) |
|
229 | 229 | assert_equal Issue.find(1), assigns(:issue) |
|
230 | 230 | |
|
231 | 231 | # anonymous role is allowed to add a note |
|
232 | 232 | assert_tag :tag => 'form', |
|
233 | 233 | :descendant => { :tag => 'fieldset', |
|
234 | 234 | :child => { :tag => 'legend', |
|
235 | 235 | :content => /Notes/ } } |
|
236 | 236 | end |
|
237 | 237 | |
|
238 | 238 | def test_show_by_manager |
|
239 | 239 | @request.session[:user_id] = 2 |
|
240 | 240 | get :show, :id => 1 |
|
241 | 241 | assert_response :success |
|
242 | 242 | |
|
243 | 243 | assert_tag :tag => 'form', |
|
244 | 244 | :descendant => { :tag => 'fieldset', |
|
245 | 245 | :child => { :tag => 'legend', |
|
246 | 246 | :content => /Change properties/ } }, |
|
247 | 247 | :descendant => { :tag => 'fieldset', |
|
248 | 248 | :child => { :tag => 'legend', |
|
249 | 249 | :content => /Log time/ } }, |
|
250 | 250 | :descendant => { :tag => 'fieldset', |
|
251 | 251 | :child => { :tag => 'legend', |
|
252 | 252 | :content => /Notes/ } } |
|
253 | 253 | end |
|
254 | 254 | |
|
255 | 255 | def test_show_export_to_pdf |
|
256 | 256 | get :show, :id => 1, :format => 'pdf' |
|
257 | 257 | assert_response :success |
|
258 | 258 | assert_equal 'application/pdf', @response.content_type |
|
259 | 259 | assert @response.body.starts_with?('%PDF') |
|
260 | 260 | assert_not_nil assigns(:issue) |
|
261 | 261 | end |
|
262 | 262 | |
|
263 | 263 | def test_get_new |
|
264 | 264 | @request.session[:user_id] = 2 |
|
265 | 265 | get :new, :project_id => 1, :tracker_id => 1 |
|
266 | 266 | assert_response :success |
|
267 | 267 | assert_template 'new' |
|
268 | 268 | |
|
269 | 269 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
270 | 270 | :value => 'Default string' } |
|
271 | 271 | end |
|
272 | 272 | |
|
273 | 273 | def test_get_new_without_tracker_id |
|
274 | 274 | @request.session[:user_id] = 2 |
|
275 | 275 | get :new, :project_id => 1 |
|
276 | 276 | assert_response :success |
|
277 | 277 | assert_template 'new' |
|
278 | 278 | |
|
279 | 279 | issue = assigns(:issue) |
|
280 | 280 | assert_not_nil issue |
|
281 | 281 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | def test_update_new_form |
|
285 | 285 | @request.session[:user_id] = 2 |
|
286 | 286 | xhr :post, :new, :project_id => 1, |
|
287 | 287 | :issue => {:tracker_id => 2, |
|
288 | 288 | :subject => 'This is the test_new issue', |
|
289 | 289 | :description => 'This is the description', |
|
290 | 290 | :priority_id => 5} |
|
291 | 291 | assert_response :success |
|
292 | 292 | assert_template 'new' |
|
293 | 293 | end |
|
294 | 294 | |
|
295 | 295 | def test_post_new |
|
296 | 296 | @request.session[:user_id] = 2 |
|
297 | 297 | post :new, :project_id => 1, |
|
298 | 298 | :issue => {:tracker_id => 3, |
|
299 | 299 | :subject => 'This is the test_new issue', |
|
300 | 300 | :description => 'This is the description', |
|
301 | 301 | :priority_id => 5, |
|
302 | 302 | :estimated_hours => '', |
|
303 | 303 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
304 | 304 | assert_redirected_to :controller => 'issues', :action => 'show' |
|
305 | 305 | |
|
306 | 306 | issue = Issue.find_by_subject('This is the test_new issue') |
|
307 | 307 | assert_not_nil issue |
|
308 | 308 | assert_equal 2, issue.author_id |
|
309 | 309 | assert_equal 3, issue.tracker_id |
|
310 | 310 | assert_nil issue.estimated_hours |
|
311 | 311 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
312 | 312 | assert_not_nil v |
|
313 | 313 | assert_equal 'Value for field 2', v.value |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def test_post_new_without_custom_fields_param |
|
317 | 317 | @request.session[:user_id] = 2 |
|
318 | 318 | post :new, :project_id => 1, |
|
319 | 319 | :issue => {:tracker_id => 1, |
|
320 | 320 | :subject => 'This is the test_new issue', |
|
321 | 321 | :description => 'This is the description', |
|
322 | 322 | :priority_id => 5} |
|
323 | 323 | assert_redirected_to :controller => 'issues', :action => 'show' |
|
324 | 324 | end |
|
325 | 325 | |
|
326 | 326 | def test_post_new_with_required_custom_field_and_without_custom_fields_param |
|
327 | 327 | field = IssueCustomField.find_by_name('Database') |
|
328 | 328 | field.update_attribute(:is_required, true) |
|
329 | 329 | |
|
330 | 330 | @request.session[:user_id] = 2 |
|
331 | 331 | post :new, :project_id => 1, |
|
332 | 332 | :issue => {:tracker_id => 1, |
|
333 | 333 | :subject => 'This is the test_new issue', |
|
334 | 334 | :description => 'This is the description', |
|
335 | 335 | :priority_id => 5} |
|
336 | 336 | assert_response :success |
|
337 | 337 | assert_template 'new' |
|
338 | 338 | issue = assigns(:issue) |
|
339 | 339 | assert_not_nil issue |
|
340 | 340 | assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) |
|
341 | 341 | end |
|
342 | 342 | |
|
343 | 343 | def test_post_new_with_watchers |
|
344 | 344 | @request.session[:user_id] = 2 |
|
345 | 345 | ActionMailer::Base.deliveries.clear |
|
346 | 346 | |
|
347 | 347 | assert_difference 'Watcher.count', 2 do |
|
348 | 348 | post :new, :project_id => 1, |
|
349 | 349 | :issue => {:tracker_id => 1, |
|
350 | 350 | :subject => 'This is a new issue with watchers', |
|
351 | 351 | :description => 'This is the description', |
|
352 | 352 | :priority_id => 5, |
|
353 | 353 | :watcher_user_ids => ['2', '3']} |
|
354 | 354 | end |
|
355 | 355 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
356 | 356 | assert_not_nil issue |
|
357 | 357 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
358 | 358 | |
|
359 | 359 | # Watchers added |
|
360 | 360 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
361 | 361 | assert issue.watched_by?(User.find(3)) |
|
362 | 362 | # Watchers notified |
|
363 | 363 | mail = ActionMailer::Base.deliveries.last |
|
364 | 364 | assert_kind_of TMail::Mail, mail |
|
365 | 365 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
366 | 366 | end |
|
367 | 367 | |
|
368 | 368 | def test_post_should_preserve_fields_values_on_validation_failure |
|
369 | 369 | @request.session[:user_id] = 2 |
|
370 | 370 | post :new, :project_id => 1, |
|
371 | 371 | :issue => {:tracker_id => 1, |
|
372 | 372 | # empty subject |
|
373 | 373 | :subject => '', |
|
374 | 374 | :description => 'This is a description', |
|
375 | 375 | :priority_id => 6, |
|
376 | 376 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
377 | 377 | assert_response :success |
|
378 | 378 | assert_template 'new' |
|
379 | 379 | |
|
380 | 380 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
381 | 381 | :content => 'This is a description' |
|
382 | 382 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
383 | 383 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
384 | 384 | :value => '6' }, |
|
385 | 385 | :content => 'High' } |
|
386 | 386 | # Custom fields |
|
387 | 387 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
388 | 388 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
389 | 389 | :value => 'Oracle' }, |
|
390 | 390 | :content => 'Oracle' } |
|
391 | 391 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
392 | 392 | :value => 'Value for field 2'} |
|
393 | 393 | end |
|
394 | 394 | |
|
395 | 395 | def test_copy_issue |
|
396 | 396 | @request.session[:user_id] = 2 |
|
397 | 397 | get :new, :project_id => 1, :copy_from => 1 |
|
398 | 398 | assert_template 'new' |
|
399 | 399 | assert_not_nil assigns(:issue) |
|
400 | 400 | orig = Issue.find(1) |
|
401 | 401 | assert_equal orig.subject, assigns(:issue).subject |
|
402 | 402 | end |
|
403 | 403 | |
|
404 | 404 | def test_get_edit |
|
405 | 405 | @request.session[:user_id] = 2 |
|
406 | 406 | get :edit, :id => 1 |
|
407 | 407 | assert_response :success |
|
408 | 408 | assert_template 'edit' |
|
409 | 409 | assert_not_nil assigns(:issue) |
|
410 | 410 | assert_equal Issue.find(1), assigns(:issue) |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | def test_get_edit_with_params |
|
414 | 414 | @request.session[:user_id] = 2 |
|
415 | 415 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } |
|
416 | 416 | assert_response :success |
|
417 | 417 | assert_template 'edit' |
|
418 | 418 | |
|
419 | 419 | issue = assigns(:issue) |
|
420 | 420 | assert_not_nil issue |
|
421 | 421 | |
|
422 | 422 | assert_equal 5, issue.status_id |
|
423 | 423 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
424 | 424 | :child => { :tag => 'option', |
|
425 | 425 | :content => 'Closed', |
|
426 | 426 | :attributes => { :selected => 'selected' } } |
|
427 | 427 | |
|
428 | 428 | assert_equal 7, issue.priority_id |
|
429 | 429 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
430 | 430 | :child => { :tag => 'option', |
|
431 | 431 | :content => 'Urgent', |
|
432 | 432 | :attributes => { :selected => 'selected' } } |
|
433 | 433 | end |
|
434 | 434 | |
|
435 | 435 | def test_reply_to_issue |
|
436 | 436 | @request.session[:user_id] = 2 |
|
437 | 437 | get :reply, :id => 1 |
|
438 | 438 | assert_response :success |
|
439 | 439 | assert_select_rjs :show, "update" |
|
440 | 440 | end |
|
441 | 441 | |
|
442 | 442 | def test_reply_to_note |
|
443 | 443 | @request.session[:user_id] = 2 |
|
444 | 444 | get :reply, :id => 1, :journal_id => 2 |
|
445 | 445 | assert_response :success |
|
446 | 446 | assert_select_rjs :show, "update" |
|
447 | 447 | end |
|
448 | 448 | |
|
449 | 449 | def test_post_edit_without_custom_fields_param |
|
450 | 450 | @request.session[:user_id] = 2 |
|
451 | 451 | ActionMailer::Base.deliveries.clear |
|
452 | 452 | |
|
453 | 453 | issue = Issue.find(1) |
|
454 | 454 | assert_equal '125', issue.custom_value_for(2).value |
|
455 | 455 | old_subject = issue.subject |
|
456 | 456 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
457 | 457 | |
|
458 | 458 | assert_difference('Journal.count') do |
|
459 | 459 | assert_difference('JournalDetail.count', 2) do |
|
460 | 460 | post :edit, :id => 1, :issue => {:subject => new_subject, |
|
461 | 461 | :priority_id => '6', |
|
462 | 462 | :category_id => '1' # no change |
|
463 | 463 | } |
|
464 | 464 | end |
|
465 | 465 | end |
|
466 | 466 | assert_redirected_to 'issues/show/1' |
|
467 | 467 | issue.reload |
|
468 | 468 | assert_equal new_subject, issue.subject |
|
469 | 469 | # Make sure custom fields were not cleared |
|
470 | 470 | assert_equal '125', issue.custom_value_for(2).value |
|
471 | 471 | |
|
472 | 472 | mail = ActionMailer::Base.deliveries.last |
|
473 | 473 | assert_kind_of TMail::Mail, mail |
|
474 | 474 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
475 | 475 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
476 | 476 | end |
|
477 | 477 | |
|
478 | 478 | def test_post_edit_with_custom_field_change |
|
479 | 479 | @request.session[:user_id] = 2 |
|
480 | 480 | issue = Issue.find(1) |
|
481 | 481 | assert_equal '125', issue.custom_value_for(2).value |
|
482 | 482 | |
|
483 | 483 | assert_difference('Journal.count') do |
|
484 | 484 | assert_difference('JournalDetail.count', 3) do |
|
485 | 485 | post :edit, :id => 1, :issue => {:subject => 'Custom field change', |
|
486 | 486 | :priority_id => '6', |
|
487 | 487 | :category_id => '1', # no change |
|
488 | 488 | :custom_field_values => { '2' => 'New custom value' } |
|
489 | 489 | } |
|
490 | 490 | end |
|
491 | 491 | end |
|
492 | 492 | assert_redirected_to 'issues/show/1' |
|
493 | 493 | issue.reload |
|
494 | 494 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
495 | 495 | |
|
496 | 496 | mail = ActionMailer::Base.deliveries.last |
|
497 | 497 | assert_kind_of TMail::Mail, mail |
|
498 | 498 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
499 | 499 | end |
|
500 | 500 | |
|
501 | 501 | def test_post_edit_with_status_and_assignee_change |
|
502 | 502 | issue = Issue.find(1) |
|
503 | 503 | assert_equal 1, issue.status_id |
|
504 | 504 | @request.session[:user_id] = 2 |
|
505 | 505 | assert_difference('TimeEntry.count', 0) do |
|
506 | 506 | post :edit, |
|
507 | 507 | :id => 1, |
|
508 | 508 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
509 | 509 | :notes => 'Assigned to dlopper', |
|
510 | 510 | :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } |
|
511 | 511 | end |
|
512 | 512 | assert_redirected_to 'issues/show/1' |
|
513 | 513 | issue.reload |
|
514 | 514 | assert_equal 2, issue.status_id |
|
515 | 515 | j = issue.journals.find(:first, :order => 'id DESC') |
|
516 | 516 | assert_equal 'Assigned to dlopper', j.notes |
|
517 | 517 | assert_equal 2, j.details.size |
|
518 | 518 | |
|
519 | 519 | mail = ActionMailer::Base.deliveries.last |
|
520 | 520 | assert mail.body.include?("Status changed from New to Assigned") |
|
521 | 521 | end |
|
522 | 522 | |
|
523 | 523 | def test_post_edit_with_note_only |
|
524 | 524 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
525 | 525 | # anonymous user |
|
526 | 526 | post :edit, |
|
527 | 527 | :id => 1, |
|
528 | 528 | :notes => notes |
|
529 | 529 | assert_redirected_to 'issues/show/1' |
|
530 | 530 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
531 | 531 | assert_equal notes, j.notes |
|
532 | 532 | assert_equal 0, j.details.size |
|
533 | 533 | assert_equal User.anonymous, j.user |
|
534 | 534 | |
|
535 | 535 | mail = ActionMailer::Base.deliveries.last |
|
536 | 536 | assert mail.body.include?(notes) |
|
537 | 537 | end |
|
538 | 538 | |
|
539 | 539 | def test_post_edit_with_note_and_spent_time |
|
540 | 540 | @request.session[:user_id] = 2 |
|
541 | 541 | spent_hours_before = Issue.find(1).spent_hours |
|
542 | 542 | assert_difference('TimeEntry.count') do |
|
543 | 543 | post :edit, |
|
544 | 544 | :id => 1, |
|
545 | 545 | :notes => '2.5 hours added', |
|
546 | 546 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } |
|
547 | 547 | end |
|
548 | 548 | assert_redirected_to 'issues/show/1' |
|
549 | 549 | |
|
550 | 550 | issue = Issue.find(1) |
|
551 | 551 | |
|
552 | 552 | j = issue.journals.find(:first, :order => 'id DESC') |
|
553 | 553 | assert_equal '2.5 hours added', j.notes |
|
554 | 554 | assert_equal 0, j.details.size |
|
555 | 555 | |
|
556 | 556 | t = issue.time_entries.find(:first, :order => 'id DESC') |
|
557 | 557 | assert_not_nil t |
|
558 | 558 | assert_equal 2.5, t.hours |
|
559 | 559 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
560 | 560 | end |
|
561 | 561 | |
|
562 | 562 | def test_post_edit_with_attachment_only |
|
563 | 563 | set_tmp_attachments_directory |
|
564 | 564 | |
|
565 | 565 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
566 | 566 | # journal to get fetched in the next find. |
|
567 | 567 | Journal.delete_all |
|
568 | 568 | |
|
569 | 569 | # anonymous user |
|
570 | 570 | post :edit, |
|
571 | 571 | :id => 1, |
|
572 | 572 | :notes => '', |
|
573 | 573 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} |
|
574 | 574 | assert_redirected_to 'issues/show/1' |
|
575 | 575 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
576 | 576 | assert j.notes.blank? |
|
577 | 577 | assert_equal 1, j.details.size |
|
578 | 578 | assert_equal 'testfile.txt', j.details.first.value |
|
579 | 579 | assert_equal User.anonymous, j.user |
|
580 | 580 | |
|
581 | 581 | mail = ActionMailer::Base.deliveries.last |
|
582 | 582 | assert mail.body.include?('testfile.txt') |
|
583 | 583 | end |
|
584 | 584 | |
|
585 | 585 | def test_post_edit_with_no_change |
|
586 | 586 | issue = Issue.find(1) |
|
587 | 587 | issue.journals.clear |
|
588 | 588 | ActionMailer::Base.deliveries.clear |
|
589 | 589 | |
|
590 | 590 | post :edit, |
|
591 | 591 | :id => 1, |
|
592 | 592 | :notes => '' |
|
593 | 593 | assert_redirected_to 'issues/show/1' |
|
594 | 594 | |
|
595 | 595 | issue.reload |
|
596 | 596 | assert issue.journals.empty? |
|
597 | 597 | # No email should be sent |
|
598 | 598 | assert ActionMailer::Base.deliveries.empty? |
|
599 | 599 | end |
|
600 | 600 | |
|
601 | def test_post_edit_with_invalid_spent_time | |
|
602 | @request.session[:user_id] = 2 | |
|
603 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
|
604 | ||
|
605 | assert_no_difference('Journal.count') do | |
|
606 | post :edit, | |
|
607 | :id => 1, | |
|
608 | :notes => notes, | |
|
609 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
|
610 | end | |
|
611 | assert_response :success | |
|
612 | assert_template 'edit' | |
|
613 | ||
|
614 | assert_tag :textarea, :attributes => { :name => 'notes' }, | |
|
615 | :content => notes | |
|
616 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | |
|
617 | end | |
|
618 | ||
|
601 | 619 | def test_bulk_edit |
|
602 | 620 | @request.session[:user_id] = 2 |
|
603 | 621 | # update issues priority |
|
604 | 622 | post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' |
|
605 | 623 | assert_response 302 |
|
606 | 624 | # check that the issues were updated |
|
607 | 625 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
608 | 626 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
609 | 627 | end |
|
610 | 628 | |
|
611 | 629 | def test_bulk_unassign |
|
612 | 630 | assert_not_nil Issue.find(2).assigned_to |
|
613 | 631 | @request.session[:user_id] = 2 |
|
614 | 632 | # unassign issues |
|
615 | 633 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none' |
|
616 | 634 | assert_response 302 |
|
617 | 635 | # check that the issues were updated |
|
618 | 636 | assert_nil Issue.find(2).assigned_to |
|
619 | 637 | end |
|
620 | 638 | |
|
621 | 639 | def test_move_one_issue_to_another_project |
|
622 | 640 | @request.session[:user_id] = 1 |
|
623 | 641 | post :move, :id => 1, :new_project_id => 2 |
|
624 | 642 | assert_redirected_to 'projects/ecookbook/issues' |
|
625 | 643 | assert_equal 2, Issue.find(1).project_id |
|
626 | 644 | end |
|
627 | 645 | |
|
628 | 646 | def test_bulk_move_to_another_project |
|
629 | 647 | @request.session[:user_id] = 1 |
|
630 | 648 | post :move, :ids => [1, 2], :new_project_id => 2 |
|
631 | 649 | assert_redirected_to 'projects/ecookbook/issues' |
|
632 | 650 | # Issues moved to project 2 |
|
633 | 651 | assert_equal 2, Issue.find(1).project_id |
|
634 | 652 | assert_equal 2, Issue.find(2).project_id |
|
635 | 653 | # No tracker change |
|
636 | 654 | assert_equal 1, Issue.find(1).tracker_id |
|
637 | 655 | assert_equal 2, Issue.find(2).tracker_id |
|
638 | 656 | end |
|
639 | 657 | |
|
640 | 658 | def test_bulk_move_to_another_tracker |
|
641 | 659 | @request.session[:user_id] = 1 |
|
642 | 660 | post :move, :ids => [1, 2], :new_tracker_id => 2 |
|
643 | 661 | assert_redirected_to 'projects/ecookbook/issues' |
|
644 | 662 | assert_equal 2, Issue.find(1).tracker_id |
|
645 | 663 | assert_equal 2, Issue.find(2).tracker_id |
|
646 | 664 | end |
|
647 | 665 | |
|
648 | 666 | def test_context_menu_one_issue |
|
649 | 667 | @request.session[:user_id] = 2 |
|
650 | 668 | get :context_menu, :ids => [1] |
|
651 | 669 | assert_response :success |
|
652 | 670 | assert_template 'context_menu' |
|
653 | 671 | assert_tag :tag => 'a', :content => 'Edit', |
|
654 | 672 | :attributes => { :href => '/issues/edit/1', |
|
655 | 673 | :class => 'icon-edit' } |
|
656 | 674 | assert_tag :tag => 'a', :content => 'Closed', |
|
657 | 675 | :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5', |
|
658 | 676 | :class => '' } |
|
659 | 677 | assert_tag :tag => 'a', :content => 'Immediate', |
|
660 | 678 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', |
|
661 | 679 | :class => '' } |
|
662 | 680 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
663 | 681 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', |
|
664 | 682 | :class => '' } |
|
665 | 683 | assert_tag :tag => 'a', :content => 'Copy', |
|
666 | 684 | :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1', |
|
667 | 685 | :class => 'icon-copy' } |
|
668 | 686 | assert_tag :tag => 'a', :content => 'Move', |
|
669 | 687 | :attributes => { :href => '/issues/move?ids%5B%5D=1', |
|
670 | 688 | :class => 'icon-move' } |
|
671 | 689 | assert_tag :tag => 'a', :content => 'Delete', |
|
672 | 690 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', |
|
673 | 691 | :class => 'icon-del' } |
|
674 | 692 | end |
|
675 | 693 | |
|
676 | 694 | def test_context_menu_one_issue_by_anonymous |
|
677 | 695 | get :context_menu, :ids => [1] |
|
678 | 696 | assert_response :success |
|
679 | 697 | assert_template 'context_menu' |
|
680 | 698 | assert_tag :tag => 'a', :content => 'Delete', |
|
681 | 699 | :attributes => { :href => '#', |
|
682 | 700 | :class => 'icon-del disabled' } |
|
683 | 701 | end |
|
684 | 702 | |
|
685 | 703 | def test_context_menu_multiple_issues_of_same_project |
|
686 | 704 | @request.session[:user_id] = 2 |
|
687 | 705 | get :context_menu, :ids => [1, 2] |
|
688 | 706 | assert_response :success |
|
689 | 707 | assert_template 'context_menu' |
|
690 | 708 | assert_tag :tag => 'a', :content => 'Edit', |
|
691 | 709 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', |
|
692 | 710 | :class => 'icon-edit' } |
|
693 | 711 | assert_tag :tag => 'a', :content => 'Immediate', |
|
694 | 712 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', |
|
695 | 713 | :class => '' } |
|
696 | 714 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
697 | 715 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', |
|
698 | 716 | :class => '' } |
|
699 | 717 | assert_tag :tag => 'a', :content => 'Move', |
|
700 | 718 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', |
|
701 | 719 | :class => 'icon-move' } |
|
702 | 720 | assert_tag :tag => 'a', :content => 'Delete', |
|
703 | 721 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', |
|
704 | 722 | :class => 'icon-del' } |
|
705 | 723 | end |
|
706 | 724 | |
|
707 | 725 | def test_context_menu_multiple_issues_of_different_project |
|
708 | 726 | @request.session[:user_id] = 2 |
|
709 | 727 | get :context_menu, :ids => [1, 2, 4] |
|
710 | 728 | assert_response :success |
|
711 | 729 | assert_template 'context_menu' |
|
712 | 730 | assert_tag :tag => 'a', :content => 'Delete', |
|
713 | 731 | :attributes => { :href => '#', |
|
714 | 732 | :class => 'icon-del disabled' } |
|
715 | 733 | end |
|
716 | 734 | |
|
717 | 735 | def test_destroy_issue_with_no_time_entries |
|
718 | 736 | assert_nil TimeEntry.find_by_issue_id(2) |
|
719 | 737 | @request.session[:user_id] = 2 |
|
720 | 738 | post :destroy, :id => 2 |
|
721 | 739 | assert_redirected_to 'projects/ecookbook/issues' |
|
722 | 740 | assert_nil Issue.find_by_id(2) |
|
723 | 741 | end |
|
724 | 742 | |
|
725 | 743 | def test_destroy_issues_with_time_entries |
|
726 | 744 | @request.session[:user_id] = 2 |
|
727 | 745 | post :destroy, :ids => [1, 3] |
|
728 | 746 | assert_response :success |
|
729 | 747 | assert_template 'destroy' |
|
730 | 748 | assert_not_nil assigns(:hours) |
|
731 | 749 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
732 | 750 | end |
|
733 | 751 | |
|
734 | 752 | def test_destroy_issues_and_destroy_time_entries |
|
735 | 753 | @request.session[:user_id] = 2 |
|
736 | 754 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
737 | 755 | assert_redirected_to 'projects/ecookbook/issues' |
|
738 | 756 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
739 | 757 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
740 | 758 | end |
|
741 | 759 | |
|
742 | 760 | def test_destroy_issues_and_assign_time_entries_to_project |
|
743 | 761 | @request.session[:user_id] = 2 |
|
744 | 762 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
745 | 763 | assert_redirected_to 'projects/ecookbook/issues' |
|
746 | 764 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
747 | 765 | assert_nil TimeEntry.find(1).issue_id |
|
748 | 766 | assert_nil TimeEntry.find(2).issue_id |
|
749 | 767 | end |
|
750 | 768 | |
|
751 | 769 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
752 | 770 | @request.session[:user_id] = 2 |
|
753 | 771 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
754 | 772 | assert_redirected_to 'projects/ecookbook/issues' |
|
755 | 773 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
756 | 774 | assert_equal 2, TimeEntry.find(1).issue_id |
|
757 | 775 | assert_equal 2, TimeEntry.find(2).issue_id |
|
758 | 776 | end |
|
759 | 777 | end |
@@ -1,46 +1,47 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class TimeEntryTest < Test::Unit::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 | "1,5h" => 1.5, | |
|
27 | 28 | "7:12" => 7.2, |
|
28 | 29 | "10h" => 10.0, |
|
29 | 30 | "10 h" => 10.0, |
|
30 | 31 | "45m" => 0.75, |
|
31 | 32 | "45 m" => 0.75, |
|
32 | 33 | "3h15" => 3.25, |
|
33 | 34 | "3h 15" => 3.25, |
|
34 | 35 | "3 h 15" => 3.25, |
|
35 | 36 | "3 h 15m" => 3.25, |
|
36 | 37 | "3 h 15 m" => 3.25, |
|
37 | 38 | "3 hours" => 3.0, |
|
38 | 39 | "12min" => 0.2, |
|
39 | 40 | } |
|
40 | 41 | |
|
41 | 42 | assertions.each do |k, v| |
|
42 | 43 | t = TimeEntry.new(:hours => k) |
|
43 | assert_equal v, t.hours | |
|
44 | assert_equal v, t.hours, "Converting #{k} failed:" | |
|
44 | 45 | end |
|
45 | 46 | end |
|
46 | 47 | end |
General Comments 0
You need to be logged in to leave comments.
Login now