##// END OF EJS Templates
Merged r9382 from trunk....
Jean-Philippe Lang -
r9249:4c82fbb6f88a
parent child
Show More
@@ -1,33 +1,33
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module Redmine
18 module Redmine
19 module Views
19 module Views
20 class OtherFormatsBuilder
20 class OtherFormatsBuilder
21 def initialize(view)
21 def initialize(view)
22 @view = view
22 @view = view
23 end
23 end
24
24
25 def link_to(name, options={})
25 def link_to(name, options={})
26 url = { :format => name.to_s.downcase }.merge(options.delete(:url) || {})
26 url = { :format => name.to_s.downcase }.merge(options.delete(:url) || {}).except('page')
27 caption = options.delete(:caption) || name
27 caption = options.delete(:caption) || name
28 html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
28 html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
29 @view.content_tag('span', @view.link_to(caption, url, html_options))
29 @view.content_tag('span', @view.link_to(caption, url, html_options))
30 end
30 end
31 end
31 end
32 end
32 end
33 end
33 end
@@ -1,3193 +1,3202
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 class IssuesControllerTest < ActionController::TestCase
21 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects,
22 fixtures :projects,
23 :users,
23 :users,
24 :roles,
24 :roles,
25 :members,
25 :members,
26 :member_roles,
26 :member_roles,
27 :issues,
27 :issues,
28 :issue_statuses,
28 :issue_statuses,
29 :versions,
29 :versions,
30 :trackers,
30 :trackers,
31 :projects_trackers,
31 :projects_trackers,
32 :issue_categories,
32 :issue_categories,
33 :enabled_modules,
33 :enabled_modules,
34 :enumerations,
34 :enumerations,
35 :attachments,
35 :attachments,
36 :workflows,
36 :workflows,
37 :custom_fields,
37 :custom_fields,
38 :custom_values,
38 :custom_values,
39 :custom_fields_projects,
39 :custom_fields_projects,
40 :custom_fields_trackers,
40 :custom_fields_trackers,
41 :time_entries,
41 :time_entries,
42 :journals,
42 :journals,
43 :journal_details,
43 :journal_details,
44 :queries,
44 :queries,
45 :repositories,
45 :repositories,
46 :changesets
46 :changesets
47
47
48 include Redmine::I18n
48 include Redmine::I18n
49
49
50 def setup
50 def setup
51 @controller = IssuesController.new
51 @controller = IssuesController.new
52 @request = ActionController::TestRequest.new
52 @request = ActionController::TestRequest.new
53 @response = ActionController::TestResponse.new
53 @response = ActionController::TestResponse.new
54 User.current = nil
54 User.current = nil
55 end
55 end
56
56
57 def test_index
57 def test_index
58 with_settings :default_language => "en" do
58 with_settings :default_language => "en" do
59 get :index
59 get :index
60 assert_response :success
60 assert_response :success
61 assert_template 'index'
61 assert_template 'index'
62 assert_not_nil assigns(:issues)
62 assert_not_nil assigns(:issues)
63 assert_nil assigns(:project)
63 assert_nil assigns(:project)
64 assert_tag :tag => 'a', :content => /Can't print recipes/
64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 assert_tag :tag => 'a', :content => /Subproject issue/
65 assert_tag :tag => 'a', :content => /Subproject issue/
66 # private projects hidden
66 # private projects hidden
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 # project column
69 # project column
70 assert_tag :tag => 'th', :content => /Project/
70 assert_tag :tag => 'th', :content => /Project/
71 end
71 end
72 end
72 end
73
73
74 def test_index_should_not_list_issues_when_module_disabled
74 def test_index_should_not_list_issues_when_module_disabled
75 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
76 get :index
76 get :index
77 assert_response :success
77 assert_response :success
78 assert_template 'index'
78 assert_template 'index'
79 assert_not_nil assigns(:issues)
79 assert_not_nil assigns(:issues)
80 assert_nil assigns(:project)
80 assert_nil assigns(:project)
81 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 assert_no_tag :tag => 'a', :content => /Can't print recipes/
82 assert_tag :tag => 'a', :content => /Subproject issue/
82 assert_tag :tag => 'a', :content => /Subproject issue/
83 end
83 end
84
84
85 def test_index_should_list_visible_issues_only
85 def test_index_should_list_visible_issues_only
86 get :index, :per_page => 100
86 get :index, :per_page => 100
87 assert_response :success
87 assert_response :success
88 assert_not_nil assigns(:issues)
88 assert_not_nil assigns(:issues)
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
90 end
90 end
91
91
92 def test_index_with_project
92 def test_index_with_project
93 Setting.display_subprojects_issues = 0
93 Setting.display_subprojects_issues = 0
94 get :index, :project_id => 1
94 get :index, :project_id => 1
95 assert_response :success
95 assert_response :success
96 assert_template 'index'
96 assert_template 'index'
97 assert_not_nil assigns(:issues)
97 assert_not_nil assigns(:issues)
98 assert_tag :tag => 'a', :content => /Can't print recipes/
98 assert_tag :tag => 'a', :content => /Can't print recipes/
99 assert_no_tag :tag => 'a', :content => /Subproject issue/
99 assert_no_tag :tag => 'a', :content => /Subproject issue/
100 end
100 end
101
101
102 def test_index_with_project_and_subprojects
102 def test_index_with_project_and_subprojects
103 Setting.display_subprojects_issues = 1
103 Setting.display_subprojects_issues = 1
104 get :index, :project_id => 1
104 get :index, :project_id => 1
105 assert_response :success
105 assert_response :success
106 assert_template 'index'
106 assert_template 'index'
107 assert_not_nil assigns(:issues)
107 assert_not_nil assigns(:issues)
108 assert_tag :tag => 'a', :content => /Can't print recipes/
108 assert_tag :tag => 'a', :content => /Can't print recipes/
109 assert_tag :tag => 'a', :content => /Subproject issue/
109 assert_tag :tag => 'a', :content => /Subproject issue/
110 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
110 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
111 end
111 end
112
112
113 def test_index_with_project_and_subprojects_should_show_private_subprojects
113 def test_index_with_project_and_subprojects_should_show_private_subprojects
114 @request.session[:user_id] = 2
114 @request.session[:user_id] = 2
115 Setting.display_subprojects_issues = 1
115 Setting.display_subprojects_issues = 1
116 get :index, :project_id => 1
116 get :index, :project_id => 1
117 assert_response :success
117 assert_response :success
118 assert_template 'index'
118 assert_template 'index'
119 assert_not_nil assigns(:issues)
119 assert_not_nil assigns(:issues)
120 assert_tag :tag => 'a', :content => /Can't print recipes/
120 assert_tag :tag => 'a', :content => /Can't print recipes/
121 assert_tag :tag => 'a', :content => /Subproject issue/
121 assert_tag :tag => 'a', :content => /Subproject issue/
122 assert_tag :tag => 'a', :content => /Issue of a private subproject/
122 assert_tag :tag => 'a', :content => /Issue of a private subproject/
123 end
123 end
124
124
125 def test_index_with_project_and_default_filter
125 def test_index_with_project_and_default_filter
126 get :index, :project_id => 1, :set_filter => 1
126 get :index, :project_id => 1, :set_filter => 1
127 assert_response :success
127 assert_response :success
128 assert_template 'index'
128 assert_template 'index'
129 assert_not_nil assigns(:issues)
129 assert_not_nil assigns(:issues)
130
130
131 query = assigns(:query)
131 query = assigns(:query)
132 assert_not_nil query
132 assert_not_nil query
133 # default filter
133 # default filter
134 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
134 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
135 end
135 end
136
136
137 def test_index_with_project_and_filter
137 def test_index_with_project_and_filter
138 get :index, :project_id => 1, :set_filter => 1,
138 get :index, :project_id => 1, :set_filter => 1,
139 :f => ['tracker_id'],
139 :f => ['tracker_id'],
140 :op => {'tracker_id' => '='},
140 :op => {'tracker_id' => '='},
141 :v => {'tracker_id' => ['1']}
141 :v => {'tracker_id' => ['1']}
142 assert_response :success
142 assert_response :success
143 assert_template 'index'
143 assert_template 'index'
144 assert_not_nil assigns(:issues)
144 assert_not_nil assigns(:issues)
145
145
146 query = assigns(:query)
146 query = assigns(:query)
147 assert_not_nil query
147 assert_not_nil query
148 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
148 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
149 end
149 end
150
150
151 def test_index_with_short_filters
151 def test_index_with_short_filters
152 to_test = {
152 to_test = {
153 'status_id' => {
153 'status_id' => {
154 'o' => { :op => 'o', :values => [''] },
154 'o' => { :op => 'o', :values => [''] },
155 'c' => { :op => 'c', :values => [''] },
155 'c' => { :op => 'c', :values => [''] },
156 '7' => { :op => '=', :values => ['7'] },
156 '7' => { :op => '=', :values => ['7'] },
157 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
157 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
158 '=7' => { :op => '=', :values => ['7'] },
158 '=7' => { :op => '=', :values => ['7'] },
159 '!3' => { :op => '!', :values => ['3'] },
159 '!3' => { :op => '!', :values => ['3'] },
160 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
160 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
161 'subject' => {
161 'subject' => {
162 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
162 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
163 'o' => { :op => '=', :values => ['o'] },
163 'o' => { :op => '=', :values => ['o'] },
164 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
164 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
165 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
165 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
166 'tracker_id' => {
166 'tracker_id' => {
167 '3' => { :op => '=', :values => ['3'] },
167 '3' => { :op => '=', :values => ['3'] },
168 '=3' => { :op => '=', :values => ['3'] }},
168 '=3' => { :op => '=', :values => ['3'] }},
169 'start_date' => {
169 'start_date' => {
170 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
171 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
171 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
172 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
172 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
173 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
173 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
174 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
174 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
175 '<t+2' => { :op => '<t+', :values => ['2'] },
175 '<t+2' => { :op => '<t+', :values => ['2'] },
176 '>t+2' => { :op => '>t+', :values => ['2'] },
176 '>t+2' => { :op => '>t+', :values => ['2'] },
177 't+2' => { :op => 't+', :values => ['2'] },
177 't+2' => { :op => 't+', :values => ['2'] },
178 't' => { :op => 't', :values => [''] },
178 't' => { :op => 't', :values => [''] },
179 'w' => { :op => 'w', :values => [''] },
179 'w' => { :op => 'w', :values => [''] },
180 '>t-2' => { :op => '>t-', :values => ['2'] },
180 '>t-2' => { :op => '>t-', :values => ['2'] },
181 '<t-2' => { :op => '<t-', :values => ['2'] },
181 '<t-2' => { :op => '<t-', :values => ['2'] },
182 't-2' => { :op => 't-', :values => ['2'] }},
182 't-2' => { :op => 't-', :values => ['2'] }},
183 'created_on' => {
183 'created_on' => {
184 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
184 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
185 '<t-2' => { :op => '<t-', :values => ['2'] },
185 '<t-2' => { :op => '<t-', :values => ['2'] },
186 '>t-2' => { :op => '>t-', :values => ['2'] },
186 '>t-2' => { :op => '>t-', :values => ['2'] },
187 't-2' => { :op => 't-', :values => ['2'] }},
187 't-2' => { :op => 't-', :values => ['2'] }},
188 'cf_1' => {
188 'cf_1' => {
189 'c' => { :op => '=', :values => ['c'] },
189 'c' => { :op => '=', :values => ['c'] },
190 '!c' => { :op => '!', :values => ['c'] },
190 '!c' => { :op => '!', :values => ['c'] },
191 '!*' => { :op => '!*', :values => [''] },
191 '!*' => { :op => '!*', :values => [''] },
192 '*' => { :op => '*', :values => [''] }},
192 '*' => { :op => '*', :values => [''] }},
193 'estimated_hours' => {
193 'estimated_hours' => {
194 '=13.4' => { :op => '=', :values => ['13.4'] },
194 '=13.4' => { :op => '=', :values => ['13.4'] },
195 '>=45' => { :op => '>=', :values => ['45'] },
195 '>=45' => { :op => '>=', :values => ['45'] },
196 '<=125' => { :op => '<=', :values => ['125'] },
196 '<=125' => { :op => '<=', :values => ['125'] },
197 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
197 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
198 '!*' => { :op => '!*', :values => [''] },
198 '!*' => { :op => '!*', :values => [''] },
199 '*' => { :op => '*', :values => [''] }}
199 '*' => { :op => '*', :values => [''] }}
200 }
200 }
201
201
202 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
202 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
203
203
204 to_test.each do |field, expression_and_expected|
204 to_test.each do |field, expression_and_expected|
205 expression_and_expected.each do |filter_expression, expected|
205 expression_and_expected.each do |filter_expression, expected|
206
206
207 get :index, :set_filter => 1, field => filter_expression
207 get :index, :set_filter => 1, field => filter_expression
208
208
209 assert_response :success
209 assert_response :success
210 assert_template 'index'
210 assert_template 'index'
211 assert_not_nil assigns(:issues)
211 assert_not_nil assigns(:issues)
212
212
213 query = assigns(:query)
213 query = assigns(:query)
214 assert_not_nil query
214 assert_not_nil query
215 assert query.has_filter?(field)
215 assert query.has_filter?(field)
216 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
216 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
217 end
217 end
218 end
218 end
219 end
219 end
220
220
221 def test_index_with_project_and_empty_filters
221 def test_index_with_project_and_empty_filters
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
223 assert_response :success
223 assert_response :success
224 assert_template 'index'
224 assert_template 'index'
225 assert_not_nil assigns(:issues)
225 assert_not_nil assigns(:issues)
226
226
227 query = assigns(:query)
227 query = assigns(:query)
228 assert_not_nil query
228 assert_not_nil query
229 # no filter
229 # no filter
230 assert_equal({}, query.filters)
230 assert_equal({}, query.filters)
231 end
231 end
232
232
233 def test_index_with_query
233 def test_index_with_query
234 get :index, :project_id => 1, :query_id => 5
234 get :index, :project_id => 1, :query_id => 5
235 assert_response :success
235 assert_response :success
236 assert_template 'index'
236 assert_template 'index'
237 assert_not_nil assigns(:issues)
237 assert_not_nil assigns(:issues)
238 assert_nil assigns(:issue_count_by_group)
238 assert_nil assigns(:issue_count_by_group)
239 end
239 end
240
240
241 def test_index_with_query_grouped_by_tracker
241 def test_index_with_query_grouped_by_tracker
242 get :index, :project_id => 1, :query_id => 6
242 get :index, :project_id => 1, :query_id => 6
243 assert_response :success
243 assert_response :success
244 assert_template 'index'
244 assert_template 'index'
245 assert_not_nil assigns(:issues)
245 assert_not_nil assigns(:issues)
246 assert_not_nil assigns(:issue_count_by_group)
246 assert_not_nil assigns(:issue_count_by_group)
247 end
247 end
248
248
249 def test_index_with_query_grouped_by_list_custom_field
249 def test_index_with_query_grouped_by_list_custom_field
250 get :index, :project_id => 1, :query_id => 9
250 get :index, :project_id => 1, :query_id => 9
251 assert_response :success
251 assert_response :success
252 assert_template 'index'
252 assert_template 'index'
253 assert_not_nil assigns(:issues)
253 assert_not_nil assigns(:issues)
254 assert_not_nil assigns(:issue_count_by_group)
254 assert_not_nil assigns(:issue_count_by_group)
255 end
255 end
256
256
257 def test_index_with_query_id_and_project_id_should_set_session_query
257 def test_index_with_query_id_and_project_id_should_set_session_query
258 get :index, :project_id => 1, :query_id => 4
258 get :index, :project_id => 1, :query_id => 4
259 assert_response :success
259 assert_response :success
260 assert_kind_of Hash, session[:query]
260 assert_kind_of Hash, session[:query]
261 assert_equal 4, session[:query][:id]
261 assert_equal 4, session[:query][:id]
262 assert_equal 1, session[:query][:project_id]
262 assert_equal 1, session[:query][:project_id]
263 end
263 end
264
264
265 def test_index_with_invalid_query_id_should_respond_404
265 def test_index_with_invalid_query_id_should_respond_404
266 get :index, :project_id => 1, :query_id => 999
266 get :index, :project_id => 1, :query_id => 999
267 assert_response 404
267 assert_response 404
268 end
268 end
269
269
270 def test_index_with_cross_project_query_in_session_should_show_project_issues
270 def test_index_with_cross_project_query_in_session_should_show_project_issues
271 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
271 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
272 @request.session[:query] = {:id => q.id, :project_id => 1}
272 @request.session[:query] = {:id => q.id, :project_id => 1}
273
273
274 with_settings :display_subprojects_issues => '0' do
274 with_settings :display_subprojects_issues => '0' do
275 get :index, :project_id => 1
275 get :index, :project_id => 1
276 end
276 end
277 assert_response :success
277 assert_response :success
278 assert_not_nil assigns(:query)
278 assert_not_nil assigns(:query)
279 assert_equal q.id, assigns(:query).id
279 assert_equal q.id, assigns(:query).id
280 assert_equal 1, assigns(:query).project_id
280 assert_equal 1, assigns(:query).project_id
281 assert_equal [1], assigns(:issues).map(&:project_id).uniq
281 assert_equal [1], assigns(:issues).map(&:project_id).uniq
282 end
282 end
283
283
284 def test_private_query_should_not_be_available_to_other_users
284 def test_private_query_should_not_be_available_to_other_users
285 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
285 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
286 @request.session[:user_id] = 3
286 @request.session[:user_id] = 3
287
287
288 get :index, :query_id => q.id
288 get :index, :query_id => q.id
289 assert_response 403
289 assert_response 403
290 end
290 end
291
291
292 def test_private_query_should_be_available_to_its_user
292 def test_private_query_should_be_available_to_its_user
293 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
293 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
294 @request.session[:user_id] = 2
294 @request.session[:user_id] = 2
295
295
296 get :index, :query_id => q.id
296 get :index, :query_id => q.id
297 assert_response :success
297 assert_response :success
298 end
298 end
299
299
300 def test_public_query_should_be_available_to_other_users
300 def test_public_query_should_be_available_to_other_users
301 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
301 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
302 @request.session[:user_id] = 3
302 @request.session[:user_id] = 3
303
303
304 get :index, :query_id => q.id
304 get :index, :query_id => q.id
305 assert_response :success
305 assert_response :success
306 end
306 end
307
307
308 def test_index_should_omit_page_param_in_export_links
309 get :index, :page => 2
310 assert_response :success
311 assert_select 'a.atom[href=/issues.atom]'
312 assert_select 'a.csv[href=/issues.csv]'
313 assert_select 'a.pdf[href=/issues.pdf]'
314 assert_select 'form#csv-export-form[action=/issues.csv]'
315 end
316
308 def test_index_csv
317 def test_index_csv
309 get :index, :format => 'csv'
318 get :index, :format => 'csv'
310 assert_response :success
319 assert_response :success
311 assert_not_nil assigns(:issues)
320 assert_not_nil assigns(:issues)
312 assert_equal 'text/csv', @response.content_type
321 assert_equal 'text/csv', @response.content_type
313 assert @response.body.starts_with?("#,")
322 assert @response.body.starts_with?("#,")
314 lines = @response.body.chomp.split("\n")
323 lines = @response.body.chomp.split("\n")
315 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
324 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
316 end
325 end
317
326
318 def test_index_csv_with_project
327 def test_index_csv_with_project
319 get :index, :project_id => 1, :format => 'csv'
328 get :index, :project_id => 1, :format => 'csv'
320 assert_response :success
329 assert_response :success
321 assert_not_nil assigns(:issues)
330 assert_not_nil assigns(:issues)
322 assert_equal 'text/csv', @response.content_type
331 assert_equal 'text/csv', @response.content_type
323 end
332 end
324
333
325 def test_index_csv_with_description
334 def test_index_csv_with_description
326 get :index, :format => 'csv', :description => '1'
335 get :index, :format => 'csv', :description => '1'
327 assert_response :success
336 assert_response :success
328 assert_not_nil assigns(:issues)
337 assert_not_nil assigns(:issues)
329 assert_equal 'text/csv', @response.content_type
338 assert_equal 'text/csv', @response.content_type
330 assert @response.body.starts_with?("#,")
339 assert @response.body.starts_with?("#,")
331 lines = @response.body.chomp.split("\n")
340 lines = @response.body.chomp.split("\n")
332 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
341 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
333 end
342 end
334
343
335 def test_index_csv_with_spent_time_column
344 def test_index_csv_with_spent_time_column
336 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
345 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
337 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
346 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
338
347
339 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
348 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
340 assert_response :success
349 assert_response :success
341 assert_equal 'text/csv', @response.content_type
350 assert_equal 'text/csv', @response.content_type
342 lines = @response.body.chomp.split("\n")
351 lines = @response.body.chomp.split("\n")
343 assert_include "#{issue.id},#{issue.subject},7.33", lines
352 assert_include "#{issue.id},#{issue.subject},7.33", lines
344 end
353 end
345
354
346 def test_index_csv_with_all_columns
355 def test_index_csv_with_all_columns
347 get :index, :format => 'csv', :columns => 'all'
356 get :index, :format => 'csv', :columns => 'all'
348 assert_response :success
357 assert_response :success
349 assert_not_nil assigns(:issues)
358 assert_not_nil assigns(:issues)
350 assert_equal 'text/csv', @response.content_type
359 assert_equal 'text/csv', @response.content_type
351 assert @response.body.starts_with?("#,")
360 assert @response.body.starts_with?("#,")
352 lines = @response.body.chomp.split("\n")
361 lines = @response.body.chomp.split("\n")
353 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
362 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
354 end
363 end
355
364
356 def test_index_csv_with_multi_column_field
365 def test_index_csv_with_multi_column_field
357 CustomField.find(1).update_attribute :multiple, true
366 CustomField.find(1).update_attribute :multiple, true
358 issue = Issue.find(1)
367 issue = Issue.find(1)
359 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
368 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
360 issue.save!
369 issue.save!
361
370
362 get :index, :format => 'csv', :columns => 'all'
371 get :index, :format => 'csv', :columns => 'all'
363 assert_response :success
372 assert_response :success
364 lines = @response.body.chomp.split("\n")
373 lines = @response.body.chomp.split("\n")
365 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
374 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
366 end
375 end
367
376
368 def test_index_csv_big_5
377 def test_index_csv_big_5
369 with_settings :default_language => "zh-TW" do
378 with_settings :default_language => "zh-TW" do
370 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
379 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
371 str_big5 = "\xa4@\xa4\xeb"
380 str_big5 = "\xa4@\xa4\xeb"
372 if str_utf8.respond_to?(:force_encoding)
381 if str_utf8.respond_to?(:force_encoding)
373 str_utf8.force_encoding('UTF-8')
382 str_utf8.force_encoding('UTF-8')
374 str_big5.force_encoding('Big5')
383 str_big5.force_encoding('Big5')
375 end
384 end
376 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
385 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
377 :status_id => 1, :priority => IssuePriority.all.first,
386 :status_id => 1, :priority => IssuePriority.all.first,
378 :subject => str_utf8)
387 :subject => str_utf8)
379 assert issue.save
388 assert issue.save
380
389
381 get :index, :project_id => 1,
390 get :index, :project_id => 1,
382 :f => ['subject'],
391 :f => ['subject'],
383 :op => '=', :values => [str_utf8],
392 :op => '=', :values => [str_utf8],
384 :format => 'csv'
393 :format => 'csv'
385 assert_equal 'text/csv', @response.content_type
394 assert_equal 'text/csv', @response.content_type
386 lines = @response.body.chomp.split("\n")
395 lines = @response.body.chomp.split("\n")
387 s1 = "\xaa\xac\xbaA"
396 s1 = "\xaa\xac\xbaA"
388 if str_utf8.respond_to?(:force_encoding)
397 if str_utf8.respond_to?(:force_encoding)
389 s1.force_encoding('Big5')
398 s1.force_encoding('Big5')
390 end
399 end
391 assert lines[0].include?(s1)
400 assert lines[0].include?(s1)
392 assert lines[1].include?(str_big5)
401 assert lines[1].include?(str_big5)
393 end
402 end
394 end
403 end
395
404
396 def test_index_csv_cannot_convert_should_be_replaced_big_5
405 def test_index_csv_cannot_convert_should_be_replaced_big_5
397 with_settings :default_language => "zh-TW" do
406 with_settings :default_language => "zh-TW" do
398 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
407 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
399 if str_utf8.respond_to?(:force_encoding)
408 if str_utf8.respond_to?(:force_encoding)
400 str_utf8.force_encoding('UTF-8')
409 str_utf8.force_encoding('UTF-8')
401 end
410 end
402 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
411 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
403 :status_id => 1, :priority => IssuePriority.all.first,
412 :status_id => 1, :priority => IssuePriority.all.first,
404 :subject => str_utf8)
413 :subject => str_utf8)
405 assert issue.save
414 assert issue.save
406
415
407 get :index, :project_id => 1,
416 get :index, :project_id => 1,
408 :f => ['subject'],
417 :f => ['subject'],
409 :op => '=', :values => [str_utf8],
418 :op => '=', :values => [str_utf8],
410 :c => ['status', 'subject'],
419 :c => ['status', 'subject'],
411 :format => 'csv',
420 :format => 'csv',
412 :set_filter => 1
421 :set_filter => 1
413 assert_equal 'text/csv', @response.content_type
422 assert_equal 'text/csv', @response.content_type
414 lines = @response.body.chomp.split("\n")
423 lines = @response.body.chomp.split("\n")
415 s1 = "\xaa\xac\xbaA" # status
424 s1 = "\xaa\xac\xbaA" # status
416 if str_utf8.respond_to?(:force_encoding)
425 if str_utf8.respond_to?(:force_encoding)
417 s1.force_encoding('Big5')
426 s1.force_encoding('Big5')
418 end
427 end
419 assert lines[0].include?(s1)
428 assert lines[0].include?(s1)
420 s2 = lines[1].split(",")[2]
429 s2 = lines[1].split(",")[2]
421 if s1.respond_to?(:force_encoding)
430 if s1.respond_to?(:force_encoding)
422 s3 = "\xa5H?" # subject
431 s3 = "\xa5H?" # subject
423 s3.force_encoding('Big5')
432 s3.force_encoding('Big5')
424 assert_equal s3, s2
433 assert_equal s3, s2
425 elsif RUBY_PLATFORM == 'java'
434 elsif RUBY_PLATFORM == 'java'
426 assert_equal "??", s2
435 assert_equal "??", s2
427 else
436 else
428 assert_equal "\xa5H???", s2
437 assert_equal "\xa5H???", s2
429 end
438 end
430 end
439 end
431 end
440 end
432
441
433 def test_index_csv_tw
442 def test_index_csv_tw
434 with_settings :default_language => "zh-TW" do
443 with_settings :default_language => "zh-TW" do
435 str1 = "test_index_csv_tw"
444 str1 = "test_index_csv_tw"
436 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
445 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
437 :status_id => 1, :priority => IssuePriority.all.first,
446 :status_id => 1, :priority => IssuePriority.all.first,
438 :subject => str1, :estimated_hours => '1234.5')
447 :subject => str1, :estimated_hours => '1234.5')
439 assert issue.save
448 assert issue.save
440 assert_equal 1234.5, issue.estimated_hours
449 assert_equal 1234.5, issue.estimated_hours
441
450
442 get :index, :project_id => 1,
451 get :index, :project_id => 1,
443 :f => ['subject'],
452 :f => ['subject'],
444 :op => '=', :values => [str1],
453 :op => '=', :values => [str1],
445 :c => ['estimated_hours', 'subject'],
454 :c => ['estimated_hours', 'subject'],
446 :format => 'csv',
455 :format => 'csv',
447 :set_filter => 1
456 :set_filter => 1
448 assert_equal 'text/csv', @response.content_type
457 assert_equal 'text/csv', @response.content_type
449 lines = @response.body.chomp.split("\n")
458 lines = @response.body.chomp.split("\n")
450 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
459 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
451
460
452 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
461 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
453 if str_tw.respond_to?(:force_encoding)
462 if str_tw.respond_to?(:force_encoding)
454 str_tw.force_encoding('UTF-8')
463 str_tw.force_encoding('UTF-8')
455 end
464 end
456 assert_equal str_tw, l(:general_lang_name)
465 assert_equal str_tw, l(:general_lang_name)
457 assert_equal ',', l(:general_csv_separator)
466 assert_equal ',', l(:general_csv_separator)
458 assert_equal '.', l(:general_csv_decimal_separator)
467 assert_equal '.', l(:general_csv_decimal_separator)
459 end
468 end
460 end
469 end
461
470
462 def test_index_csv_fr
471 def test_index_csv_fr
463 with_settings :default_language => "fr" do
472 with_settings :default_language => "fr" do
464 str1 = "test_index_csv_fr"
473 str1 = "test_index_csv_fr"
465 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
474 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
466 :status_id => 1, :priority => IssuePriority.all.first,
475 :status_id => 1, :priority => IssuePriority.all.first,
467 :subject => str1, :estimated_hours => '1234.5')
476 :subject => str1, :estimated_hours => '1234.5')
468 assert issue.save
477 assert issue.save
469 assert_equal 1234.5, issue.estimated_hours
478 assert_equal 1234.5, issue.estimated_hours
470
479
471 get :index, :project_id => 1,
480 get :index, :project_id => 1,
472 :f => ['subject'],
481 :f => ['subject'],
473 :op => '=', :values => [str1],
482 :op => '=', :values => [str1],
474 :c => ['estimated_hours', 'subject'],
483 :c => ['estimated_hours', 'subject'],
475 :format => 'csv',
484 :format => 'csv',
476 :set_filter => 1
485 :set_filter => 1
477 assert_equal 'text/csv', @response.content_type
486 assert_equal 'text/csv', @response.content_type
478 lines = @response.body.chomp.split("\n")
487 lines = @response.body.chomp.split("\n")
479 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
488 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
480
489
481 str_fr = "Fran\xc3\xa7ais"
490 str_fr = "Fran\xc3\xa7ais"
482 if str_fr.respond_to?(:force_encoding)
491 if str_fr.respond_to?(:force_encoding)
483 str_fr.force_encoding('UTF-8')
492 str_fr.force_encoding('UTF-8')
484 end
493 end
485 assert_equal str_fr, l(:general_lang_name)
494 assert_equal str_fr, l(:general_lang_name)
486 assert_equal ';', l(:general_csv_separator)
495 assert_equal ';', l(:general_csv_separator)
487 assert_equal ',', l(:general_csv_decimal_separator)
496 assert_equal ',', l(:general_csv_decimal_separator)
488 end
497 end
489 end
498 end
490
499
491 def test_index_pdf
500 def test_index_pdf
492 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
501 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
493 with_settings :default_language => lang do
502 with_settings :default_language => lang do
494
503
495 get :index
504 get :index
496 assert_response :success
505 assert_response :success
497 assert_template 'index'
506 assert_template 'index'
498
507
499 if lang == "ja"
508 if lang == "ja"
500 if RUBY_PLATFORM != 'java'
509 if RUBY_PLATFORM != 'java'
501 assert_equal "CP932", l(:general_pdf_encoding)
510 assert_equal "CP932", l(:general_pdf_encoding)
502 end
511 end
503 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
512 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
504 next
513 next
505 end
514 end
506 end
515 end
507
516
508 get :index, :format => 'pdf'
517 get :index, :format => 'pdf'
509 assert_response :success
518 assert_response :success
510 assert_not_nil assigns(:issues)
519 assert_not_nil assigns(:issues)
511 assert_equal 'application/pdf', @response.content_type
520 assert_equal 'application/pdf', @response.content_type
512
521
513 get :index, :project_id => 1, :format => 'pdf'
522 get :index, :project_id => 1, :format => 'pdf'
514 assert_response :success
523 assert_response :success
515 assert_not_nil assigns(:issues)
524 assert_not_nil assigns(:issues)
516 assert_equal 'application/pdf', @response.content_type
525 assert_equal 'application/pdf', @response.content_type
517
526
518 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
527 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
519 assert_response :success
528 assert_response :success
520 assert_not_nil assigns(:issues)
529 assert_not_nil assigns(:issues)
521 assert_equal 'application/pdf', @response.content_type
530 assert_equal 'application/pdf', @response.content_type
522 end
531 end
523 end
532 end
524 end
533 end
525
534
526 def test_index_pdf_with_query_grouped_by_list_custom_field
535 def test_index_pdf_with_query_grouped_by_list_custom_field
527 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
536 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
528 assert_response :success
537 assert_response :success
529 assert_not_nil assigns(:issues)
538 assert_not_nil assigns(:issues)
530 assert_not_nil assigns(:issue_count_by_group)
539 assert_not_nil assigns(:issue_count_by_group)
531 assert_equal 'application/pdf', @response.content_type
540 assert_equal 'application/pdf', @response.content_type
532 end
541 end
533
542
534 def test_index_atom
543 def test_index_atom
535 get :index, :project_id => 'ecookbook', :format => 'atom'
544 get :index, :project_id => 'ecookbook', :format => 'atom'
536 assert_response :success
545 assert_response :success
537 assert_template 'common/feed'
546 assert_template 'common/feed'
538
547
539 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
548 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
540 :attributes => {:rel => 'self', :href => 'http://test.host/projects/ecookbook/issues.atom'}
549 :attributes => {:rel => 'self', :href => 'http://test.host/projects/ecookbook/issues.atom'}
541 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
550 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
542 :attributes => {:rel => 'alternate', :href => 'http://test.host/projects/ecookbook/issues'}
551 :attributes => {:rel => 'alternate', :href => 'http://test.host/projects/ecookbook/issues'}
543
552
544 assert_tag :tag => 'entry', :child => {
553 assert_tag :tag => 'entry', :child => {
545 :tag => 'link',
554 :tag => 'link',
546 :attributes => {:href => 'http://test.host/issues/1'}}
555 :attributes => {:href => 'http://test.host/issues/1'}}
547 end
556 end
548
557
549 def test_index_sort
558 def test_index_sort
550 get :index, :sort => 'tracker,id:desc'
559 get :index, :sort => 'tracker,id:desc'
551 assert_response :success
560 assert_response :success
552
561
553 sort_params = @request.session['issues_index_sort']
562 sort_params = @request.session['issues_index_sort']
554 assert sort_params.is_a?(String)
563 assert sort_params.is_a?(String)
555 assert_equal 'tracker,id:desc', sort_params
564 assert_equal 'tracker,id:desc', sort_params
556
565
557 issues = assigns(:issues)
566 issues = assigns(:issues)
558 assert_not_nil issues
567 assert_not_nil issues
559 assert !issues.empty?
568 assert !issues.empty?
560 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
569 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
561 end
570 end
562
571
563 def test_index_sort_by_field_not_included_in_columns
572 def test_index_sort_by_field_not_included_in_columns
564 Setting.issue_list_default_columns = %w(subject author)
573 Setting.issue_list_default_columns = %w(subject author)
565 get :index, :sort => 'tracker'
574 get :index, :sort => 'tracker'
566 end
575 end
567
576
568 def test_index_sort_by_assigned_to
577 def test_index_sort_by_assigned_to
569 get :index, :sort => 'assigned_to'
578 get :index, :sort => 'assigned_to'
570 assert_response :success
579 assert_response :success
571 assignees = assigns(:issues).collect(&:assigned_to).compact
580 assignees = assigns(:issues).collect(&:assigned_to).compact
572 assert_equal assignees.sort, assignees
581 assert_equal assignees.sort, assignees
573 end
582 end
574
583
575 def test_index_sort_by_assigned_to_desc
584 def test_index_sort_by_assigned_to_desc
576 get :index, :sort => 'assigned_to:desc'
585 get :index, :sort => 'assigned_to:desc'
577 assert_response :success
586 assert_response :success
578 assignees = assigns(:issues).collect(&:assigned_to).compact
587 assignees = assigns(:issues).collect(&:assigned_to).compact
579 assert_equal assignees.sort.reverse, assignees
588 assert_equal assignees.sort.reverse, assignees
580 end
589 end
581
590
582 def test_index_group_by_assigned_to
591 def test_index_group_by_assigned_to
583 get :index, :group_by => 'assigned_to', :sort => 'priority'
592 get :index, :group_by => 'assigned_to', :sort => 'priority'
584 assert_response :success
593 assert_response :success
585 end
594 end
586
595
587 def test_index_sort_by_author
596 def test_index_sort_by_author
588 get :index, :sort => 'author'
597 get :index, :sort => 'author'
589 assert_response :success
598 assert_response :success
590 authors = assigns(:issues).collect(&:author)
599 authors = assigns(:issues).collect(&:author)
591 assert_equal authors.sort, authors
600 assert_equal authors.sort, authors
592 end
601 end
593
602
594 def test_index_sort_by_author_desc
603 def test_index_sort_by_author_desc
595 get :index, :sort => 'author:desc'
604 get :index, :sort => 'author:desc'
596 assert_response :success
605 assert_response :success
597 authors = assigns(:issues).collect(&:author)
606 authors = assigns(:issues).collect(&:author)
598 assert_equal authors.sort.reverse, authors
607 assert_equal authors.sort.reverse, authors
599 end
608 end
600
609
601 def test_index_group_by_author
610 def test_index_group_by_author
602 get :index, :group_by => 'author', :sort => 'priority'
611 get :index, :group_by => 'author', :sort => 'priority'
603 assert_response :success
612 assert_response :success
604 end
613 end
605
614
606 def test_index_sort_by_spent_hours
615 def test_index_sort_by_spent_hours
607 get :index, :sort => 'spent_hours:desc'
616 get :index, :sort => 'spent_hours:desc'
608 assert_response :success
617 assert_response :success
609 hours = assigns(:issues).collect(&:spent_hours)
618 hours = assigns(:issues).collect(&:spent_hours)
610 assert_equal hours.sort.reverse, hours
619 assert_equal hours.sort.reverse, hours
611 end
620 end
612
621
613 def test_index_with_columns
622 def test_index_with_columns
614 columns = ['tracker', 'subject', 'assigned_to']
623 columns = ['tracker', 'subject', 'assigned_to']
615 get :index, :set_filter => 1, :c => columns
624 get :index, :set_filter => 1, :c => columns
616 assert_response :success
625 assert_response :success
617
626
618 # query should use specified columns
627 # query should use specified columns
619 query = assigns(:query)
628 query = assigns(:query)
620 assert_kind_of Query, query
629 assert_kind_of Query, query
621 assert_equal columns, query.column_names.map(&:to_s)
630 assert_equal columns, query.column_names.map(&:to_s)
622
631
623 # columns should be stored in session
632 # columns should be stored in session
624 assert_kind_of Hash, session[:query]
633 assert_kind_of Hash, session[:query]
625 assert_kind_of Array, session[:query][:column_names]
634 assert_kind_of Array, session[:query][:column_names]
626 assert_equal columns, session[:query][:column_names].map(&:to_s)
635 assert_equal columns, session[:query][:column_names].map(&:to_s)
627
636
628 # ensure only these columns are kept in the selected columns list
637 # ensure only these columns are kept in the selected columns list
629 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
638 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
630 :children => { :count => 3 }
639 :children => { :count => 3 }
631 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
640 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
632 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
641 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
633 end
642 end
634
643
635 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
644 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
636 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
645 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
637 get :index, :set_filter => 1
646 get :index, :set_filter => 1
638
647
639 # query should use specified columns
648 # query should use specified columns
640 query = assigns(:query)
649 query = assigns(:query)
641 assert_kind_of Query, query
650 assert_kind_of Query, query
642 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
651 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
643 end
652 end
644
653
645 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
654 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
646 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
655 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
647 columns = ['tracker', 'subject', 'assigned_to']
656 columns = ['tracker', 'subject', 'assigned_to']
648 get :index, :set_filter => 1, :c => columns
657 get :index, :set_filter => 1, :c => columns
649
658
650 # query should use specified columns
659 # query should use specified columns
651 query = assigns(:query)
660 query = assigns(:query)
652 assert_kind_of Query, query
661 assert_kind_of Query, query
653 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
662 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
654 end
663 end
655
664
656 def test_index_with_custom_field_column
665 def test_index_with_custom_field_column
657 columns = %w(tracker subject cf_2)
666 columns = %w(tracker subject cf_2)
658 get :index, :set_filter => 1, :c => columns
667 get :index, :set_filter => 1, :c => columns
659 assert_response :success
668 assert_response :success
660
669
661 # query should use specified columns
670 # query should use specified columns
662 query = assigns(:query)
671 query = assigns(:query)
663 assert_kind_of Query, query
672 assert_kind_of Query, query
664 assert_equal columns, query.column_names.map(&:to_s)
673 assert_equal columns, query.column_names.map(&:to_s)
665
674
666 assert_tag :td,
675 assert_tag :td,
667 :attributes => {:class => 'cf_2 string'},
676 :attributes => {:class => 'cf_2 string'},
668 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
677 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
669 end
678 end
670
679
671 def test_index_with_multi_custom_field_column
680 def test_index_with_multi_custom_field_column
672 field = CustomField.find(1)
681 field = CustomField.find(1)
673 field.update_attribute :multiple, true
682 field.update_attribute :multiple, true
674 issue = Issue.find(1)
683 issue = Issue.find(1)
675 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
684 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
676 issue.save!
685 issue.save!
677
686
678 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
687 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
679 assert_response :success
688 assert_response :success
680
689
681 assert_tag :td,
690 assert_tag :td,
682 :attributes => {:class => /cf_1/},
691 :attributes => {:class => /cf_1/},
683 :content => 'MySQL, Oracle'
692 :content => 'MySQL, Oracle'
684 end
693 end
685
694
686 def test_index_with_multi_user_custom_field_column
695 def test_index_with_multi_user_custom_field_column
687 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
696 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
688 :tracker_ids => [1], :is_for_all => true)
697 :tracker_ids => [1], :is_for_all => true)
689 issue = Issue.find(1)
698 issue = Issue.find(1)
690 issue.custom_field_values = {field.id => ['2', '3']}
699 issue.custom_field_values = {field.id => ['2', '3']}
691 issue.save!
700 issue.save!
692
701
693 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
702 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
694 assert_response :success
703 assert_response :success
695
704
696 assert_tag :td,
705 assert_tag :td,
697 :attributes => {:class => /cf_#{field.id}/},
706 :attributes => {:class => /cf_#{field.id}/},
698 :child => {:tag => 'a', :content => 'John Smith'}
707 :child => {:tag => 'a', :content => 'John Smith'}
699 end
708 end
700
709
701 def test_index_with_date_column
710 def test_index_with_date_column
702 Issue.find(1).update_attribute :start_date, '1987-08-24'
711 Issue.find(1).update_attribute :start_date, '1987-08-24'
703
712
704 with_settings :date_format => '%d/%m/%Y' do
713 with_settings :date_format => '%d/%m/%Y' do
705 get :index, :set_filter => 1, :c => %w(start_date)
714 get :index, :set_filter => 1, :c => %w(start_date)
706 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
715 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
707 end
716 end
708 end
717 end
709
718
710 def test_index_with_done_ratio
719 def test_index_with_done_ratio
711 Issue.find(1).update_attribute :done_ratio, 40
720 Issue.find(1).update_attribute :done_ratio, 40
712
721
713 get :index, :set_filter => 1, :c => %w(done_ratio)
722 get :index, :set_filter => 1, :c => %w(done_ratio)
714 assert_tag 'td', :attributes => {:class => /done_ratio/},
723 assert_tag 'td', :attributes => {:class => /done_ratio/},
715 :child => {:tag => 'table', :attributes => {:class => 'progress'},
724 :child => {:tag => 'table', :attributes => {:class => 'progress'},
716 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
725 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
717 }
726 }
718 end
727 end
719
728
720 def test_index_with_spent_hours_column
729 def test_index_with_spent_hours_column
721 get :index, :set_filter => 1, :c => %w(subject spent_hours)
730 get :index, :set_filter => 1, :c => %w(subject spent_hours)
722
731
723 assert_tag 'tr', :attributes => {:id => 'issue-3'},
732 assert_tag 'tr', :attributes => {:id => 'issue-3'},
724 :child => {
733 :child => {
725 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
734 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
726 }
735 }
727 end
736 end
728
737
729 def test_index_should_not_show_spent_hours_column_without_permission
738 def test_index_should_not_show_spent_hours_column_without_permission
730 Role.anonymous.remove_permission! :view_time_entries
739 Role.anonymous.remove_permission! :view_time_entries
731 get :index, :set_filter => 1, :c => %w(subject spent_hours)
740 get :index, :set_filter => 1, :c => %w(subject spent_hours)
732
741
733 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
742 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
734 end
743 end
735
744
736 def test_index_with_fixed_version
745 def test_index_with_fixed_version
737 get :index, :set_filter => 1, :c => %w(fixed_version)
746 get :index, :set_filter => 1, :c => %w(fixed_version)
738 assert_tag 'td', :attributes => {:class => /fixed_version/},
747 assert_tag 'td', :attributes => {:class => /fixed_version/},
739 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
748 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
740 end
749 end
741
750
742 def test_index_send_html_if_query_is_invalid
751 def test_index_send_html_if_query_is_invalid
743 get :index, :f => ['start_date'], :op => {:start_date => '='}
752 get :index, :f => ['start_date'], :op => {:start_date => '='}
744 assert_equal 'text/html', @response.content_type
753 assert_equal 'text/html', @response.content_type
745 assert_template 'index'
754 assert_template 'index'
746 end
755 end
747
756
748 def test_index_send_nothing_if_query_is_invalid
757 def test_index_send_nothing_if_query_is_invalid
749 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
758 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
750 assert_equal 'text/csv', @response.content_type
759 assert_equal 'text/csv', @response.content_type
751 assert @response.body.blank?
760 assert @response.body.blank?
752 end
761 end
753
762
754 def test_show_by_anonymous
763 def test_show_by_anonymous
755 get :show, :id => 1
764 get :show, :id => 1
756 assert_response :success
765 assert_response :success
757 assert_template 'show'
766 assert_template 'show'
758 assert_not_nil assigns(:issue)
767 assert_not_nil assigns(:issue)
759 assert_equal Issue.find(1), assigns(:issue)
768 assert_equal Issue.find(1), assigns(:issue)
760
769
761 # anonymous role is allowed to add a note
770 # anonymous role is allowed to add a note
762 assert_tag :tag => 'form',
771 assert_tag :tag => 'form',
763 :descendant => { :tag => 'fieldset',
772 :descendant => { :tag => 'fieldset',
764 :child => { :tag => 'legend',
773 :child => { :tag => 'legend',
765 :content => /Notes/ } }
774 :content => /Notes/ } }
766 assert_tag :tag => 'title',
775 assert_tag :tag => 'title',
767 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
776 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
768 end
777 end
769
778
770 def test_show_by_manager
779 def test_show_by_manager
771 @request.session[:user_id] = 2
780 @request.session[:user_id] = 2
772 get :show, :id => 1
781 get :show, :id => 1
773 assert_response :success
782 assert_response :success
774
783
775 assert_tag :tag => 'a',
784 assert_tag :tag => 'a',
776 :content => /Quote/
785 :content => /Quote/
777
786
778 assert_tag :tag => 'form',
787 assert_tag :tag => 'form',
779 :descendant => { :tag => 'fieldset',
788 :descendant => { :tag => 'fieldset',
780 :child => { :tag => 'legend',
789 :child => { :tag => 'legend',
781 :content => /Change properties/ } },
790 :content => /Change properties/ } },
782 :descendant => { :tag => 'fieldset',
791 :descendant => { :tag => 'fieldset',
783 :child => { :tag => 'legend',
792 :child => { :tag => 'legend',
784 :content => /Log time/ } },
793 :content => /Log time/ } },
785 :descendant => { :tag => 'fieldset',
794 :descendant => { :tag => 'fieldset',
786 :child => { :tag => 'legend',
795 :child => { :tag => 'legend',
787 :content => /Notes/ } }
796 :content => /Notes/ } }
788 end
797 end
789
798
790 def test_show_should_display_update_form
799 def test_show_should_display_update_form
791 @request.session[:user_id] = 2
800 @request.session[:user_id] = 2
792 get :show, :id => 1
801 get :show, :id => 1
793 assert_response :success
802 assert_response :success
794
803
795 assert_tag 'form', :attributes => {:id => 'issue-form'}
804 assert_tag 'form', :attributes => {:id => 'issue-form'}
796 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
805 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
797 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
806 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
798 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
807 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
799 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
808 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
800 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
809 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
801 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
810 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
802 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
811 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
803 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
812 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
804 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
813 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
805 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
814 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
806 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
815 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
807 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
816 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
808 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
817 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
809 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
818 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
810 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
819 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
811 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
820 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
812 assert_tag 'textarea', :attributes => {:name => 'notes'}
821 assert_tag 'textarea', :attributes => {:name => 'notes'}
813 end
822 end
814
823
815 def test_show_should_display_update_form_with_minimal_permissions
824 def test_show_should_display_update_form_with_minimal_permissions
816 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
825 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
817 Workflow.delete_all :role_id => 1
826 Workflow.delete_all :role_id => 1
818
827
819 @request.session[:user_id] = 2
828 @request.session[:user_id] = 2
820 get :show, :id => 1
829 get :show, :id => 1
821 assert_response :success
830 assert_response :success
822
831
823 assert_tag 'form', :attributes => {:id => 'issue-form'}
832 assert_tag 'form', :attributes => {:id => 'issue-form'}
824 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
833 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
825 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
834 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
826 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
835 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
827 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
836 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
828 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
837 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
829 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
838 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
830 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
839 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
831 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
840 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
832 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
841 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
833 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
842 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
834 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
843 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
835 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
844 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
836 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
845 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
837 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
846 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
838 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
847 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
839 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
848 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
840 assert_tag 'textarea', :attributes => {:name => 'notes'}
849 assert_tag 'textarea', :attributes => {:name => 'notes'}
841 end
850 end
842
851
843 def test_show_should_display_update_form_with_workflow_permissions
852 def test_show_should_display_update_form_with_workflow_permissions
844 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
853 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
845
854
846 @request.session[:user_id] = 2
855 @request.session[:user_id] = 2
847 get :show, :id => 1
856 get :show, :id => 1
848 assert_response :success
857 assert_response :success
849
858
850 assert_tag 'form', :attributes => {:id => 'issue-form'}
859 assert_tag 'form', :attributes => {:id => 'issue-form'}
851 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
860 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
852 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
861 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
853 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
862 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
854 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
863 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
855 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
864 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
856 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
865 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
857 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
866 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
858 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
867 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
859 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
868 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
860 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
869 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
861 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
870 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
862 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
871 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
863 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
872 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
864 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
873 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
865 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
874 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
866 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
875 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
867 assert_tag 'textarea', :attributes => {:name => 'notes'}
876 assert_tag 'textarea', :attributes => {:name => 'notes'}
868 end
877 end
869
878
870 def test_show_should_not_display_update_form_without_permissions
879 def test_show_should_not_display_update_form_without_permissions
871 Role.find(1).update_attribute :permissions, [:view_issues]
880 Role.find(1).update_attribute :permissions, [:view_issues]
872
881
873 @request.session[:user_id] = 2
882 @request.session[:user_id] = 2
874 get :show, :id => 1
883 get :show, :id => 1
875 assert_response :success
884 assert_response :success
876
885
877 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
886 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
878 end
887 end
879
888
880 def test_update_form_should_not_display_inactive_enumerations
889 def test_update_form_should_not_display_inactive_enumerations
881 @request.session[:user_id] = 2
890 @request.session[:user_id] = 2
882 get :show, :id => 1
891 get :show, :id => 1
883 assert_response :success
892 assert_response :success
884
893
885 assert ! IssuePriority.find(15).active?
894 assert ! IssuePriority.find(15).active?
886 assert_no_tag :option, :attributes => {:value => '15'},
895 assert_no_tag :option, :attributes => {:value => '15'},
887 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
896 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
888 end
897 end
889
898
890 def test_update_form_should_allow_attachment_upload
899 def test_update_form_should_allow_attachment_upload
891 @request.session[:user_id] = 2
900 @request.session[:user_id] = 2
892 get :show, :id => 1
901 get :show, :id => 1
893
902
894 assert_tag :tag => 'form',
903 assert_tag :tag => 'form',
895 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
904 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
896 :descendant => {
905 :descendant => {
897 :tag => 'input',
906 :tag => 'input',
898 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
907 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
899 }
908 }
900 end
909 end
901
910
902 def test_show_should_deny_anonymous_access_without_permission
911 def test_show_should_deny_anonymous_access_without_permission
903 Role.anonymous.remove_permission!(:view_issues)
912 Role.anonymous.remove_permission!(:view_issues)
904 get :show, :id => 1
913 get :show, :id => 1
905 assert_response :redirect
914 assert_response :redirect
906 end
915 end
907
916
908 def test_show_should_deny_anonymous_access_to_private_issue
917 def test_show_should_deny_anonymous_access_to_private_issue
909 Issue.update_all(["is_private = ?", true], "id = 1")
918 Issue.update_all(["is_private = ?", true], "id = 1")
910 get :show, :id => 1
919 get :show, :id => 1
911 assert_response :redirect
920 assert_response :redirect
912 end
921 end
913
922
914 def test_show_should_deny_non_member_access_without_permission
923 def test_show_should_deny_non_member_access_without_permission
915 Role.non_member.remove_permission!(:view_issues)
924 Role.non_member.remove_permission!(:view_issues)
916 @request.session[:user_id] = 9
925 @request.session[:user_id] = 9
917 get :show, :id => 1
926 get :show, :id => 1
918 assert_response 403
927 assert_response 403
919 end
928 end
920
929
921 def test_show_should_deny_non_member_access_to_private_issue
930 def test_show_should_deny_non_member_access_to_private_issue
922 Issue.update_all(["is_private = ?", true], "id = 1")
931 Issue.update_all(["is_private = ?", true], "id = 1")
923 @request.session[:user_id] = 9
932 @request.session[:user_id] = 9
924 get :show, :id => 1
933 get :show, :id => 1
925 assert_response 403
934 assert_response 403
926 end
935 end
927
936
928 def test_show_should_deny_member_access_without_permission
937 def test_show_should_deny_member_access_without_permission
929 Role.find(1).remove_permission!(:view_issues)
938 Role.find(1).remove_permission!(:view_issues)
930 @request.session[:user_id] = 2
939 @request.session[:user_id] = 2
931 get :show, :id => 1
940 get :show, :id => 1
932 assert_response 403
941 assert_response 403
933 end
942 end
934
943
935 def test_show_should_deny_member_access_to_private_issue_without_permission
944 def test_show_should_deny_member_access_to_private_issue_without_permission
936 Issue.update_all(["is_private = ?", true], "id = 1")
945 Issue.update_all(["is_private = ?", true], "id = 1")
937 @request.session[:user_id] = 3
946 @request.session[:user_id] = 3
938 get :show, :id => 1
947 get :show, :id => 1
939 assert_response 403
948 assert_response 403
940 end
949 end
941
950
942 def test_show_should_allow_author_access_to_private_issue
951 def test_show_should_allow_author_access_to_private_issue
943 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
952 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
944 @request.session[:user_id] = 3
953 @request.session[:user_id] = 3
945 get :show, :id => 1
954 get :show, :id => 1
946 assert_response :success
955 assert_response :success
947 end
956 end
948
957
949 def test_show_should_allow_assignee_access_to_private_issue
958 def test_show_should_allow_assignee_access_to_private_issue
950 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
959 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
951 @request.session[:user_id] = 3
960 @request.session[:user_id] = 3
952 get :show, :id => 1
961 get :show, :id => 1
953 assert_response :success
962 assert_response :success
954 end
963 end
955
964
956 def test_show_should_allow_member_access_to_private_issue_with_permission
965 def test_show_should_allow_member_access_to_private_issue_with_permission
957 Issue.update_all(["is_private = ?", true], "id = 1")
966 Issue.update_all(["is_private = ?", true], "id = 1")
958 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
967 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
959 @request.session[:user_id] = 3
968 @request.session[:user_id] = 3
960 get :show, :id => 1
969 get :show, :id => 1
961 assert_response :success
970 assert_response :success
962 end
971 end
963
972
964 def test_show_should_not_disclose_relations_to_invisible_issues
973 def test_show_should_not_disclose_relations_to_invisible_issues
965 Setting.cross_project_issue_relations = '1'
974 Setting.cross_project_issue_relations = '1'
966 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
975 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
967 # Relation to a private project issue
976 # Relation to a private project issue
968 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
977 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
969
978
970 get :show, :id => 1
979 get :show, :id => 1
971 assert_response :success
980 assert_response :success
972
981
973 assert_tag :div, :attributes => { :id => 'relations' },
982 assert_tag :div, :attributes => { :id => 'relations' },
974 :descendant => { :tag => 'a', :content => /#2$/ }
983 :descendant => { :tag => 'a', :content => /#2$/ }
975 assert_no_tag :div, :attributes => { :id => 'relations' },
984 assert_no_tag :div, :attributes => { :id => 'relations' },
976 :descendant => { :tag => 'a', :content => /#4$/ }
985 :descendant => { :tag => 'a', :content => /#4$/ }
977 end
986 end
978
987
979 def test_show_should_list_subtasks
988 def test_show_should_list_subtasks
980 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
989 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
981
990
982 get :show, :id => 1
991 get :show, :id => 1
983 assert_response :success
992 assert_response :success
984 assert_tag 'div', :attributes => {:id => 'issue_tree'},
993 assert_tag 'div', :attributes => {:id => 'issue_tree'},
985 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
994 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
986 end
995 end
987
996
988 def test_show_should_list_parents
997 def test_show_should_list_parents
989 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
998 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
990
999
991 get :show, :id => issue.id
1000 get :show, :id => issue.id
992 assert_response :success
1001 assert_response :success
993 assert_tag 'div', :attributes => {:class => 'subject'},
1002 assert_tag 'div', :attributes => {:class => 'subject'},
994 :descendant => {:tag => 'h3', :content => 'Child Issue'}
1003 :descendant => {:tag => 'h3', :content => 'Child Issue'}
995 assert_tag 'div', :attributes => {:class => 'subject'},
1004 assert_tag 'div', :attributes => {:class => 'subject'},
996 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
1005 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
997 end
1006 end
998
1007
999 def test_show_should_not_display_prev_next_links_without_query_in_session
1008 def test_show_should_not_display_prev_next_links_without_query_in_session
1000 get :show, :id => 1
1009 get :show, :id => 1
1001 assert_response :success
1010 assert_response :success
1002 assert_nil assigns(:prev_issue_id)
1011 assert_nil assigns(:prev_issue_id)
1003 assert_nil assigns(:next_issue_id)
1012 assert_nil assigns(:next_issue_id)
1004
1013
1005 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
1014 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
1006 end
1015 end
1007
1016
1008 def test_show_should_display_prev_next_links_with_query_in_session
1017 def test_show_should_display_prev_next_links_with_query_in_session
1009 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1018 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1010 @request.session['issues_index_sort'] = 'id'
1019 @request.session['issues_index_sort'] = 'id'
1011
1020
1012 with_settings :display_subprojects_issues => '0' do
1021 with_settings :display_subprojects_issues => '0' do
1013 get :show, :id => 3
1022 get :show, :id => 3
1014 end
1023 end
1015
1024
1016 assert_response :success
1025 assert_response :success
1017 # Previous and next issues for all projects
1026 # Previous and next issues for all projects
1018 assert_equal 2, assigns(:prev_issue_id)
1027 assert_equal 2, assigns(:prev_issue_id)
1019 assert_equal 5, assigns(:next_issue_id)
1028 assert_equal 5, assigns(:next_issue_id)
1020
1029
1021 assert_tag 'div', :attributes => {:class => /next-prev-links/}
1030 assert_tag 'div', :attributes => {:class => /next-prev-links/}
1022 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1031 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1023 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
1032 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
1024
1033
1025 count = Issue.open.visible.count
1034 count = Issue.open.visible.count
1026 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
1035 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
1027 end
1036 end
1028
1037
1029 def test_show_should_display_prev_next_links_with_saved_query_in_session
1038 def test_show_should_display_prev_next_links_with_saved_query_in_session
1030 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1039 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1031 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1040 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1032 :sort_criteria => [['id', 'asc']])
1041 :sort_criteria => [['id', 'asc']])
1033 @request.session[:query] = {:id => query.id, :project_id => nil}
1042 @request.session[:query] = {:id => query.id, :project_id => nil}
1034
1043
1035 get :show, :id => 11
1044 get :show, :id => 11
1036
1045
1037 assert_response :success
1046 assert_response :success
1038 assert_equal query, assigns(:query)
1047 assert_equal query, assigns(:query)
1039 # Previous and next issues for all projects
1048 # Previous and next issues for all projects
1040 assert_equal 8, assigns(:prev_issue_id)
1049 assert_equal 8, assigns(:prev_issue_id)
1041 assert_equal 12, assigns(:next_issue_id)
1050 assert_equal 12, assigns(:next_issue_id)
1042
1051
1043 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
1052 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
1044 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
1053 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
1045 end
1054 end
1046
1055
1047 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1056 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1048 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1057 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1049
1058
1050 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1059 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1051 @request.session['issues_index_sort'] = assoc_sort
1060 @request.session['issues_index_sort'] = assoc_sort
1052
1061
1053 get :show, :id => 3
1062 get :show, :id => 3
1054 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1063 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1055
1064
1056 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/
1065 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/
1057 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/
1066 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/
1058 end
1067 end
1059 end
1068 end
1060
1069
1061 def test_show_should_display_prev_next_links_with_project_query_in_session
1070 def test_show_should_display_prev_next_links_with_project_query_in_session
1062 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1071 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1063 @request.session['issues_index_sort'] = 'id'
1072 @request.session['issues_index_sort'] = 'id'
1064
1073
1065 with_settings :display_subprojects_issues => '0' do
1074 with_settings :display_subprojects_issues => '0' do
1066 get :show, :id => 3
1075 get :show, :id => 3
1067 end
1076 end
1068
1077
1069 assert_response :success
1078 assert_response :success
1070 # Previous and next issues inside project
1079 # Previous and next issues inside project
1071 assert_equal 2, assigns(:prev_issue_id)
1080 assert_equal 2, assigns(:prev_issue_id)
1072 assert_equal 7, assigns(:next_issue_id)
1081 assert_equal 7, assigns(:next_issue_id)
1073
1082
1074 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1083 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1075 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1084 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1076 end
1085 end
1077
1086
1078 def test_show_should_not_display_prev_link_for_first_issue
1087 def test_show_should_not_display_prev_link_for_first_issue
1079 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1088 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1080 @request.session['issues_index_sort'] = 'id'
1089 @request.session['issues_index_sort'] = 'id'
1081
1090
1082 with_settings :display_subprojects_issues => '0' do
1091 with_settings :display_subprojects_issues => '0' do
1083 get :show, :id => 1
1092 get :show, :id => 1
1084 end
1093 end
1085
1094
1086 assert_response :success
1095 assert_response :success
1087 assert_nil assigns(:prev_issue_id)
1096 assert_nil assigns(:prev_issue_id)
1088 assert_equal 2, assigns(:next_issue_id)
1097 assert_equal 2, assigns(:next_issue_id)
1089
1098
1090 assert_no_tag 'a', :content => /Previous/
1099 assert_no_tag 'a', :content => /Previous/
1091 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1100 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1092 end
1101 end
1093
1102
1094 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1103 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1095 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1104 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1096 @request.session['issues_index_sort'] = 'id'
1105 @request.session['issues_index_sort'] = 'id'
1097
1106
1098 get :show, :id => 1
1107 get :show, :id => 1
1099
1108
1100 assert_response :success
1109 assert_response :success
1101 assert_nil assigns(:prev_issue_id)
1110 assert_nil assigns(:prev_issue_id)
1102 assert_nil assigns(:next_issue_id)
1111 assert_nil assigns(:next_issue_id)
1103
1112
1104 assert_no_tag 'a', :content => /Previous/
1113 assert_no_tag 'a', :content => /Previous/
1105 assert_no_tag 'a', :content => /Next/
1114 assert_no_tag 'a', :content => /Next/
1106 end
1115 end
1107
1116
1108 def test_show_should_display_visible_changesets_from_other_projects
1117 def test_show_should_display_visible_changesets_from_other_projects
1109 project = Project.find(2)
1118 project = Project.find(2)
1110 issue = project.issues.first
1119 issue = project.issues.first
1111 issue.changeset_ids = [102]
1120 issue.changeset_ids = [102]
1112 issue.save!
1121 issue.save!
1113 project.disable_module! :repository
1122 project.disable_module! :repository
1114
1123
1115 @request.session[:user_id] = 2
1124 @request.session[:user_id] = 2
1116 get :show, :id => issue.id
1125 get :show, :id => issue.id
1117 assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
1126 assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
1118 end
1127 end
1119
1128
1120 def test_show_with_multi_custom_field
1129 def test_show_with_multi_custom_field
1121 field = CustomField.find(1)
1130 field = CustomField.find(1)
1122 field.update_attribute :multiple, true
1131 field.update_attribute :multiple, true
1123 issue = Issue.find(1)
1132 issue = Issue.find(1)
1124 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1133 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1125 issue.save!
1134 issue.save!
1126
1135
1127 get :show, :id => 1
1136 get :show, :id => 1
1128 assert_response :success
1137 assert_response :success
1129
1138
1130 assert_tag :td, :content => 'MySQL, Oracle'
1139 assert_tag :td, :content => 'MySQL, Oracle'
1131 end
1140 end
1132
1141
1133 def test_show_with_multi_user_custom_field
1142 def test_show_with_multi_user_custom_field
1134 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1143 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1135 :tracker_ids => [1], :is_for_all => true)
1144 :tracker_ids => [1], :is_for_all => true)
1136 issue = Issue.find(1)
1145 issue = Issue.find(1)
1137 issue.custom_field_values = {field.id => ['2', '3']}
1146 issue.custom_field_values = {field.id => ['2', '3']}
1138 issue.save!
1147 issue.save!
1139
1148
1140 get :show, :id => 1
1149 get :show, :id => 1
1141 assert_response :success
1150 assert_response :success
1142
1151
1143 # TODO: should display links
1152 # TODO: should display links
1144 assert_tag :td, :content => 'Dave Lopper, John Smith'
1153 assert_tag :td, :content => 'Dave Lopper, John Smith'
1145 end
1154 end
1146
1155
1147 def test_show_atom
1156 def test_show_atom
1148 get :show, :id => 2, :format => 'atom'
1157 get :show, :id => 2, :format => 'atom'
1149 assert_response :success
1158 assert_response :success
1150 assert_template 'journals/index'
1159 assert_template 'journals/index'
1151 # Inline image
1160 # Inline image
1152 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1161 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1153 end
1162 end
1154
1163
1155 def test_show_export_to_pdf
1164 def test_show_export_to_pdf
1156 get :show, :id => 3, :format => 'pdf'
1165 get :show, :id => 3, :format => 'pdf'
1157 assert_response :success
1166 assert_response :success
1158 assert_equal 'application/pdf', @response.content_type
1167 assert_equal 'application/pdf', @response.content_type
1159 assert @response.body.starts_with?('%PDF')
1168 assert @response.body.starts_with?('%PDF')
1160 assert_not_nil assigns(:issue)
1169 assert_not_nil assigns(:issue)
1161 end
1170 end
1162
1171
1163 def test_get_new
1172 def test_get_new
1164 @request.session[:user_id] = 2
1173 @request.session[:user_id] = 2
1165 get :new, :project_id => 1, :tracker_id => 1
1174 get :new, :project_id => 1, :tracker_id => 1
1166 assert_response :success
1175 assert_response :success
1167 assert_template 'new'
1176 assert_template 'new'
1168
1177
1169 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1178 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1170 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1179 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1171 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1180 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1172 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1181 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1173 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1182 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1174 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1183 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1175 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1184 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1176 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1185 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1177 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1186 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1178 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1187 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1179 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1188 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1180 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1189 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1181 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1190 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1182 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1191 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1183 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1192 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1184 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1193 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1185
1194
1186 # Be sure we don't display inactive IssuePriorities
1195 # Be sure we don't display inactive IssuePriorities
1187 assert ! IssuePriority.find(15).active?
1196 assert ! IssuePriority.find(15).active?
1188 assert_no_tag :option, :attributes => {:value => '15'},
1197 assert_no_tag :option, :attributes => {:value => '15'},
1189 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1198 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1190 end
1199 end
1191
1200
1192 def test_get_new_with_minimal_permissions
1201 def test_get_new_with_minimal_permissions
1193 Role.find(1).update_attribute :permissions, [:add_issues]
1202 Role.find(1).update_attribute :permissions, [:add_issues]
1194 Workflow.delete_all :role_id => 1
1203 Workflow.delete_all :role_id => 1
1195
1204
1196 @request.session[:user_id] = 2
1205 @request.session[:user_id] = 2
1197 get :new, :project_id => 1, :tracker_id => 1
1206 get :new, :project_id => 1, :tracker_id => 1
1198 assert_response :success
1207 assert_response :success
1199 assert_template 'new'
1208 assert_template 'new'
1200
1209
1201 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1210 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1202 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1211 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1203 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1212 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1204 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1213 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1205 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1214 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1206 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1215 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1207 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1216 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1208 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1217 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1209 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1218 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1210 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1219 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1211 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1220 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1212 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1221 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1213 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1222 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1214 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1223 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1215 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1224 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1216 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1225 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1217 end
1226 end
1218
1227
1219 def test_get_new_with_list_custom_field
1228 def test_get_new_with_list_custom_field
1220 @request.session[:user_id] = 2
1229 @request.session[:user_id] = 2
1221 get :new, :project_id => 1, :tracker_id => 1
1230 get :new, :project_id => 1, :tracker_id => 1
1222 assert_response :success
1231 assert_response :success
1223 assert_template 'new'
1232 assert_template 'new'
1224
1233
1225 assert_tag 'select',
1234 assert_tag 'select',
1226 :attributes => {:name => 'issue[custom_field_values][1]'},
1235 :attributes => {:name => 'issue[custom_field_values][1]'},
1227 :children => {:count => 4},
1236 :children => {:count => 4},
1228 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1237 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1229 end
1238 end
1230
1239
1231 def test_get_new_with_multi_custom_field
1240 def test_get_new_with_multi_custom_field
1232 field = IssueCustomField.find(1)
1241 field = IssueCustomField.find(1)
1233 field.update_attribute :multiple, true
1242 field.update_attribute :multiple, true
1234
1243
1235 @request.session[:user_id] = 2
1244 @request.session[:user_id] = 2
1236 get :new, :project_id => 1, :tracker_id => 1
1245 get :new, :project_id => 1, :tracker_id => 1
1237 assert_response :success
1246 assert_response :success
1238 assert_template 'new'
1247 assert_template 'new'
1239
1248
1240 assert_tag 'select',
1249 assert_tag 'select',
1241 :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'},
1250 :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'},
1242 :children => {:count => 3},
1251 :children => {:count => 3},
1243 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1252 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1244 assert_tag 'input',
1253 assert_tag 'input',
1245 :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''}
1254 :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''}
1246 end
1255 end
1247
1256
1248 def test_get_new_with_multi_user_custom_field
1257 def test_get_new_with_multi_user_custom_field
1249 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1258 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1250 :tracker_ids => [1], :is_for_all => true)
1259 :tracker_ids => [1], :is_for_all => true)
1251
1260
1252 @request.session[:user_id] = 2
1261 @request.session[:user_id] = 2
1253 get :new, :project_id => 1, :tracker_id => 1
1262 get :new, :project_id => 1, :tracker_id => 1
1254 assert_response :success
1263 assert_response :success
1255 assert_template 'new'
1264 assert_template 'new'
1256
1265
1257 assert_tag 'select',
1266 assert_tag 'select',
1258 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'},
1267 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'},
1259 :children => {:count => Project.find(1).users.count},
1268 :children => {:count => Project.find(1).users.count},
1260 :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'}
1269 :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'}
1261 assert_tag 'input',
1270 assert_tag 'input',
1262 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''}
1271 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''}
1263 end
1272 end
1264
1273
1265 def test_get_new_without_default_start_date_is_creation_date
1274 def test_get_new_without_default_start_date_is_creation_date
1266 Setting.default_issue_start_date_to_creation_date = 0
1275 Setting.default_issue_start_date_to_creation_date = 0
1267
1276
1268 @request.session[:user_id] = 2
1277 @request.session[:user_id] = 2
1269 get :new, :project_id => 1, :tracker_id => 1
1278 get :new, :project_id => 1, :tracker_id => 1
1270 assert_response :success
1279 assert_response :success
1271 assert_template 'new'
1280 assert_template 'new'
1272
1281
1273 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1282 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1274 :value => nil }
1283 :value => nil }
1275 end
1284 end
1276
1285
1277 def test_get_new_with_default_start_date_is_creation_date
1286 def test_get_new_with_default_start_date_is_creation_date
1278 Setting.default_issue_start_date_to_creation_date = 1
1287 Setting.default_issue_start_date_to_creation_date = 1
1279
1288
1280 @request.session[:user_id] = 2
1289 @request.session[:user_id] = 2
1281 get :new, :project_id => 1, :tracker_id => 1
1290 get :new, :project_id => 1, :tracker_id => 1
1282 assert_response :success
1291 assert_response :success
1283 assert_template 'new'
1292 assert_template 'new'
1284
1293
1285 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1294 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1286 :value => Date.today.to_s }
1295 :value => Date.today.to_s }
1287 end
1296 end
1288
1297
1289 def test_get_new_form_should_allow_attachment_upload
1298 def test_get_new_form_should_allow_attachment_upload
1290 @request.session[:user_id] = 2
1299 @request.session[:user_id] = 2
1291 get :new, :project_id => 1, :tracker_id => 1
1300 get :new, :project_id => 1, :tracker_id => 1
1292
1301
1293 assert_tag :tag => 'form',
1302 assert_tag :tag => 'form',
1294 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1303 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1295 :descendant => {
1304 :descendant => {
1296 :tag => 'input',
1305 :tag => 'input',
1297 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1306 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1298 }
1307 }
1299 end
1308 end
1300
1309
1301 def test_get_new_should_prefill_the_form_from_params
1310 def test_get_new_should_prefill_the_form_from_params
1302 @request.session[:user_id] = 2
1311 @request.session[:user_id] = 2
1303 get :new, :project_id => 1,
1312 get :new, :project_id => 1,
1304 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1313 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1305
1314
1306 issue = assigns(:issue)
1315 issue = assigns(:issue)
1307 assert_equal 3, issue.tracker_id
1316 assert_equal 3, issue.tracker_id
1308 assert_equal 'Prefilled', issue.description
1317 assert_equal 'Prefilled', issue.description
1309 assert_equal 'Custom field value', issue.custom_field_value(2)
1318 assert_equal 'Custom field value', issue.custom_field_value(2)
1310
1319
1311 assert_tag 'select',
1320 assert_tag 'select',
1312 :attributes => {:name => 'issue[tracker_id]'},
1321 :attributes => {:name => 'issue[tracker_id]'},
1313 :child => {:tag => 'option', :attributes => {:value => '3', :selected => 'selected'}}
1322 :child => {:tag => 'option', :attributes => {:value => '3', :selected => 'selected'}}
1314 assert_tag 'textarea',
1323 assert_tag 'textarea',
1315 :attributes => {:name => 'issue[description]'}, :content => 'Prefilled'
1324 :attributes => {:name => 'issue[description]'}, :content => 'Prefilled'
1316 assert_tag 'input',
1325 assert_tag 'input',
1317 :attributes => {:name => 'issue[custom_field_values][2]', :value => 'Custom field value'}
1326 :attributes => {:name => 'issue[custom_field_values][2]', :value => 'Custom field value'}
1318 end
1327 end
1319
1328
1320 def test_get_new_without_tracker_id
1329 def test_get_new_without_tracker_id
1321 @request.session[:user_id] = 2
1330 @request.session[:user_id] = 2
1322 get :new, :project_id => 1
1331 get :new, :project_id => 1
1323 assert_response :success
1332 assert_response :success
1324 assert_template 'new'
1333 assert_template 'new'
1325
1334
1326 issue = assigns(:issue)
1335 issue = assigns(:issue)
1327 assert_not_nil issue
1336 assert_not_nil issue
1328 assert_equal Project.find(1).trackers.first, issue.tracker
1337 assert_equal Project.find(1).trackers.first, issue.tracker
1329 end
1338 end
1330
1339
1331 def test_get_new_with_no_default_status_should_display_an_error
1340 def test_get_new_with_no_default_status_should_display_an_error
1332 @request.session[:user_id] = 2
1341 @request.session[:user_id] = 2
1333 IssueStatus.delete_all
1342 IssueStatus.delete_all
1334
1343
1335 get :new, :project_id => 1
1344 get :new, :project_id => 1
1336 assert_response 500
1345 assert_response 500
1337 assert_error_tag :content => /No default issue/
1346 assert_error_tag :content => /No default issue/
1338 end
1347 end
1339
1348
1340 def test_get_new_with_no_tracker_should_display_an_error
1349 def test_get_new_with_no_tracker_should_display_an_error
1341 @request.session[:user_id] = 2
1350 @request.session[:user_id] = 2
1342 Tracker.delete_all
1351 Tracker.delete_all
1343
1352
1344 get :new, :project_id => 1
1353 get :new, :project_id => 1
1345 assert_response 500
1354 assert_response 500
1346 assert_error_tag :content => /No tracker/
1355 assert_error_tag :content => /No tracker/
1347 end
1356 end
1348
1357
1349 def test_update_new_form
1358 def test_update_new_form
1350 @request.session[:user_id] = 2
1359 @request.session[:user_id] = 2
1351 xhr :post, :new, :project_id => 1,
1360 xhr :post, :new, :project_id => 1,
1352 :issue => {:tracker_id => 2,
1361 :issue => {:tracker_id => 2,
1353 :subject => 'This is the test_new issue',
1362 :subject => 'This is the test_new issue',
1354 :description => 'This is the description',
1363 :description => 'This is the description',
1355 :priority_id => 5}
1364 :priority_id => 5}
1356 assert_response :success
1365 assert_response :success
1357 assert_template 'attributes'
1366 assert_template 'attributes'
1358
1367
1359 issue = assigns(:issue)
1368 issue = assigns(:issue)
1360 assert_kind_of Issue, issue
1369 assert_kind_of Issue, issue
1361 assert_equal 1, issue.project_id
1370 assert_equal 1, issue.project_id
1362 assert_equal 2, issue.tracker_id
1371 assert_equal 2, issue.tracker_id
1363 assert_equal 'This is the test_new issue', issue.subject
1372 assert_equal 'This is the test_new issue', issue.subject
1364 end
1373 end
1365
1374
1366 def test_post_create
1375 def test_post_create
1367 @request.session[:user_id] = 2
1376 @request.session[:user_id] = 2
1368 assert_difference 'Issue.count' do
1377 assert_difference 'Issue.count' do
1369 post :create, :project_id => 1,
1378 post :create, :project_id => 1,
1370 :issue => {:tracker_id => 3,
1379 :issue => {:tracker_id => 3,
1371 :status_id => 2,
1380 :status_id => 2,
1372 :subject => 'This is the test_new issue',
1381 :subject => 'This is the test_new issue',
1373 :description => 'This is the description',
1382 :description => 'This is the description',
1374 :priority_id => 5,
1383 :priority_id => 5,
1375 :start_date => '2010-11-07',
1384 :start_date => '2010-11-07',
1376 :estimated_hours => '',
1385 :estimated_hours => '',
1377 :custom_field_values => {'2' => 'Value for field 2'}}
1386 :custom_field_values => {'2' => 'Value for field 2'}}
1378 end
1387 end
1379 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1388 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1380
1389
1381 issue = Issue.find_by_subject('This is the test_new issue')
1390 issue = Issue.find_by_subject('This is the test_new issue')
1382 assert_not_nil issue
1391 assert_not_nil issue
1383 assert_equal 2, issue.author_id
1392 assert_equal 2, issue.author_id
1384 assert_equal 3, issue.tracker_id
1393 assert_equal 3, issue.tracker_id
1385 assert_equal 2, issue.status_id
1394 assert_equal 2, issue.status_id
1386 assert_equal Date.parse('2010-11-07'), issue.start_date
1395 assert_equal Date.parse('2010-11-07'), issue.start_date
1387 assert_nil issue.estimated_hours
1396 assert_nil issue.estimated_hours
1388 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1397 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1389 assert_not_nil v
1398 assert_not_nil v
1390 assert_equal 'Value for field 2', v.value
1399 assert_equal 'Value for field 2', v.value
1391 end
1400 end
1392
1401
1393 def test_post_new_with_group_assignment
1402 def test_post_new_with_group_assignment
1394 group = Group.find(11)
1403 group = Group.find(11)
1395 project = Project.find(1)
1404 project = Project.find(1)
1396 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1405 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1397
1406
1398 with_settings :issue_group_assignment => '1' do
1407 with_settings :issue_group_assignment => '1' do
1399 @request.session[:user_id] = 2
1408 @request.session[:user_id] = 2
1400 assert_difference 'Issue.count' do
1409 assert_difference 'Issue.count' do
1401 post :create, :project_id => project.id,
1410 post :create, :project_id => project.id,
1402 :issue => {:tracker_id => 3,
1411 :issue => {:tracker_id => 3,
1403 :status_id => 1,
1412 :status_id => 1,
1404 :subject => 'This is the test_new_with_group_assignment issue',
1413 :subject => 'This is the test_new_with_group_assignment issue',
1405 :assigned_to_id => group.id}
1414 :assigned_to_id => group.id}
1406 end
1415 end
1407 end
1416 end
1408 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1417 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1409
1418
1410 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1419 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1411 assert_not_nil issue
1420 assert_not_nil issue
1412 assert_equal group, issue.assigned_to
1421 assert_equal group, issue.assigned_to
1413 end
1422 end
1414
1423
1415 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1424 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1416 Setting.default_issue_start_date_to_creation_date = 0
1425 Setting.default_issue_start_date_to_creation_date = 0
1417
1426
1418 @request.session[:user_id] = 2
1427 @request.session[:user_id] = 2
1419 assert_difference 'Issue.count' do
1428 assert_difference 'Issue.count' do
1420 post :create, :project_id => 1,
1429 post :create, :project_id => 1,
1421 :issue => {:tracker_id => 3,
1430 :issue => {:tracker_id => 3,
1422 :status_id => 2,
1431 :status_id => 2,
1423 :subject => 'This is the test_new issue',
1432 :subject => 'This is the test_new issue',
1424 :description => 'This is the description',
1433 :description => 'This is the description',
1425 :priority_id => 5,
1434 :priority_id => 5,
1426 :estimated_hours => '',
1435 :estimated_hours => '',
1427 :custom_field_values => {'2' => 'Value for field 2'}}
1436 :custom_field_values => {'2' => 'Value for field 2'}}
1428 end
1437 end
1429 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1438 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1430
1439
1431 issue = Issue.find_by_subject('This is the test_new issue')
1440 issue = Issue.find_by_subject('This is the test_new issue')
1432 assert_not_nil issue
1441 assert_not_nil issue
1433 assert_nil issue.start_date
1442 assert_nil issue.start_date
1434 end
1443 end
1435
1444
1436 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1445 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1437 Setting.default_issue_start_date_to_creation_date = 1
1446 Setting.default_issue_start_date_to_creation_date = 1
1438
1447
1439 @request.session[:user_id] = 2
1448 @request.session[:user_id] = 2
1440 assert_difference 'Issue.count' do
1449 assert_difference 'Issue.count' do
1441 post :create, :project_id => 1,
1450 post :create, :project_id => 1,
1442 :issue => {:tracker_id => 3,
1451 :issue => {:tracker_id => 3,
1443 :status_id => 2,
1452 :status_id => 2,
1444 :subject => 'This is the test_new issue',
1453 :subject => 'This is the test_new issue',
1445 :description => 'This is the description',
1454 :description => 'This is the description',
1446 :priority_id => 5,
1455 :priority_id => 5,
1447 :estimated_hours => '',
1456 :estimated_hours => '',
1448 :custom_field_values => {'2' => 'Value for field 2'}}
1457 :custom_field_values => {'2' => 'Value for field 2'}}
1449 end
1458 end
1450 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1459 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1451
1460
1452 issue = Issue.find_by_subject('This is the test_new issue')
1461 issue = Issue.find_by_subject('This is the test_new issue')
1453 assert_not_nil issue
1462 assert_not_nil issue
1454 assert_equal Date.today, issue.start_date
1463 assert_equal Date.today, issue.start_date
1455 end
1464 end
1456
1465
1457 def test_post_create_and_continue
1466 def test_post_create_and_continue
1458 @request.session[:user_id] = 2
1467 @request.session[:user_id] = 2
1459 assert_difference 'Issue.count' do
1468 assert_difference 'Issue.count' do
1460 post :create, :project_id => 1,
1469 post :create, :project_id => 1,
1461 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1470 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1462 :continue => ''
1471 :continue => ''
1463 end
1472 end
1464
1473
1465 issue = Issue.first(:order => 'id DESC')
1474 issue = Issue.first(:order => 'id DESC')
1466 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1475 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1467 assert_not_nil flash[:notice], "flash was not set"
1476 assert_not_nil flash[:notice], "flash was not set"
1468 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1477 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1469 end
1478 end
1470
1479
1471 def test_post_create_without_custom_fields_param
1480 def test_post_create_without_custom_fields_param
1472 @request.session[:user_id] = 2
1481 @request.session[:user_id] = 2
1473 assert_difference 'Issue.count' do
1482 assert_difference 'Issue.count' do
1474 post :create, :project_id => 1,
1483 post :create, :project_id => 1,
1475 :issue => {:tracker_id => 1,
1484 :issue => {:tracker_id => 1,
1476 :subject => 'This is the test_new issue',
1485 :subject => 'This is the test_new issue',
1477 :description => 'This is the description',
1486 :description => 'This is the description',
1478 :priority_id => 5}
1487 :priority_id => 5}
1479 end
1488 end
1480 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1489 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1481 end
1490 end
1482
1491
1483 def test_post_create_with_multi_custom_field
1492 def test_post_create_with_multi_custom_field
1484 field = IssueCustomField.find_by_name('Database')
1493 field = IssueCustomField.find_by_name('Database')
1485 field.update_attribute(:multiple, true)
1494 field.update_attribute(:multiple, true)
1486
1495
1487 @request.session[:user_id] = 2
1496 @request.session[:user_id] = 2
1488 assert_difference 'Issue.count' do
1497 assert_difference 'Issue.count' do
1489 post :create, :project_id => 1,
1498 post :create, :project_id => 1,
1490 :issue => {:tracker_id => 1,
1499 :issue => {:tracker_id => 1,
1491 :subject => 'This is the test_new issue',
1500 :subject => 'This is the test_new issue',
1492 :description => 'This is the description',
1501 :description => 'This is the description',
1493 :priority_id => 5,
1502 :priority_id => 5,
1494 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1503 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1495 end
1504 end
1496 assert_response 302
1505 assert_response 302
1497 issue = Issue.first(:order => 'id DESC')
1506 issue = Issue.first(:order => 'id DESC')
1498 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1507 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1499 end
1508 end
1500
1509
1501 def test_post_create_with_empty_multi_custom_field
1510 def test_post_create_with_empty_multi_custom_field
1502 field = IssueCustomField.find_by_name('Database')
1511 field = IssueCustomField.find_by_name('Database')
1503 field.update_attribute(:multiple, true)
1512 field.update_attribute(:multiple, true)
1504
1513
1505 @request.session[:user_id] = 2
1514 @request.session[:user_id] = 2
1506 assert_difference 'Issue.count' do
1515 assert_difference 'Issue.count' do
1507 post :create, :project_id => 1,
1516 post :create, :project_id => 1,
1508 :issue => {:tracker_id => 1,
1517 :issue => {:tracker_id => 1,
1509 :subject => 'This is the test_new issue',
1518 :subject => 'This is the test_new issue',
1510 :description => 'This is the description',
1519 :description => 'This is the description',
1511 :priority_id => 5,
1520 :priority_id => 5,
1512 :custom_field_values => {'1' => ['']}}
1521 :custom_field_values => {'1' => ['']}}
1513 end
1522 end
1514 assert_response 302
1523 assert_response 302
1515 issue = Issue.first(:order => 'id DESC')
1524 issue = Issue.first(:order => 'id DESC')
1516 assert_equal [''], issue.custom_field_value(1).sort
1525 assert_equal [''], issue.custom_field_value(1).sort
1517 end
1526 end
1518
1527
1519 def test_post_create_with_multi_user_custom_field
1528 def test_post_create_with_multi_user_custom_field
1520 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1529 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1521 :tracker_ids => [1], :is_for_all => true)
1530 :tracker_ids => [1], :is_for_all => true)
1522
1531
1523 @request.session[:user_id] = 2
1532 @request.session[:user_id] = 2
1524 assert_difference 'Issue.count' do
1533 assert_difference 'Issue.count' do
1525 post :create, :project_id => 1,
1534 post :create, :project_id => 1,
1526 :issue => {:tracker_id => 1,
1535 :issue => {:tracker_id => 1,
1527 :subject => 'This is the test_new issue',
1536 :subject => 'This is the test_new issue',
1528 :description => 'This is the description',
1537 :description => 'This is the description',
1529 :priority_id => 5,
1538 :priority_id => 5,
1530 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1539 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1531 end
1540 end
1532 assert_response 302
1541 assert_response 302
1533 issue = Issue.first(:order => 'id DESC')
1542 issue = Issue.first(:order => 'id DESC')
1534 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1543 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1535 end
1544 end
1536
1545
1537 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1546 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1538 field = IssueCustomField.find_by_name('Database')
1547 field = IssueCustomField.find_by_name('Database')
1539 field.update_attribute(:is_required, true)
1548 field.update_attribute(:is_required, true)
1540
1549
1541 @request.session[:user_id] = 2
1550 @request.session[:user_id] = 2
1542 assert_no_difference 'Issue.count' do
1551 assert_no_difference 'Issue.count' do
1543 post :create, :project_id => 1,
1552 post :create, :project_id => 1,
1544 :issue => {:tracker_id => 1,
1553 :issue => {:tracker_id => 1,
1545 :subject => 'This is the test_new issue',
1554 :subject => 'This is the test_new issue',
1546 :description => 'This is the description',
1555 :description => 'This is the description',
1547 :priority_id => 5}
1556 :priority_id => 5}
1548 end
1557 end
1549 assert_response :success
1558 assert_response :success
1550 assert_template 'new'
1559 assert_template 'new'
1551 issue = assigns(:issue)
1560 issue = assigns(:issue)
1552 assert_not_nil issue
1561 assert_not_nil issue
1553 assert_error_tag :content => /Database can't be blank/
1562 assert_error_tag :content => /Database can't be blank/
1554 end
1563 end
1555
1564
1556 def test_post_create_with_watchers
1565 def test_post_create_with_watchers
1557 @request.session[:user_id] = 2
1566 @request.session[:user_id] = 2
1558 ActionMailer::Base.deliveries.clear
1567 ActionMailer::Base.deliveries.clear
1559
1568
1560 assert_difference 'Watcher.count', 2 do
1569 assert_difference 'Watcher.count', 2 do
1561 post :create, :project_id => 1,
1570 post :create, :project_id => 1,
1562 :issue => {:tracker_id => 1,
1571 :issue => {:tracker_id => 1,
1563 :subject => 'This is a new issue with watchers',
1572 :subject => 'This is a new issue with watchers',
1564 :description => 'This is the description',
1573 :description => 'This is the description',
1565 :priority_id => 5,
1574 :priority_id => 5,
1566 :watcher_user_ids => ['2', '3']}
1575 :watcher_user_ids => ['2', '3']}
1567 end
1576 end
1568 issue = Issue.find_by_subject('This is a new issue with watchers')
1577 issue = Issue.find_by_subject('This is a new issue with watchers')
1569 assert_not_nil issue
1578 assert_not_nil issue
1570 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1579 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1571
1580
1572 # Watchers added
1581 # Watchers added
1573 assert_equal [2, 3], issue.watcher_user_ids.sort
1582 assert_equal [2, 3], issue.watcher_user_ids.sort
1574 assert issue.watched_by?(User.find(3))
1583 assert issue.watched_by?(User.find(3))
1575 # Watchers notified
1584 # Watchers notified
1576 mail = ActionMailer::Base.deliveries.last
1585 mail = ActionMailer::Base.deliveries.last
1577 assert_not_nil mail
1586 assert_not_nil mail
1578 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1587 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1579 end
1588 end
1580
1589
1581 def test_post_create_subissue
1590 def test_post_create_subissue
1582 @request.session[:user_id] = 2
1591 @request.session[:user_id] = 2
1583
1592
1584 assert_difference 'Issue.count' do
1593 assert_difference 'Issue.count' do
1585 post :create, :project_id => 1,
1594 post :create, :project_id => 1,
1586 :issue => {:tracker_id => 1,
1595 :issue => {:tracker_id => 1,
1587 :subject => 'This is a child issue',
1596 :subject => 'This is a child issue',
1588 :parent_issue_id => 2}
1597 :parent_issue_id => 2}
1589 end
1598 end
1590 issue = Issue.find_by_subject('This is a child issue')
1599 issue = Issue.find_by_subject('This is a child issue')
1591 assert_not_nil issue
1600 assert_not_nil issue
1592 assert_equal Issue.find(2), issue.parent
1601 assert_equal Issue.find(2), issue.parent
1593 end
1602 end
1594
1603
1595 def test_post_create_subissue_with_non_numeric_parent_id
1604 def test_post_create_subissue_with_non_numeric_parent_id
1596 @request.session[:user_id] = 2
1605 @request.session[:user_id] = 2
1597
1606
1598 assert_difference 'Issue.count' do
1607 assert_difference 'Issue.count' do
1599 post :create, :project_id => 1,
1608 post :create, :project_id => 1,
1600 :issue => {:tracker_id => 1,
1609 :issue => {:tracker_id => 1,
1601 :subject => 'This is a child issue',
1610 :subject => 'This is a child issue',
1602 :parent_issue_id => 'ABC'}
1611 :parent_issue_id => 'ABC'}
1603 end
1612 end
1604 issue = Issue.find_by_subject('This is a child issue')
1613 issue = Issue.find_by_subject('This is a child issue')
1605 assert_not_nil issue
1614 assert_not_nil issue
1606 assert_nil issue.parent
1615 assert_nil issue.parent
1607 end
1616 end
1608
1617
1609 def test_post_create_private
1618 def test_post_create_private
1610 @request.session[:user_id] = 2
1619 @request.session[:user_id] = 2
1611
1620
1612 assert_difference 'Issue.count' do
1621 assert_difference 'Issue.count' do
1613 post :create, :project_id => 1,
1622 post :create, :project_id => 1,
1614 :issue => {:tracker_id => 1,
1623 :issue => {:tracker_id => 1,
1615 :subject => 'This is a private issue',
1624 :subject => 'This is a private issue',
1616 :is_private => '1'}
1625 :is_private => '1'}
1617 end
1626 end
1618 issue = Issue.first(:order => 'id DESC')
1627 issue = Issue.first(:order => 'id DESC')
1619 assert issue.is_private?
1628 assert issue.is_private?
1620 end
1629 end
1621
1630
1622 def test_post_create_private_with_set_own_issues_private_permission
1631 def test_post_create_private_with_set_own_issues_private_permission
1623 role = Role.find(1)
1632 role = Role.find(1)
1624 role.remove_permission! :set_issues_private
1633 role.remove_permission! :set_issues_private
1625 role.add_permission! :set_own_issues_private
1634 role.add_permission! :set_own_issues_private
1626
1635
1627 @request.session[:user_id] = 2
1636 @request.session[:user_id] = 2
1628
1637
1629 assert_difference 'Issue.count' do
1638 assert_difference 'Issue.count' do
1630 post :create, :project_id => 1,
1639 post :create, :project_id => 1,
1631 :issue => {:tracker_id => 1,
1640 :issue => {:tracker_id => 1,
1632 :subject => 'This is a private issue',
1641 :subject => 'This is a private issue',
1633 :is_private => '1'}
1642 :is_private => '1'}
1634 end
1643 end
1635 issue = Issue.first(:order => 'id DESC')
1644 issue = Issue.first(:order => 'id DESC')
1636 assert issue.is_private?
1645 assert issue.is_private?
1637 end
1646 end
1638
1647
1639 def test_post_create_should_send_a_notification
1648 def test_post_create_should_send_a_notification
1640 ActionMailer::Base.deliveries.clear
1649 ActionMailer::Base.deliveries.clear
1641 @request.session[:user_id] = 2
1650 @request.session[:user_id] = 2
1642 assert_difference 'Issue.count' do
1651 assert_difference 'Issue.count' do
1643 post :create, :project_id => 1,
1652 post :create, :project_id => 1,
1644 :issue => {:tracker_id => 3,
1653 :issue => {:tracker_id => 3,
1645 :subject => 'This is the test_new issue',
1654 :subject => 'This is the test_new issue',
1646 :description => 'This is the description',
1655 :description => 'This is the description',
1647 :priority_id => 5,
1656 :priority_id => 5,
1648 :estimated_hours => '',
1657 :estimated_hours => '',
1649 :custom_field_values => {'2' => 'Value for field 2'}}
1658 :custom_field_values => {'2' => 'Value for field 2'}}
1650 end
1659 end
1651 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1660 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1652
1661
1653 assert_equal 1, ActionMailer::Base.deliveries.size
1662 assert_equal 1, ActionMailer::Base.deliveries.size
1654 end
1663 end
1655
1664
1656 def test_post_create_should_preserve_fields_values_on_validation_failure
1665 def test_post_create_should_preserve_fields_values_on_validation_failure
1657 @request.session[:user_id] = 2
1666 @request.session[:user_id] = 2
1658 post :create, :project_id => 1,
1667 post :create, :project_id => 1,
1659 :issue => {:tracker_id => 1,
1668 :issue => {:tracker_id => 1,
1660 # empty subject
1669 # empty subject
1661 :subject => '',
1670 :subject => '',
1662 :description => 'This is a description',
1671 :description => 'This is a description',
1663 :priority_id => 6,
1672 :priority_id => 6,
1664 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1673 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1665 assert_response :success
1674 assert_response :success
1666 assert_template 'new'
1675 assert_template 'new'
1667
1676
1668 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1677 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1669 :content => 'This is a description'
1678 :content => 'This is a description'
1670 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1679 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1671 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1680 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1672 :value => '6' },
1681 :value => '6' },
1673 :content => 'High' }
1682 :content => 'High' }
1674 # Custom fields
1683 # Custom fields
1675 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1684 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1676 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1685 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1677 :value => 'Oracle' },
1686 :value => 'Oracle' },
1678 :content => 'Oracle' }
1687 :content => 'Oracle' }
1679 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1688 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1680 :value => 'Value for field 2'}
1689 :value => 'Value for field 2'}
1681 end
1690 end
1682
1691
1683 def test_post_create_with_failure_should_preserve_watchers
1692 def test_post_create_with_failure_should_preserve_watchers
1684 assert !User.find(8).member_of?(Project.find(1))
1693 assert !User.find(8).member_of?(Project.find(1))
1685
1694
1686 @request.session[:user_id] = 2
1695 @request.session[:user_id] = 2
1687 post :create, :project_id => 1,
1696 post :create, :project_id => 1,
1688 :issue => {:tracker_id => 1,
1697 :issue => {:tracker_id => 1,
1689 :watcher_user_ids => ['3', '8']}
1698 :watcher_user_ids => ['3', '8']}
1690 assert_response :success
1699 assert_response :success
1691 assert_template 'new'
1700 assert_template 'new'
1692
1701
1693 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
1702 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
1694 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
1703 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
1695 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
1704 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
1696 end
1705 end
1697
1706
1698 def test_post_create_should_ignore_non_safe_attributes
1707 def test_post_create_should_ignore_non_safe_attributes
1699 @request.session[:user_id] = 2
1708 @request.session[:user_id] = 2
1700 assert_nothing_raised do
1709 assert_nothing_raised do
1701 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1710 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1702 end
1711 end
1703 end
1712 end
1704
1713
1705 def test_post_create_with_attachment
1714 def test_post_create_with_attachment
1706 set_tmp_attachments_directory
1715 set_tmp_attachments_directory
1707 @request.session[:user_id] = 2
1716 @request.session[:user_id] = 2
1708
1717
1709 assert_difference 'Issue.count' do
1718 assert_difference 'Issue.count' do
1710 assert_difference 'Attachment.count' do
1719 assert_difference 'Attachment.count' do
1711 post :create, :project_id => 1,
1720 post :create, :project_id => 1,
1712 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1721 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1713 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1722 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1714 end
1723 end
1715 end
1724 end
1716
1725
1717 issue = Issue.first(:order => 'id DESC')
1726 issue = Issue.first(:order => 'id DESC')
1718 attachment = Attachment.first(:order => 'id DESC')
1727 attachment = Attachment.first(:order => 'id DESC')
1719
1728
1720 assert_equal issue, attachment.container
1729 assert_equal issue, attachment.container
1721 assert_equal 2, attachment.author_id
1730 assert_equal 2, attachment.author_id
1722 assert_equal 'testfile.txt', attachment.filename
1731 assert_equal 'testfile.txt', attachment.filename
1723 assert_equal 'text/plain', attachment.content_type
1732 assert_equal 'text/plain', attachment.content_type
1724 assert_equal 'test file', attachment.description
1733 assert_equal 'test file', attachment.description
1725 assert_equal 59, attachment.filesize
1734 assert_equal 59, attachment.filesize
1726 assert File.exists?(attachment.diskfile)
1735 assert File.exists?(attachment.diskfile)
1727 assert_equal 59, File.size(attachment.diskfile)
1736 assert_equal 59, File.size(attachment.diskfile)
1728 end
1737 end
1729
1738
1730 def test_post_create_with_failure_should_save_attachments
1739 def test_post_create_with_failure_should_save_attachments
1731 set_tmp_attachments_directory
1740 set_tmp_attachments_directory
1732 @request.session[:user_id] = 2
1741 @request.session[:user_id] = 2
1733
1742
1734 assert_no_difference 'Issue.count' do
1743 assert_no_difference 'Issue.count' do
1735 assert_difference 'Attachment.count' do
1744 assert_difference 'Attachment.count' do
1736 post :create, :project_id => 1,
1745 post :create, :project_id => 1,
1737 :issue => { :tracker_id => '1', :subject => '' },
1746 :issue => { :tracker_id => '1', :subject => '' },
1738 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1747 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1739 assert_response :success
1748 assert_response :success
1740 assert_template 'new'
1749 assert_template 'new'
1741 end
1750 end
1742 end
1751 end
1743
1752
1744 attachment = Attachment.first(:order => 'id DESC')
1753 attachment = Attachment.first(:order => 'id DESC')
1745 assert_equal 'testfile.txt', attachment.filename
1754 assert_equal 'testfile.txt', attachment.filename
1746 assert File.exists?(attachment.diskfile)
1755 assert File.exists?(attachment.diskfile)
1747 assert_nil attachment.container
1756 assert_nil attachment.container
1748
1757
1749 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1758 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1750 assert_tag 'span', :content => /testfile.txt/
1759 assert_tag 'span', :content => /testfile.txt/
1751 end
1760 end
1752
1761
1753 def test_post_create_with_failure_should_keep_saved_attachments
1762 def test_post_create_with_failure_should_keep_saved_attachments
1754 set_tmp_attachments_directory
1763 set_tmp_attachments_directory
1755 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1764 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1756 @request.session[:user_id] = 2
1765 @request.session[:user_id] = 2
1757
1766
1758 assert_no_difference 'Issue.count' do
1767 assert_no_difference 'Issue.count' do
1759 assert_no_difference 'Attachment.count' do
1768 assert_no_difference 'Attachment.count' do
1760 post :create, :project_id => 1,
1769 post :create, :project_id => 1,
1761 :issue => { :tracker_id => '1', :subject => '' },
1770 :issue => { :tracker_id => '1', :subject => '' },
1762 :attachments => {'p0' => {'token' => attachment.token}}
1771 :attachments => {'p0' => {'token' => attachment.token}}
1763 assert_response :success
1772 assert_response :success
1764 assert_template 'new'
1773 assert_template 'new'
1765 end
1774 end
1766 end
1775 end
1767
1776
1768 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1777 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1769 assert_tag 'span', :content => /testfile.txt/
1778 assert_tag 'span', :content => /testfile.txt/
1770 end
1779 end
1771
1780
1772 def test_post_create_should_attach_saved_attachments
1781 def test_post_create_should_attach_saved_attachments
1773 set_tmp_attachments_directory
1782 set_tmp_attachments_directory
1774 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1783 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1775 @request.session[:user_id] = 2
1784 @request.session[:user_id] = 2
1776
1785
1777 assert_difference 'Issue.count' do
1786 assert_difference 'Issue.count' do
1778 assert_no_difference 'Attachment.count' do
1787 assert_no_difference 'Attachment.count' do
1779 post :create, :project_id => 1,
1788 post :create, :project_id => 1,
1780 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1789 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1781 :attachments => {'p0' => {'token' => attachment.token}}
1790 :attachments => {'p0' => {'token' => attachment.token}}
1782 assert_response 302
1791 assert_response 302
1783 end
1792 end
1784 end
1793 end
1785
1794
1786 issue = Issue.first(:order => 'id DESC')
1795 issue = Issue.first(:order => 'id DESC')
1787 assert_equal 1, issue.attachments.count
1796 assert_equal 1, issue.attachments.count
1788
1797
1789 attachment.reload
1798 attachment.reload
1790 assert_equal issue, attachment.container
1799 assert_equal issue, attachment.container
1791 end
1800 end
1792
1801
1793 context "without workflow privilege" do
1802 context "without workflow privilege" do
1794 setup do
1803 setup do
1795 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1804 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1796 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1805 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1797 end
1806 end
1798
1807
1799 context "#new" do
1808 context "#new" do
1800 should "propose default status only" do
1809 should "propose default status only" do
1801 get :new, :project_id => 1
1810 get :new, :project_id => 1
1802 assert_response :success
1811 assert_response :success
1803 assert_template 'new'
1812 assert_template 'new'
1804 assert_tag :tag => 'select',
1813 assert_tag :tag => 'select',
1805 :attributes => {:name => 'issue[status_id]'},
1814 :attributes => {:name => 'issue[status_id]'},
1806 :children => {:count => 1},
1815 :children => {:count => 1},
1807 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1816 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1808 end
1817 end
1809
1818
1810 should "accept default status" do
1819 should "accept default status" do
1811 assert_difference 'Issue.count' do
1820 assert_difference 'Issue.count' do
1812 post :create, :project_id => 1,
1821 post :create, :project_id => 1,
1813 :issue => {:tracker_id => 1,
1822 :issue => {:tracker_id => 1,
1814 :subject => 'This is an issue',
1823 :subject => 'This is an issue',
1815 :status_id => 1}
1824 :status_id => 1}
1816 end
1825 end
1817 issue = Issue.last(:order => 'id')
1826 issue = Issue.last(:order => 'id')
1818 assert_equal IssueStatus.default, issue.status
1827 assert_equal IssueStatus.default, issue.status
1819 end
1828 end
1820
1829
1821 should "ignore unauthorized status" do
1830 should "ignore unauthorized status" do
1822 assert_difference 'Issue.count' do
1831 assert_difference 'Issue.count' do
1823 post :create, :project_id => 1,
1832 post :create, :project_id => 1,
1824 :issue => {:tracker_id => 1,
1833 :issue => {:tracker_id => 1,
1825 :subject => 'This is an issue',
1834 :subject => 'This is an issue',
1826 :status_id => 3}
1835 :status_id => 3}
1827 end
1836 end
1828 issue = Issue.last(:order => 'id')
1837 issue = Issue.last(:order => 'id')
1829 assert_equal IssueStatus.default, issue.status
1838 assert_equal IssueStatus.default, issue.status
1830 end
1839 end
1831 end
1840 end
1832
1841
1833 context "#update" do
1842 context "#update" do
1834 should "ignore status change" do
1843 should "ignore status change" do
1835 assert_difference 'Journal.count' do
1844 assert_difference 'Journal.count' do
1836 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1845 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1837 end
1846 end
1838 assert_equal 1, Issue.find(1).status_id
1847 assert_equal 1, Issue.find(1).status_id
1839 end
1848 end
1840
1849
1841 should "ignore attributes changes" do
1850 should "ignore attributes changes" do
1842 assert_difference 'Journal.count' do
1851 assert_difference 'Journal.count' do
1843 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1852 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1844 end
1853 end
1845 issue = Issue.find(1)
1854 issue = Issue.find(1)
1846 assert_equal "Can't print recipes", issue.subject
1855 assert_equal "Can't print recipes", issue.subject
1847 assert_nil issue.assigned_to
1856 assert_nil issue.assigned_to
1848 end
1857 end
1849 end
1858 end
1850 end
1859 end
1851
1860
1852 context "with workflow privilege" do
1861 context "with workflow privilege" do
1853 setup do
1862 setup do
1854 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1863 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1855 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1864 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1856 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1865 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1857 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1866 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1858 end
1867 end
1859
1868
1860 context "#update" do
1869 context "#update" do
1861 should "accept authorized status" do
1870 should "accept authorized status" do
1862 assert_difference 'Journal.count' do
1871 assert_difference 'Journal.count' do
1863 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1872 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1864 end
1873 end
1865 assert_equal 3, Issue.find(1).status_id
1874 assert_equal 3, Issue.find(1).status_id
1866 end
1875 end
1867
1876
1868 should "ignore unauthorized status" do
1877 should "ignore unauthorized status" do
1869 assert_difference 'Journal.count' do
1878 assert_difference 'Journal.count' do
1870 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1879 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1871 end
1880 end
1872 assert_equal 1, Issue.find(1).status_id
1881 assert_equal 1, Issue.find(1).status_id
1873 end
1882 end
1874
1883
1875 should "accept authorized attributes changes" do
1884 should "accept authorized attributes changes" do
1876 assert_difference 'Journal.count' do
1885 assert_difference 'Journal.count' do
1877 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1886 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1878 end
1887 end
1879 issue = Issue.find(1)
1888 issue = Issue.find(1)
1880 assert_equal 2, issue.assigned_to_id
1889 assert_equal 2, issue.assigned_to_id
1881 end
1890 end
1882
1891
1883 should "ignore unauthorized attributes changes" do
1892 should "ignore unauthorized attributes changes" do
1884 assert_difference 'Journal.count' do
1893 assert_difference 'Journal.count' do
1885 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1894 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1886 end
1895 end
1887 issue = Issue.find(1)
1896 issue = Issue.find(1)
1888 assert_equal "Can't print recipes", issue.subject
1897 assert_equal "Can't print recipes", issue.subject
1889 end
1898 end
1890 end
1899 end
1891
1900
1892 context "and :edit_issues permission" do
1901 context "and :edit_issues permission" do
1893 setup do
1902 setup do
1894 Role.anonymous.add_permission! :add_issues, :edit_issues
1903 Role.anonymous.add_permission! :add_issues, :edit_issues
1895 end
1904 end
1896
1905
1897 should "accept authorized status" do
1906 should "accept authorized status" do
1898 assert_difference 'Journal.count' do
1907 assert_difference 'Journal.count' do
1899 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1908 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1900 end
1909 end
1901 assert_equal 3, Issue.find(1).status_id
1910 assert_equal 3, Issue.find(1).status_id
1902 end
1911 end
1903
1912
1904 should "ignore unauthorized status" do
1913 should "ignore unauthorized status" do
1905 assert_difference 'Journal.count' do
1914 assert_difference 'Journal.count' do
1906 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1915 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1907 end
1916 end
1908 assert_equal 1, Issue.find(1).status_id
1917 assert_equal 1, Issue.find(1).status_id
1909 end
1918 end
1910
1919
1911 should "accept authorized attributes changes" do
1920 should "accept authorized attributes changes" do
1912 assert_difference 'Journal.count' do
1921 assert_difference 'Journal.count' do
1913 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1922 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1914 end
1923 end
1915 issue = Issue.find(1)
1924 issue = Issue.find(1)
1916 assert_equal "changed", issue.subject
1925 assert_equal "changed", issue.subject
1917 assert_equal 2, issue.assigned_to_id
1926 assert_equal 2, issue.assigned_to_id
1918 end
1927 end
1919 end
1928 end
1920 end
1929 end
1921
1930
1922 def test_new_as_copy
1931 def test_new_as_copy
1923 @request.session[:user_id] = 2
1932 @request.session[:user_id] = 2
1924 get :new, :project_id => 1, :copy_from => 1
1933 get :new, :project_id => 1, :copy_from => 1
1925
1934
1926 assert_response :success
1935 assert_response :success
1927 assert_template 'new'
1936 assert_template 'new'
1928
1937
1929 assert_not_nil assigns(:issue)
1938 assert_not_nil assigns(:issue)
1930 orig = Issue.find(1)
1939 orig = Issue.find(1)
1931 assert_equal 1, assigns(:issue).project_id
1940 assert_equal 1, assigns(:issue).project_id
1932 assert_equal orig.subject, assigns(:issue).subject
1941 assert_equal orig.subject, assigns(:issue).subject
1933 assert assigns(:issue).copy?
1942 assert assigns(:issue).copy?
1934
1943
1935 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1944 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1936 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1945 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1937 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1946 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1938 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1947 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1939 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1948 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1940 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1949 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1941 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1950 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1942 end
1951 end
1943
1952
1944 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1953 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1945 @request.session[:user_id] = 2
1954 @request.session[:user_id] = 2
1946 issue = Issue.find(3)
1955 issue = Issue.find(3)
1947 assert issue.attachments.count > 0
1956 assert issue.attachments.count > 0
1948 get :new, :project_id => 1, :copy_from => 3
1957 get :new, :project_id => 1, :copy_from => 3
1949
1958
1950 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1959 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1951 end
1960 end
1952
1961
1953 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1962 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1954 @request.session[:user_id] = 2
1963 @request.session[:user_id] = 2
1955 issue = Issue.find(3)
1964 issue = Issue.find(3)
1956 issue.attachments.delete_all
1965 issue.attachments.delete_all
1957 get :new, :project_id => 1, :copy_from => 3
1966 get :new, :project_id => 1, :copy_from => 3
1958
1967
1959 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1968 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1960 end
1969 end
1961
1970
1962 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1971 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1963 @request.session[:user_id] = 2
1972 @request.session[:user_id] = 2
1964 get :new, :project_id => 1, :copy_from => 99999
1973 get :new, :project_id => 1, :copy_from => 99999
1965 assert_response 404
1974 assert_response 404
1966 end
1975 end
1967
1976
1968 def test_create_as_copy_on_different_project
1977 def test_create_as_copy_on_different_project
1969 @request.session[:user_id] = 2
1978 @request.session[:user_id] = 2
1970 assert_difference 'Issue.count' do
1979 assert_difference 'Issue.count' do
1971 post :create, :project_id => 1, :copy_from => 1,
1980 post :create, :project_id => 1, :copy_from => 1,
1972 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1981 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1973
1982
1974 assert_not_nil assigns(:issue)
1983 assert_not_nil assigns(:issue)
1975 assert assigns(:issue).copy?
1984 assert assigns(:issue).copy?
1976 end
1985 end
1977 issue = Issue.first(:order => 'id DESC')
1986 issue = Issue.first(:order => 'id DESC')
1978 assert_redirected_to "/issues/#{issue.id}"
1987 assert_redirected_to "/issues/#{issue.id}"
1979
1988
1980 assert_equal 2, issue.project_id
1989 assert_equal 2, issue.project_id
1981 assert_equal 3, issue.tracker_id
1990 assert_equal 3, issue.tracker_id
1982 assert_equal 'Copy', issue.subject
1991 assert_equal 'Copy', issue.subject
1983 end
1992 end
1984
1993
1985 def test_create_as_copy_should_copy_attachments
1994 def test_create_as_copy_should_copy_attachments
1986 @request.session[:user_id] = 2
1995 @request.session[:user_id] = 2
1987 issue = Issue.find(3)
1996 issue = Issue.find(3)
1988 count = issue.attachments.count
1997 count = issue.attachments.count
1989 assert count > 0
1998 assert count > 0
1990
1999
1991 assert_difference 'Issue.count' do
2000 assert_difference 'Issue.count' do
1992 assert_difference 'Attachment.count', count do
2001 assert_difference 'Attachment.count', count do
1993 assert_no_difference 'Journal.count' do
2002 assert_no_difference 'Journal.count' do
1994 post :create, :project_id => 1, :copy_from => 3,
2003 post :create, :project_id => 1, :copy_from => 3,
1995 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2004 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1996 :copy_attachments => '1'
2005 :copy_attachments => '1'
1997 end
2006 end
1998 end
2007 end
1999 end
2008 end
2000 copy = Issue.first(:order => 'id DESC')
2009 copy = Issue.first(:order => 'id DESC')
2001 assert_equal count, copy.attachments.count
2010 assert_equal count, copy.attachments.count
2002 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2011 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2003 end
2012 end
2004
2013
2005 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2014 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2006 @request.session[:user_id] = 2
2015 @request.session[:user_id] = 2
2007 issue = Issue.find(3)
2016 issue = Issue.find(3)
2008 count = issue.attachments.count
2017 count = issue.attachments.count
2009 assert count > 0
2018 assert count > 0
2010
2019
2011 assert_difference 'Issue.count' do
2020 assert_difference 'Issue.count' do
2012 assert_no_difference 'Attachment.count' do
2021 assert_no_difference 'Attachment.count' do
2013 assert_no_difference 'Journal.count' do
2022 assert_no_difference 'Journal.count' do
2014 post :create, :project_id => 1, :copy_from => 3,
2023 post :create, :project_id => 1, :copy_from => 3,
2015 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2024 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2016 end
2025 end
2017 end
2026 end
2018 end
2027 end
2019 copy = Issue.first(:order => 'id DESC')
2028 copy = Issue.first(:order => 'id DESC')
2020 assert_equal 0, copy.attachments.count
2029 assert_equal 0, copy.attachments.count
2021 end
2030 end
2022
2031
2023 def test_create_as_copy_with_attachments_should_add_new_files
2032 def test_create_as_copy_with_attachments_should_add_new_files
2024 @request.session[:user_id] = 2
2033 @request.session[:user_id] = 2
2025 issue = Issue.find(3)
2034 issue = Issue.find(3)
2026 count = issue.attachments.count
2035 count = issue.attachments.count
2027 assert count > 0
2036 assert count > 0
2028
2037
2029 assert_difference 'Issue.count' do
2038 assert_difference 'Issue.count' do
2030 assert_difference 'Attachment.count', count + 1 do
2039 assert_difference 'Attachment.count', count + 1 do
2031 assert_no_difference 'Journal.count' do
2040 assert_no_difference 'Journal.count' do
2032 post :create, :project_id => 1, :copy_from => 3,
2041 post :create, :project_id => 1, :copy_from => 3,
2033 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2042 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2034 :copy_attachments => '1',
2043 :copy_attachments => '1',
2035 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2044 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2036 end
2045 end
2037 end
2046 end
2038 end
2047 end
2039 copy = Issue.first(:order => 'id DESC')
2048 copy = Issue.first(:order => 'id DESC')
2040 assert_equal count + 1, copy.attachments.count
2049 assert_equal count + 1, copy.attachments.count
2041 end
2050 end
2042
2051
2043 def test_create_as_copy_with_failure
2052 def test_create_as_copy_with_failure
2044 @request.session[:user_id] = 2
2053 @request.session[:user_id] = 2
2045 post :create, :project_id => 1, :copy_from => 1,
2054 post :create, :project_id => 1, :copy_from => 1,
2046 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2055 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2047
2056
2048 assert_response :success
2057 assert_response :success
2049 assert_template 'new'
2058 assert_template 'new'
2050
2059
2051 assert_not_nil assigns(:issue)
2060 assert_not_nil assigns(:issue)
2052 assert assigns(:issue).copy?
2061 assert assigns(:issue).copy?
2053
2062
2054 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2063 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2055 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2064 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2056 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2065 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2057 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2066 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2058 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2067 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2059 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2068 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2060 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2069 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2061 end
2070 end
2062
2071
2063 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2072 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2064 @request.session[:user_id] = 2
2073 @request.session[:user_id] = 2
2065 assert !User.find(2).member_of?(Project.find(4))
2074 assert !User.find(2).member_of?(Project.find(4))
2066
2075
2067 assert_difference 'Issue.count' do
2076 assert_difference 'Issue.count' do
2068 post :create, :project_id => 1, :copy_from => 1,
2077 post :create, :project_id => 1, :copy_from => 1,
2069 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2078 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2070 end
2079 end
2071 issue = Issue.first(:order => 'id DESC')
2080 issue = Issue.first(:order => 'id DESC')
2072 assert_equal 1, issue.project_id
2081 assert_equal 1, issue.project_id
2073 end
2082 end
2074
2083
2075 def test_get_edit
2084 def test_get_edit
2076 @request.session[:user_id] = 2
2085 @request.session[:user_id] = 2
2077 get :edit, :id => 1
2086 get :edit, :id => 1
2078 assert_response :success
2087 assert_response :success
2079 assert_template 'edit'
2088 assert_template 'edit'
2080 assert_not_nil assigns(:issue)
2089 assert_not_nil assigns(:issue)
2081 assert_equal Issue.find(1), assigns(:issue)
2090 assert_equal Issue.find(1), assigns(:issue)
2082
2091
2083 # Be sure we don't display inactive IssuePriorities
2092 # Be sure we don't display inactive IssuePriorities
2084 assert ! IssuePriority.find(15).active?
2093 assert ! IssuePriority.find(15).active?
2085 assert_no_tag :option, :attributes => {:value => '15'},
2094 assert_no_tag :option, :attributes => {:value => '15'},
2086 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2095 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2087 end
2096 end
2088
2097
2089 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2098 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2090 @request.session[:user_id] = 2
2099 @request.session[:user_id] = 2
2091 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2100 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2092
2101
2093 get :edit, :id => 1
2102 get :edit, :id => 1
2094 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2103 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2095 end
2104 end
2096
2105
2097 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2106 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2098 @request.session[:user_id] = 2
2107 @request.session[:user_id] = 2
2099 Role.find_by_name('Manager').remove_permission! :log_time
2108 Role.find_by_name('Manager').remove_permission! :log_time
2100
2109
2101 get :edit, :id => 1
2110 get :edit, :id => 1
2102 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2111 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2103 end
2112 end
2104
2113
2105 def test_get_edit_with_params
2114 def test_get_edit_with_params
2106 @request.session[:user_id] = 2
2115 @request.session[:user_id] = 2
2107 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2116 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2108 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2117 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2109 assert_response :success
2118 assert_response :success
2110 assert_template 'edit'
2119 assert_template 'edit'
2111
2120
2112 issue = assigns(:issue)
2121 issue = assigns(:issue)
2113 assert_not_nil issue
2122 assert_not_nil issue
2114
2123
2115 assert_equal 5, issue.status_id
2124 assert_equal 5, issue.status_id
2116 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2125 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2117 :child => { :tag => 'option',
2126 :child => { :tag => 'option',
2118 :content => 'Closed',
2127 :content => 'Closed',
2119 :attributes => { :selected => 'selected' } }
2128 :attributes => { :selected => 'selected' } }
2120
2129
2121 assert_equal 7, issue.priority_id
2130 assert_equal 7, issue.priority_id
2122 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2131 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2123 :child => { :tag => 'option',
2132 :child => { :tag => 'option',
2124 :content => 'Urgent',
2133 :content => 'Urgent',
2125 :attributes => { :selected => 'selected' } }
2134 :attributes => { :selected => 'selected' } }
2126
2135
2127 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2136 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2128 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2137 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2129 :child => { :tag => 'option',
2138 :child => { :tag => 'option',
2130 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2139 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2131 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2140 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2132 end
2141 end
2133
2142
2134 def test_get_edit_with_multi_custom_field
2143 def test_get_edit_with_multi_custom_field
2135 field = CustomField.find(1)
2144 field = CustomField.find(1)
2136 field.update_attribute :multiple, true
2145 field.update_attribute :multiple, true
2137 issue = Issue.find(1)
2146 issue = Issue.find(1)
2138 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2147 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2139 issue.save!
2148 issue.save!
2140
2149
2141 @request.session[:user_id] = 2
2150 @request.session[:user_id] = 2
2142 get :edit, :id => 1
2151 get :edit, :id => 1
2143 assert_response :success
2152 assert_response :success
2144 assert_template 'edit'
2153 assert_template 'edit'
2145
2154
2146 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2155 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2147 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2156 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2148 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2157 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2149 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2158 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2150 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2159 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2151 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2160 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2152 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2161 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2153 end
2162 end
2154
2163
2155 def test_update_edit_form
2164 def test_update_edit_form
2156 @request.session[:user_id] = 2
2165 @request.session[:user_id] = 2
2157 xhr :put, :new, :project_id => 1,
2166 xhr :put, :new, :project_id => 1,
2158 :id => 1,
2167 :id => 1,
2159 :issue => {:tracker_id => 2,
2168 :issue => {:tracker_id => 2,
2160 :subject => 'This is the test_new issue',
2169 :subject => 'This is the test_new issue',
2161 :description => 'This is the description',
2170 :description => 'This is the description',
2162 :priority_id => 5}
2171 :priority_id => 5}
2163 assert_response :success
2172 assert_response :success
2164 assert_template 'attributes'
2173 assert_template 'attributes'
2165
2174
2166 issue = assigns(:issue)
2175 issue = assigns(:issue)
2167 assert_kind_of Issue, issue
2176 assert_kind_of Issue, issue
2168 assert_equal 1, issue.id
2177 assert_equal 1, issue.id
2169 assert_equal 1, issue.project_id
2178 assert_equal 1, issue.project_id
2170 assert_equal 2, issue.tracker_id
2179 assert_equal 2, issue.tracker_id
2171 assert_equal 'This is the test_new issue', issue.subject
2180 assert_equal 'This is the test_new issue', issue.subject
2172 end
2181 end
2173
2182
2174 def test_update_edit_form_with_project_change
2183 def test_update_edit_form_with_project_change
2175 @request.session[:user_id] = 2
2184 @request.session[:user_id] = 2
2176 xhr :put, :new, :project_id => 1,
2185 xhr :put, :new, :project_id => 1,
2177 :id => 1,
2186 :id => 1,
2178 :project_change => '1',
2187 :project_change => '1',
2179 :issue => {:project_id => 2,
2188 :issue => {:project_id => 2,
2180 :tracker_id => 2,
2189 :tracker_id => 2,
2181 :subject => 'This is the test_new issue',
2190 :subject => 'This is the test_new issue',
2182 :description => 'This is the description',
2191 :description => 'This is the description',
2183 :priority_id => 5}
2192 :priority_id => 5}
2184 assert_response :success
2193 assert_response :success
2185 assert_template 'form'
2194 assert_template 'form'
2186
2195
2187 issue = assigns(:issue)
2196 issue = assigns(:issue)
2188 assert_kind_of Issue, issue
2197 assert_kind_of Issue, issue
2189 assert_equal 1, issue.id
2198 assert_equal 1, issue.id
2190 assert_equal 2, issue.project_id
2199 assert_equal 2, issue.project_id
2191 assert_equal 2, issue.tracker_id
2200 assert_equal 2, issue.tracker_id
2192 assert_equal 'This is the test_new issue', issue.subject
2201 assert_equal 'This is the test_new issue', issue.subject
2193 end
2202 end
2194
2203
2195 def test_put_update_without_custom_fields_param
2204 def test_put_update_without_custom_fields_param
2196 @request.session[:user_id] = 2
2205 @request.session[:user_id] = 2
2197 ActionMailer::Base.deliveries.clear
2206 ActionMailer::Base.deliveries.clear
2198
2207
2199 issue = Issue.find(1)
2208 issue = Issue.find(1)
2200 assert_equal '125', issue.custom_value_for(2).value
2209 assert_equal '125', issue.custom_value_for(2).value
2201 old_subject = issue.subject
2210 old_subject = issue.subject
2202 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2211 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2203
2212
2204 assert_difference('Journal.count') do
2213 assert_difference('Journal.count') do
2205 assert_difference('JournalDetail.count', 2) do
2214 assert_difference('JournalDetail.count', 2) do
2206 put :update, :id => 1, :issue => {:subject => new_subject,
2215 put :update, :id => 1, :issue => {:subject => new_subject,
2207 :priority_id => '6',
2216 :priority_id => '6',
2208 :category_id => '1' # no change
2217 :category_id => '1' # no change
2209 }
2218 }
2210 end
2219 end
2211 end
2220 end
2212 assert_redirected_to :action => 'show', :id => '1'
2221 assert_redirected_to :action => 'show', :id => '1'
2213 issue.reload
2222 issue.reload
2214 assert_equal new_subject, issue.subject
2223 assert_equal new_subject, issue.subject
2215 # Make sure custom fields were not cleared
2224 # Make sure custom fields were not cleared
2216 assert_equal '125', issue.custom_value_for(2).value
2225 assert_equal '125', issue.custom_value_for(2).value
2217
2226
2218 mail = ActionMailer::Base.deliveries.last
2227 mail = ActionMailer::Base.deliveries.last
2219 assert_not_nil mail
2228 assert_not_nil mail
2220 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2229 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2221 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2230 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2222 end
2231 end
2223
2232
2224 def test_put_update_with_project_change
2233 def test_put_update_with_project_change
2225 @request.session[:user_id] = 2
2234 @request.session[:user_id] = 2
2226 ActionMailer::Base.deliveries.clear
2235 ActionMailer::Base.deliveries.clear
2227
2236
2228 assert_difference('Journal.count') do
2237 assert_difference('Journal.count') do
2229 assert_difference('JournalDetail.count', 3) do
2238 assert_difference('JournalDetail.count', 3) do
2230 put :update, :id => 1, :issue => {:project_id => '2',
2239 put :update, :id => 1, :issue => {:project_id => '2',
2231 :tracker_id => '1', # no change
2240 :tracker_id => '1', # no change
2232 :priority_id => '6',
2241 :priority_id => '6',
2233 :category_id => '3'
2242 :category_id => '3'
2234 }
2243 }
2235 end
2244 end
2236 end
2245 end
2237 assert_redirected_to :action => 'show', :id => '1'
2246 assert_redirected_to :action => 'show', :id => '1'
2238 issue = Issue.find(1)
2247 issue = Issue.find(1)
2239 assert_equal 2, issue.project_id
2248 assert_equal 2, issue.project_id
2240 assert_equal 1, issue.tracker_id
2249 assert_equal 1, issue.tracker_id
2241 assert_equal 6, issue.priority_id
2250 assert_equal 6, issue.priority_id
2242 assert_equal 3, issue.category_id
2251 assert_equal 3, issue.category_id
2243
2252
2244 mail = ActionMailer::Base.deliveries.last
2253 mail = ActionMailer::Base.deliveries.last
2245 assert_not_nil mail
2254 assert_not_nil mail
2246 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2255 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2247 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2256 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2248 end
2257 end
2249
2258
2250 def test_put_update_with_tracker_change
2259 def test_put_update_with_tracker_change
2251 @request.session[:user_id] = 2
2260 @request.session[:user_id] = 2
2252 ActionMailer::Base.deliveries.clear
2261 ActionMailer::Base.deliveries.clear
2253
2262
2254 assert_difference('Journal.count') do
2263 assert_difference('Journal.count') do
2255 assert_difference('JournalDetail.count', 2) do
2264 assert_difference('JournalDetail.count', 2) do
2256 put :update, :id => 1, :issue => {:project_id => '1',
2265 put :update, :id => 1, :issue => {:project_id => '1',
2257 :tracker_id => '2',
2266 :tracker_id => '2',
2258 :priority_id => '6'
2267 :priority_id => '6'
2259 }
2268 }
2260 end
2269 end
2261 end
2270 end
2262 assert_redirected_to :action => 'show', :id => '1'
2271 assert_redirected_to :action => 'show', :id => '1'
2263 issue = Issue.find(1)
2272 issue = Issue.find(1)
2264 assert_equal 1, issue.project_id
2273 assert_equal 1, issue.project_id
2265 assert_equal 2, issue.tracker_id
2274 assert_equal 2, issue.tracker_id
2266 assert_equal 6, issue.priority_id
2275 assert_equal 6, issue.priority_id
2267 assert_equal 1, issue.category_id
2276 assert_equal 1, issue.category_id
2268
2277
2269 mail = ActionMailer::Base.deliveries.last
2278 mail = ActionMailer::Base.deliveries.last
2270 assert_not_nil mail
2279 assert_not_nil mail
2271 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2280 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2272 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2281 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2273 end
2282 end
2274
2283
2275 def test_put_update_with_custom_field_change
2284 def test_put_update_with_custom_field_change
2276 @request.session[:user_id] = 2
2285 @request.session[:user_id] = 2
2277 issue = Issue.find(1)
2286 issue = Issue.find(1)
2278 assert_equal '125', issue.custom_value_for(2).value
2287 assert_equal '125', issue.custom_value_for(2).value
2279
2288
2280 assert_difference('Journal.count') do
2289 assert_difference('Journal.count') do
2281 assert_difference('JournalDetail.count', 3) do
2290 assert_difference('JournalDetail.count', 3) do
2282 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2291 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2283 :priority_id => '6',
2292 :priority_id => '6',
2284 :category_id => '1', # no change
2293 :category_id => '1', # no change
2285 :custom_field_values => { '2' => 'New custom value' }
2294 :custom_field_values => { '2' => 'New custom value' }
2286 }
2295 }
2287 end
2296 end
2288 end
2297 end
2289 assert_redirected_to :action => 'show', :id => '1'
2298 assert_redirected_to :action => 'show', :id => '1'
2290 issue.reload
2299 issue.reload
2291 assert_equal 'New custom value', issue.custom_value_for(2).value
2300 assert_equal 'New custom value', issue.custom_value_for(2).value
2292
2301
2293 mail = ActionMailer::Base.deliveries.last
2302 mail = ActionMailer::Base.deliveries.last
2294 assert_not_nil mail
2303 assert_not_nil mail
2295 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2304 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2296 end
2305 end
2297
2306
2298 def test_put_update_with_multi_custom_field_change
2307 def test_put_update_with_multi_custom_field_change
2299 field = CustomField.find(1)
2308 field = CustomField.find(1)
2300 field.update_attribute :multiple, true
2309 field.update_attribute :multiple, true
2301 issue = Issue.find(1)
2310 issue = Issue.find(1)
2302 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2311 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2303 issue.save!
2312 issue.save!
2304
2313
2305 @request.session[:user_id] = 2
2314 @request.session[:user_id] = 2
2306 assert_difference('Journal.count') do
2315 assert_difference('Journal.count') do
2307 assert_difference('JournalDetail.count', 3) do
2316 assert_difference('JournalDetail.count', 3) do
2308 put :update, :id => 1,
2317 put :update, :id => 1,
2309 :issue => {
2318 :issue => {
2310 :subject => 'Custom field change',
2319 :subject => 'Custom field change',
2311 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2320 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2312 }
2321 }
2313 end
2322 end
2314 end
2323 end
2315 assert_redirected_to :action => 'show', :id => '1'
2324 assert_redirected_to :action => 'show', :id => '1'
2316 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2325 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2317 end
2326 end
2318
2327
2319 def test_put_update_with_status_and_assignee_change
2328 def test_put_update_with_status_and_assignee_change
2320 issue = Issue.find(1)
2329 issue = Issue.find(1)
2321 assert_equal 1, issue.status_id
2330 assert_equal 1, issue.status_id
2322 @request.session[:user_id] = 2
2331 @request.session[:user_id] = 2
2323 assert_difference('TimeEntry.count', 0) do
2332 assert_difference('TimeEntry.count', 0) do
2324 put :update,
2333 put :update,
2325 :id => 1,
2334 :id => 1,
2326 :issue => { :status_id => 2, :assigned_to_id => 3 },
2335 :issue => { :status_id => 2, :assigned_to_id => 3 },
2327 :notes => 'Assigned to dlopper',
2336 :notes => 'Assigned to dlopper',
2328 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2337 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2329 end
2338 end
2330 assert_redirected_to :action => 'show', :id => '1'
2339 assert_redirected_to :action => 'show', :id => '1'
2331 issue.reload
2340 issue.reload
2332 assert_equal 2, issue.status_id
2341 assert_equal 2, issue.status_id
2333 j = Journal.find(:first, :order => 'id DESC')
2342 j = Journal.find(:first, :order => 'id DESC')
2334 assert_equal 'Assigned to dlopper', j.notes
2343 assert_equal 'Assigned to dlopper', j.notes
2335 assert_equal 2, j.details.size
2344 assert_equal 2, j.details.size
2336
2345
2337 mail = ActionMailer::Base.deliveries.last
2346 mail = ActionMailer::Base.deliveries.last
2338 assert_mail_body_match "Status changed from New to Assigned", mail
2347 assert_mail_body_match "Status changed from New to Assigned", mail
2339 # subject should contain the new status
2348 # subject should contain the new status
2340 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2349 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2341 end
2350 end
2342
2351
2343 def test_put_update_with_note_only
2352 def test_put_update_with_note_only
2344 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2353 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2345 # anonymous user
2354 # anonymous user
2346 put :update,
2355 put :update,
2347 :id => 1,
2356 :id => 1,
2348 :notes => notes
2357 :notes => notes
2349 assert_redirected_to :action => 'show', :id => '1'
2358 assert_redirected_to :action => 'show', :id => '1'
2350 j = Journal.find(:first, :order => 'id DESC')
2359 j = Journal.find(:first, :order => 'id DESC')
2351 assert_equal notes, j.notes
2360 assert_equal notes, j.notes
2352 assert_equal 0, j.details.size
2361 assert_equal 0, j.details.size
2353 assert_equal User.anonymous, j.user
2362 assert_equal User.anonymous, j.user
2354
2363
2355 mail = ActionMailer::Base.deliveries.last
2364 mail = ActionMailer::Base.deliveries.last
2356 assert_mail_body_match notes, mail
2365 assert_mail_body_match notes, mail
2357 end
2366 end
2358
2367
2359 def test_put_update_with_note_and_spent_time
2368 def test_put_update_with_note_and_spent_time
2360 @request.session[:user_id] = 2
2369 @request.session[:user_id] = 2
2361 spent_hours_before = Issue.find(1).spent_hours
2370 spent_hours_before = Issue.find(1).spent_hours
2362 assert_difference('TimeEntry.count') do
2371 assert_difference('TimeEntry.count') do
2363 put :update,
2372 put :update,
2364 :id => 1,
2373 :id => 1,
2365 :notes => '2.5 hours added',
2374 :notes => '2.5 hours added',
2366 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2375 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2367 end
2376 end
2368 assert_redirected_to :action => 'show', :id => '1'
2377 assert_redirected_to :action => 'show', :id => '1'
2369
2378
2370 issue = Issue.find(1)
2379 issue = Issue.find(1)
2371
2380
2372 j = Journal.find(:first, :order => 'id DESC')
2381 j = Journal.find(:first, :order => 'id DESC')
2373 assert_equal '2.5 hours added', j.notes
2382 assert_equal '2.5 hours added', j.notes
2374 assert_equal 0, j.details.size
2383 assert_equal 0, j.details.size
2375
2384
2376 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2385 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2377 assert_not_nil t
2386 assert_not_nil t
2378 assert_equal 2.5, t.hours
2387 assert_equal 2.5, t.hours
2379 assert_equal spent_hours_before + 2.5, issue.spent_hours
2388 assert_equal spent_hours_before + 2.5, issue.spent_hours
2380 end
2389 end
2381
2390
2382 def test_put_update_with_attachment_only
2391 def test_put_update_with_attachment_only
2383 set_tmp_attachments_directory
2392 set_tmp_attachments_directory
2384
2393
2385 # Delete all fixtured journals, a race condition can occur causing the wrong
2394 # Delete all fixtured journals, a race condition can occur causing the wrong
2386 # journal to get fetched in the next find.
2395 # journal to get fetched in the next find.
2387 Journal.delete_all
2396 Journal.delete_all
2388
2397
2389 # anonymous user
2398 # anonymous user
2390 assert_difference 'Attachment.count' do
2399 assert_difference 'Attachment.count' do
2391 put :update, :id => 1,
2400 put :update, :id => 1,
2392 :notes => '',
2401 :notes => '',
2393 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2402 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2394 end
2403 end
2395
2404
2396 assert_redirected_to :action => 'show', :id => '1'
2405 assert_redirected_to :action => 'show', :id => '1'
2397 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2406 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2398 assert j.notes.blank?
2407 assert j.notes.blank?
2399 assert_equal 1, j.details.size
2408 assert_equal 1, j.details.size
2400 assert_equal 'testfile.txt', j.details.first.value
2409 assert_equal 'testfile.txt', j.details.first.value
2401 assert_equal User.anonymous, j.user
2410 assert_equal User.anonymous, j.user
2402
2411
2403 attachment = Attachment.first(:order => 'id DESC')
2412 attachment = Attachment.first(:order => 'id DESC')
2404 assert_equal Issue.find(1), attachment.container
2413 assert_equal Issue.find(1), attachment.container
2405 assert_equal User.anonymous, attachment.author
2414 assert_equal User.anonymous, attachment.author
2406 assert_equal 'testfile.txt', attachment.filename
2415 assert_equal 'testfile.txt', attachment.filename
2407 assert_equal 'text/plain', attachment.content_type
2416 assert_equal 'text/plain', attachment.content_type
2408 assert_equal 'test file', attachment.description
2417 assert_equal 'test file', attachment.description
2409 assert_equal 59, attachment.filesize
2418 assert_equal 59, attachment.filesize
2410 assert File.exists?(attachment.diskfile)
2419 assert File.exists?(attachment.diskfile)
2411 assert_equal 59, File.size(attachment.diskfile)
2420 assert_equal 59, File.size(attachment.diskfile)
2412
2421
2413 mail = ActionMailer::Base.deliveries.last
2422 mail = ActionMailer::Base.deliveries.last
2414 assert_mail_body_match 'testfile.txt', mail
2423 assert_mail_body_match 'testfile.txt', mail
2415 end
2424 end
2416
2425
2417 def test_put_update_with_failure_should_save_attachments
2426 def test_put_update_with_failure_should_save_attachments
2418 set_tmp_attachments_directory
2427 set_tmp_attachments_directory
2419 @request.session[:user_id] = 2
2428 @request.session[:user_id] = 2
2420
2429
2421 assert_no_difference 'Journal.count' do
2430 assert_no_difference 'Journal.count' do
2422 assert_difference 'Attachment.count' do
2431 assert_difference 'Attachment.count' do
2423 put :update, :id => 1,
2432 put :update, :id => 1,
2424 :issue => { :subject => '' },
2433 :issue => { :subject => '' },
2425 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2434 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2426 assert_response :success
2435 assert_response :success
2427 assert_template 'edit'
2436 assert_template 'edit'
2428 end
2437 end
2429 end
2438 end
2430
2439
2431 attachment = Attachment.first(:order => 'id DESC')
2440 attachment = Attachment.first(:order => 'id DESC')
2432 assert_equal 'testfile.txt', attachment.filename
2441 assert_equal 'testfile.txt', attachment.filename
2433 assert File.exists?(attachment.diskfile)
2442 assert File.exists?(attachment.diskfile)
2434 assert_nil attachment.container
2443 assert_nil attachment.container
2435
2444
2436 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2445 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2437 assert_tag 'span', :content => /testfile.txt/
2446 assert_tag 'span', :content => /testfile.txt/
2438 end
2447 end
2439
2448
2440 def test_put_update_with_failure_should_keep_saved_attachments
2449 def test_put_update_with_failure_should_keep_saved_attachments
2441 set_tmp_attachments_directory
2450 set_tmp_attachments_directory
2442 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2451 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2443 @request.session[:user_id] = 2
2452 @request.session[:user_id] = 2
2444
2453
2445 assert_no_difference 'Journal.count' do
2454 assert_no_difference 'Journal.count' do
2446 assert_no_difference 'Attachment.count' do
2455 assert_no_difference 'Attachment.count' do
2447 put :update, :id => 1,
2456 put :update, :id => 1,
2448 :issue => { :subject => '' },
2457 :issue => { :subject => '' },
2449 :attachments => {'p0' => {'token' => attachment.token}}
2458 :attachments => {'p0' => {'token' => attachment.token}}
2450 assert_response :success
2459 assert_response :success
2451 assert_template 'edit'
2460 assert_template 'edit'
2452 end
2461 end
2453 end
2462 end
2454
2463
2455 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2464 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2456 assert_tag 'span', :content => /testfile.txt/
2465 assert_tag 'span', :content => /testfile.txt/
2457 end
2466 end
2458
2467
2459 def test_put_update_should_attach_saved_attachments
2468 def test_put_update_should_attach_saved_attachments
2460 set_tmp_attachments_directory
2469 set_tmp_attachments_directory
2461 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2470 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2462 @request.session[:user_id] = 2
2471 @request.session[:user_id] = 2
2463
2472
2464 assert_difference 'Journal.count' do
2473 assert_difference 'Journal.count' do
2465 assert_difference 'JournalDetail.count' do
2474 assert_difference 'JournalDetail.count' do
2466 assert_no_difference 'Attachment.count' do
2475 assert_no_difference 'Attachment.count' do
2467 put :update, :id => 1,
2476 put :update, :id => 1,
2468 :notes => 'Attachment added',
2477 :notes => 'Attachment added',
2469 :attachments => {'p0' => {'token' => attachment.token}}
2478 :attachments => {'p0' => {'token' => attachment.token}}
2470 assert_redirected_to '/issues/1'
2479 assert_redirected_to '/issues/1'
2471 end
2480 end
2472 end
2481 end
2473 end
2482 end
2474
2483
2475 attachment.reload
2484 attachment.reload
2476 assert_equal Issue.find(1), attachment.container
2485 assert_equal Issue.find(1), attachment.container
2477
2486
2478 journal = Journal.first(:order => 'id DESC')
2487 journal = Journal.first(:order => 'id DESC')
2479 assert_equal 1, journal.details.size
2488 assert_equal 1, journal.details.size
2480 assert_equal 'testfile.txt', journal.details.first.value
2489 assert_equal 'testfile.txt', journal.details.first.value
2481 end
2490 end
2482
2491
2483 def test_put_update_with_attachment_that_fails_to_save
2492 def test_put_update_with_attachment_that_fails_to_save
2484 set_tmp_attachments_directory
2493 set_tmp_attachments_directory
2485
2494
2486 # Delete all fixtured journals, a race condition can occur causing the wrong
2495 # Delete all fixtured journals, a race condition can occur causing the wrong
2487 # journal to get fetched in the next find.
2496 # journal to get fetched in the next find.
2488 Journal.delete_all
2497 Journal.delete_all
2489
2498
2490 # Mock out the unsaved attachment
2499 # Mock out the unsaved attachment
2491 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2500 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2492
2501
2493 # anonymous user
2502 # anonymous user
2494 put :update,
2503 put :update,
2495 :id => 1,
2504 :id => 1,
2496 :notes => '',
2505 :notes => '',
2497 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2506 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2498 assert_redirected_to :action => 'show', :id => '1'
2507 assert_redirected_to :action => 'show', :id => '1'
2499 assert_equal '1 file(s) could not be saved.', flash[:warning]
2508 assert_equal '1 file(s) could not be saved.', flash[:warning]
2500 end
2509 end
2501
2510
2502 def test_put_update_with_no_change
2511 def test_put_update_with_no_change
2503 issue = Issue.find(1)
2512 issue = Issue.find(1)
2504 issue.journals.clear
2513 issue.journals.clear
2505 ActionMailer::Base.deliveries.clear
2514 ActionMailer::Base.deliveries.clear
2506
2515
2507 put :update,
2516 put :update,
2508 :id => 1,
2517 :id => 1,
2509 :notes => ''
2518 :notes => ''
2510 assert_redirected_to :action => 'show', :id => '1'
2519 assert_redirected_to :action => 'show', :id => '1'
2511
2520
2512 issue.reload
2521 issue.reload
2513 assert issue.journals.empty?
2522 assert issue.journals.empty?
2514 # No email should be sent
2523 # No email should be sent
2515 assert ActionMailer::Base.deliveries.empty?
2524 assert ActionMailer::Base.deliveries.empty?
2516 end
2525 end
2517
2526
2518 def test_put_update_should_send_a_notification
2527 def test_put_update_should_send_a_notification
2519 @request.session[:user_id] = 2
2528 @request.session[:user_id] = 2
2520 ActionMailer::Base.deliveries.clear
2529 ActionMailer::Base.deliveries.clear
2521 issue = Issue.find(1)
2530 issue = Issue.find(1)
2522 old_subject = issue.subject
2531 old_subject = issue.subject
2523 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2532 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2524
2533
2525 put :update, :id => 1, :issue => {:subject => new_subject,
2534 put :update, :id => 1, :issue => {:subject => new_subject,
2526 :priority_id => '6',
2535 :priority_id => '6',
2527 :category_id => '1' # no change
2536 :category_id => '1' # no change
2528 }
2537 }
2529 assert_equal 1, ActionMailer::Base.deliveries.size
2538 assert_equal 1, ActionMailer::Base.deliveries.size
2530 end
2539 end
2531
2540
2532 def test_put_update_with_invalid_spent_time_hours_only
2541 def test_put_update_with_invalid_spent_time_hours_only
2533 @request.session[:user_id] = 2
2542 @request.session[:user_id] = 2
2534 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2543 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2535
2544
2536 assert_no_difference('Journal.count') do
2545 assert_no_difference('Journal.count') do
2537 put :update,
2546 put :update,
2538 :id => 1,
2547 :id => 1,
2539 :notes => notes,
2548 :notes => notes,
2540 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2549 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2541 end
2550 end
2542 assert_response :success
2551 assert_response :success
2543 assert_template 'edit'
2552 assert_template 'edit'
2544
2553
2545 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2554 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2546 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2555 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2547 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2556 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2548 end
2557 end
2549
2558
2550 def test_put_update_with_invalid_spent_time_comments_only
2559 def test_put_update_with_invalid_spent_time_comments_only
2551 @request.session[:user_id] = 2
2560 @request.session[:user_id] = 2
2552 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2561 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2553
2562
2554 assert_no_difference('Journal.count') do
2563 assert_no_difference('Journal.count') do
2555 put :update,
2564 put :update,
2556 :id => 1,
2565 :id => 1,
2557 :notes => notes,
2566 :notes => notes,
2558 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2567 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2559 end
2568 end
2560 assert_response :success
2569 assert_response :success
2561 assert_template 'edit'
2570 assert_template 'edit'
2562
2571
2563 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2572 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2564 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2573 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2565 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2574 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2566 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2575 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2567 end
2576 end
2568
2577
2569 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2578 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2570 issue = Issue.find(2)
2579 issue = Issue.find(2)
2571 @request.session[:user_id] = 2
2580 @request.session[:user_id] = 2
2572
2581
2573 put :update,
2582 put :update,
2574 :id => issue.id,
2583 :id => issue.id,
2575 :issue => {
2584 :issue => {
2576 :fixed_version_id => 4
2585 :fixed_version_id => 4
2577 }
2586 }
2578
2587
2579 assert_response :redirect
2588 assert_response :redirect
2580 issue.reload
2589 issue.reload
2581 assert_equal 4, issue.fixed_version_id
2590 assert_equal 4, issue.fixed_version_id
2582 assert_not_equal issue.project_id, issue.fixed_version.project_id
2591 assert_not_equal issue.project_id, issue.fixed_version.project_id
2583 end
2592 end
2584
2593
2585 def test_put_update_should_redirect_back_using_the_back_url_parameter
2594 def test_put_update_should_redirect_back_using_the_back_url_parameter
2586 issue = Issue.find(2)
2595 issue = Issue.find(2)
2587 @request.session[:user_id] = 2
2596 @request.session[:user_id] = 2
2588
2597
2589 put :update,
2598 put :update,
2590 :id => issue.id,
2599 :id => issue.id,
2591 :issue => {
2600 :issue => {
2592 :fixed_version_id => 4
2601 :fixed_version_id => 4
2593 },
2602 },
2594 :back_url => '/issues'
2603 :back_url => '/issues'
2595
2604
2596 assert_response :redirect
2605 assert_response :redirect
2597 assert_redirected_to '/issues'
2606 assert_redirected_to '/issues'
2598 end
2607 end
2599
2608
2600 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2609 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2601 issue = Issue.find(2)
2610 issue = Issue.find(2)
2602 @request.session[:user_id] = 2
2611 @request.session[:user_id] = 2
2603
2612
2604 put :update,
2613 put :update,
2605 :id => issue.id,
2614 :id => issue.id,
2606 :issue => {
2615 :issue => {
2607 :fixed_version_id => 4
2616 :fixed_version_id => 4
2608 },
2617 },
2609 :back_url => 'http://google.com'
2618 :back_url => 'http://google.com'
2610
2619
2611 assert_response :redirect
2620 assert_response :redirect
2612 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2621 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2613 end
2622 end
2614
2623
2615 def test_get_bulk_edit
2624 def test_get_bulk_edit
2616 @request.session[:user_id] = 2
2625 @request.session[:user_id] = 2
2617 get :bulk_edit, :ids => [1, 2]
2626 get :bulk_edit, :ids => [1, 2]
2618 assert_response :success
2627 assert_response :success
2619 assert_template 'bulk_edit'
2628 assert_template 'bulk_edit'
2620
2629
2621 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2630 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2622 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2631 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2623
2632
2624 # Project specific custom field, date type
2633 # Project specific custom field, date type
2625 field = CustomField.find(9)
2634 field = CustomField.find(9)
2626 assert !field.is_for_all?
2635 assert !field.is_for_all?
2627 assert_equal 'date', field.field_format
2636 assert_equal 'date', field.field_format
2628 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2637 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2629
2638
2630 # System wide custom field
2639 # System wide custom field
2631 assert CustomField.find(1).is_for_all?
2640 assert CustomField.find(1).is_for_all?
2632 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2641 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2633
2642
2634 # Be sure we don't display inactive IssuePriorities
2643 # Be sure we don't display inactive IssuePriorities
2635 assert ! IssuePriority.find(15).active?
2644 assert ! IssuePriority.find(15).active?
2636 assert_no_tag :option, :attributes => {:value => '15'},
2645 assert_no_tag :option, :attributes => {:value => '15'},
2637 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2646 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2638 end
2647 end
2639
2648
2640 def test_get_bulk_edit_on_different_projects
2649 def test_get_bulk_edit_on_different_projects
2641 @request.session[:user_id] = 2
2650 @request.session[:user_id] = 2
2642 get :bulk_edit, :ids => [1, 2, 6]
2651 get :bulk_edit, :ids => [1, 2, 6]
2643 assert_response :success
2652 assert_response :success
2644 assert_template 'bulk_edit'
2653 assert_template 'bulk_edit'
2645
2654
2646 # Can not set issues from different projects as children of an issue
2655 # Can not set issues from different projects as children of an issue
2647 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2656 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2648
2657
2649 # Project specific custom field, date type
2658 # Project specific custom field, date type
2650 field = CustomField.find(9)
2659 field = CustomField.find(9)
2651 assert !field.is_for_all?
2660 assert !field.is_for_all?
2652 assert !field.project_ids.include?(Issue.find(6).project_id)
2661 assert !field.project_ids.include?(Issue.find(6).project_id)
2653 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2662 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2654 end
2663 end
2655
2664
2656 def test_get_bulk_edit_with_user_custom_field
2665 def test_get_bulk_edit_with_user_custom_field
2657 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2666 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2658
2667
2659 @request.session[:user_id] = 2
2668 @request.session[:user_id] = 2
2660 get :bulk_edit, :ids => [1, 2]
2669 get :bulk_edit, :ids => [1, 2]
2661 assert_response :success
2670 assert_response :success
2662 assert_template 'bulk_edit'
2671 assert_template 'bulk_edit'
2663
2672
2664 assert_tag :select,
2673 assert_tag :select,
2665 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2674 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2666 :children => {
2675 :children => {
2667 :only => {:tag => 'option'},
2676 :only => {:tag => 'option'},
2668 :count => Project.find(1).users.count + 2 # "no change" + "none" options
2677 :count => Project.find(1).users.count + 2 # "no change" + "none" options
2669 }
2678 }
2670 end
2679 end
2671
2680
2672 def test_get_bulk_edit_with_version_custom_field
2681 def test_get_bulk_edit_with_version_custom_field
2673 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2682 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2674
2683
2675 @request.session[:user_id] = 2
2684 @request.session[:user_id] = 2
2676 get :bulk_edit, :ids => [1, 2]
2685 get :bulk_edit, :ids => [1, 2]
2677 assert_response :success
2686 assert_response :success
2678 assert_template 'bulk_edit'
2687 assert_template 'bulk_edit'
2679
2688
2680 assert_tag :select,
2689 assert_tag :select,
2681 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2690 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2682 :children => {
2691 :children => {
2683 :only => {:tag => 'option'},
2692 :only => {:tag => 'option'},
2684 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
2693 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
2685 }
2694 }
2686 end
2695 end
2687
2696
2688 def test_get_bulk_edit_with_multi_custom_field
2697 def test_get_bulk_edit_with_multi_custom_field
2689 field = CustomField.find(1)
2698 field = CustomField.find(1)
2690 field.update_attribute :multiple, true
2699 field.update_attribute :multiple, true
2691
2700
2692 @request.session[:user_id] = 2
2701 @request.session[:user_id] = 2
2693 get :bulk_edit, :ids => [1, 2]
2702 get :bulk_edit, :ids => [1, 2]
2694 assert_response :success
2703 assert_response :success
2695 assert_template 'bulk_edit'
2704 assert_template 'bulk_edit'
2696
2705
2697 assert_tag :select,
2706 assert_tag :select,
2698 :attributes => {:name => "issue[custom_field_values][1][]"},
2707 :attributes => {:name => "issue[custom_field_values][1][]"},
2699 :children => {
2708 :children => {
2700 :only => {:tag => 'option'},
2709 :only => {:tag => 'option'},
2701 :count => field.possible_values.size + 1 # "none" options
2710 :count => field.possible_values.size + 1 # "none" options
2702 }
2711 }
2703 end
2712 end
2704
2713
2705 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2714 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2706 Workflow.delete_all
2715 Workflow.delete_all
2707 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2716 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2708 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2717 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2709 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2718 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2710 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2719 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2711 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2720 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2712 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2721 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2713 @request.session[:user_id] = 2
2722 @request.session[:user_id] = 2
2714 get :bulk_edit, :ids => [1, 2]
2723 get :bulk_edit, :ids => [1, 2]
2715
2724
2716 assert_response :success
2725 assert_response :success
2717 statuses = assigns(:available_statuses)
2726 statuses = assigns(:available_statuses)
2718 assert_not_nil statuses
2727 assert_not_nil statuses
2719 assert_equal [1, 3], statuses.map(&:id).sort
2728 assert_equal [1, 3], statuses.map(&:id).sort
2720
2729
2721 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2730 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2722 :children => {:count => 3} # 2 statuses + "no change" option
2731 :children => {:count => 3} # 2 statuses + "no change" option
2723 end
2732 end
2724
2733
2725 def test_bulk_edit_should_propose_target_project_open_shared_versions
2734 def test_bulk_edit_should_propose_target_project_open_shared_versions
2726 @request.session[:user_id] = 2
2735 @request.session[:user_id] = 2
2727 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2736 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2728 assert_response :success
2737 assert_response :success
2729 assert_template 'bulk_edit'
2738 assert_template 'bulk_edit'
2730 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2739 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2731 assert_tag 'select',
2740 assert_tag 'select',
2732 :attributes => {:name => 'issue[fixed_version_id]'},
2741 :attributes => {:name => 'issue[fixed_version_id]'},
2733 :descendant => {:tag => 'option', :content => '2.0'}
2742 :descendant => {:tag => 'option', :content => '2.0'}
2734 end
2743 end
2735
2744
2736 def test_bulk_edit_should_propose_target_project_categories
2745 def test_bulk_edit_should_propose_target_project_categories
2737 @request.session[:user_id] = 2
2746 @request.session[:user_id] = 2
2738 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2747 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2739 assert_response :success
2748 assert_response :success
2740 assert_template 'bulk_edit'
2749 assert_template 'bulk_edit'
2741 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2750 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2742 assert_tag 'select',
2751 assert_tag 'select',
2743 :attributes => {:name => 'issue[category_id]'},
2752 :attributes => {:name => 'issue[category_id]'},
2744 :descendant => {:tag => 'option', :content => 'Recipes'}
2753 :descendant => {:tag => 'option', :content => 'Recipes'}
2745 end
2754 end
2746
2755
2747 def test_bulk_update
2756 def test_bulk_update
2748 @request.session[:user_id] = 2
2757 @request.session[:user_id] = 2
2749 # update issues priority
2758 # update issues priority
2750 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2759 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2751 :issue => {:priority_id => 7,
2760 :issue => {:priority_id => 7,
2752 :assigned_to_id => '',
2761 :assigned_to_id => '',
2753 :custom_field_values => {'2' => ''}}
2762 :custom_field_values => {'2' => ''}}
2754
2763
2755 assert_response 302
2764 assert_response 302
2756 # check that the issues were updated
2765 # check that the issues were updated
2757 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2766 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2758
2767
2759 issue = Issue.find(1)
2768 issue = Issue.find(1)
2760 journal = issue.journals.find(:first, :order => 'created_on DESC')
2769 journal = issue.journals.find(:first, :order => 'created_on DESC')
2761 assert_equal '125', issue.custom_value_for(2).value
2770 assert_equal '125', issue.custom_value_for(2).value
2762 assert_equal 'Bulk editing', journal.notes
2771 assert_equal 'Bulk editing', journal.notes
2763 assert_equal 1, journal.details.size
2772 assert_equal 1, journal.details.size
2764 end
2773 end
2765
2774
2766 def test_bulk_update_with_group_assignee
2775 def test_bulk_update_with_group_assignee
2767 group = Group.find(11)
2776 group = Group.find(11)
2768 project = Project.find(1)
2777 project = Project.find(1)
2769 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2778 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2770
2779
2771 @request.session[:user_id] = 2
2780 @request.session[:user_id] = 2
2772 # update issues assignee
2781 # update issues assignee
2773 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2782 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2774 :issue => {:priority_id => '',
2783 :issue => {:priority_id => '',
2775 :assigned_to_id => group.id,
2784 :assigned_to_id => group.id,
2776 :custom_field_values => {'2' => ''}}
2785 :custom_field_values => {'2' => ''}}
2777
2786
2778 assert_response 302
2787 assert_response 302
2779 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2788 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2780 end
2789 end
2781
2790
2782 def test_bulk_update_on_different_projects
2791 def test_bulk_update_on_different_projects
2783 @request.session[:user_id] = 2
2792 @request.session[:user_id] = 2
2784 # update issues priority
2793 # update issues priority
2785 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2794 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2786 :issue => {:priority_id => 7,
2795 :issue => {:priority_id => 7,
2787 :assigned_to_id => '',
2796 :assigned_to_id => '',
2788 :custom_field_values => {'2' => ''}}
2797 :custom_field_values => {'2' => ''}}
2789
2798
2790 assert_response 302
2799 assert_response 302
2791 # check that the issues were updated
2800 # check that the issues were updated
2792 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2801 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2793
2802
2794 issue = Issue.find(1)
2803 issue = Issue.find(1)
2795 journal = issue.journals.find(:first, :order => 'created_on DESC')
2804 journal = issue.journals.find(:first, :order => 'created_on DESC')
2796 assert_equal '125', issue.custom_value_for(2).value
2805 assert_equal '125', issue.custom_value_for(2).value
2797 assert_equal 'Bulk editing', journal.notes
2806 assert_equal 'Bulk editing', journal.notes
2798 assert_equal 1, journal.details.size
2807 assert_equal 1, journal.details.size
2799 end
2808 end
2800
2809
2801 def test_bulk_update_on_different_projects_without_rights
2810 def test_bulk_update_on_different_projects_without_rights
2802 @request.session[:user_id] = 3
2811 @request.session[:user_id] = 3
2803 user = User.find(3)
2812 user = User.find(3)
2804 action = { :controller => "issues", :action => "bulk_update" }
2813 action = { :controller => "issues", :action => "bulk_update" }
2805 assert user.allowed_to?(action, Issue.find(1).project)
2814 assert user.allowed_to?(action, Issue.find(1).project)
2806 assert ! user.allowed_to?(action, Issue.find(6).project)
2815 assert ! user.allowed_to?(action, Issue.find(6).project)
2807 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2816 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2808 :issue => {:priority_id => 7,
2817 :issue => {:priority_id => 7,
2809 :assigned_to_id => '',
2818 :assigned_to_id => '',
2810 :custom_field_values => {'2' => ''}}
2819 :custom_field_values => {'2' => ''}}
2811 assert_response 403
2820 assert_response 403
2812 assert_not_equal "Bulk should fail", Journal.last.notes
2821 assert_not_equal "Bulk should fail", Journal.last.notes
2813 end
2822 end
2814
2823
2815 def test_bullk_update_should_send_a_notification
2824 def test_bullk_update_should_send_a_notification
2816 @request.session[:user_id] = 2
2825 @request.session[:user_id] = 2
2817 ActionMailer::Base.deliveries.clear
2826 ActionMailer::Base.deliveries.clear
2818 post(:bulk_update,
2827 post(:bulk_update,
2819 {
2828 {
2820 :ids => [1, 2],
2829 :ids => [1, 2],
2821 :notes => 'Bulk editing',
2830 :notes => 'Bulk editing',
2822 :issue => {
2831 :issue => {
2823 :priority_id => 7,
2832 :priority_id => 7,
2824 :assigned_to_id => '',
2833 :assigned_to_id => '',
2825 :custom_field_values => {'2' => ''}
2834 :custom_field_values => {'2' => ''}
2826 }
2835 }
2827 })
2836 })
2828
2837
2829 assert_response 302
2838 assert_response 302
2830 assert_equal 2, ActionMailer::Base.deliveries.size
2839 assert_equal 2, ActionMailer::Base.deliveries.size
2831 end
2840 end
2832
2841
2833 def test_bulk_update_project
2842 def test_bulk_update_project
2834 @request.session[:user_id] = 2
2843 @request.session[:user_id] = 2
2835 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2844 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2836 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2845 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2837 # Issues moved to project 2
2846 # Issues moved to project 2
2838 assert_equal 2, Issue.find(1).project_id
2847 assert_equal 2, Issue.find(1).project_id
2839 assert_equal 2, Issue.find(2).project_id
2848 assert_equal 2, Issue.find(2).project_id
2840 # No tracker change
2849 # No tracker change
2841 assert_equal 1, Issue.find(1).tracker_id
2850 assert_equal 1, Issue.find(1).tracker_id
2842 assert_equal 2, Issue.find(2).tracker_id
2851 assert_equal 2, Issue.find(2).tracker_id
2843 end
2852 end
2844
2853
2845 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2854 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2846 @request.session[:user_id] = 2
2855 @request.session[:user_id] = 2
2847 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2856 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2848 assert_redirected_to '/issues/1'
2857 assert_redirected_to '/issues/1'
2849 end
2858 end
2850
2859
2851 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2860 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2852 @request.session[:user_id] = 2
2861 @request.session[:user_id] = 2
2853 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2862 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2854 assert_redirected_to '/projects/onlinestore/issues'
2863 assert_redirected_to '/projects/onlinestore/issues'
2855 end
2864 end
2856
2865
2857 def test_bulk_update_tracker
2866 def test_bulk_update_tracker
2858 @request.session[:user_id] = 2
2867 @request.session[:user_id] = 2
2859 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2868 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2860 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2869 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2861 assert_equal 2, Issue.find(1).tracker_id
2870 assert_equal 2, Issue.find(1).tracker_id
2862 assert_equal 2, Issue.find(2).tracker_id
2871 assert_equal 2, Issue.find(2).tracker_id
2863 end
2872 end
2864
2873
2865 def test_bulk_update_status
2874 def test_bulk_update_status
2866 @request.session[:user_id] = 2
2875 @request.session[:user_id] = 2
2867 # update issues priority
2876 # update issues priority
2868 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2877 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2869 :issue => {:priority_id => '',
2878 :issue => {:priority_id => '',
2870 :assigned_to_id => '',
2879 :assigned_to_id => '',
2871 :status_id => '5'}
2880 :status_id => '5'}
2872
2881
2873 assert_response 302
2882 assert_response 302
2874 issue = Issue.find(1)
2883 issue = Issue.find(1)
2875 assert issue.closed?
2884 assert issue.closed?
2876 end
2885 end
2877
2886
2878 def test_bulk_update_priority
2887 def test_bulk_update_priority
2879 @request.session[:user_id] = 2
2888 @request.session[:user_id] = 2
2880 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2889 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2881
2890
2882 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2891 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2883 assert_equal 6, Issue.find(1).priority_id
2892 assert_equal 6, Issue.find(1).priority_id
2884 assert_equal 6, Issue.find(2).priority_id
2893 assert_equal 6, Issue.find(2).priority_id
2885 end
2894 end
2886
2895
2887 def test_bulk_update_with_notes
2896 def test_bulk_update_with_notes
2888 @request.session[:user_id] = 2
2897 @request.session[:user_id] = 2
2889 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2898 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2890
2899
2891 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2900 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2892 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2901 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2893 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2902 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2894 end
2903 end
2895
2904
2896 def test_bulk_update_parent_id
2905 def test_bulk_update_parent_id
2897 @request.session[:user_id] = 2
2906 @request.session[:user_id] = 2
2898 post :bulk_update, :ids => [1, 3],
2907 post :bulk_update, :ids => [1, 3],
2899 :notes => 'Bulk editing parent',
2908 :notes => 'Bulk editing parent',
2900 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2909 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2901
2910
2902 assert_response 302
2911 assert_response 302
2903 parent = Issue.find(2)
2912 parent = Issue.find(2)
2904 assert_equal parent.id, Issue.find(1).parent_id
2913 assert_equal parent.id, Issue.find(1).parent_id
2905 assert_equal parent.id, Issue.find(3).parent_id
2914 assert_equal parent.id, Issue.find(3).parent_id
2906 assert_equal [1, 3], parent.children.collect(&:id).sort
2915 assert_equal [1, 3], parent.children.collect(&:id).sort
2907 end
2916 end
2908
2917
2909 def test_bulk_update_custom_field
2918 def test_bulk_update_custom_field
2910 @request.session[:user_id] = 2
2919 @request.session[:user_id] = 2
2911 # update issues priority
2920 # update issues priority
2912 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2921 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2913 :issue => {:priority_id => '',
2922 :issue => {:priority_id => '',
2914 :assigned_to_id => '',
2923 :assigned_to_id => '',
2915 :custom_field_values => {'2' => '777'}}
2924 :custom_field_values => {'2' => '777'}}
2916
2925
2917 assert_response 302
2926 assert_response 302
2918
2927
2919 issue = Issue.find(1)
2928 issue = Issue.find(1)
2920 journal = issue.journals.find(:first, :order => 'created_on DESC')
2929 journal = issue.journals.find(:first, :order => 'created_on DESC')
2921 assert_equal '777', issue.custom_value_for(2).value
2930 assert_equal '777', issue.custom_value_for(2).value
2922 assert_equal 1, journal.details.size
2931 assert_equal 1, journal.details.size
2923 assert_equal '125', journal.details.first.old_value
2932 assert_equal '125', journal.details.first.old_value
2924 assert_equal '777', journal.details.first.value
2933 assert_equal '777', journal.details.first.value
2925 end
2934 end
2926
2935
2927 def test_bulk_update_custom_field_to_blank
2936 def test_bulk_update_custom_field_to_blank
2928 @request.session[:user_id] = 2
2937 @request.session[:user_id] = 2
2929 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
2938 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
2930 :issue => {:priority_id => '',
2939 :issue => {:priority_id => '',
2931 :assigned_to_id => '',
2940 :assigned_to_id => '',
2932 :custom_field_values => {'1' => '__none__'}}
2941 :custom_field_values => {'1' => '__none__'}}
2933 assert_response 302
2942 assert_response 302
2934 assert_equal '', Issue.find(1).custom_field_value(1)
2943 assert_equal '', Issue.find(1).custom_field_value(1)
2935 assert_equal '', Issue.find(3).custom_field_value(1)
2944 assert_equal '', Issue.find(3).custom_field_value(1)
2936 end
2945 end
2937
2946
2938 def test_bulk_update_multi_custom_field
2947 def test_bulk_update_multi_custom_field
2939 field = CustomField.find(1)
2948 field = CustomField.find(1)
2940 field.update_attribute :multiple, true
2949 field.update_attribute :multiple, true
2941
2950
2942 @request.session[:user_id] = 2
2951 @request.session[:user_id] = 2
2943 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2952 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2944 :issue => {:priority_id => '',
2953 :issue => {:priority_id => '',
2945 :assigned_to_id => '',
2954 :assigned_to_id => '',
2946 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2955 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2947
2956
2948 assert_response 302
2957 assert_response 302
2949
2958
2950 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2959 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2951 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2960 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2952 # the custom field is not associated with the issue tracker
2961 # the custom field is not associated with the issue tracker
2953 assert_nil Issue.find(2).custom_field_value(1)
2962 assert_nil Issue.find(2).custom_field_value(1)
2954 end
2963 end
2955
2964
2956 def test_bulk_update_multi_custom_field_to_blank
2965 def test_bulk_update_multi_custom_field_to_blank
2957 field = CustomField.find(1)
2966 field = CustomField.find(1)
2958 field.update_attribute :multiple, true
2967 field.update_attribute :multiple, true
2959
2968
2960 @request.session[:user_id] = 2
2969 @request.session[:user_id] = 2
2961 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
2970 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
2962 :issue => {:priority_id => '',
2971 :issue => {:priority_id => '',
2963 :assigned_to_id => '',
2972 :assigned_to_id => '',
2964 :custom_field_values => {'1' => ['__none__']}}
2973 :custom_field_values => {'1' => ['__none__']}}
2965 assert_response 302
2974 assert_response 302
2966 assert_equal [''], Issue.find(1).custom_field_value(1)
2975 assert_equal [''], Issue.find(1).custom_field_value(1)
2967 assert_equal [''], Issue.find(3).custom_field_value(1)
2976 assert_equal [''], Issue.find(3).custom_field_value(1)
2968 end
2977 end
2969
2978
2970 def test_bulk_update_unassign
2979 def test_bulk_update_unassign
2971 assert_not_nil Issue.find(2).assigned_to
2980 assert_not_nil Issue.find(2).assigned_to
2972 @request.session[:user_id] = 2
2981 @request.session[:user_id] = 2
2973 # unassign issues
2982 # unassign issues
2974 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2983 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2975 assert_response 302
2984 assert_response 302
2976 # check that the issues were updated
2985 # check that the issues were updated
2977 assert_nil Issue.find(2).assigned_to
2986 assert_nil Issue.find(2).assigned_to
2978 end
2987 end
2979
2988
2980 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2989 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2981 @request.session[:user_id] = 2
2990 @request.session[:user_id] = 2
2982
2991
2983 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2992 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2984
2993
2985 assert_response :redirect
2994 assert_response :redirect
2986 issues = Issue.find([1,2])
2995 issues = Issue.find([1,2])
2987 issues.each do |issue|
2996 issues.each do |issue|
2988 assert_equal 4, issue.fixed_version_id
2997 assert_equal 4, issue.fixed_version_id
2989 assert_not_equal issue.project_id, issue.fixed_version.project_id
2998 assert_not_equal issue.project_id, issue.fixed_version.project_id
2990 end
2999 end
2991 end
3000 end
2992
3001
2993 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3002 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2994 @request.session[:user_id] = 2
3003 @request.session[:user_id] = 2
2995 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3004 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2996
3005
2997 assert_response :redirect
3006 assert_response :redirect
2998 assert_redirected_to '/issues'
3007 assert_redirected_to '/issues'
2999 end
3008 end
3000
3009
3001 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3010 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3002 @request.session[:user_id] = 2
3011 @request.session[:user_id] = 2
3003 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3012 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3004
3013
3005 assert_response :redirect
3014 assert_response :redirect
3006 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3015 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3007 end
3016 end
3008
3017
3009 def test_bulk_update_with_failure_should_set_flash
3018 def test_bulk_update_with_failure_should_set_flash
3010 @request.session[:user_id] = 2
3019 @request.session[:user_id] = 2
3011 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3020 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3012 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3021 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3013
3022
3014 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3023 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3015 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3024 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3016 end
3025 end
3017
3026
3018 def test_bulk_copy_to_another_project
3027 def test_bulk_copy_to_another_project
3019 @request.session[:user_id] = 2
3028 @request.session[:user_id] = 2
3020 assert_difference 'Issue.count', 2 do
3029 assert_difference 'Issue.count', 2 do
3021 assert_no_difference 'Project.find(1).issues.count' do
3030 assert_no_difference 'Project.find(1).issues.count' do
3022 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3031 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3023 end
3032 end
3024 end
3033 end
3025 assert_redirected_to '/projects/ecookbook/issues'
3034 assert_redirected_to '/projects/ecookbook/issues'
3026 end
3035 end
3027
3036
3028 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3037 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3029 @request.session[:user_id] = 2
3038 @request.session[:user_id] = 2
3030 issue_before_move = Issue.find(1)
3039 issue_before_move = Issue.find(1)
3031 assert_difference 'Issue.count', 1 do
3040 assert_difference 'Issue.count', 1 do
3032 assert_no_difference 'Project.find(1).issues.count' do
3041 assert_no_difference 'Project.find(1).issues.count' do
3033 post :bulk_update, :ids => [1], :copy => '1',
3042 post :bulk_update, :ids => [1], :copy => '1',
3034 :issue => {
3043 :issue => {
3035 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
3044 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
3036 :status_id => '', :start_date => '', :due_date => ''
3045 :status_id => '', :start_date => '', :due_date => ''
3037 }
3046 }
3038 end
3047 end
3039 end
3048 end
3040 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
3049 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
3041 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
3050 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
3042 assert_equal issue_before_move.status_id, issue_after_move.status_id
3051 assert_equal issue_before_move.status_id, issue_after_move.status_id
3043 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
3052 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
3044 end
3053 end
3045
3054
3046 def test_bulk_copy_should_allow_changing_the_issue_attributes
3055 def test_bulk_copy_should_allow_changing_the_issue_attributes
3047 # Fixes random test failure with Mysql
3056 # Fixes random test failure with Mysql
3048 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3057 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3049 # doesn't return the expected results
3058 # doesn't return the expected results
3050 Issue.delete_all("project_id=2")
3059 Issue.delete_all("project_id=2")
3051
3060
3052 @request.session[:user_id] = 2
3061 @request.session[:user_id] = 2
3053 assert_difference 'Issue.count', 2 do
3062 assert_difference 'Issue.count', 2 do
3054 assert_no_difference 'Project.find(1).issues.count' do
3063 assert_no_difference 'Project.find(1).issues.count' do
3055 post :bulk_update, :ids => [1, 2], :copy => '1',
3064 post :bulk_update, :ids => [1, 2], :copy => '1',
3056 :issue => {
3065 :issue => {
3057 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3066 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3058 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3067 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3059 }
3068 }
3060 end
3069 end
3061 end
3070 end
3062
3071
3063 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3072 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3064 assert_equal 2, copied_issues.size
3073 assert_equal 2, copied_issues.size
3065 copied_issues.each do |issue|
3074 copied_issues.each do |issue|
3066 assert_equal 2, issue.project_id, "Project is incorrect"
3075 assert_equal 2, issue.project_id, "Project is incorrect"
3067 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3076 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3068 assert_equal 3, issue.status_id, "Status is incorrect"
3077 assert_equal 3, issue.status_id, "Status is incorrect"
3069 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3078 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3070 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3079 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3071 end
3080 end
3072 end
3081 end
3073
3082
3074 def test_bulk_copy_should_allow_adding_a_note
3083 def test_bulk_copy_should_allow_adding_a_note
3075 @request.session[:user_id] = 2
3084 @request.session[:user_id] = 2
3076 assert_difference 'Issue.count', 1 do
3085 assert_difference 'Issue.count', 1 do
3077 post :bulk_update, :ids => [1], :copy => '1',
3086 post :bulk_update, :ids => [1], :copy => '1',
3078 :notes => 'Copying one issue',
3087 :notes => 'Copying one issue',
3079 :issue => {
3088 :issue => {
3080 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3089 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3081 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3090 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3082 }
3091 }
3083 end
3092 end
3084
3093
3085 issue = Issue.first(:order => 'id DESC')
3094 issue = Issue.first(:order => 'id DESC')
3086 assert_equal 1, issue.journals.size
3095 assert_equal 1, issue.journals.size
3087 journal = issue.journals.first
3096 journal = issue.journals.first
3088 assert_equal 0, journal.details.size
3097 assert_equal 0, journal.details.size
3089 assert_equal 'Copying one issue', journal.notes
3098 assert_equal 'Copying one issue', journal.notes
3090 end
3099 end
3091
3100
3092 def test_bulk_copy_to_another_project_should_follow_when_needed
3101 def test_bulk_copy_to_another_project_should_follow_when_needed
3093 @request.session[:user_id] = 2
3102 @request.session[:user_id] = 2
3094 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3103 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3095 issue = Issue.first(:order => 'id DESC')
3104 issue = Issue.first(:order => 'id DESC')
3096 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3105 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3097 end
3106 end
3098
3107
3099 def test_destroy_issue_with_no_time_entries
3108 def test_destroy_issue_with_no_time_entries
3100 assert_nil TimeEntry.find_by_issue_id(2)
3109 assert_nil TimeEntry.find_by_issue_id(2)
3101 @request.session[:user_id] = 2
3110 @request.session[:user_id] = 2
3102
3111
3103 assert_difference 'Issue.count', -1 do
3112 assert_difference 'Issue.count', -1 do
3104 delete :destroy, :id => 2
3113 delete :destroy, :id => 2
3105 end
3114 end
3106 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3115 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3107 assert_nil Issue.find_by_id(2)
3116 assert_nil Issue.find_by_id(2)
3108 end
3117 end
3109
3118
3110 def test_destroy_issues_with_time_entries
3119 def test_destroy_issues_with_time_entries
3111 @request.session[:user_id] = 2
3120 @request.session[:user_id] = 2
3112
3121
3113 assert_no_difference 'Issue.count' do
3122 assert_no_difference 'Issue.count' do
3114 delete :destroy, :ids => [1, 3]
3123 delete :destroy, :ids => [1, 3]
3115 end
3124 end
3116 assert_response :success
3125 assert_response :success
3117 assert_template 'destroy'
3126 assert_template 'destroy'
3118 assert_not_nil assigns(:hours)
3127 assert_not_nil assigns(:hours)
3119 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3128 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3120 assert_tag 'form',
3129 assert_tag 'form',
3121 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3130 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3122 end
3131 end
3123
3132
3124 def test_destroy_issues_and_destroy_time_entries
3133 def test_destroy_issues_and_destroy_time_entries
3125 @request.session[:user_id] = 2
3134 @request.session[:user_id] = 2
3126
3135
3127 assert_difference 'Issue.count', -2 do
3136 assert_difference 'Issue.count', -2 do
3128 assert_difference 'TimeEntry.count', -3 do
3137 assert_difference 'TimeEntry.count', -3 do
3129 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3138 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3130 end
3139 end
3131 end
3140 end
3132 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3141 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3133 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3142 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3134 assert_nil TimeEntry.find_by_id([1, 2])
3143 assert_nil TimeEntry.find_by_id([1, 2])
3135 end
3144 end
3136
3145
3137 def test_destroy_issues_and_assign_time_entries_to_project
3146 def test_destroy_issues_and_assign_time_entries_to_project
3138 @request.session[:user_id] = 2
3147 @request.session[:user_id] = 2
3139
3148
3140 assert_difference 'Issue.count', -2 do
3149 assert_difference 'Issue.count', -2 do
3141 assert_no_difference 'TimeEntry.count' do
3150 assert_no_difference 'TimeEntry.count' do
3142 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3151 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3143 end
3152 end
3144 end
3153 end
3145 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3154 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3146 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3155 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3147 assert_nil TimeEntry.find(1).issue_id
3156 assert_nil TimeEntry.find(1).issue_id
3148 assert_nil TimeEntry.find(2).issue_id
3157 assert_nil TimeEntry.find(2).issue_id
3149 end
3158 end
3150
3159
3151 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3160 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3152 @request.session[:user_id] = 2
3161 @request.session[:user_id] = 2
3153
3162
3154 assert_difference 'Issue.count', -2 do
3163 assert_difference 'Issue.count', -2 do
3155 assert_no_difference 'TimeEntry.count' do
3164 assert_no_difference 'TimeEntry.count' do
3156 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3165 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3157 end
3166 end
3158 end
3167 end
3159 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3168 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3160 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3169 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3161 assert_equal 2, TimeEntry.find(1).issue_id
3170 assert_equal 2, TimeEntry.find(1).issue_id
3162 assert_equal 2, TimeEntry.find(2).issue_id
3171 assert_equal 2, TimeEntry.find(2).issue_id
3163 end
3172 end
3164
3173
3165 def test_destroy_issues_from_different_projects
3174 def test_destroy_issues_from_different_projects
3166 @request.session[:user_id] = 2
3175 @request.session[:user_id] = 2
3167
3176
3168 assert_difference 'Issue.count', -3 do
3177 assert_difference 'Issue.count', -3 do
3169 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3178 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3170 end
3179 end
3171 assert_redirected_to :controller => 'issues', :action => 'index'
3180 assert_redirected_to :controller => 'issues', :action => 'index'
3172 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3181 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3173 end
3182 end
3174
3183
3175 def test_destroy_parent_and_child_issues
3184 def test_destroy_parent_and_child_issues
3176 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3185 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3177 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3186 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3178 assert child.is_descendant_of?(parent.reload)
3187 assert child.is_descendant_of?(parent.reload)
3179
3188
3180 @request.session[:user_id] = 2
3189 @request.session[:user_id] = 2
3181 assert_difference 'Issue.count', -2 do
3190 assert_difference 'Issue.count', -2 do
3182 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3191 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3183 end
3192 end
3184 assert_response 302
3193 assert_response 302
3185 end
3194 end
3186
3195
3187 def test_default_search_scope
3196 def test_default_search_scope
3188 get :index
3197 get :index
3189 assert_tag :div, :attributes => {:id => 'quick-search'},
3198 assert_tag :div, :attributes => {:id => 'quick-search'},
3190 :child => {:tag => 'form',
3199 :child => {:tag => 'form',
3191 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3200 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3192 end
3201 end
3193 end
3202 end
General Comments 0
You need to be logged in to leave comments. Login now