##// END OF EJS Templates
Functional tests fail when run on their own (#1895)....
Jean-Philippe Lang -
r1826:f6b05ea3fb6b
parent child
Show More
@@ -1,79 +1,79
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'attachments_controller'
19 require 'attachments_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AttachmentsController; def rescue_action(e) raise e end; end
22 class AttachmentsController; def rescue_action(e) raise e end; end
23
23
24
24
25 class AttachmentsControllerTest < Test::Unit::TestCase
25 class AttachmentsControllerTest < Test::Unit::TestCase
26 fixtures :users, :projects, :issues, :attachments
26 fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments
27
27
28 def setup
28 def setup
29 @controller = AttachmentsController.new
29 @controller = AttachmentsController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
32 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
33 User.current = nil
33 User.current = nil
34 end
34 end
35
35
36 def test_routing
36 def test_routing
37 assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1')
37 assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1')
38 assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext')
38 assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext')
39 assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1')
39 assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1')
40 assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext')
40 assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext')
41 end
41 end
42
42
43 def test_recognizes
43 def test_recognizes
44 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1')
44 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1')
45 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1')
45 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1')
46 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext')
46 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext')
47 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1')
47 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1')
48 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext')
48 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext')
49 end
49 end
50
50
51 def test_show_diff
51 def test_show_diff
52 get :show, :id => 5
52 get :show, :id => 5
53 assert_response :success
53 assert_response :success
54 assert_template 'diff'
54 assert_template 'diff'
55 end
55 end
56
56
57 def test_show_text_file
57 def test_show_text_file
58 get :show, :id => 4
58 get :show, :id => 4
59 assert_response :success
59 assert_response :success
60 assert_template 'file'
60 assert_template 'file'
61 end
61 end
62
62
63 def test_show_other
63 def test_show_other
64 get :show, :id => 6
64 get :show, :id => 6
65 assert_response :success
65 assert_response :success
66 assert_equal 'application/octet-stream', @response.content_type
66 assert_equal 'application/octet-stream', @response.content_type
67 end
67 end
68
68
69 def test_download_text_file
69 def test_download_text_file
70 get :download, :id => 4
70 get :download, :id => 4
71 assert_response :success
71 assert_response :success
72 assert_equal 'application/x-ruby', @response.content_type
72 assert_equal 'application/x-ruby', @response.content_type
73 end
73 end
74
74
75 def test_anonymous_on_private_private
75 def test_anonymous_on_private_private
76 get :download, :id => 7
76 get :download, :id => 7
77 assert_redirected_to 'account/login'
77 assert_redirected_to 'account/login'
78 end
78 end
79 end
79 end
@@ -1,689 +1,690
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
22 class IssuesController; def rescue_action(e) raise e end; end
23
23
24 class IssuesControllerTest < Test::Unit::TestCase
24 class IssuesControllerTest < Test::Unit::TestCase
25 fixtures :projects,
25 fixtures :projects,
26 :users,
26 :users,
27 :roles,
27 :roles,
28 :members,
28 :members,
29 :issues,
29 :issues,
30 :issue_statuses,
30 :issue_statuses,
31 :versions,
31 :trackers,
32 :trackers,
32 :projects_trackers,
33 :projects_trackers,
33 :issue_categories,
34 :issue_categories,
34 :enabled_modules,
35 :enabled_modules,
35 :enumerations,
36 :enumerations,
36 :attachments,
37 :attachments,
37 :workflows,
38 :workflows,
38 :custom_fields,
39 :custom_fields,
39 :custom_values,
40 :custom_values,
40 :custom_fields_trackers,
41 :custom_fields_trackers,
41 :time_entries,
42 :time_entries,
42 :journals,
43 :journals,
43 :journal_details
44 :journal_details
44
45
45 def setup
46 def setup
46 @controller = IssuesController.new
47 @controller = IssuesController.new
47 @request = ActionController::TestRequest.new
48 @request = ActionController::TestRequest.new
48 @response = ActionController::TestResponse.new
49 @response = ActionController::TestResponse.new
49 User.current = nil
50 User.current = nil
50 end
51 end
51
52
52 def test_index
53 def test_index
53 get :index
54 get :index
54 assert_response :success
55 assert_response :success
55 assert_template 'index.rhtml'
56 assert_template 'index.rhtml'
56 assert_not_nil assigns(:issues)
57 assert_not_nil assigns(:issues)
57 assert_nil assigns(:project)
58 assert_nil assigns(:project)
58 assert_tag :tag => 'a', :content => /Can't print recipes/
59 assert_tag :tag => 'a', :content => /Can't print recipes/
59 assert_tag :tag => 'a', :content => /Subproject issue/
60 assert_tag :tag => 'a', :content => /Subproject issue/
60 # private projects hidden
61 # private projects hidden
61 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
62 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
62 assert_no_tag :tag => 'a', :content => /Issue on project 2/
63 assert_no_tag :tag => 'a', :content => /Issue on project 2/
63 end
64 end
64
65
65 def test_index_with_project
66 def test_index_with_project
66 Setting.display_subprojects_issues = 0
67 Setting.display_subprojects_issues = 0
67 get :index, :project_id => 1
68 get :index, :project_id => 1
68 assert_response :success
69 assert_response :success
69 assert_template 'index.rhtml'
70 assert_template 'index.rhtml'
70 assert_not_nil assigns(:issues)
71 assert_not_nil assigns(:issues)
71 assert_tag :tag => 'a', :content => /Can't print recipes/
72 assert_tag :tag => 'a', :content => /Can't print recipes/
72 assert_no_tag :tag => 'a', :content => /Subproject issue/
73 assert_no_tag :tag => 'a', :content => /Subproject issue/
73 end
74 end
74
75
75 def test_index_with_project_and_subprojects
76 def test_index_with_project_and_subprojects
76 Setting.display_subprojects_issues = 1
77 Setting.display_subprojects_issues = 1
77 get :index, :project_id => 1
78 get :index, :project_id => 1
78 assert_response :success
79 assert_response :success
79 assert_template 'index.rhtml'
80 assert_template 'index.rhtml'
80 assert_not_nil assigns(:issues)
81 assert_not_nil assigns(:issues)
81 assert_tag :tag => 'a', :content => /Can't print recipes/
82 assert_tag :tag => 'a', :content => /Can't print recipes/
82 assert_tag :tag => 'a', :content => /Subproject issue/
83 assert_tag :tag => 'a', :content => /Subproject issue/
83 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
84 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
84 end
85 end
85
86
86 def test_index_with_project_and_subprojects_should_show_private_subprojects
87 def test_index_with_project_and_subprojects_should_show_private_subprojects
87 @request.session[:user_id] = 2
88 @request.session[:user_id] = 2
88 Setting.display_subprojects_issues = 1
89 Setting.display_subprojects_issues = 1
89 get :index, :project_id => 1
90 get :index, :project_id => 1
90 assert_response :success
91 assert_response :success
91 assert_template 'index.rhtml'
92 assert_template 'index.rhtml'
92 assert_not_nil assigns(:issues)
93 assert_not_nil assigns(:issues)
93 assert_tag :tag => 'a', :content => /Can't print recipes/
94 assert_tag :tag => 'a', :content => /Can't print recipes/
94 assert_tag :tag => 'a', :content => /Subproject issue/
95 assert_tag :tag => 'a', :content => /Subproject issue/
95 assert_tag :tag => 'a', :content => /Issue of a private subproject/
96 assert_tag :tag => 'a', :content => /Issue of a private subproject/
96 end
97 end
97
98
98 def test_index_with_project_and_filter
99 def test_index_with_project_and_filter
99 get :index, :project_id => 1, :set_filter => 1
100 get :index, :project_id => 1, :set_filter => 1
100 assert_response :success
101 assert_response :success
101 assert_template 'index.rhtml'
102 assert_template 'index.rhtml'
102 assert_not_nil assigns(:issues)
103 assert_not_nil assigns(:issues)
103 end
104 end
104
105
105 def test_index_csv_with_project
106 def test_index_csv_with_project
106 get :index, :format => 'csv'
107 get :index, :format => 'csv'
107 assert_response :success
108 assert_response :success
108 assert_not_nil assigns(:issues)
109 assert_not_nil assigns(:issues)
109 assert_equal 'text/csv', @response.content_type
110 assert_equal 'text/csv', @response.content_type
110
111
111 get :index, :project_id => 1, :format => 'csv'
112 get :index, :project_id => 1, :format => 'csv'
112 assert_response :success
113 assert_response :success
113 assert_not_nil assigns(:issues)
114 assert_not_nil assigns(:issues)
114 assert_equal 'text/csv', @response.content_type
115 assert_equal 'text/csv', @response.content_type
115 end
116 end
116
117
117 def test_index_pdf
118 def test_index_pdf
118 get :index, :format => 'pdf'
119 get :index, :format => 'pdf'
119 assert_response :success
120 assert_response :success
120 assert_not_nil assigns(:issues)
121 assert_not_nil assigns(:issues)
121 assert_equal 'application/pdf', @response.content_type
122 assert_equal 'application/pdf', @response.content_type
122
123
123 get :index, :project_id => 1, :format => 'pdf'
124 get :index, :project_id => 1, :format => 'pdf'
124 assert_response :success
125 assert_response :success
125 assert_not_nil assigns(:issues)
126 assert_not_nil assigns(:issues)
126 assert_equal 'application/pdf', @response.content_type
127 assert_equal 'application/pdf', @response.content_type
127 end
128 end
128
129
129 def test_gantt
130 def test_gantt
130 get :gantt, :project_id => 1
131 get :gantt, :project_id => 1
131 assert_response :success
132 assert_response :success
132 assert_template 'gantt.rhtml'
133 assert_template 'gantt.rhtml'
133 assert_not_nil assigns(:gantt)
134 assert_not_nil assigns(:gantt)
134 events = assigns(:gantt).events
135 events = assigns(:gantt).events
135 assert_not_nil events
136 assert_not_nil events
136 # Issue with start and due dates
137 # Issue with start and due dates
137 i = Issue.find(1)
138 i = Issue.find(1)
138 assert_not_nil i.due_date
139 assert_not_nil i.due_date
139 assert events.include?(Issue.find(1))
140 assert events.include?(Issue.find(1))
140 # Issue with without due date but targeted to a version with date
141 # Issue with without due date but targeted to a version with date
141 i = Issue.find(2)
142 i = Issue.find(2)
142 assert_nil i.due_date
143 assert_nil i.due_date
143 assert events.include?(i)
144 assert events.include?(i)
144 end
145 end
145
146
146 def test_gantt_export_to_pdf
147 def test_gantt_export_to_pdf
147 get :gantt, :project_id => 1, :format => 'pdf'
148 get :gantt, :project_id => 1, :format => 'pdf'
148 assert_response :success
149 assert_response :success
149 assert_template 'gantt.rfpdf'
150 assert_template 'gantt.rfpdf'
150 assert_equal 'application/pdf', @response.content_type
151 assert_equal 'application/pdf', @response.content_type
151 assert_not_nil assigns(:gantt)
152 assert_not_nil assigns(:gantt)
152 end
153 end
153
154
154 if Object.const_defined?(:Magick)
155 if Object.const_defined?(:Magick)
155 def test_gantt_image
156 def test_gantt_image
156 get :gantt, :project_id => 1, :format => 'png'
157 get :gantt, :project_id => 1, :format => 'png'
157 assert_response :success
158 assert_response :success
158 assert_equal 'image/png', @response.content_type
159 assert_equal 'image/png', @response.content_type
159 end
160 end
160 else
161 else
161 puts "RMagick not installed. Skipping tests !!!"
162 puts "RMagick not installed. Skipping tests !!!"
162 end
163 end
163
164
164 def test_calendar
165 def test_calendar
165 get :calendar, :project_id => 1
166 get :calendar, :project_id => 1
166 assert_response :success
167 assert_response :success
167 assert_template 'calendar'
168 assert_template 'calendar'
168 assert_not_nil assigns(:calendar)
169 assert_not_nil assigns(:calendar)
169 end
170 end
170
171
171 def test_changes
172 def test_changes
172 get :changes, :project_id => 1
173 get :changes, :project_id => 1
173 assert_response :success
174 assert_response :success
174 assert_not_nil assigns(:journals)
175 assert_not_nil assigns(:journals)
175 assert_equal 'application/atom+xml', @response.content_type
176 assert_equal 'application/atom+xml', @response.content_type
176 end
177 end
177
178
178 def test_show_by_anonymous
179 def test_show_by_anonymous
179 get :show, :id => 1
180 get :show, :id => 1
180 assert_response :success
181 assert_response :success
181 assert_template 'show.rhtml'
182 assert_template 'show.rhtml'
182 assert_not_nil assigns(:issue)
183 assert_not_nil assigns(:issue)
183 assert_equal Issue.find(1), assigns(:issue)
184 assert_equal Issue.find(1), assigns(:issue)
184
185
185 # anonymous role is allowed to add a note
186 # anonymous role is allowed to add a note
186 assert_tag :tag => 'form',
187 assert_tag :tag => 'form',
187 :descendant => { :tag => 'fieldset',
188 :descendant => { :tag => 'fieldset',
188 :child => { :tag => 'legend',
189 :child => { :tag => 'legend',
189 :content => /Notes/ } }
190 :content => /Notes/ } }
190 end
191 end
191
192
192 def test_show_by_manager
193 def test_show_by_manager
193 @request.session[:user_id] = 2
194 @request.session[:user_id] = 2
194 get :show, :id => 1
195 get :show, :id => 1
195 assert_response :success
196 assert_response :success
196
197
197 assert_tag :tag => 'form',
198 assert_tag :tag => 'form',
198 :descendant => { :tag => 'fieldset',
199 :descendant => { :tag => 'fieldset',
199 :child => { :tag => 'legend',
200 :child => { :tag => 'legend',
200 :content => /Change properties/ } },
201 :content => /Change properties/ } },
201 :descendant => { :tag => 'fieldset',
202 :descendant => { :tag => 'fieldset',
202 :child => { :tag => 'legend',
203 :child => { :tag => 'legend',
203 :content => /Log time/ } },
204 :content => /Log time/ } },
204 :descendant => { :tag => 'fieldset',
205 :descendant => { :tag => 'fieldset',
205 :child => { :tag => 'legend',
206 :child => { :tag => 'legend',
206 :content => /Notes/ } }
207 :content => /Notes/ } }
207 end
208 end
208
209
209 def test_get_new
210 def test_get_new
210 @request.session[:user_id] = 2
211 @request.session[:user_id] = 2
211 get :new, :project_id => 1, :tracker_id => 1
212 get :new, :project_id => 1, :tracker_id => 1
212 assert_response :success
213 assert_response :success
213 assert_template 'new'
214 assert_template 'new'
214
215
215 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
216 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
216 :value => 'Default string' }
217 :value => 'Default string' }
217 end
218 end
218
219
219 def test_get_new_without_tracker_id
220 def test_get_new_without_tracker_id
220 @request.session[:user_id] = 2
221 @request.session[:user_id] = 2
221 get :new, :project_id => 1
222 get :new, :project_id => 1
222 assert_response :success
223 assert_response :success
223 assert_template 'new'
224 assert_template 'new'
224
225
225 issue = assigns(:issue)
226 issue = assigns(:issue)
226 assert_not_nil issue
227 assert_not_nil issue
227 assert_equal Project.find(1).trackers.first, issue.tracker
228 assert_equal Project.find(1).trackers.first, issue.tracker
228 end
229 end
229
230
230 def test_update_new_form
231 def test_update_new_form
231 @request.session[:user_id] = 2
232 @request.session[:user_id] = 2
232 xhr :post, :new, :project_id => 1,
233 xhr :post, :new, :project_id => 1,
233 :issue => {:tracker_id => 2,
234 :issue => {:tracker_id => 2,
234 :subject => 'This is the test_new issue',
235 :subject => 'This is the test_new issue',
235 :description => 'This is the description',
236 :description => 'This is the description',
236 :priority_id => 5}
237 :priority_id => 5}
237 assert_response :success
238 assert_response :success
238 assert_template 'new'
239 assert_template 'new'
239 end
240 end
240
241
241 def test_post_new
242 def test_post_new
242 @request.session[:user_id] = 2
243 @request.session[:user_id] = 2
243 post :new, :project_id => 1,
244 post :new, :project_id => 1,
244 :issue => {:tracker_id => 3,
245 :issue => {:tracker_id => 3,
245 :subject => 'This is the test_new issue',
246 :subject => 'This is the test_new issue',
246 :description => 'This is the description',
247 :description => 'This is the description',
247 :priority_id => 5,
248 :priority_id => 5,
248 :estimated_hours => '',
249 :estimated_hours => '',
249 :custom_field_values => {'2' => 'Value for field 2'}}
250 :custom_field_values => {'2' => 'Value for field 2'}}
250 assert_redirected_to 'issues/show'
251 assert_redirected_to 'issues/show'
251
252
252 issue = Issue.find_by_subject('This is the test_new issue')
253 issue = Issue.find_by_subject('This is the test_new issue')
253 assert_not_nil issue
254 assert_not_nil issue
254 assert_equal 2, issue.author_id
255 assert_equal 2, issue.author_id
255 assert_equal 3, issue.tracker_id
256 assert_equal 3, issue.tracker_id
256 assert_nil issue.estimated_hours
257 assert_nil issue.estimated_hours
257 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
258 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
258 assert_not_nil v
259 assert_not_nil v
259 assert_equal 'Value for field 2', v.value
260 assert_equal 'Value for field 2', v.value
260 end
261 end
261
262
262 def test_post_new_without_custom_fields_param
263 def test_post_new_without_custom_fields_param
263 @request.session[:user_id] = 2
264 @request.session[:user_id] = 2
264 post :new, :project_id => 1,
265 post :new, :project_id => 1,
265 :issue => {:tracker_id => 1,
266 :issue => {:tracker_id => 1,
266 :subject => 'This is the test_new issue',
267 :subject => 'This is the test_new issue',
267 :description => 'This is the description',
268 :description => 'This is the description',
268 :priority_id => 5}
269 :priority_id => 5}
269 assert_redirected_to 'issues/show'
270 assert_redirected_to 'issues/show'
270 end
271 end
271
272
272 def test_post_new_with_required_custom_field_and_without_custom_fields_param
273 def test_post_new_with_required_custom_field_and_without_custom_fields_param
273 field = IssueCustomField.find_by_name('Database')
274 field = IssueCustomField.find_by_name('Database')
274 field.update_attribute(:is_required, true)
275 field.update_attribute(:is_required, true)
275
276
276 @request.session[:user_id] = 2
277 @request.session[:user_id] = 2
277 post :new, :project_id => 1,
278 post :new, :project_id => 1,
278 :issue => {:tracker_id => 1,
279 :issue => {:tracker_id => 1,
279 :subject => 'This is the test_new issue',
280 :subject => 'This is the test_new issue',
280 :description => 'This is the description',
281 :description => 'This is the description',
281 :priority_id => 5}
282 :priority_id => 5}
282 assert_response :success
283 assert_response :success
283 assert_template 'new'
284 assert_template 'new'
284 issue = assigns(:issue)
285 issue = assigns(:issue)
285 assert_not_nil issue
286 assert_not_nil issue
286 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
287 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
287 end
288 end
288
289
289 def test_post_should_preserve_fields_values_on_validation_failure
290 def test_post_should_preserve_fields_values_on_validation_failure
290 @request.session[:user_id] = 2
291 @request.session[:user_id] = 2
291 post :new, :project_id => 1,
292 post :new, :project_id => 1,
292 :issue => {:tracker_id => 1,
293 :issue => {:tracker_id => 1,
293 :subject => 'This is the test_new issue',
294 :subject => 'This is the test_new issue',
294 # empty description
295 # empty description
295 :description => '',
296 :description => '',
296 :priority_id => 6,
297 :priority_id => 6,
297 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
298 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
298 assert_response :success
299 assert_response :success
299 assert_template 'new'
300 assert_template 'new'
300
301
301 assert_tag :input, :attributes => { :name => 'issue[subject]',
302 assert_tag :input, :attributes => { :name => 'issue[subject]',
302 :value => 'This is the test_new issue' }
303 :value => 'This is the test_new issue' }
303 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
304 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
304 :child => { :tag => 'option', :attributes => { :selected => 'selected',
305 :child => { :tag => 'option', :attributes => { :selected => 'selected',
305 :value => '6' },
306 :value => '6' },
306 :content => 'High' }
307 :content => 'High' }
307 # Custom fields
308 # Custom fields
308 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
309 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
309 :child => { :tag => 'option', :attributes => { :selected => 'selected',
310 :child => { :tag => 'option', :attributes => { :selected => 'selected',
310 :value => 'Oracle' },
311 :value => 'Oracle' },
311 :content => 'Oracle' }
312 :content => 'Oracle' }
312 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
313 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
313 :value => 'Value for field 2'}
314 :value => 'Value for field 2'}
314 end
315 end
315
316
316 def test_copy_issue
317 def test_copy_issue
317 @request.session[:user_id] = 2
318 @request.session[:user_id] = 2
318 get :new, :project_id => 1, :copy_from => 1
319 get :new, :project_id => 1, :copy_from => 1
319 assert_template 'new'
320 assert_template 'new'
320 assert_not_nil assigns(:issue)
321 assert_not_nil assigns(:issue)
321 orig = Issue.find(1)
322 orig = Issue.find(1)
322 assert_equal orig.subject, assigns(:issue).subject
323 assert_equal orig.subject, assigns(:issue).subject
323 end
324 end
324
325
325 def test_get_edit
326 def test_get_edit
326 @request.session[:user_id] = 2
327 @request.session[:user_id] = 2
327 get :edit, :id => 1
328 get :edit, :id => 1
328 assert_response :success
329 assert_response :success
329 assert_template 'edit'
330 assert_template 'edit'
330 assert_not_nil assigns(:issue)
331 assert_not_nil assigns(:issue)
331 assert_equal Issue.find(1), assigns(:issue)
332 assert_equal Issue.find(1), assigns(:issue)
332 end
333 end
333
334
334 def test_get_edit_with_params
335 def test_get_edit_with_params
335 @request.session[:user_id] = 2
336 @request.session[:user_id] = 2
336 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
337 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
337 assert_response :success
338 assert_response :success
338 assert_template 'edit'
339 assert_template 'edit'
339
340
340 issue = assigns(:issue)
341 issue = assigns(:issue)
341 assert_not_nil issue
342 assert_not_nil issue
342
343
343 assert_equal 5, issue.status_id
344 assert_equal 5, issue.status_id
344 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
345 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
345 :child => { :tag => 'option',
346 :child => { :tag => 'option',
346 :content => 'Closed',
347 :content => 'Closed',
347 :attributes => { :selected => 'selected' } }
348 :attributes => { :selected => 'selected' } }
348
349
349 assert_equal 7, issue.priority_id
350 assert_equal 7, issue.priority_id
350 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
351 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
351 :child => { :tag => 'option',
352 :child => { :tag => 'option',
352 :content => 'Urgent',
353 :content => 'Urgent',
353 :attributes => { :selected => 'selected' } }
354 :attributes => { :selected => 'selected' } }
354 end
355 end
355
356
356 def test_reply_to_issue
357 def test_reply_to_issue
357 @request.session[:user_id] = 2
358 @request.session[:user_id] = 2
358 get :reply, :id => 1
359 get :reply, :id => 1
359 assert_response :success
360 assert_response :success
360 assert_select_rjs :show, "update"
361 assert_select_rjs :show, "update"
361 end
362 end
362
363
363 def test_reply_to_note
364 def test_reply_to_note
364 @request.session[:user_id] = 2
365 @request.session[:user_id] = 2
365 get :reply, :id => 1, :journal_id => 2
366 get :reply, :id => 1, :journal_id => 2
366 assert_response :success
367 assert_response :success
367 assert_select_rjs :show, "update"
368 assert_select_rjs :show, "update"
368 end
369 end
369
370
370 def test_post_edit_without_custom_fields_param
371 def test_post_edit_without_custom_fields_param
371 @request.session[:user_id] = 2
372 @request.session[:user_id] = 2
372 ActionMailer::Base.deliveries.clear
373 ActionMailer::Base.deliveries.clear
373
374
374 issue = Issue.find(1)
375 issue = Issue.find(1)
375 assert_equal '125', issue.custom_value_for(2).value
376 assert_equal '125', issue.custom_value_for(2).value
376 old_subject = issue.subject
377 old_subject = issue.subject
377 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
378 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
378
379
379 assert_difference('Journal.count') do
380 assert_difference('Journal.count') do
380 assert_difference('JournalDetail.count', 2) do
381 assert_difference('JournalDetail.count', 2) do
381 post :edit, :id => 1, :issue => {:subject => new_subject,
382 post :edit, :id => 1, :issue => {:subject => new_subject,
382 :priority_id => '6',
383 :priority_id => '6',
383 :category_id => '1' # no change
384 :category_id => '1' # no change
384 }
385 }
385 end
386 end
386 end
387 end
387 assert_redirected_to 'issues/show/1'
388 assert_redirected_to 'issues/show/1'
388 issue.reload
389 issue.reload
389 assert_equal new_subject, issue.subject
390 assert_equal new_subject, issue.subject
390 # Make sure custom fields were not cleared
391 # Make sure custom fields were not cleared
391 assert_equal '125', issue.custom_value_for(2).value
392 assert_equal '125', issue.custom_value_for(2).value
392
393
393 mail = ActionMailer::Base.deliveries.last
394 mail = ActionMailer::Base.deliveries.last
394 assert_kind_of TMail::Mail, mail
395 assert_kind_of TMail::Mail, mail
395 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
396 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
396 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
397 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
397 end
398 end
398
399
399 def test_post_edit_with_custom_field_change
400 def test_post_edit_with_custom_field_change
400 @request.session[:user_id] = 2
401 @request.session[:user_id] = 2
401 issue = Issue.find(1)
402 issue = Issue.find(1)
402 assert_equal '125', issue.custom_value_for(2).value
403 assert_equal '125', issue.custom_value_for(2).value
403
404
404 assert_difference('Journal.count') do
405 assert_difference('Journal.count') do
405 assert_difference('JournalDetail.count', 3) do
406 assert_difference('JournalDetail.count', 3) do
406 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
407 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
407 :priority_id => '6',
408 :priority_id => '6',
408 :category_id => '1', # no change
409 :category_id => '1', # no change
409 :custom_field_values => { '2' => 'New custom value' }
410 :custom_field_values => { '2' => 'New custom value' }
410 }
411 }
411 end
412 end
412 end
413 end
413 assert_redirected_to 'issues/show/1'
414 assert_redirected_to 'issues/show/1'
414 issue.reload
415 issue.reload
415 assert_equal 'New custom value', issue.custom_value_for(2).value
416 assert_equal 'New custom value', issue.custom_value_for(2).value
416
417
417 mail = ActionMailer::Base.deliveries.last
418 mail = ActionMailer::Base.deliveries.last
418 assert_kind_of TMail::Mail, mail
419 assert_kind_of TMail::Mail, mail
419 assert mail.body.include?("Searchable field changed from 125 to New custom value")
420 assert mail.body.include?("Searchable field changed from 125 to New custom value")
420 end
421 end
421
422
422 def test_post_edit_with_status_and_assignee_change
423 def test_post_edit_with_status_and_assignee_change
423 issue = Issue.find(1)
424 issue = Issue.find(1)
424 assert_equal 1, issue.status_id
425 assert_equal 1, issue.status_id
425 @request.session[:user_id] = 2
426 @request.session[:user_id] = 2
426 assert_difference('TimeEntry.count', 0) do
427 assert_difference('TimeEntry.count', 0) do
427 post :edit,
428 post :edit,
428 :id => 1,
429 :id => 1,
429 :issue => { :status_id => 2, :assigned_to_id => 3 },
430 :issue => { :status_id => 2, :assigned_to_id => 3 },
430 :notes => 'Assigned to dlopper',
431 :notes => 'Assigned to dlopper',
431 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
432 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
432 end
433 end
433 assert_redirected_to 'issues/show/1'
434 assert_redirected_to 'issues/show/1'
434 issue.reload
435 issue.reload
435 assert_equal 2, issue.status_id
436 assert_equal 2, issue.status_id
436 j = issue.journals.find(:first, :order => 'id DESC')
437 j = issue.journals.find(:first, :order => 'id DESC')
437 assert_equal 'Assigned to dlopper', j.notes
438 assert_equal 'Assigned to dlopper', j.notes
438 assert_equal 2, j.details.size
439 assert_equal 2, j.details.size
439
440
440 mail = ActionMailer::Base.deliveries.last
441 mail = ActionMailer::Base.deliveries.last
441 assert mail.body.include?("Status changed from New to Assigned")
442 assert mail.body.include?("Status changed from New to Assigned")
442 end
443 end
443
444
444 def test_post_edit_with_note_only
445 def test_post_edit_with_note_only
445 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
446 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
446 # anonymous user
447 # anonymous user
447 post :edit,
448 post :edit,
448 :id => 1,
449 :id => 1,
449 :notes => notes
450 :notes => notes
450 assert_redirected_to 'issues/show/1'
451 assert_redirected_to 'issues/show/1'
451 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
452 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
452 assert_equal notes, j.notes
453 assert_equal notes, j.notes
453 assert_equal 0, j.details.size
454 assert_equal 0, j.details.size
454 assert_equal User.anonymous, j.user
455 assert_equal User.anonymous, j.user
455
456
456 mail = ActionMailer::Base.deliveries.last
457 mail = ActionMailer::Base.deliveries.last
457 assert mail.body.include?(notes)
458 assert mail.body.include?(notes)
458 end
459 end
459
460
460 def test_post_edit_with_note_and_spent_time
461 def test_post_edit_with_note_and_spent_time
461 @request.session[:user_id] = 2
462 @request.session[:user_id] = 2
462 spent_hours_before = Issue.find(1).spent_hours
463 spent_hours_before = Issue.find(1).spent_hours
463 assert_difference('TimeEntry.count') do
464 assert_difference('TimeEntry.count') do
464 post :edit,
465 post :edit,
465 :id => 1,
466 :id => 1,
466 :notes => '2.5 hours added',
467 :notes => '2.5 hours added',
467 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
468 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
468 end
469 end
469 assert_redirected_to 'issues/show/1'
470 assert_redirected_to 'issues/show/1'
470
471
471 issue = Issue.find(1)
472 issue = Issue.find(1)
472
473
473 j = issue.journals.find(:first, :order => 'id DESC')
474 j = issue.journals.find(:first, :order => 'id DESC')
474 assert_equal '2.5 hours added', j.notes
475 assert_equal '2.5 hours added', j.notes
475 assert_equal 0, j.details.size
476 assert_equal 0, j.details.size
476
477
477 t = issue.time_entries.find(:first, :order => 'id DESC')
478 t = issue.time_entries.find(:first, :order => 'id DESC')
478 assert_not_nil t
479 assert_not_nil t
479 assert_equal 2.5, t.hours
480 assert_equal 2.5, t.hours
480 assert_equal spent_hours_before + 2.5, issue.spent_hours
481 assert_equal spent_hours_before + 2.5, issue.spent_hours
481 end
482 end
482
483
483 def test_post_edit_with_attachment_only
484 def test_post_edit_with_attachment_only
484 set_tmp_attachments_directory
485 set_tmp_attachments_directory
485
486
486 # anonymous user
487 # anonymous user
487 post :edit,
488 post :edit,
488 :id => 1,
489 :id => 1,
489 :notes => '',
490 :notes => '',
490 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
491 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
491 assert_redirected_to 'issues/show/1'
492 assert_redirected_to 'issues/show/1'
492 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
493 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
493 assert j.notes.blank?
494 assert j.notes.blank?
494 assert_equal 1, j.details.size
495 assert_equal 1, j.details.size
495 assert_equal 'testfile.txt', j.details.first.value
496 assert_equal 'testfile.txt', j.details.first.value
496 assert_equal User.anonymous, j.user
497 assert_equal User.anonymous, j.user
497
498
498 mail = ActionMailer::Base.deliveries.last
499 mail = ActionMailer::Base.deliveries.last
499 assert mail.body.include?('testfile.txt')
500 assert mail.body.include?('testfile.txt')
500 end
501 end
501
502
502 def test_post_edit_with_no_change
503 def test_post_edit_with_no_change
503 issue = Issue.find(1)
504 issue = Issue.find(1)
504 issue.journals.clear
505 issue.journals.clear
505 ActionMailer::Base.deliveries.clear
506 ActionMailer::Base.deliveries.clear
506
507
507 post :edit,
508 post :edit,
508 :id => 1,
509 :id => 1,
509 :notes => ''
510 :notes => ''
510 assert_redirected_to 'issues/show/1'
511 assert_redirected_to 'issues/show/1'
511
512
512 issue.reload
513 issue.reload
513 assert issue.journals.empty?
514 assert issue.journals.empty?
514 # No email should be sent
515 # No email should be sent
515 assert ActionMailer::Base.deliveries.empty?
516 assert ActionMailer::Base.deliveries.empty?
516 end
517 end
517
518
518 def test_bulk_edit
519 def test_bulk_edit
519 @request.session[:user_id] = 2
520 @request.session[:user_id] = 2
520 # update issues priority
521 # update issues priority
521 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
522 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
522 assert_response 302
523 assert_response 302
523 # check that the issues were updated
524 # check that the issues were updated
524 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
525 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
525 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
526 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
526 end
527 end
527
528
528 def test_bulk_unassign
529 def test_bulk_unassign
529 assert_not_nil Issue.find(2).assigned_to
530 assert_not_nil Issue.find(2).assigned_to
530 @request.session[:user_id] = 2
531 @request.session[:user_id] = 2
531 # unassign issues
532 # unassign issues
532 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
533 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
533 assert_response 302
534 assert_response 302
534 # check that the issues were updated
535 # check that the issues were updated
535 assert_nil Issue.find(2).assigned_to
536 assert_nil Issue.find(2).assigned_to
536 end
537 end
537
538
538 def test_move_one_issue_to_another_project
539 def test_move_one_issue_to_another_project
539 @request.session[:user_id] = 1
540 @request.session[:user_id] = 1
540 post :move, :id => 1, :new_project_id => 2
541 post :move, :id => 1, :new_project_id => 2
541 assert_redirected_to 'projects/ecookbook/issues'
542 assert_redirected_to 'projects/ecookbook/issues'
542 assert_equal 2, Issue.find(1).project_id
543 assert_equal 2, Issue.find(1).project_id
543 end
544 end
544
545
545 def test_bulk_move_to_another_project
546 def test_bulk_move_to_another_project
546 @request.session[:user_id] = 1
547 @request.session[:user_id] = 1
547 post :move, :ids => [1, 2], :new_project_id => 2
548 post :move, :ids => [1, 2], :new_project_id => 2
548 assert_redirected_to 'projects/ecookbook/issues'
549 assert_redirected_to 'projects/ecookbook/issues'
549 # Issues moved to project 2
550 # Issues moved to project 2
550 assert_equal 2, Issue.find(1).project_id
551 assert_equal 2, Issue.find(1).project_id
551 assert_equal 2, Issue.find(2).project_id
552 assert_equal 2, Issue.find(2).project_id
552 # No tracker change
553 # No tracker change
553 assert_equal 1, Issue.find(1).tracker_id
554 assert_equal 1, Issue.find(1).tracker_id
554 assert_equal 2, Issue.find(2).tracker_id
555 assert_equal 2, Issue.find(2).tracker_id
555 end
556 end
556
557
557 def test_bulk_move_to_another_tracker
558 def test_bulk_move_to_another_tracker
558 @request.session[:user_id] = 1
559 @request.session[:user_id] = 1
559 post :move, :ids => [1, 2], :new_tracker_id => 2
560 post :move, :ids => [1, 2], :new_tracker_id => 2
560 assert_redirected_to 'projects/ecookbook/issues'
561 assert_redirected_to 'projects/ecookbook/issues'
561 assert_equal 2, Issue.find(1).tracker_id
562 assert_equal 2, Issue.find(1).tracker_id
562 assert_equal 2, Issue.find(2).tracker_id
563 assert_equal 2, Issue.find(2).tracker_id
563 end
564 end
564
565
565 def test_context_menu_one_issue
566 def test_context_menu_one_issue
566 @request.session[:user_id] = 2
567 @request.session[:user_id] = 2
567 get :context_menu, :ids => [1]
568 get :context_menu, :ids => [1]
568 assert_response :success
569 assert_response :success
569 assert_template 'context_menu'
570 assert_template 'context_menu'
570 assert_tag :tag => 'a', :content => 'Edit',
571 assert_tag :tag => 'a', :content => 'Edit',
571 :attributes => { :href => '/issues/edit/1',
572 :attributes => { :href => '/issues/edit/1',
572 :class => 'icon-edit' }
573 :class => 'icon-edit' }
573 assert_tag :tag => 'a', :content => 'Closed',
574 assert_tag :tag => 'a', :content => 'Closed',
574 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
575 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
575 :class => '' }
576 :class => '' }
576 assert_tag :tag => 'a', :content => 'Immediate',
577 assert_tag :tag => 'a', :content => 'Immediate',
577 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
578 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
578 :class => '' }
579 :class => '' }
579 assert_tag :tag => 'a', :content => 'Dave Lopper',
580 assert_tag :tag => 'a', :content => 'Dave Lopper',
580 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
581 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
581 :class => '' }
582 :class => '' }
582 assert_tag :tag => 'a', :content => 'Copy',
583 assert_tag :tag => 'a', :content => 'Copy',
583 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
584 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
584 :class => 'icon-copy' }
585 :class => 'icon-copy' }
585 assert_tag :tag => 'a', :content => 'Move',
586 assert_tag :tag => 'a', :content => 'Move',
586 :attributes => { :href => '/issues/move?ids%5B%5D=1',
587 :attributes => { :href => '/issues/move?ids%5B%5D=1',
587 :class => 'icon-move' }
588 :class => 'icon-move' }
588 assert_tag :tag => 'a', :content => 'Delete',
589 assert_tag :tag => 'a', :content => 'Delete',
589 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
590 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
590 :class => 'icon-del' }
591 :class => 'icon-del' }
591 end
592 end
592
593
593 def test_context_menu_one_issue_by_anonymous
594 def test_context_menu_one_issue_by_anonymous
594 get :context_menu, :ids => [1]
595 get :context_menu, :ids => [1]
595 assert_response :success
596 assert_response :success
596 assert_template 'context_menu'
597 assert_template 'context_menu'
597 assert_tag :tag => 'a', :content => 'Delete',
598 assert_tag :tag => 'a', :content => 'Delete',
598 :attributes => { :href => '#',
599 :attributes => { :href => '#',
599 :class => 'icon-del disabled' }
600 :class => 'icon-del disabled' }
600 end
601 end
601
602
602 def test_context_menu_multiple_issues_of_same_project
603 def test_context_menu_multiple_issues_of_same_project
603 @request.session[:user_id] = 2
604 @request.session[:user_id] = 2
604 get :context_menu, :ids => [1, 2]
605 get :context_menu, :ids => [1, 2]
605 assert_response :success
606 assert_response :success
606 assert_template 'context_menu'
607 assert_template 'context_menu'
607 assert_tag :tag => 'a', :content => 'Edit',
608 assert_tag :tag => 'a', :content => 'Edit',
608 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
609 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
609 :class => 'icon-edit' }
610 :class => 'icon-edit' }
610 assert_tag :tag => 'a', :content => 'Immediate',
611 assert_tag :tag => 'a', :content => 'Immediate',
611 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
612 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
612 :class => '' }
613 :class => '' }
613 assert_tag :tag => 'a', :content => 'Dave Lopper',
614 assert_tag :tag => 'a', :content => 'Dave Lopper',
614 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
615 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
615 :class => '' }
616 :class => '' }
616 assert_tag :tag => 'a', :content => 'Move',
617 assert_tag :tag => 'a', :content => 'Move',
617 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
618 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
618 :class => 'icon-move' }
619 :class => 'icon-move' }
619 assert_tag :tag => 'a', :content => 'Delete',
620 assert_tag :tag => 'a', :content => 'Delete',
620 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
621 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
621 :class => 'icon-del' }
622 :class => 'icon-del' }
622 end
623 end
623
624
624 def test_context_menu_multiple_issues_of_different_project
625 def test_context_menu_multiple_issues_of_different_project
625 @request.session[:user_id] = 2
626 @request.session[:user_id] = 2
626 get :context_menu, :ids => [1, 2, 4]
627 get :context_menu, :ids => [1, 2, 4]
627 assert_response :success
628 assert_response :success
628 assert_template 'context_menu'
629 assert_template 'context_menu'
629 assert_tag :tag => 'a', :content => 'Delete',
630 assert_tag :tag => 'a', :content => 'Delete',
630 :attributes => { :href => '#',
631 :attributes => { :href => '#',
631 :class => 'icon-del disabled' }
632 :class => 'icon-del disabled' }
632 end
633 end
633
634
634 def test_destroy_issue_with_no_time_entries
635 def test_destroy_issue_with_no_time_entries
635 assert_nil TimeEntry.find_by_issue_id(2)
636 assert_nil TimeEntry.find_by_issue_id(2)
636 @request.session[:user_id] = 2
637 @request.session[:user_id] = 2
637 post :destroy, :id => 2
638 post :destroy, :id => 2
638 assert_redirected_to 'projects/ecookbook/issues'
639 assert_redirected_to 'projects/ecookbook/issues'
639 assert_nil Issue.find_by_id(2)
640 assert_nil Issue.find_by_id(2)
640 end
641 end
641
642
642 def test_destroy_issues_with_time_entries
643 def test_destroy_issues_with_time_entries
643 @request.session[:user_id] = 2
644 @request.session[:user_id] = 2
644 post :destroy, :ids => [1, 3]
645 post :destroy, :ids => [1, 3]
645 assert_response :success
646 assert_response :success
646 assert_template 'destroy'
647 assert_template 'destroy'
647 assert_not_nil assigns(:hours)
648 assert_not_nil assigns(:hours)
648 assert Issue.find_by_id(1) && Issue.find_by_id(3)
649 assert Issue.find_by_id(1) && Issue.find_by_id(3)
649 end
650 end
650
651
651 def test_destroy_issues_and_destroy_time_entries
652 def test_destroy_issues_and_destroy_time_entries
652 @request.session[:user_id] = 2
653 @request.session[:user_id] = 2
653 post :destroy, :ids => [1, 3], :todo => 'destroy'
654 post :destroy, :ids => [1, 3], :todo => 'destroy'
654 assert_redirected_to 'projects/ecookbook/issues'
655 assert_redirected_to 'projects/ecookbook/issues'
655 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
656 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
656 assert_nil TimeEntry.find_by_id([1, 2])
657 assert_nil TimeEntry.find_by_id([1, 2])
657 end
658 end
658
659
659 def test_destroy_issues_and_assign_time_entries_to_project
660 def test_destroy_issues_and_assign_time_entries_to_project
660 @request.session[:user_id] = 2
661 @request.session[:user_id] = 2
661 post :destroy, :ids => [1, 3], :todo => 'nullify'
662 post :destroy, :ids => [1, 3], :todo => 'nullify'
662 assert_redirected_to 'projects/ecookbook/issues'
663 assert_redirected_to 'projects/ecookbook/issues'
663 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
664 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
664 assert_nil TimeEntry.find(1).issue_id
665 assert_nil TimeEntry.find(1).issue_id
665 assert_nil TimeEntry.find(2).issue_id
666 assert_nil TimeEntry.find(2).issue_id
666 end
667 end
667
668
668 def test_destroy_issues_and_reassign_time_entries_to_another_issue
669 def test_destroy_issues_and_reassign_time_entries_to_another_issue
669 @request.session[:user_id] = 2
670 @request.session[:user_id] = 2
670 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
671 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
671 assert_redirected_to 'projects/ecookbook/issues'
672 assert_redirected_to 'projects/ecookbook/issues'
672 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
673 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
673 assert_equal 2, TimeEntry.find(1).issue_id
674 assert_equal 2, TimeEntry.find(1).issue_id
674 assert_equal 2, TimeEntry.find(2).issue_id
675 assert_equal 2, TimeEntry.find(2).issue_id
675 end
676 end
676
677
677 def test_destroy_attachment
678 def test_destroy_attachment
678 issue = Issue.find(3)
679 issue = Issue.find(3)
679 a = issue.attachments.size
680 a = issue.attachments.size
680 @request.session[:user_id] = 2
681 @request.session[:user_id] = 2
681 post :destroy_attachment, :id => 3, :attachment_id => 1
682 post :destroy_attachment, :id => 3, :attachment_id => 1
682 assert_redirected_to 'issues/show/3'
683 assert_redirected_to 'issues/show/3'
683 assert_nil Attachment.find_by_id(1)
684 assert_nil Attachment.find_by_id(1)
684 issue.reload
685 issue.reload
685 assert_equal((a-1), issue.attachments.size)
686 assert_equal((a-1), issue.attachments.size)
686 j = issue.journals.find(:first, :order => 'created_on DESC')
687 j = issue.journals.find(:first, :order => 'created_on DESC')
687 assert_equal 'attachment', j.details.first.property
688 assert_equal 'attachment', j.details.first.property
688 end
689 end
689 end
690 end
@@ -1,168 +1,170
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesSubversionControllerTest < Test::Unit::TestCase
24 class RepositoriesSubversionControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
25 fixtures :projects, :users, :roles, :members, :enabled_modules,
26 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26
28
27 # No '..' in the repository path for svn
29 # No '..' in the repository path for svn
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
30 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
29
31
30 def setup
32 def setup
31 @controller = RepositoriesController.new
33 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new
34 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new
35 @response = ActionController::TestResponse.new
34 Setting.default_language = 'en'
36 Setting.default_language = 'en'
35 User.current = nil
37 User.current = nil
36 end
38 end
37
39
38 if File.directory?(REPOSITORY_PATH)
40 if File.directory?(REPOSITORY_PATH)
39 def test_show
41 def test_show
40 get :show, :id => 1
42 get :show, :id => 1
41 assert_response :success
43 assert_response :success
42 assert_template 'show'
44 assert_template 'show'
43 assert_not_nil assigns(:entries)
45 assert_not_nil assigns(:entries)
44 assert_not_nil assigns(:changesets)
46 assert_not_nil assigns(:changesets)
45 end
47 end
46
48
47 def test_browse_root
49 def test_browse_root
48 get :browse, :id => 1
50 get :browse, :id => 1
49 assert_response :success
51 assert_response :success
50 assert_template 'browse'
52 assert_template 'browse'
51 assert_not_nil assigns(:entries)
53 assert_not_nil assigns(:entries)
52 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
54 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
53 assert_equal 'dir', entry.kind
55 assert_equal 'dir', entry.kind
54 end
56 end
55
57
56 def test_browse_directory
58 def test_browse_directory
57 get :browse, :id => 1, :path => ['subversion_test']
59 get :browse, :id => 1, :path => ['subversion_test']
58 assert_response :success
60 assert_response :success
59 assert_template 'browse'
61 assert_template 'browse'
60 assert_not_nil assigns(:entries)
62 assert_not_nil assigns(:entries)
61 assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
63 assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
62 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
64 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
63 assert_equal 'file', entry.kind
65 assert_equal 'file', entry.kind
64 assert_equal 'subversion_test/helloworld.c', entry.path
66 assert_equal 'subversion_test/helloworld.c', entry.path
65 end
67 end
66
68
67 def test_browse_at_given_revision
69 def test_browse_at_given_revision
68 get :browse, :id => 1, :path => ['subversion_test'], :rev => 4
70 get :browse, :id => 1, :path => ['subversion_test'], :rev => 4
69 assert_response :success
71 assert_response :success
70 assert_template 'browse'
72 assert_template 'browse'
71 assert_not_nil assigns(:entries)
73 assert_not_nil assigns(:entries)
72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
74 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
73 end
75 end
74
76
75 def test_changes
77 def test_changes
76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
78 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
77 assert_response :success
79 assert_response :success
78 assert_template 'changes'
80 assert_template 'changes'
79 # svn properties
81 # svn properties
80 assert_not_nil assigns(:properties)
82 assert_not_nil assigns(:properties)
81 assert_equal 'native', assigns(:properties)['svn:eol-style']
83 assert_equal 'native', assigns(:properties)['svn:eol-style']
82 assert_tag :ul,
84 assert_tag :ul,
83 :child => { :tag => 'li',
85 :child => { :tag => 'li',
84 :child => { :tag => 'b', :content => 'svn:eol-style' },
86 :child => { :tag => 'b', :content => 'svn:eol-style' },
85 :child => { :tag => 'span', :content => 'native' } }
87 :child => { :tag => 'span', :content => 'native' } }
86 end
88 end
87
89
88 def test_entry
90 def test_entry
89 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
91 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
90 assert_response :success
92 assert_response :success
91 assert_template 'entry'
93 assert_template 'entry'
92 end
94 end
93
95
94 def test_entry_at_given_revision
96 def test_entry_at_given_revision
95 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
97 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
96 assert_response :success
98 assert_response :success
97 assert_template 'entry'
99 assert_template 'entry'
98 # this line was removed in r3 and file was moved in r6
100 # this line was removed in r3 and file was moved in r6
99 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
101 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
100 :content => /Here's the code/
102 :content => /Here's the code/
101 end
103 end
102
104
103 def test_entry_not_found
105 def test_entry_not_found
104 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
106 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
105 assert_tag :tag => 'div', :attributes => { :class => /error/ },
107 assert_tag :tag => 'div', :attributes => { :class => /error/ },
106 :content => /The entry or revision was not found in the repository/
108 :content => /The entry or revision was not found in the repository/
107 end
109 end
108
110
109 def test_entry_download
111 def test_entry_download
110 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
112 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
111 assert_response :success
113 assert_response :success
112 end
114 end
113
115
114 def test_directory_entry
116 def test_directory_entry
115 get :entry, :id => 1, :path => ['subversion_test', 'folder']
117 get :entry, :id => 1, :path => ['subversion_test', 'folder']
116 assert_response :success
118 assert_response :success
117 assert_template 'browse'
119 assert_template 'browse'
118 assert_not_nil assigns(:entry)
120 assert_not_nil assigns(:entry)
119 assert_equal 'folder', assigns(:entry).name
121 assert_equal 'folder', assigns(:entry).name
120 end
122 end
121
123
122 def test_revision
124 def test_revision
123 get :revision, :id => 1, :rev => 2
125 get :revision, :id => 1, :rev => 2
124 assert_response :success
126 assert_response :success
125 assert_template 'revision'
127 assert_template 'revision'
126 assert_tag :tag => 'tr',
128 assert_tag :tag => 'tr',
127 :child => { :tag => 'td',
129 :child => { :tag => 'td',
128 # link to the entry at rev 2
130 # link to the entry at rev 2
129 :child => { :tag => 'a', :attributes => {:href => 'repositories/entry/ecookbook/test/some/path/in/the/repo?rev=2'},
131 :child => { :tag => 'a', :attributes => {:href => 'repositories/entry/ecookbook/test/some/path/in/the/repo?rev=2'},
130 :content => %r{/test/some/path/in/the/repo} }
132 :content => %r{/test/some/path/in/the/repo} }
131 },
133 },
132 :child => { :tag => 'td',
134 :child => { :tag => 'td',
133 # link to partial diff
135 # link to partial diff
134 :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } }
136 :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } }
135 }
137 }
136 end
138 end
137
139
138 def test_revision_with_repository_pointing_to_a_subdirectory
140 def test_revision_with_repository_pointing_to_a_subdirectory
139 r = Project.find(1).repository
141 r = Project.find(1).repository
140 # Changes repository url to a subdirectory
142 # Changes repository url to a subdirectory
141 r.update_attribute :url, (r.url + '/test/some')
143 r.update_attribute :url, (r.url + '/test/some')
142
144
143 get :revision, :id => 1, :rev => 2
145 get :revision, :id => 1, :rev => 2
144 assert_response :success
146 assert_response :success
145 assert_template 'revision'
147 assert_template 'revision'
146 assert_tag :tag => 'tr',
148 assert_tag :tag => 'tr',
147 :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} },
149 :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} },
148 :child => { :tag => 'td',
150 :child => { :tag => 'td',
149 :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } }
151 :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } }
150 }
152 }
151 end
153 end
152
154
153 def test_diff
155 def test_diff
154 get :diff, :id => 1, :rev => 3
156 get :diff, :id => 1, :rev => 3
155 assert_response :success
157 assert_response :success
156 assert_template 'diff'
158 assert_template 'diff'
157 end
159 end
158
160
159 def test_annotate
161 def test_annotate
160 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
162 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
161 assert_response :success
163 assert_response :success
162 assert_template 'annotate'
164 assert_template 'annotate'
163 end
165 end
164 else
166 else
165 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
167 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
166 def test_fake; assert true end
168 def test_fake; assert true end
167 end
169 end
168 end
170 end
General Comments 0
You need to be logged in to leave comments. Login now