##// END OF EJS Templates
Fixed: Routing error when deleting an issue with spent time....
Jean-Philippe Lang -
r8512:3c75d6036fda
parent child
Show More
@@ -1,15 +1,15
1 <h2><%= l(:label_confirmation) %></h2>
1 <h2><%= l(:label_confirmation) %></h2>
2
2
3 <% form_tag do %>
3 <% form_tag({}, :method => :delete) do %>
4 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
4 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
5 <div class="box">
5 <div class="box">
6 <p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
6 <p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
7 <p>
7 <p>
8 <label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
8 <label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
9 <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
9 <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
10 <label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
10 <label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
11 <%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("todo_reassign").checked=true;' %>
11 <%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("todo_reassign").checked=true;' %>
12 </p>
12 </p>
13 </div>
13 </div>
14 <%= submit_tag l(:button_apply) %>
14 <%= submit_tag l(:button_apply) %>
15 <% end %>
15 <% end %>
@@ -1,2547 +1,2549
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 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
45
46 include Redmine::I18n
46 include Redmine::I18n
47
47
48 def setup
48 def setup
49 @controller = IssuesController.new
49 @controller = IssuesController.new
50 @request = ActionController::TestRequest.new
50 @request = ActionController::TestRequest.new
51 @response = ActionController::TestResponse.new
51 @response = ActionController::TestResponse.new
52 User.current = nil
52 User.current = nil
53 end
53 end
54
54
55 def test_index
55 def test_index
56 Setting.default_language = 'en'
56 Setting.default_language = 'en'
57
57
58 get :index
58 get :index
59 assert_response :success
59 assert_response :success
60 assert_template 'index'
60 assert_template 'index'
61 assert_not_nil assigns(:issues)
61 assert_not_nil assigns(:issues)
62 assert_nil assigns(:project)
62 assert_nil assigns(:project)
63 assert_tag :tag => 'a', :content => /Can't print recipes/
63 assert_tag :tag => 'a', :content => /Can't print recipes/
64 assert_tag :tag => 'a', :content => /Subproject issue/
64 assert_tag :tag => 'a', :content => /Subproject issue/
65 # private projects hidden
65 # private projects hidden
66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 # project column
68 # project column
69 assert_tag :tag => 'th', :content => /Project/
69 assert_tag :tag => 'th', :content => /Project/
70 end
70 end
71
71
72 def test_index_should_not_list_issues_when_module_disabled
72 def test_index_should_not_list_issues_when_module_disabled
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 get :index
74 get :index
75 assert_response :success
75 assert_response :success
76 assert_template 'index'
76 assert_template 'index'
77 assert_not_nil assigns(:issues)
77 assert_not_nil assigns(:issues)
78 assert_nil assigns(:project)
78 assert_nil assigns(:project)
79 assert_no_tag :tag => 'a', :content => /Can't print recipes/
79 assert_no_tag :tag => 'a', :content => /Can't print recipes/
80 assert_tag :tag => 'a', :content => /Subproject issue/
80 assert_tag :tag => 'a', :content => /Subproject issue/
81 end
81 end
82
82
83 def test_index_should_list_visible_issues_only
83 def test_index_should_list_visible_issues_only
84 get :index, :per_page => 100
84 get :index, :per_page => 100
85 assert_response :success
85 assert_response :success
86 assert_not_nil assigns(:issues)
86 assert_not_nil assigns(:issues)
87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
88 end
88 end
89
89
90 def test_index_with_project
90 def test_index_with_project
91 Setting.display_subprojects_issues = 0
91 Setting.display_subprojects_issues = 0
92 get :index, :project_id => 1
92 get :index, :project_id => 1
93 assert_response :success
93 assert_response :success
94 assert_template 'index'
94 assert_template 'index'
95 assert_not_nil assigns(:issues)
95 assert_not_nil assigns(:issues)
96 assert_tag :tag => 'a', :content => /Can't print recipes/
96 assert_tag :tag => 'a', :content => /Can't print recipes/
97 assert_no_tag :tag => 'a', :content => /Subproject issue/
97 assert_no_tag :tag => 'a', :content => /Subproject issue/
98 end
98 end
99
99
100 def test_index_with_project_and_subprojects
100 def test_index_with_project_and_subprojects
101 Setting.display_subprojects_issues = 1
101 Setting.display_subprojects_issues = 1
102 get :index, :project_id => 1
102 get :index, :project_id => 1
103 assert_response :success
103 assert_response :success
104 assert_template 'index'
104 assert_template 'index'
105 assert_not_nil assigns(:issues)
105 assert_not_nil assigns(:issues)
106 assert_tag :tag => 'a', :content => /Can't print recipes/
106 assert_tag :tag => 'a', :content => /Can't print recipes/
107 assert_tag :tag => 'a', :content => /Subproject issue/
107 assert_tag :tag => 'a', :content => /Subproject issue/
108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
109 end
109 end
110
110
111 def test_index_with_project_and_subprojects_should_show_private_subprojects
111 def test_index_with_project_and_subprojects_should_show_private_subprojects
112 @request.session[:user_id] = 2
112 @request.session[:user_id] = 2
113 Setting.display_subprojects_issues = 1
113 Setting.display_subprojects_issues = 1
114 get :index, :project_id => 1
114 get :index, :project_id => 1
115 assert_response :success
115 assert_response :success
116 assert_template 'index'
116 assert_template 'index'
117 assert_not_nil assigns(:issues)
117 assert_not_nil assigns(:issues)
118 assert_tag :tag => 'a', :content => /Can't print recipes/
118 assert_tag :tag => 'a', :content => /Can't print recipes/
119 assert_tag :tag => 'a', :content => /Subproject issue/
119 assert_tag :tag => 'a', :content => /Subproject issue/
120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
121 end
121 end
122
122
123 def test_index_with_project_and_default_filter
123 def test_index_with_project_and_default_filter
124 get :index, :project_id => 1, :set_filter => 1
124 get :index, :project_id => 1, :set_filter => 1
125 assert_response :success
125 assert_response :success
126 assert_template 'index'
126 assert_template 'index'
127 assert_not_nil assigns(:issues)
127 assert_not_nil assigns(:issues)
128
128
129 query = assigns(:query)
129 query = assigns(:query)
130 assert_not_nil query
130 assert_not_nil query
131 # default filter
131 # default filter
132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
133 end
133 end
134
134
135 def test_index_with_project_and_filter
135 def test_index_with_project_and_filter
136 get :index, :project_id => 1, :set_filter => 1,
136 get :index, :project_id => 1, :set_filter => 1,
137 :f => ['tracker_id'],
137 :f => ['tracker_id'],
138 :op => {'tracker_id' => '='},
138 :op => {'tracker_id' => '='},
139 :v => {'tracker_id' => ['1']}
139 :v => {'tracker_id' => ['1']}
140 assert_response :success
140 assert_response :success
141 assert_template 'index'
141 assert_template 'index'
142 assert_not_nil assigns(:issues)
142 assert_not_nil assigns(:issues)
143
143
144 query = assigns(:query)
144 query = assigns(:query)
145 assert_not_nil query
145 assert_not_nil query
146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
147 end
147 end
148
148
149 def test_index_with_short_filters
149 def test_index_with_short_filters
150
150
151 to_test = {
151 to_test = {
152 'status_id' => {
152 'status_id' => {
153 'o' => { :op => 'o', :values => [''] },
153 'o' => { :op => 'o', :values => [''] },
154 'c' => { :op => 'c', :values => [''] },
154 'c' => { :op => 'c', :values => [''] },
155 '7' => { :op => '=', :values => ['7'] },
155 '7' => { :op => '=', :values => ['7'] },
156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
157 '=7' => { :op => '=', :values => ['7'] },
157 '=7' => { :op => '=', :values => ['7'] },
158 '!3' => { :op => '!', :values => ['3'] },
158 '!3' => { :op => '!', :values => ['3'] },
159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
160 'subject' => {
160 'subject' => {
161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
162 'o' => { :op => '=', :values => ['o'] },
162 'o' => { :op => '=', :values => ['o'] },
163 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
163 '~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'] }},
164 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
165 'tracker_id' => {
165 'tracker_id' => {
166 '3' => { :op => '=', :values => ['3'] },
166 '3' => { :op => '=', :values => ['3'] },
167 '=3' => { :op => '=', :values => ['3'] }},
167 '=3' => { :op => '=', :values => ['3'] }},
168 'start_date' => {
168 'start_date' => {
169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
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-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
173 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
174 '<t+2' => { :op => '<t+', :values => ['2'] },
174 '<t+2' => { :op => '<t+', :values => ['2'] },
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' => { :op => 't', :values => [''] },
177 't' => { :op => 't', :values => [''] },
178 'w' => { :op => 'w', :values => [''] },
178 'w' => { :op => 'w', :values => [''] },
179 '>t-2' => { :op => '>t-', :values => ['2'] },
179 '>t-2' => { :op => '>t-', :values => ['2'] },
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 'created_on' => {
182 'created_on' => {
183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
184 '<t+2' => { :op => '=', :values => ['<t+2'] },
184 '<t+2' => { :op => '=', :values => ['<t+2'] },
185 '>t+2' => { :op => '=', :values => ['>t+2'] },
185 '>t+2' => { :op => '=', :values => ['>t+2'] },
186 't+2' => { :op => 't', :values => ['+2'] }},
186 't+2' => { :op => 't', :values => ['+2'] }},
187 'cf_1' => {
187 'cf_1' => {
188 'c' => { :op => '=', :values => ['c'] },
188 'c' => { :op => '=', :values => ['c'] },
189 '!c' => { :op => '!', :values => ['c'] },
189 '!c' => { :op => '!', :values => ['c'] },
190 '!*' => { :op => '!*', :values => [''] },
190 '!*' => { :op => '!*', :values => [''] },
191 '*' => { :op => '*', :values => [''] }},
191 '*' => { :op => '*', :values => [''] }},
192 'estimated_hours' => {
192 'estimated_hours' => {
193 '=13.4' => { :op => '=', :values => ['13.4'] },
193 '=13.4' => { :op => '=', :values => ['13.4'] },
194 '>=45' => { :op => '>=', :values => ['45'] },
194 '>=45' => { :op => '>=', :values => ['45'] },
195 '<=125' => { :op => '<=', :values => ['125'] },
195 '<=125' => { :op => '<=', :values => ['125'] },
196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
197 '!*' => { :op => '!*', :values => [''] },
197 '!*' => { :op => '!*', :values => [''] },
198 '*' => { :op => '*', :values => [''] }}
198 '*' => { :op => '*', :values => [''] }}
199 }
199 }
200
200
201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
202
202
203 to_test.each do |field, expression_and_expected|
203 to_test.each do |field, expression_and_expected|
204 expression_and_expected.each do |filter_expression, expected|
204 expression_and_expected.each do |filter_expression, expected|
205
205
206 get :index, :set_filter => 1, field => filter_expression
206 get :index, :set_filter => 1, field => filter_expression
207
207
208 assert_response :success
208 assert_response :success
209 assert_template 'index'
209 assert_template 'index'
210 assert_not_nil assigns(:issues)
210 assert_not_nil assigns(:issues)
211
211
212 query = assigns(:query)
212 query = assigns(:query)
213 assert_not_nil query
213 assert_not_nil query
214 assert query.has_filter?(field)
214 assert query.has_filter?(field)
215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
216 end
216 end
217 end
217 end
218
218
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_cross_project_query_in_session_should_show_project_issues
265 def test_index_with_cross_project_query_in_session_should_show_project_issues
266 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
266 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
267 @request.session[:query] = {:id => q.id, :project_id => 1}
267 @request.session[:query] = {:id => q.id, :project_id => 1}
268
268
269 with_settings :display_subprojects_issues => '0' do
269 with_settings :display_subprojects_issues => '0' do
270 get :index, :project_id => 1
270 get :index, :project_id => 1
271 end
271 end
272 assert_response :success
272 assert_response :success
273 assert_not_nil assigns(:query)
273 assert_not_nil assigns(:query)
274 assert_equal q.id, assigns(:query).id
274 assert_equal q.id, assigns(:query).id
275 assert_equal 1, assigns(:query).project_id
275 assert_equal 1, assigns(:query).project_id
276 assert_equal [1], assigns(:issues).map(&:project_id).uniq
276 assert_equal [1], assigns(:issues).map(&:project_id).uniq
277 end
277 end
278
278
279 def test_private_query_should_not_be_available_to_other_users
279 def test_private_query_should_not_be_available_to_other_users
280 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
280 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
281 @request.session[:user_id] = 3
281 @request.session[:user_id] = 3
282
282
283 get :index, :query_id => q.id
283 get :index, :query_id => q.id
284 assert_response 403
284 assert_response 403
285 end
285 end
286
286
287 def test_private_query_should_be_available_to_its_user
287 def test_private_query_should_be_available_to_its_user
288 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
288 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
289 @request.session[:user_id] = 2
289 @request.session[:user_id] = 2
290
290
291 get :index, :query_id => q.id
291 get :index, :query_id => q.id
292 assert_response :success
292 assert_response :success
293 end
293 end
294
294
295 def test_public_query_should_be_available_to_other_users
295 def test_public_query_should_be_available_to_other_users
296 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
296 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
297 @request.session[:user_id] = 3
297 @request.session[:user_id] = 3
298
298
299 get :index, :query_id => q.id
299 get :index, :query_id => q.id
300 assert_response :success
300 assert_response :success
301 end
301 end
302
302
303 def test_index_csv
303 def test_index_csv
304 get :index, :format => 'csv'
304 get :index, :format => 'csv'
305 assert_response :success
305 assert_response :success
306 assert_not_nil assigns(:issues)
306 assert_not_nil assigns(:issues)
307 assert_equal 'text/csv', @response.content_type
307 assert_equal 'text/csv', @response.content_type
308 assert @response.body.starts_with?("#,")
308 assert @response.body.starts_with?("#,")
309 lines = @response.body.chomp.split("\n")
309 lines = @response.body.chomp.split("\n")
310 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
310 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
311 end
311 end
312
312
313 def test_index_csv_with_project
313 def test_index_csv_with_project
314 get :index, :project_id => 1, :format => 'csv'
314 get :index, :project_id => 1, :format => 'csv'
315 assert_response :success
315 assert_response :success
316 assert_not_nil assigns(:issues)
316 assert_not_nil assigns(:issues)
317 assert_equal 'text/csv', @response.content_type
317 assert_equal 'text/csv', @response.content_type
318 end
318 end
319
319
320 def test_index_csv_with_description
320 def test_index_csv_with_description
321 get :index, :format => 'csv', :description => '1'
321 get :index, :format => 'csv', :description => '1'
322 assert_response :success
322 assert_response :success
323 assert_not_nil assigns(:issues)
323 assert_not_nil assigns(:issues)
324 assert_equal 'text/csv', @response.content_type
324 assert_equal 'text/csv', @response.content_type
325 assert @response.body.starts_with?("#,")
325 assert @response.body.starts_with?("#,")
326 lines = @response.body.chomp.split("\n")
326 lines = @response.body.chomp.split("\n")
327 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
327 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
328 end
328 end
329
329
330 def test_index_csv_with_all_columns
330 def test_index_csv_with_all_columns
331 get :index, :format => 'csv', :columns => 'all'
331 get :index, :format => 'csv', :columns => 'all'
332 assert_response :success
332 assert_response :success
333 assert_not_nil assigns(:issues)
333 assert_not_nil assigns(:issues)
334 assert_equal 'text/csv', @response.content_type
334 assert_equal 'text/csv', @response.content_type
335 assert @response.body.starts_with?("#,")
335 assert @response.body.starts_with?("#,")
336 lines = @response.body.chomp.split("\n")
336 lines = @response.body.chomp.split("\n")
337 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
337 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
338 end
338 end
339
339
340 def test_index_csv_big_5
340 def test_index_csv_big_5
341 with_settings :default_language => "zh-TW" do
341 with_settings :default_language => "zh-TW" do
342 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
342 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
343 str_big5 = "\xa4@\xa4\xeb"
343 str_big5 = "\xa4@\xa4\xeb"
344 if str_utf8.respond_to?(:force_encoding)
344 if str_utf8.respond_to?(:force_encoding)
345 str_utf8.force_encoding('UTF-8')
345 str_utf8.force_encoding('UTF-8')
346 str_big5.force_encoding('Big5')
346 str_big5.force_encoding('Big5')
347 end
347 end
348 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
348 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
349 :status_id => 1, :priority => IssuePriority.all.first,
349 :status_id => 1, :priority => IssuePriority.all.first,
350 :subject => str_utf8)
350 :subject => str_utf8)
351 assert issue.save
351 assert issue.save
352
352
353 get :index, :project_id => 1,
353 get :index, :project_id => 1,
354 :f => ['subject'],
354 :f => ['subject'],
355 :op => '=', :values => [str_utf8],
355 :op => '=', :values => [str_utf8],
356 :format => 'csv'
356 :format => 'csv'
357 assert_equal 'text/csv', @response.content_type
357 assert_equal 'text/csv', @response.content_type
358 lines = @response.body.chomp.split("\n")
358 lines = @response.body.chomp.split("\n")
359 s1 = "\xaa\xac\xbaA"
359 s1 = "\xaa\xac\xbaA"
360 if str_utf8.respond_to?(:force_encoding)
360 if str_utf8.respond_to?(:force_encoding)
361 s1.force_encoding('Big5')
361 s1.force_encoding('Big5')
362 end
362 end
363 assert lines[0].include?(s1)
363 assert lines[0].include?(s1)
364 assert lines[1].include?(str_big5)
364 assert lines[1].include?(str_big5)
365 end
365 end
366 end
366 end
367
367
368 def test_index_csv_cannot_convert_should_be_replaced_big_5
368 def test_index_csv_cannot_convert_should_be_replaced_big_5
369 with_settings :default_language => "zh-TW" do
369 with_settings :default_language => "zh-TW" do
370 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
370 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
371 if str_utf8.respond_to?(:force_encoding)
371 if str_utf8.respond_to?(:force_encoding)
372 str_utf8.force_encoding('UTF-8')
372 str_utf8.force_encoding('UTF-8')
373 end
373 end
374 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
374 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
375 :status_id => 1, :priority => IssuePriority.all.first,
375 :status_id => 1, :priority => IssuePriority.all.first,
376 :subject => str_utf8)
376 :subject => str_utf8)
377 assert issue.save
377 assert issue.save
378
378
379 get :index, :project_id => 1,
379 get :index, :project_id => 1,
380 :f => ['subject'],
380 :f => ['subject'],
381 :op => '=', :values => [str_utf8],
381 :op => '=', :values => [str_utf8],
382 :c => ['status', 'subject'],
382 :c => ['status', 'subject'],
383 :format => 'csv',
383 :format => 'csv',
384 :set_filter => 1
384 :set_filter => 1
385 assert_equal 'text/csv', @response.content_type
385 assert_equal 'text/csv', @response.content_type
386 lines = @response.body.chomp.split("\n")
386 lines = @response.body.chomp.split("\n")
387 s1 = "\xaa\xac\xbaA" # status
387 s1 = "\xaa\xac\xbaA" # status
388 if str_utf8.respond_to?(:force_encoding)
388 if str_utf8.respond_to?(:force_encoding)
389 s1.force_encoding('Big5')
389 s1.force_encoding('Big5')
390 end
390 end
391 assert lines[0].include?(s1)
391 assert lines[0].include?(s1)
392 s2 = lines[1].split(",")[2]
392 s2 = lines[1].split(",")[2]
393 if s1.respond_to?(:force_encoding)
393 if s1.respond_to?(:force_encoding)
394 s3 = "\xa5H?" # subject
394 s3 = "\xa5H?" # subject
395 s3.force_encoding('Big5')
395 s3.force_encoding('Big5')
396 assert_equal s3, s2
396 assert_equal s3, s2
397 elsif RUBY_PLATFORM == 'java'
397 elsif RUBY_PLATFORM == 'java'
398 assert_equal "??", s2
398 assert_equal "??", s2
399 else
399 else
400 assert_equal "\xa5H???", s2
400 assert_equal "\xa5H???", s2
401 end
401 end
402 end
402 end
403 end
403 end
404
404
405 def test_index_csv_tw
405 def test_index_csv_tw
406 with_settings :default_language => "zh-TW" do
406 with_settings :default_language => "zh-TW" do
407 str1 = "test_index_csv_tw"
407 str1 = "test_index_csv_tw"
408 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
408 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
409 :status_id => 1, :priority => IssuePriority.all.first,
409 :status_id => 1, :priority => IssuePriority.all.first,
410 :subject => str1, :estimated_hours => '1234.5')
410 :subject => str1, :estimated_hours => '1234.5')
411 assert issue.save
411 assert issue.save
412 assert_equal 1234.5, issue.estimated_hours
412 assert_equal 1234.5, issue.estimated_hours
413
413
414 get :index, :project_id => 1,
414 get :index, :project_id => 1,
415 :f => ['subject'],
415 :f => ['subject'],
416 :op => '=', :values => [str1],
416 :op => '=', :values => [str1],
417 :c => ['estimated_hours', 'subject'],
417 :c => ['estimated_hours', 'subject'],
418 :format => 'csv',
418 :format => 'csv',
419 :set_filter => 1
419 :set_filter => 1
420 assert_equal 'text/csv', @response.content_type
420 assert_equal 'text/csv', @response.content_type
421 lines = @response.body.chomp.split("\n")
421 lines = @response.body.chomp.split("\n")
422 assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
422 assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
423
423
424 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
424 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
425 if str_tw.respond_to?(:force_encoding)
425 if str_tw.respond_to?(:force_encoding)
426 str_tw.force_encoding('UTF-8')
426 str_tw.force_encoding('UTF-8')
427 end
427 end
428 assert_equal str_tw, l(:general_lang_name)
428 assert_equal str_tw, l(:general_lang_name)
429 assert_equal ',', l(:general_csv_separator)
429 assert_equal ',', l(:general_csv_separator)
430 assert_equal '.', l(:general_csv_decimal_separator)
430 assert_equal '.', l(:general_csv_decimal_separator)
431 end
431 end
432 end
432 end
433
433
434 def test_index_csv_fr
434 def test_index_csv_fr
435 with_settings :default_language => "fr" do
435 with_settings :default_language => "fr" do
436 str1 = "test_index_csv_fr"
436 str1 = "test_index_csv_fr"
437 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
437 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
438 :status_id => 1, :priority => IssuePriority.all.first,
438 :status_id => 1, :priority => IssuePriority.all.first,
439 :subject => str1, :estimated_hours => '1234.5')
439 :subject => str1, :estimated_hours => '1234.5')
440 assert issue.save
440 assert issue.save
441 assert_equal 1234.5, issue.estimated_hours
441 assert_equal 1234.5, issue.estimated_hours
442
442
443 get :index, :project_id => 1,
443 get :index, :project_id => 1,
444 :f => ['subject'],
444 :f => ['subject'],
445 :op => '=', :values => [str1],
445 :op => '=', :values => [str1],
446 :c => ['estimated_hours', 'subject'],
446 :c => ['estimated_hours', 'subject'],
447 :format => 'csv',
447 :format => 'csv',
448 :set_filter => 1
448 :set_filter => 1
449 assert_equal 'text/csv', @response.content_type
449 assert_equal 'text/csv', @response.content_type
450 lines = @response.body.chomp.split("\n")
450 lines = @response.body.chomp.split("\n")
451 assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
451 assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
452
452
453 str_fr = "Fran\xc3\xa7ais"
453 str_fr = "Fran\xc3\xa7ais"
454 if str_fr.respond_to?(:force_encoding)
454 if str_fr.respond_to?(:force_encoding)
455 str_fr.force_encoding('UTF-8')
455 str_fr.force_encoding('UTF-8')
456 end
456 end
457 assert_equal str_fr, l(:general_lang_name)
457 assert_equal str_fr, l(:general_lang_name)
458 assert_equal ';', l(:general_csv_separator)
458 assert_equal ';', l(:general_csv_separator)
459 assert_equal ',', l(:general_csv_decimal_separator)
459 assert_equal ',', l(:general_csv_decimal_separator)
460 end
460 end
461 end
461 end
462
462
463 def test_index_pdf
463 def test_index_pdf
464 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
464 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
465 with_settings :default_language => lang do
465 with_settings :default_language => lang do
466
466
467 get :index
467 get :index
468 assert_response :success
468 assert_response :success
469 assert_template 'index'
469 assert_template 'index'
470
470
471 if lang == "ja"
471 if lang == "ja"
472 if RUBY_PLATFORM != 'java'
472 if RUBY_PLATFORM != 'java'
473 assert_equal "CP932", l(:general_pdf_encoding)
473 assert_equal "CP932", l(:general_pdf_encoding)
474 end
474 end
475 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
475 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
476 next
476 next
477 end
477 end
478 end
478 end
479
479
480 get :index, :format => 'pdf'
480 get :index, :format => 'pdf'
481 assert_response :success
481 assert_response :success
482 assert_not_nil assigns(:issues)
482 assert_not_nil assigns(:issues)
483 assert_equal 'application/pdf', @response.content_type
483 assert_equal 'application/pdf', @response.content_type
484
484
485 get :index, :project_id => 1, :format => 'pdf'
485 get :index, :project_id => 1, :format => 'pdf'
486 assert_response :success
486 assert_response :success
487 assert_not_nil assigns(:issues)
487 assert_not_nil assigns(:issues)
488 assert_equal 'application/pdf', @response.content_type
488 assert_equal 'application/pdf', @response.content_type
489
489
490 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
490 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
491 assert_response :success
491 assert_response :success
492 assert_not_nil assigns(:issues)
492 assert_not_nil assigns(:issues)
493 assert_equal 'application/pdf', @response.content_type
493 assert_equal 'application/pdf', @response.content_type
494 end
494 end
495 end
495 end
496 end
496 end
497
497
498 def test_index_pdf_with_query_grouped_by_list_custom_field
498 def test_index_pdf_with_query_grouped_by_list_custom_field
499 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
499 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
500 assert_response :success
500 assert_response :success
501 assert_not_nil assigns(:issues)
501 assert_not_nil assigns(:issues)
502 assert_not_nil assigns(:issue_count_by_group)
502 assert_not_nil assigns(:issue_count_by_group)
503 assert_equal 'application/pdf', @response.content_type
503 assert_equal 'application/pdf', @response.content_type
504 end
504 end
505
505
506 def test_index_sort
506 def test_index_sort
507 get :index, :sort => 'tracker,id:desc'
507 get :index, :sort => 'tracker,id:desc'
508 assert_response :success
508 assert_response :success
509
509
510 sort_params = @request.session['issues_index_sort']
510 sort_params = @request.session['issues_index_sort']
511 assert sort_params.is_a?(String)
511 assert sort_params.is_a?(String)
512 assert_equal 'tracker,id:desc', sort_params
512 assert_equal 'tracker,id:desc', sort_params
513
513
514 issues = assigns(:issues)
514 issues = assigns(:issues)
515 assert_not_nil issues
515 assert_not_nil issues
516 assert !issues.empty?
516 assert !issues.empty?
517 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
517 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
518 end
518 end
519
519
520 def test_index_sort_by_field_not_included_in_columns
520 def test_index_sort_by_field_not_included_in_columns
521 Setting.issue_list_default_columns = %w(subject author)
521 Setting.issue_list_default_columns = %w(subject author)
522 get :index, :sort => 'tracker'
522 get :index, :sort => 'tracker'
523 end
523 end
524
524
525 def test_index_sort_by_assigned_to
525 def test_index_sort_by_assigned_to
526 get :index, :sort => 'assigned_to'
526 get :index, :sort => 'assigned_to'
527 assert_response :success
527 assert_response :success
528 assignees = assigns(:issues).collect(&:assigned_to).compact
528 assignees = assigns(:issues).collect(&:assigned_to).compact
529 assert_equal assignees.sort, assignees
529 assert_equal assignees.sort, assignees
530 end
530 end
531
531
532 def test_index_sort_by_assigned_to_desc
532 def test_index_sort_by_assigned_to_desc
533 get :index, :sort => 'assigned_to:desc'
533 get :index, :sort => 'assigned_to:desc'
534 assert_response :success
534 assert_response :success
535 assignees = assigns(:issues).collect(&:assigned_to).compact
535 assignees = assigns(:issues).collect(&:assigned_to).compact
536 assert_equal assignees.sort.reverse, assignees
536 assert_equal assignees.sort.reverse, assignees
537 end
537 end
538
538
539 def test_index_group_by_assigned_to
539 def test_index_group_by_assigned_to
540 get :index, :group_by => 'assigned_to', :sort => 'priority'
540 get :index, :group_by => 'assigned_to', :sort => 'priority'
541 assert_response :success
541 assert_response :success
542 end
542 end
543
543
544 def test_index_sort_by_author
544 def test_index_sort_by_author
545 get :index, :sort => 'author'
545 get :index, :sort => 'author'
546 assert_response :success
546 assert_response :success
547 authors = assigns(:issues).collect(&:author)
547 authors = assigns(:issues).collect(&:author)
548 assert_equal authors.sort, authors
548 assert_equal authors.sort, authors
549 end
549 end
550
550
551 def test_index_sort_by_author_desc
551 def test_index_sort_by_author_desc
552 get :index, :sort => 'author:desc'
552 get :index, :sort => 'author:desc'
553 assert_response :success
553 assert_response :success
554 authors = assigns(:issues).collect(&:author)
554 authors = assigns(:issues).collect(&:author)
555 assert_equal authors.sort.reverse, authors
555 assert_equal authors.sort.reverse, authors
556 end
556 end
557
557
558 def test_index_group_by_author
558 def test_index_group_by_author
559 get :index, :group_by => 'author', :sort => 'priority'
559 get :index, :group_by => 'author', :sort => 'priority'
560 assert_response :success
560 assert_response :success
561 end
561 end
562
562
563 def test_index_sort_by_spent_hours
563 def test_index_sort_by_spent_hours
564 get :index, :sort => 'spent_hours:desc'
564 get :index, :sort => 'spent_hours:desc'
565 assert_response :success
565 assert_response :success
566 hours = assigns(:issues).collect(&:spent_hours)
566 hours = assigns(:issues).collect(&:spent_hours)
567 assert_equal hours.sort.reverse, hours
567 assert_equal hours.sort.reverse, hours
568 end
568 end
569
569
570 def test_index_with_columns
570 def test_index_with_columns
571 columns = ['tracker', 'subject', 'assigned_to']
571 columns = ['tracker', 'subject', 'assigned_to']
572 get :index, :set_filter => 1, :c => columns
572 get :index, :set_filter => 1, :c => columns
573 assert_response :success
573 assert_response :success
574
574
575 # query should use specified columns
575 # query should use specified columns
576 query = assigns(:query)
576 query = assigns(:query)
577 assert_kind_of Query, query
577 assert_kind_of Query, query
578 assert_equal columns, query.column_names.map(&:to_s)
578 assert_equal columns, query.column_names.map(&:to_s)
579
579
580 # columns should be stored in session
580 # columns should be stored in session
581 assert_kind_of Hash, session[:query]
581 assert_kind_of Hash, session[:query]
582 assert_kind_of Array, session[:query][:column_names]
582 assert_kind_of Array, session[:query][:column_names]
583 assert_equal columns, session[:query][:column_names].map(&:to_s)
583 assert_equal columns, session[:query][:column_names].map(&:to_s)
584
584
585 # ensure only these columns are kept in the selected columns list
585 # ensure only these columns are kept in the selected columns list
586 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
586 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
587 :children => { :count => 3 }
587 :children => { :count => 3 }
588 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
588 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
589 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
589 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
590 end
590 end
591
591
592 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
592 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
593 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
593 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
594 get :index, :set_filter => 1
594 get :index, :set_filter => 1
595
595
596 # query should use specified columns
596 # query should use specified columns
597 query = assigns(:query)
597 query = assigns(:query)
598 assert_kind_of Query, query
598 assert_kind_of Query, query
599 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
599 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
600 end
600 end
601
601
602 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
602 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
603 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
603 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
604 columns = ['tracker', 'subject', 'assigned_to']
604 columns = ['tracker', 'subject', 'assigned_to']
605 get :index, :set_filter => 1, :c => columns
605 get :index, :set_filter => 1, :c => columns
606
606
607 # query should use specified columns
607 # query should use specified columns
608 query = assigns(:query)
608 query = assigns(:query)
609 assert_kind_of Query, query
609 assert_kind_of Query, query
610 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
610 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
611 end
611 end
612
612
613 def test_index_with_custom_field_column
613 def test_index_with_custom_field_column
614 columns = %w(tracker subject cf_2)
614 columns = %w(tracker subject cf_2)
615 get :index, :set_filter => 1, :c => columns
615 get :index, :set_filter => 1, :c => columns
616 assert_response :success
616 assert_response :success
617
617
618 # query should use specified columns
618 # query should use specified columns
619 query = assigns(:query)
619 query = assigns(:query)
620 assert_kind_of Query, query
620 assert_kind_of Query, query
621 assert_equal columns, query.column_names.map(&:to_s)
621 assert_equal columns, query.column_names.map(&:to_s)
622
622
623 assert_tag :td,
623 assert_tag :td,
624 :attributes => {:class => 'cf_2 string'},
624 :attributes => {:class => 'cf_2 string'},
625 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
625 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
626 end
626 end
627
627
628 def test_index_with_date_column
628 def test_index_with_date_column
629 Issue.find(1).update_attribute :start_date, '1987-08-24'
629 Issue.find(1).update_attribute :start_date, '1987-08-24'
630
630
631 with_settings :date_format => '%d/%m/%Y' do
631 with_settings :date_format => '%d/%m/%Y' do
632 get :index, :set_filter => 1, :c => %w(start_date)
632 get :index, :set_filter => 1, :c => %w(start_date)
633 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
633 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
634 end
634 end
635 end
635 end
636
636
637 def test_index_with_done_ratio
637 def test_index_with_done_ratio
638 Issue.find(1).update_attribute :done_ratio, 40
638 Issue.find(1).update_attribute :done_ratio, 40
639
639
640 get :index, :set_filter => 1, :c => %w(done_ratio)
640 get :index, :set_filter => 1, :c => %w(done_ratio)
641 assert_tag 'td', :attributes => {:class => /done_ratio/},
641 assert_tag 'td', :attributes => {:class => /done_ratio/},
642 :child => {:tag => 'table', :attributes => {:class => 'progress'},
642 :child => {:tag => 'table', :attributes => {:class => 'progress'},
643 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
643 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
644 }
644 }
645 end
645 end
646
646
647 def test_index_with_spent_hours_column
647 def test_index_with_spent_hours_column
648 get :index, :set_filter => 1, :c => %w(subject spent_hours)
648 get :index, :set_filter => 1, :c => %w(subject spent_hours)
649
649
650 assert_tag 'tr', :attributes => {:id => 'issue-3'},
650 assert_tag 'tr', :attributes => {:id => 'issue-3'},
651 :child => {
651 :child => {
652 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
652 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
653 }
653 }
654 end
654 end
655
655
656 def test_index_should_not_show_spent_hours_column_without_permission
656 def test_index_should_not_show_spent_hours_column_without_permission
657 Role.anonymous.remove_permission! :view_time_entries
657 Role.anonymous.remove_permission! :view_time_entries
658 get :index, :set_filter => 1, :c => %w(subject spent_hours)
658 get :index, :set_filter => 1, :c => %w(subject spent_hours)
659
659
660 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
660 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
661 end
661 end
662
662
663 def test_index_with_fixed_version
663 def test_index_with_fixed_version
664 get :index, :set_filter => 1, :c => %w(fixed_version)
664 get :index, :set_filter => 1, :c => %w(fixed_version)
665 assert_tag 'td', :attributes => {:class => /fixed_version/},
665 assert_tag 'td', :attributes => {:class => /fixed_version/},
666 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
666 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
667 end
667 end
668
668
669 def test_index_send_html_if_query_is_invalid
669 def test_index_send_html_if_query_is_invalid
670 get :index, :f => ['start_date'], :op => {:start_date => '='}
670 get :index, :f => ['start_date'], :op => {:start_date => '='}
671 assert_equal 'text/html', @response.content_type
671 assert_equal 'text/html', @response.content_type
672 assert_template 'index'
672 assert_template 'index'
673 end
673 end
674
674
675 def test_index_send_nothing_if_query_is_invalid
675 def test_index_send_nothing_if_query_is_invalid
676 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
676 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
677 assert_equal 'text/csv', @response.content_type
677 assert_equal 'text/csv', @response.content_type
678 assert @response.body.blank?
678 assert @response.body.blank?
679 end
679 end
680
680
681 def test_show_by_anonymous
681 def test_show_by_anonymous
682 get :show, :id => 1
682 get :show, :id => 1
683 assert_response :success
683 assert_response :success
684 assert_template 'show'
684 assert_template 'show'
685 assert_not_nil assigns(:issue)
685 assert_not_nil assigns(:issue)
686 assert_equal Issue.find(1), assigns(:issue)
686 assert_equal Issue.find(1), assigns(:issue)
687
687
688 # anonymous role is allowed to add a note
688 # anonymous role is allowed to add a note
689 assert_tag :tag => 'form',
689 assert_tag :tag => 'form',
690 :descendant => { :tag => 'fieldset',
690 :descendant => { :tag => 'fieldset',
691 :child => { :tag => 'legend',
691 :child => { :tag => 'legend',
692 :content => /Notes/ } }
692 :content => /Notes/ } }
693 assert_tag :tag => 'title',
693 assert_tag :tag => 'title',
694 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
694 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
695 end
695 end
696
696
697 def test_show_by_manager
697 def test_show_by_manager
698 @request.session[:user_id] = 2
698 @request.session[:user_id] = 2
699 get :show, :id => 1
699 get :show, :id => 1
700 assert_response :success
700 assert_response :success
701
701
702 assert_tag :tag => 'a',
702 assert_tag :tag => 'a',
703 :content => /Quote/
703 :content => /Quote/
704
704
705 assert_tag :tag => 'form',
705 assert_tag :tag => 'form',
706 :descendant => { :tag => 'fieldset',
706 :descendant => { :tag => 'fieldset',
707 :child => { :tag => 'legend',
707 :child => { :tag => 'legend',
708 :content => /Change properties/ } },
708 :content => /Change properties/ } },
709 :descendant => { :tag => 'fieldset',
709 :descendant => { :tag => 'fieldset',
710 :child => { :tag => 'legend',
710 :child => { :tag => 'legend',
711 :content => /Log time/ } },
711 :content => /Log time/ } },
712 :descendant => { :tag => 'fieldset',
712 :descendant => { :tag => 'fieldset',
713 :child => { :tag => 'legend',
713 :child => { :tag => 'legend',
714 :content => /Notes/ } }
714 :content => /Notes/ } }
715 end
715 end
716
716
717 def test_show_should_display_update_form
717 def test_show_should_display_update_form
718 @request.session[:user_id] = 2
718 @request.session[:user_id] = 2
719 get :show, :id => 1
719 get :show, :id => 1
720 assert_response :success
720 assert_response :success
721
721
722 assert_tag 'form', :attributes => {:id => 'issue-form'}
722 assert_tag 'form', :attributes => {:id => 'issue-form'}
723 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
723 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
724 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
724 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
725 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
725 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
726 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
726 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
727 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
727 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
728 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
728 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
729 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
729 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
730 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
730 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
731 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
731 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
732 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
732 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
733 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
733 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
734 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
734 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
735 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
735 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
736 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
736 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
737 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
737 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
738 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
738 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
739 assert_tag 'textarea', :attributes => {:name => 'notes'}
739 assert_tag 'textarea', :attributes => {:name => 'notes'}
740 end
740 end
741
741
742 def test_show_should_display_update_form_with_minimal_permissions
742 def test_show_should_display_update_form_with_minimal_permissions
743 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
743 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
744 Workflow.delete_all :role_id => 1
744 Workflow.delete_all :role_id => 1
745
745
746 @request.session[:user_id] = 2
746 @request.session[:user_id] = 2
747 get :show, :id => 1
747 get :show, :id => 1
748 assert_response :success
748 assert_response :success
749
749
750 assert_tag 'form', :attributes => {:id => 'issue-form'}
750 assert_tag 'form', :attributes => {:id => 'issue-form'}
751 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
751 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
752 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
752 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
753 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
753 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
754 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
754 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
755 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
755 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
756 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
756 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
757 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
757 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
758 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
758 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
759 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
759 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
760 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
760 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
761 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
761 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
762 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
762 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
763 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
763 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
764 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
764 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
765 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
765 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
766 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
766 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
767 assert_tag 'textarea', :attributes => {:name => 'notes'}
767 assert_tag 'textarea', :attributes => {:name => 'notes'}
768 end
768 end
769
769
770 def test_show_should_display_update_form_with_workflow_permissions
770 def test_show_should_display_update_form_with_workflow_permissions
771 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
771 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
772
772
773 @request.session[:user_id] = 2
773 @request.session[:user_id] = 2
774 get :show, :id => 1
774 get :show, :id => 1
775 assert_response :success
775 assert_response :success
776
776
777 assert_tag 'form', :attributes => {:id => 'issue-form'}
777 assert_tag 'form', :attributes => {:id => 'issue-form'}
778 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
778 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
779 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
779 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
780 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
780 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
781 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
781 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
782 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
782 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
783 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
783 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
784 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
784 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
785 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
785 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
786 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
786 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
787 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
787 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
788 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
788 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
789 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
789 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
790 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
790 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
791 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
791 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
792 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
792 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
793 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
793 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
794 assert_tag 'textarea', :attributes => {:name => 'notes'}
794 assert_tag 'textarea', :attributes => {:name => 'notes'}
795 end
795 end
796
796
797 def test_show_should_not_display_update_form_without_permissions
797 def test_show_should_not_display_update_form_without_permissions
798 Role.find(1).update_attribute :permissions, [:view_issues]
798 Role.find(1).update_attribute :permissions, [:view_issues]
799
799
800 @request.session[:user_id] = 2
800 @request.session[:user_id] = 2
801 get :show, :id => 1
801 get :show, :id => 1
802 assert_response :success
802 assert_response :success
803
803
804 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
804 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
805 end
805 end
806
806
807 def test_update_form_should_not_display_inactive_enumerations
807 def test_update_form_should_not_display_inactive_enumerations
808 @request.session[:user_id] = 2
808 @request.session[:user_id] = 2
809 get :show, :id => 1
809 get :show, :id => 1
810 assert_response :success
810 assert_response :success
811
811
812 assert ! IssuePriority.find(15).active?
812 assert ! IssuePriority.find(15).active?
813 assert_no_tag :option, :attributes => {:value => '15'},
813 assert_no_tag :option, :attributes => {:value => '15'},
814 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
814 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
815 end
815 end
816
816
817 def test_update_form_should_allow_attachment_upload
817 def test_update_form_should_allow_attachment_upload
818 @request.session[:user_id] = 2
818 @request.session[:user_id] = 2
819 get :show, :id => 1
819 get :show, :id => 1
820
820
821 assert_tag :tag => 'form',
821 assert_tag :tag => 'form',
822 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
822 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
823 :descendant => {
823 :descendant => {
824 :tag => 'input',
824 :tag => 'input',
825 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
825 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
826 }
826 }
827 end
827 end
828
828
829 def test_show_should_deny_anonymous_access_without_permission
829 def test_show_should_deny_anonymous_access_without_permission
830 Role.anonymous.remove_permission!(:view_issues)
830 Role.anonymous.remove_permission!(:view_issues)
831 get :show, :id => 1
831 get :show, :id => 1
832 assert_response :redirect
832 assert_response :redirect
833 end
833 end
834
834
835 def test_show_should_deny_anonymous_access_to_private_issue
835 def test_show_should_deny_anonymous_access_to_private_issue
836 Issue.update_all(["is_private = ?", true], "id = 1")
836 Issue.update_all(["is_private = ?", true], "id = 1")
837 get :show, :id => 1
837 get :show, :id => 1
838 assert_response :redirect
838 assert_response :redirect
839 end
839 end
840
840
841 def test_show_should_deny_non_member_access_without_permission
841 def test_show_should_deny_non_member_access_without_permission
842 Role.non_member.remove_permission!(:view_issues)
842 Role.non_member.remove_permission!(:view_issues)
843 @request.session[:user_id] = 9
843 @request.session[:user_id] = 9
844 get :show, :id => 1
844 get :show, :id => 1
845 assert_response 403
845 assert_response 403
846 end
846 end
847
847
848 def test_show_should_deny_non_member_access_to_private_issue
848 def test_show_should_deny_non_member_access_to_private_issue
849 Issue.update_all(["is_private = ?", true], "id = 1")
849 Issue.update_all(["is_private = ?", true], "id = 1")
850 @request.session[:user_id] = 9
850 @request.session[:user_id] = 9
851 get :show, :id => 1
851 get :show, :id => 1
852 assert_response 403
852 assert_response 403
853 end
853 end
854
854
855 def test_show_should_deny_member_access_without_permission
855 def test_show_should_deny_member_access_without_permission
856 Role.find(1).remove_permission!(:view_issues)
856 Role.find(1).remove_permission!(:view_issues)
857 @request.session[:user_id] = 2
857 @request.session[:user_id] = 2
858 get :show, :id => 1
858 get :show, :id => 1
859 assert_response 403
859 assert_response 403
860 end
860 end
861
861
862 def test_show_should_deny_member_access_to_private_issue_without_permission
862 def test_show_should_deny_member_access_to_private_issue_without_permission
863 Issue.update_all(["is_private = ?", true], "id = 1")
863 Issue.update_all(["is_private = ?", true], "id = 1")
864 @request.session[:user_id] = 3
864 @request.session[:user_id] = 3
865 get :show, :id => 1
865 get :show, :id => 1
866 assert_response 403
866 assert_response 403
867 end
867 end
868
868
869 def test_show_should_allow_author_access_to_private_issue
869 def test_show_should_allow_author_access_to_private_issue
870 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
870 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
871 @request.session[:user_id] = 3
871 @request.session[:user_id] = 3
872 get :show, :id => 1
872 get :show, :id => 1
873 assert_response :success
873 assert_response :success
874 end
874 end
875
875
876 def test_show_should_allow_assignee_access_to_private_issue
876 def test_show_should_allow_assignee_access_to_private_issue
877 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
877 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
878 @request.session[:user_id] = 3
878 @request.session[:user_id] = 3
879 get :show, :id => 1
879 get :show, :id => 1
880 assert_response :success
880 assert_response :success
881 end
881 end
882
882
883 def test_show_should_allow_member_access_to_private_issue_with_permission
883 def test_show_should_allow_member_access_to_private_issue_with_permission
884 Issue.update_all(["is_private = ?", true], "id = 1")
884 Issue.update_all(["is_private = ?", true], "id = 1")
885 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
885 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
886 @request.session[:user_id] = 3
886 @request.session[:user_id] = 3
887 get :show, :id => 1
887 get :show, :id => 1
888 assert_response :success
888 assert_response :success
889 end
889 end
890
890
891 def test_show_should_not_disclose_relations_to_invisible_issues
891 def test_show_should_not_disclose_relations_to_invisible_issues
892 Setting.cross_project_issue_relations = '1'
892 Setting.cross_project_issue_relations = '1'
893 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
893 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
894 # Relation to a private project issue
894 # Relation to a private project issue
895 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
895 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
896
896
897 get :show, :id => 1
897 get :show, :id => 1
898 assert_response :success
898 assert_response :success
899
899
900 assert_tag :div, :attributes => { :id => 'relations' },
900 assert_tag :div, :attributes => { :id => 'relations' },
901 :descendant => { :tag => 'a', :content => /#2$/ }
901 :descendant => { :tag => 'a', :content => /#2$/ }
902 assert_no_tag :div, :attributes => { :id => 'relations' },
902 assert_no_tag :div, :attributes => { :id => 'relations' },
903 :descendant => { :tag => 'a', :content => /#4$/ }
903 :descendant => { :tag => 'a', :content => /#4$/ }
904 end
904 end
905
905
906 def test_show_should_list_subtasks
906 def test_show_should_list_subtasks
907 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
907 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
908
908
909 get :show, :id => 1
909 get :show, :id => 1
910 assert_response :success
910 assert_response :success
911 assert_tag 'div', :attributes => {:id => 'issue_tree'},
911 assert_tag 'div', :attributes => {:id => 'issue_tree'},
912 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
912 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
913 end
913 end
914
914
915 def test_show_should_list_parents
915 def test_show_should_list_parents
916 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
916 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
917
917
918 get :show, :id => issue.id
918 get :show, :id => issue.id
919 assert_response :success
919 assert_response :success
920 assert_tag 'div', :attributes => {:class => 'subject'},
920 assert_tag 'div', :attributes => {:class => 'subject'},
921 :descendant => {:tag => 'h3', :content => 'Child Issue'}
921 :descendant => {:tag => 'h3', :content => 'Child Issue'}
922 assert_tag 'div', :attributes => {:class => 'subject'},
922 assert_tag 'div', :attributes => {:class => 'subject'},
923 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
923 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
924 end
924 end
925
925
926 def test_show_should_not_display_prev_next_links_without_query_in_session
926 def test_show_should_not_display_prev_next_links_without_query_in_session
927 get :show, :id => 1
927 get :show, :id => 1
928 assert_response :success
928 assert_response :success
929 assert_nil assigns(:prev_issue_id)
929 assert_nil assigns(:prev_issue_id)
930 assert_nil assigns(:next_issue_id)
930 assert_nil assigns(:next_issue_id)
931 end
931 end
932
932
933 def test_show_should_display_prev_next_links_with_query_in_session
933 def test_show_should_display_prev_next_links_with_query_in_session
934 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
934 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
935 @request.session['issues_index_sort'] = 'id'
935 @request.session['issues_index_sort'] = 'id'
936
936
937 with_settings :display_subprojects_issues => '0' do
937 with_settings :display_subprojects_issues => '0' do
938 get :show, :id => 3
938 get :show, :id => 3
939 end
939 end
940
940
941 assert_response :success
941 assert_response :success
942 # Previous and next issues for all projects
942 # Previous and next issues for all projects
943 assert_equal 2, assigns(:prev_issue_id)
943 assert_equal 2, assigns(:prev_issue_id)
944 assert_equal 5, assigns(:next_issue_id)
944 assert_equal 5, assigns(:next_issue_id)
945
945
946 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
946 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
947 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
947 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
948 end
948 end
949
949
950 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
950 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
951 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
951 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
952
952
953 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
953 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
954 @request.session['issues_index_sort'] = assoc_sort
954 @request.session['issues_index_sort'] = assoc_sort
955
955
956 get :show, :id => 3
956 get :show, :id => 3
957 assert_response :success, "Wrong response status for #{assoc_sort} sort"
957 assert_response :success, "Wrong response status for #{assoc_sort} sort"
958
958
959 assert_tag 'a', :content => /Previous/
959 assert_tag 'a', :content => /Previous/
960 assert_tag 'a', :content => /Next/
960 assert_tag 'a', :content => /Next/
961 end
961 end
962 end
962 end
963
963
964 def test_show_should_display_prev_next_links_with_project_query_in_session
964 def test_show_should_display_prev_next_links_with_project_query_in_session
965 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
965 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
966 @request.session['issues_index_sort'] = 'id'
966 @request.session['issues_index_sort'] = 'id'
967
967
968 with_settings :display_subprojects_issues => '0' do
968 with_settings :display_subprojects_issues => '0' do
969 get :show, :id => 3
969 get :show, :id => 3
970 end
970 end
971
971
972 assert_response :success
972 assert_response :success
973 # Previous and next issues inside project
973 # Previous and next issues inside project
974 assert_equal 2, assigns(:prev_issue_id)
974 assert_equal 2, assigns(:prev_issue_id)
975 assert_equal 7, assigns(:next_issue_id)
975 assert_equal 7, assigns(:next_issue_id)
976
976
977 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
977 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
978 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
978 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
979 end
979 end
980
980
981 def test_show_should_not_display_prev_link_for_first_issue
981 def test_show_should_not_display_prev_link_for_first_issue
982 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
982 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
983 @request.session['issues_index_sort'] = 'id'
983 @request.session['issues_index_sort'] = 'id'
984
984
985 with_settings :display_subprojects_issues => '0' do
985 with_settings :display_subprojects_issues => '0' do
986 get :show, :id => 1
986 get :show, :id => 1
987 end
987 end
988
988
989 assert_response :success
989 assert_response :success
990 assert_nil assigns(:prev_issue_id)
990 assert_nil assigns(:prev_issue_id)
991 assert_equal 2, assigns(:next_issue_id)
991 assert_equal 2, assigns(:next_issue_id)
992
992
993 assert_no_tag 'a', :content => /Previous/
993 assert_no_tag 'a', :content => /Previous/
994 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
994 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
995 end
995 end
996
996
997 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
997 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
998 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
998 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
999 @request.session['issues_index_sort'] = 'id'
999 @request.session['issues_index_sort'] = 'id'
1000
1000
1001 get :show, :id => 1
1001 get :show, :id => 1
1002
1002
1003 assert_response :success
1003 assert_response :success
1004 assert_nil assigns(:prev_issue_id)
1004 assert_nil assigns(:prev_issue_id)
1005 assert_nil assigns(:next_issue_id)
1005 assert_nil assigns(:next_issue_id)
1006
1006
1007 assert_no_tag 'a', :content => /Previous/
1007 assert_no_tag 'a', :content => /Previous/
1008 assert_no_tag 'a', :content => /Next/
1008 assert_no_tag 'a', :content => /Next/
1009 end
1009 end
1010
1010
1011 def test_show_atom
1011 def test_show_atom
1012 get :show, :id => 2, :format => 'atom'
1012 get :show, :id => 2, :format => 'atom'
1013 assert_response :success
1013 assert_response :success
1014 assert_template 'journals/index'
1014 assert_template 'journals/index'
1015 # Inline image
1015 # Inline image
1016 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1016 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1017 end
1017 end
1018
1018
1019 def test_show_export_to_pdf
1019 def test_show_export_to_pdf
1020 get :show, :id => 3, :format => 'pdf'
1020 get :show, :id => 3, :format => 'pdf'
1021 assert_response :success
1021 assert_response :success
1022 assert_equal 'application/pdf', @response.content_type
1022 assert_equal 'application/pdf', @response.content_type
1023 assert @response.body.starts_with?('%PDF')
1023 assert @response.body.starts_with?('%PDF')
1024 assert_not_nil assigns(:issue)
1024 assert_not_nil assigns(:issue)
1025 end
1025 end
1026
1026
1027 def test_get_new
1027 def test_get_new
1028 @request.session[:user_id] = 2
1028 @request.session[:user_id] = 2
1029 get :new, :project_id => 1, :tracker_id => 1
1029 get :new, :project_id => 1, :tracker_id => 1
1030 assert_response :success
1030 assert_response :success
1031 assert_template 'new'
1031 assert_template 'new'
1032
1032
1033 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1033 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1034 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1034 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1035 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1035 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1036 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1036 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1037 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1037 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1038 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1038 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1039 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1039 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1040 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1040 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1041 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1041 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1042 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1042 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1043 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1043 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1044 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1044 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1045 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1045 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1046 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1046 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1047 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1047 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1048 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1048 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1049
1049
1050 # Be sure we don't display inactive IssuePriorities
1050 # Be sure we don't display inactive IssuePriorities
1051 assert ! IssuePriority.find(15).active?
1051 assert ! IssuePriority.find(15).active?
1052 assert_no_tag :option, :attributes => {:value => '15'},
1052 assert_no_tag :option, :attributes => {:value => '15'},
1053 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1053 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1054 end
1054 end
1055
1055
1056 def test_get_new_with_minimal_permissions
1056 def test_get_new_with_minimal_permissions
1057 Role.find(1).update_attribute :permissions, [:add_issues]
1057 Role.find(1).update_attribute :permissions, [:add_issues]
1058 Workflow.delete_all :role_id => 1
1058 Workflow.delete_all :role_id => 1
1059
1059
1060 @request.session[:user_id] = 2
1060 @request.session[:user_id] = 2
1061 get :new, :project_id => 1, :tracker_id => 1
1061 get :new, :project_id => 1, :tracker_id => 1
1062 assert_response :success
1062 assert_response :success
1063 assert_template 'new'
1063 assert_template 'new'
1064
1064
1065 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1065 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1066 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1066 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1067 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1067 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1068 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1068 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1069 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1069 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1070 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1070 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1071 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1071 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1072 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1072 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1073 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1073 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1074 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1074 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1075 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1075 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1076 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1076 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1077 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1077 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1078 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1078 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1079 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1079 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1080 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1080 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1081 end
1081 end
1082
1082
1083 def test_get_new_without_default_start_date_is_creation_date
1083 def test_get_new_without_default_start_date_is_creation_date
1084 Setting.default_issue_start_date_to_creation_date = 0
1084 Setting.default_issue_start_date_to_creation_date = 0
1085
1085
1086 @request.session[:user_id] = 2
1086 @request.session[:user_id] = 2
1087 get :new, :project_id => 1, :tracker_id => 1
1087 get :new, :project_id => 1, :tracker_id => 1
1088 assert_response :success
1088 assert_response :success
1089 assert_template 'new'
1089 assert_template 'new'
1090
1090
1091 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1091 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1092 :value => nil }
1092 :value => nil }
1093 end
1093 end
1094
1094
1095 def test_get_new_with_default_start_date_is_creation_date
1095 def test_get_new_with_default_start_date_is_creation_date
1096 Setting.default_issue_start_date_to_creation_date = 1
1096 Setting.default_issue_start_date_to_creation_date = 1
1097
1097
1098 @request.session[:user_id] = 2
1098 @request.session[:user_id] = 2
1099 get :new, :project_id => 1, :tracker_id => 1
1099 get :new, :project_id => 1, :tracker_id => 1
1100 assert_response :success
1100 assert_response :success
1101 assert_template 'new'
1101 assert_template 'new'
1102
1102
1103 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1103 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1104 :value => Date.today.to_s }
1104 :value => Date.today.to_s }
1105 end
1105 end
1106
1106
1107 def test_get_new_form_should_allow_attachment_upload
1107 def test_get_new_form_should_allow_attachment_upload
1108 @request.session[:user_id] = 2
1108 @request.session[:user_id] = 2
1109 get :new, :project_id => 1, :tracker_id => 1
1109 get :new, :project_id => 1, :tracker_id => 1
1110
1110
1111 assert_tag :tag => 'form',
1111 assert_tag :tag => 'form',
1112 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1112 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1113 :descendant => {
1113 :descendant => {
1114 :tag => 'input',
1114 :tag => 'input',
1115 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1115 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1116 }
1116 }
1117 end
1117 end
1118
1118
1119 def test_get_new_without_tracker_id
1119 def test_get_new_without_tracker_id
1120 @request.session[:user_id] = 2
1120 @request.session[:user_id] = 2
1121 get :new, :project_id => 1
1121 get :new, :project_id => 1
1122 assert_response :success
1122 assert_response :success
1123 assert_template 'new'
1123 assert_template 'new'
1124
1124
1125 issue = assigns(:issue)
1125 issue = assigns(:issue)
1126 assert_not_nil issue
1126 assert_not_nil issue
1127 assert_equal Project.find(1).trackers.first, issue.tracker
1127 assert_equal Project.find(1).trackers.first, issue.tracker
1128 end
1128 end
1129
1129
1130 def test_get_new_with_no_default_status_should_display_an_error
1130 def test_get_new_with_no_default_status_should_display_an_error
1131 @request.session[:user_id] = 2
1131 @request.session[:user_id] = 2
1132 IssueStatus.delete_all
1132 IssueStatus.delete_all
1133
1133
1134 get :new, :project_id => 1
1134 get :new, :project_id => 1
1135 assert_response 500
1135 assert_response 500
1136 assert_error_tag :content => /No default issue/
1136 assert_error_tag :content => /No default issue/
1137 end
1137 end
1138
1138
1139 def test_get_new_with_no_tracker_should_display_an_error
1139 def test_get_new_with_no_tracker_should_display_an_error
1140 @request.session[:user_id] = 2
1140 @request.session[:user_id] = 2
1141 Tracker.delete_all
1141 Tracker.delete_all
1142
1142
1143 get :new, :project_id => 1
1143 get :new, :project_id => 1
1144 assert_response 500
1144 assert_response 500
1145 assert_error_tag :content => /No tracker/
1145 assert_error_tag :content => /No tracker/
1146 end
1146 end
1147
1147
1148 def test_update_new_form
1148 def test_update_new_form
1149 @request.session[:user_id] = 2
1149 @request.session[:user_id] = 2
1150 xhr :post, :new, :project_id => 1,
1150 xhr :post, :new, :project_id => 1,
1151 :issue => {:tracker_id => 2,
1151 :issue => {:tracker_id => 2,
1152 :subject => 'This is the test_new issue',
1152 :subject => 'This is the test_new issue',
1153 :description => 'This is the description',
1153 :description => 'This is the description',
1154 :priority_id => 5}
1154 :priority_id => 5}
1155 assert_response :success
1155 assert_response :success
1156 assert_template 'attributes'
1156 assert_template 'attributes'
1157
1157
1158 issue = assigns(:issue)
1158 issue = assigns(:issue)
1159 assert_kind_of Issue, issue
1159 assert_kind_of Issue, issue
1160 assert_equal 1, issue.project_id
1160 assert_equal 1, issue.project_id
1161 assert_equal 2, issue.tracker_id
1161 assert_equal 2, issue.tracker_id
1162 assert_equal 'This is the test_new issue', issue.subject
1162 assert_equal 'This is the test_new issue', issue.subject
1163 end
1163 end
1164
1164
1165 def test_post_create
1165 def test_post_create
1166 @request.session[:user_id] = 2
1166 @request.session[:user_id] = 2
1167 assert_difference 'Issue.count' do
1167 assert_difference 'Issue.count' do
1168 post :create, :project_id => 1,
1168 post :create, :project_id => 1,
1169 :issue => {:tracker_id => 3,
1169 :issue => {:tracker_id => 3,
1170 :status_id => 2,
1170 :status_id => 2,
1171 :subject => 'This is the test_new issue',
1171 :subject => 'This is the test_new issue',
1172 :description => 'This is the description',
1172 :description => 'This is the description',
1173 :priority_id => 5,
1173 :priority_id => 5,
1174 :start_date => '2010-11-07',
1174 :start_date => '2010-11-07',
1175 :estimated_hours => '',
1175 :estimated_hours => '',
1176 :custom_field_values => {'2' => 'Value for field 2'}}
1176 :custom_field_values => {'2' => 'Value for field 2'}}
1177 end
1177 end
1178 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1178 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1179
1179
1180 issue = Issue.find_by_subject('This is the test_new issue')
1180 issue = Issue.find_by_subject('This is the test_new issue')
1181 assert_not_nil issue
1181 assert_not_nil issue
1182 assert_equal 2, issue.author_id
1182 assert_equal 2, issue.author_id
1183 assert_equal 3, issue.tracker_id
1183 assert_equal 3, issue.tracker_id
1184 assert_equal 2, issue.status_id
1184 assert_equal 2, issue.status_id
1185 assert_equal Date.parse('2010-11-07'), issue.start_date
1185 assert_equal Date.parse('2010-11-07'), issue.start_date
1186 assert_nil issue.estimated_hours
1186 assert_nil issue.estimated_hours
1187 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1187 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1188 assert_not_nil v
1188 assert_not_nil v
1189 assert_equal 'Value for field 2', v.value
1189 assert_equal 'Value for field 2', v.value
1190 end
1190 end
1191
1191
1192 def test_post_new_with_group_assignment
1192 def test_post_new_with_group_assignment
1193 group = Group.find(11)
1193 group = Group.find(11)
1194 project = Project.find(1)
1194 project = Project.find(1)
1195 project.members << Member.new(:principal => group, :roles => [Role.first])
1195 project.members << Member.new(:principal => group, :roles => [Role.first])
1196
1196
1197 with_settings :issue_group_assignment => '1' do
1197 with_settings :issue_group_assignment => '1' do
1198 @request.session[:user_id] = 2
1198 @request.session[:user_id] = 2
1199 assert_difference 'Issue.count' do
1199 assert_difference 'Issue.count' do
1200 post :create, :project_id => project.id,
1200 post :create, :project_id => project.id,
1201 :issue => {:tracker_id => 3,
1201 :issue => {:tracker_id => 3,
1202 :status_id => 1,
1202 :status_id => 1,
1203 :subject => 'This is the test_new_with_group_assignment issue',
1203 :subject => 'This is the test_new_with_group_assignment issue',
1204 :assigned_to_id => group.id}
1204 :assigned_to_id => group.id}
1205 end
1205 end
1206 end
1206 end
1207 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1207 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1208
1208
1209 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1209 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1210 assert_not_nil issue
1210 assert_not_nil issue
1211 assert_equal group, issue.assigned_to
1211 assert_equal group, issue.assigned_to
1212 end
1212 end
1213
1213
1214 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1214 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1215 Setting.default_issue_start_date_to_creation_date = 0
1215 Setting.default_issue_start_date_to_creation_date = 0
1216
1216
1217 @request.session[:user_id] = 2
1217 @request.session[:user_id] = 2
1218 assert_difference 'Issue.count' do
1218 assert_difference 'Issue.count' do
1219 post :create, :project_id => 1,
1219 post :create, :project_id => 1,
1220 :issue => {:tracker_id => 3,
1220 :issue => {:tracker_id => 3,
1221 :status_id => 2,
1221 :status_id => 2,
1222 :subject => 'This is the test_new issue',
1222 :subject => 'This is the test_new issue',
1223 :description => 'This is the description',
1223 :description => 'This is the description',
1224 :priority_id => 5,
1224 :priority_id => 5,
1225 :estimated_hours => '',
1225 :estimated_hours => '',
1226 :custom_field_values => {'2' => 'Value for field 2'}}
1226 :custom_field_values => {'2' => 'Value for field 2'}}
1227 end
1227 end
1228 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1228 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1229
1229
1230 issue = Issue.find_by_subject('This is the test_new issue')
1230 issue = Issue.find_by_subject('This is the test_new issue')
1231 assert_not_nil issue
1231 assert_not_nil issue
1232 assert_nil issue.start_date
1232 assert_nil issue.start_date
1233 end
1233 end
1234
1234
1235 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1235 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1236 Setting.default_issue_start_date_to_creation_date = 1
1236 Setting.default_issue_start_date_to_creation_date = 1
1237
1237
1238 @request.session[:user_id] = 2
1238 @request.session[:user_id] = 2
1239 assert_difference 'Issue.count' do
1239 assert_difference 'Issue.count' do
1240 post :create, :project_id => 1,
1240 post :create, :project_id => 1,
1241 :issue => {:tracker_id => 3,
1241 :issue => {:tracker_id => 3,
1242 :status_id => 2,
1242 :status_id => 2,
1243 :subject => 'This is the test_new issue',
1243 :subject => 'This is the test_new issue',
1244 :description => 'This is the description',
1244 :description => 'This is the description',
1245 :priority_id => 5,
1245 :priority_id => 5,
1246 :estimated_hours => '',
1246 :estimated_hours => '',
1247 :custom_field_values => {'2' => 'Value for field 2'}}
1247 :custom_field_values => {'2' => 'Value for field 2'}}
1248 end
1248 end
1249 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1249 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1250
1250
1251 issue = Issue.find_by_subject('This is the test_new issue')
1251 issue = Issue.find_by_subject('This is the test_new issue')
1252 assert_not_nil issue
1252 assert_not_nil issue
1253 assert_equal Date.today, issue.start_date
1253 assert_equal Date.today, issue.start_date
1254 end
1254 end
1255
1255
1256 def test_post_create_and_continue
1256 def test_post_create_and_continue
1257 @request.session[:user_id] = 2
1257 @request.session[:user_id] = 2
1258 assert_difference 'Issue.count' do
1258 assert_difference 'Issue.count' do
1259 post :create, :project_id => 1,
1259 post :create, :project_id => 1,
1260 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1260 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1261 :continue => ''
1261 :continue => ''
1262 end
1262 end
1263
1263
1264 issue = Issue.first(:order => 'id DESC')
1264 issue = Issue.first(:order => 'id DESC')
1265 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1265 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1266 assert_not_nil flash[:notice], "flash was not set"
1266 assert_not_nil flash[:notice], "flash was not set"
1267 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1267 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1268 end
1268 end
1269
1269
1270 def test_post_create_without_custom_fields_param
1270 def test_post_create_without_custom_fields_param
1271 @request.session[:user_id] = 2
1271 @request.session[:user_id] = 2
1272 assert_difference 'Issue.count' do
1272 assert_difference 'Issue.count' do
1273 post :create, :project_id => 1,
1273 post :create, :project_id => 1,
1274 :issue => {:tracker_id => 1,
1274 :issue => {:tracker_id => 1,
1275 :subject => 'This is the test_new issue',
1275 :subject => 'This is the test_new issue',
1276 :description => 'This is the description',
1276 :description => 'This is the description',
1277 :priority_id => 5}
1277 :priority_id => 5}
1278 end
1278 end
1279 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1279 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1280 end
1280 end
1281
1281
1282 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1282 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1283 field = IssueCustomField.find_by_name('Database')
1283 field = IssueCustomField.find_by_name('Database')
1284 field.update_attribute(:is_required, true)
1284 field.update_attribute(:is_required, true)
1285
1285
1286 @request.session[:user_id] = 2
1286 @request.session[:user_id] = 2
1287 post :create, :project_id => 1,
1287 post :create, :project_id => 1,
1288 :issue => {:tracker_id => 1,
1288 :issue => {:tracker_id => 1,
1289 :subject => 'This is the test_new issue',
1289 :subject => 'This is the test_new issue',
1290 :description => 'This is the description',
1290 :description => 'This is the description',
1291 :priority_id => 5}
1291 :priority_id => 5}
1292 assert_response :success
1292 assert_response :success
1293 assert_template 'new'
1293 assert_template 'new'
1294 issue = assigns(:issue)
1294 issue = assigns(:issue)
1295 assert_not_nil issue
1295 assert_not_nil issue
1296 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
1296 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
1297 issue.errors[:custom_values].to_s
1297 issue.errors[:custom_values].to_s
1298 end
1298 end
1299
1299
1300 def test_post_create_with_watchers
1300 def test_post_create_with_watchers
1301 @request.session[:user_id] = 2
1301 @request.session[:user_id] = 2
1302 ActionMailer::Base.deliveries.clear
1302 ActionMailer::Base.deliveries.clear
1303
1303
1304 assert_difference 'Watcher.count', 2 do
1304 assert_difference 'Watcher.count', 2 do
1305 post :create, :project_id => 1,
1305 post :create, :project_id => 1,
1306 :issue => {:tracker_id => 1,
1306 :issue => {:tracker_id => 1,
1307 :subject => 'This is a new issue with watchers',
1307 :subject => 'This is a new issue with watchers',
1308 :description => 'This is the description',
1308 :description => 'This is the description',
1309 :priority_id => 5,
1309 :priority_id => 5,
1310 :watcher_user_ids => ['2', '3']}
1310 :watcher_user_ids => ['2', '3']}
1311 end
1311 end
1312 issue = Issue.find_by_subject('This is a new issue with watchers')
1312 issue = Issue.find_by_subject('This is a new issue with watchers')
1313 assert_not_nil issue
1313 assert_not_nil issue
1314 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1314 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1315
1315
1316 # Watchers added
1316 # Watchers added
1317 assert_equal [2, 3], issue.watcher_user_ids.sort
1317 assert_equal [2, 3], issue.watcher_user_ids.sort
1318 assert issue.watched_by?(User.find(3))
1318 assert issue.watched_by?(User.find(3))
1319 # Watchers notified
1319 # Watchers notified
1320 mail = ActionMailer::Base.deliveries.last
1320 mail = ActionMailer::Base.deliveries.last
1321 assert_kind_of TMail::Mail, mail
1321 assert_kind_of TMail::Mail, mail
1322 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1322 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1323 end
1323 end
1324
1324
1325 def test_post_create_subissue
1325 def test_post_create_subissue
1326 @request.session[:user_id] = 2
1326 @request.session[:user_id] = 2
1327
1327
1328 assert_difference 'Issue.count' do
1328 assert_difference 'Issue.count' do
1329 post :create, :project_id => 1,
1329 post :create, :project_id => 1,
1330 :issue => {:tracker_id => 1,
1330 :issue => {:tracker_id => 1,
1331 :subject => 'This is a child issue',
1331 :subject => 'This is a child issue',
1332 :parent_issue_id => 2}
1332 :parent_issue_id => 2}
1333 end
1333 end
1334 issue = Issue.find_by_subject('This is a child issue')
1334 issue = Issue.find_by_subject('This is a child issue')
1335 assert_not_nil issue
1335 assert_not_nil issue
1336 assert_equal Issue.find(2), issue.parent
1336 assert_equal Issue.find(2), issue.parent
1337 end
1337 end
1338
1338
1339 def test_post_create_subissue_with_non_numeric_parent_id
1339 def test_post_create_subissue_with_non_numeric_parent_id
1340 @request.session[:user_id] = 2
1340 @request.session[:user_id] = 2
1341
1341
1342 assert_difference 'Issue.count' do
1342 assert_difference 'Issue.count' do
1343 post :create, :project_id => 1,
1343 post :create, :project_id => 1,
1344 :issue => {:tracker_id => 1,
1344 :issue => {:tracker_id => 1,
1345 :subject => 'This is a child issue',
1345 :subject => 'This is a child issue',
1346 :parent_issue_id => 'ABC'}
1346 :parent_issue_id => 'ABC'}
1347 end
1347 end
1348 issue = Issue.find_by_subject('This is a child issue')
1348 issue = Issue.find_by_subject('This is a child issue')
1349 assert_not_nil issue
1349 assert_not_nil issue
1350 assert_nil issue.parent
1350 assert_nil issue.parent
1351 end
1351 end
1352
1352
1353 def test_post_create_private
1353 def test_post_create_private
1354 @request.session[:user_id] = 2
1354 @request.session[:user_id] = 2
1355
1355
1356 assert_difference 'Issue.count' do
1356 assert_difference 'Issue.count' do
1357 post :create, :project_id => 1,
1357 post :create, :project_id => 1,
1358 :issue => {:tracker_id => 1,
1358 :issue => {:tracker_id => 1,
1359 :subject => 'This is a private issue',
1359 :subject => 'This is a private issue',
1360 :is_private => '1'}
1360 :is_private => '1'}
1361 end
1361 end
1362 issue = Issue.first(:order => 'id DESC')
1362 issue = Issue.first(:order => 'id DESC')
1363 assert issue.is_private?
1363 assert issue.is_private?
1364 end
1364 end
1365
1365
1366 def test_post_create_private_with_set_own_issues_private_permission
1366 def test_post_create_private_with_set_own_issues_private_permission
1367 role = Role.find(1)
1367 role = Role.find(1)
1368 role.remove_permission! :set_issues_private
1368 role.remove_permission! :set_issues_private
1369 role.add_permission! :set_own_issues_private
1369 role.add_permission! :set_own_issues_private
1370
1370
1371 @request.session[:user_id] = 2
1371 @request.session[:user_id] = 2
1372
1372
1373 assert_difference 'Issue.count' do
1373 assert_difference 'Issue.count' do
1374 post :create, :project_id => 1,
1374 post :create, :project_id => 1,
1375 :issue => {:tracker_id => 1,
1375 :issue => {:tracker_id => 1,
1376 :subject => 'This is a private issue',
1376 :subject => 'This is a private issue',
1377 :is_private => '1'}
1377 :is_private => '1'}
1378 end
1378 end
1379 issue = Issue.first(:order => 'id DESC')
1379 issue = Issue.first(:order => 'id DESC')
1380 assert issue.is_private?
1380 assert issue.is_private?
1381 end
1381 end
1382
1382
1383 def test_post_create_should_send_a_notification
1383 def test_post_create_should_send_a_notification
1384 ActionMailer::Base.deliveries.clear
1384 ActionMailer::Base.deliveries.clear
1385 @request.session[:user_id] = 2
1385 @request.session[:user_id] = 2
1386 assert_difference 'Issue.count' do
1386 assert_difference 'Issue.count' do
1387 post :create, :project_id => 1,
1387 post :create, :project_id => 1,
1388 :issue => {:tracker_id => 3,
1388 :issue => {:tracker_id => 3,
1389 :subject => 'This is the test_new issue',
1389 :subject => 'This is the test_new issue',
1390 :description => 'This is the description',
1390 :description => 'This is the description',
1391 :priority_id => 5,
1391 :priority_id => 5,
1392 :estimated_hours => '',
1392 :estimated_hours => '',
1393 :custom_field_values => {'2' => 'Value for field 2'}}
1393 :custom_field_values => {'2' => 'Value for field 2'}}
1394 end
1394 end
1395 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1395 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1396
1396
1397 assert_equal 1, ActionMailer::Base.deliveries.size
1397 assert_equal 1, ActionMailer::Base.deliveries.size
1398 end
1398 end
1399
1399
1400 def test_post_create_should_preserve_fields_values_on_validation_failure
1400 def test_post_create_should_preserve_fields_values_on_validation_failure
1401 @request.session[:user_id] = 2
1401 @request.session[:user_id] = 2
1402 post :create, :project_id => 1,
1402 post :create, :project_id => 1,
1403 :issue => {:tracker_id => 1,
1403 :issue => {:tracker_id => 1,
1404 # empty subject
1404 # empty subject
1405 :subject => '',
1405 :subject => '',
1406 :description => 'This is a description',
1406 :description => 'This is a description',
1407 :priority_id => 6,
1407 :priority_id => 6,
1408 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1408 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1409 assert_response :success
1409 assert_response :success
1410 assert_template 'new'
1410 assert_template 'new'
1411
1411
1412 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1412 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1413 :content => 'This is a description'
1413 :content => 'This is a description'
1414 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1414 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1415 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1415 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1416 :value => '6' },
1416 :value => '6' },
1417 :content => 'High' }
1417 :content => 'High' }
1418 # Custom fields
1418 # Custom fields
1419 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1419 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1420 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1420 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1421 :value => 'Oracle' },
1421 :value => 'Oracle' },
1422 :content => 'Oracle' }
1422 :content => 'Oracle' }
1423 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1423 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1424 :value => 'Value for field 2'}
1424 :value => 'Value for field 2'}
1425 end
1425 end
1426
1426
1427 def test_post_create_should_ignore_non_safe_attributes
1427 def test_post_create_should_ignore_non_safe_attributes
1428 @request.session[:user_id] = 2
1428 @request.session[:user_id] = 2
1429 assert_nothing_raised do
1429 assert_nothing_raised do
1430 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1430 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1431 end
1431 end
1432 end
1432 end
1433
1433
1434 def test_post_create_with_attachment
1434 def test_post_create_with_attachment
1435 set_tmp_attachments_directory
1435 set_tmp_attachments_directory
1436 @request.session[:user_id] = 2
1436 @request.session[:user_id] = 2
1437
1437
1438 assert_difference 'Issue.count' do
1438 assert_difference 'Issue.count' do
1439 assert_difference 'Attachment.count' do
1439 assert_difference 'Attachment.count' do
1440 post :create, :project_id => 1,
1440 post :create, :project_id => 1,
1441 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1441 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1442 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1442 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1443 end
1443 end
1444 end
1444 end
1445
1445
1446 issue = Issue.first(:order => 'id DESC')
1446 issue = Issue.first(:order => 'id DESC')
1447 attachment = Attachment.first(:order => 'id DESC')
1447 attachment = Attachment.first(:order => 'id DESC')
1448
1448
1449 assert_equal issue, attachment.container
1449 assert_equal issue, attachment.container
1450 assert_equal 2, attachment.author_id
1450 assert_equal 2, attachment.author_id
1451 assert_equal 'testfile.txt', attachment.filename
1451 assert_equal 'testfile.txt', attachment.filename
1452 assert_equal 'text/plain', attachment.content_type
1452 assert_equal 'text/plain', attachment.content_type
1453 assert_equal 'test file', attachment.description
1453 assert_equal 'test file', attachment.description
1454 assert_equal 59, attachment.filesize
1454 assert_equal 59, attachment.filesize
1455 assert File.exists?(attachment.diskfile)
1455 assert File.exists?(attachment.diskfile)
1456 assert_equal 59, File.size(attachment.diskfile)
1456 assert_equal 59, File.size(attachment.diskfile)
1457 end
1457 end
1458
1458
1459 context "without workflow privilege" do
1459 context "without workflow privilege" do
1460 setup do
1460 setup do
1461 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1461 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1462 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1462 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1463 end
1463 end
1464
1464
1465 context "#new" do
1465 context "#new" do
1466 should "propose default status only" do
1466 should "propose default status only" do
1467 get :new, :project_id => 1
1467 get :new, :project_id => 1
1468 assert_response :success
1468 assert_response :success
1469 assert_template 'new'
1469 assert_template 'new'
1470 assert_tag :tag => 'select',
1470 assert_tag :tag => 'select',
1471 :attributes => {:name => 'issue[status_id]'},
1471 :attributes => {:name => 'issue[status_id]'},
1472 :children => {:count => 1},
1472 :children => {:count => 1},
1473 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1473 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1474 end
1474 end
1475
1475
1476 should "accept default status" do
1476 should "accept default status" do
1477 assert_difference 'Issue.count' do
1477 assert_difference 'Issue.count' do
1478 post :create, :project_id => 1,
1478 post :create, :project_id => 1,
1479 :issue => {:tracker_id => 1,
1479 :issue => {:tracker_id => 1,
1480 :subject => 'This is an issue',
1480 :subject => 'This is an issue',
1481 :status_id => 1}
1481 :status_id => 1}
1482 end
1482 end
1483 issue = Issue.last(:order => 'id')
1483 issue = Issue.last(:order => 'id')
1484 assert_equal IssueStatus.default, issue.status
1484 assert_equal IssueStatus.default, issue.status
1485 end
1485 end
1486
1486
1487 should "ignore unauthorized status" do
1487 should "ignore unauthorized status" do
1488 assert_difference 'Issue.count' do
1488 assert_difference 'Issue.count' do
1489 post :create, :project_id => 1,
1489 post :create, :project_id => 1,
1490 :issue => {:tracker_id => 1,
1490 :issue => {:tracker_id => 1,
1491 :subject => 'This is an issue',
1491 :subject => 'This is an issue',
1492 :status_id => 3}
1492 :status_id => 3}
1493 end
1493 end
1494 issue = Issue.last(:order => 'id')
1494 issue = Issue.last(:order => 'id')
1495 assert_equal IssueStatus.default, issue.status
1495 assert_equal IssueStatus.default, issue.status
1496 end
1496 end
1497 end
1497 end
1498
1498
1499 context "#update" do
1499 context "#update" do
1500 should "ignore status change" do
1500 should "ignore status change" do
1501 assert_difference 'Journal.count' do
1501 assert_difference 'Journal.count' do
1502 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1502 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1503 end
1503 end
1504 assert_equal 1, Issue.find(1).status_id
1504 assert_equal 1, Issue.find(1).status_id
1505 end
1505 end
1506
1506
1507 should "ignore attributes changes" do
1507 should "ignore attributes changes" do
1508 assert_difference 'Journal.count' do
1508 assert_difference 'Journal.count' do
1509 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1509 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1510 end
1510 end
1511 issue = Issue.find(1)
1511 issue = Issue.find(1)
1512 assert_equal "Can't print recipes", issue.subject
1512 assert_equal "Can't print recipes", issue.subject
1513 assert_nil issue.assigned_to
1513 assert_nil issue.assigned_to
1514 end
1514 end
1515 end
1515 end
1516 end
1516 end
1517
1517
1518 context "with workflow privilege" do
1518 context "with workflow privilege" do
1519 setup do
1519 setup do
1520 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1520 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1521 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1521 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1522 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1522 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1523 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1523 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1524 end
1524 end
1525
1525
1526 context "#update" do
1526 context "#update" do
1527 should "accept authorized status" do
1527 should "accept authorized status" do
1528 assert_difference 'Journal.count' do
1528 assert_difference 'Journal.count' do
1529 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1529 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1530 end
1530 end
1531 assert_equal 3, Issue.find(1).status_id
1531 assert_equal 3, Issue.find(1).status_id
1532 end
1532 end
1533
1533
1534 should "ignore unauthorized status" do
1534 should "ignore unauthorized status" do
1535 assert_difference 'Journal.count' do
1535 assert_difference 'Journal.count' do
1536 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1536 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1537 end
1537 end
1538 assert_equal 1, Issue.find(1).status_id
1538 assert_equal 1, Issue.find(1).status_id
1539 end
1539 end
1540
1540
1541 should "accept authorized attributes changes" do
1541 should "accept authorized attributes changes" do
1542 assert_difference 'Journal.count' do
1542 assert_difference 'Journal.count' do
1543 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1543 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1544 end
1544 end
1545 issue = Issue.find(1)
1545 issue = Issue.find(1)
1546 assert_equal 2, issue.assigned_to_id
1546 assert_equal 2, issue.assigned_to_id
1547 end
1547 end
1548
1548
1549 should "ignore unauthorized attributes changes" do
1549 should "ignore unauthorized attributes changes" do
1550 assert_difference 'Journal.count' do
1550 assert_difference 'Journal.count' do
1551 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1551 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1552 end
1552 end
1553 issue = Issue.find(1)
1553 issue = Issue.find(1)
1554 assert_equal "Can't print recipes", issue.subject
1554 assert_equal "Can't print recipes", issue.subject
1555 end
1555 end
1556 end
1556 end
1557
1557
1558 context "and :edit_issues permission" do
1558 context "and :edit_issues permission" do
1559 setup do
1559 setup do
1560 Role.anonymous.add_permission! :add_issues, :edit_issues
1560 Role.anonymous.add_permission! :add_issues, :edit_issues
1561 end
1561 end
1562
1562
1563 should "accept authorized status" do
1563 should "accept authorized status" do
1564 assert_difference 'Journal.count' do
1564 assert_difference 'Journal.count' do
1565 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1565 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1566 end
1566 end
1567 assert_equal 3, Issue.find(1).status_id
1567 assert_equal 3, Issue.find(1).status_id
1568 end
1568 end
1569
1569
1570 should "ignore unauthorized status" do
1570 should "ignore unauthorized status" do
1571 assert_difference 'Journal.count' do
1571 assert_difference 'Journal.count' do
1572 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1572 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1573 end
1573 end
1574 assert_equal 1, Issue.find(1).status_id
1574 assert_equal 1, Issue.find(1).status_id
1575 end
1575 end
1576
1576
1577 should "accept authorized attributes changes" do
1577 should "accept authorized attributes changes" do
1578 assert_difference 'Journal.count' do
1578 assert_difference 'Journal.count' do
1579 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1579 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1580 end
1580 end
1581 issue = Issue.find(1)
1581 issue = Issue.find(1)
1582 assert_equal "changed", issue.subject
1582 assert_equal "changed", issue.subject
1583 assert_equal 2, issue.assigned_to_id
1583 assert_equal 2, issue.assigned_to_id
1584 end
1584 end
1585 end
1585 end
1586 end
1586 end
1587
1587
1588 def test_new_as_copy
1588 def test_new_as_copy
1589 @request.session[:user_id] = 2
1589 @request.session[:user_id] = 2
1590 get :new, :project_id => 1, :copy_from => 1
1590 get :new, :project_id => 1, :copy_from => 1
1591
1591
1592 assert_response :success
1592 assert_response :success
1593 assert_template 'new'
1593 assert_template 'new'
1594
1594
1595 assert_not_nil assigns(:issue)
1595 assert_not_nil assigns(:issue)
1596 orig = Issue.find(1)
1596 orig = Issue.find(1)
1597 assert_equal 1, assigns(:issue).project_id
1597 assert_equal 1, assigns(:issue).project_id
1598 assert_equal orig.subject, assigns(:issue).subject
1598 assert_equal orig.subject, assigns(:issue).subject
1599 assert assigns(:issue).copy?
1599 assert assigns(:issue).copy?
1600
1600
1601 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1601 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1602 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1602 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1603 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1603 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1604 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1604 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1605 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1605 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1606 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1606 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1607 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1607 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1608 end
1608 end
1609
1609
1610 def test_create_as_copy_on_different_project
1610 def test_create_as_copy_on_different_project
1611 @request.session[:user_id] = 2
1611 @request.session[:user_id] = 2
1612 assert_difference 'Issue.count' do
1612 assert_difference 'Issue.count' do
1613 post :create, :project_id => 1, :copy_from => 1,
1613 post :create, :project_id => 1, :copy_from => 1,
1614 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1614 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1615
1615
1616 assert_not_nil assigns(:issue)
1616 assert_not_nil assigns(:issue)
1617 assert assigns(:issue).copy?
1617 assert assigns(:issue).copy?
1618 end
1618 end
1619 issue = Issue.first(:order => 'id DESC')
1619 issue = Issue.first(:order => 'id DESC')
1620 assert_redirected_to "/issues/#{issue.id}"
1620 assert_redirected_to "/issues/#{issue.id}"
1621
1621
1622 assert_equal 2, issue.project_id
1622 assert_equal 2, issue.project_id
1623 assert_equal 3, issue.tracker_id
1623 assert_equal 3, issue.tracker_id
1624 assert_equal 'Copy', issue.subject
1624 assert_equal 'Copy', issue.subject
1625 end
1625 end
1626
1626
1627 def test_create_as_copy_with_failure
1627 def test_create_as_copy_with_failure
1628 @request.session[:user_id] = 2
1628 @request.session[:user_id] = 2
1629 post :create, :project_id => 1, :copy_from => 1,
1629 post :create, :project_id => 1, :copy_from => 1,
1630 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1630 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1631
1631
1632 assert_response :success
1632 assert_response :success
1633 assert_template 'new'
1633 assert_template 'new'
1634
1634
1635 assert_not_nil assigns(:issue)
1635 assert_not_nil assigns(:issue)
1636 assert assigns(:issue).copy?
1636 assert assigns(:issue).copy?
1637
1637
1638 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1638 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1639 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1639 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1640 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1640 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1641 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
1641 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
1642 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1642 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1643 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
1643 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
1644 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1644 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1645 end
1645 end
1646
1646
1647 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
1647 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
1648 @request.session[:user_id] = 2
1648 @request.session[:user_id] = 2
1649 assert !User.find(2).member_of?(Project.find(4))
1649 assert !User.find(2).member_of?(Project.find(4))
1650
1650
1651 assert_difference 'Issue.count' do
1651 assert_difference 'Issue.count' do
1652 post :create, :project_id => 1, :copy_from => 1,
1652 post :create, :project_id => 1, :copy_from => 1,
1653 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1653 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1654 end
1654 end
1655 issue = Issue.first(:order => 'id DESC')
1655 issue = Issue.first(:order => 'id DESC')
1656 assert_equal 1, issue.project_id
1656 assert_equal 1, issue.project_id
1657 end
1657 end
1658
1658
1659 def test_get_edit
1659 def test_get_edit
1660 @request.session[:user_id] = 2
1660 @request.session[:user_id] = 2
1661 get :edit, :id => 1
1661 get :edit, :id => 1
1662 assert_response :success
1662 assert_response :success
1663 assert_template 'edit'
1663 assert_template 'edit'
1664 assert_not_nil assigns(:issue)
1664 assert_not_nil assigns(:issue)
1665 assert_equal Issue.find(1), assigns(:issue)
1665 assert_equal Issue.find(1), assigns(:issue)
1666
1666
1667 # Be sure we don't display inactive IssuePriorities
1667 # Be sure we don't display inactive IssuePriorities
1668 assert ! IssuePriority.find(15).active?
1668 assert ! IssuePriority.find(15).active?
1669 assert_no_tag :option, :attributes => {:value => '15'},
1669 assert_no_tag :option, :attributes => {:value => '15'},
1670 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1670 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1671 end
1671 end
1672
1672
1673 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1673 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1674 @request.session[:user_id] = 2
1674 @request.session[:user_id] = 2
1675 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1675 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1676
1676
1677 get :edit, :id => 1
1677 get :edit, :id => 1
1678 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1678 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1679 end
1679 end
1680
1680
1681 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1681 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1682 @request.session[:user_id] = 2
1682 @request.session[:user_id] = 2
1683 Role.find_by_name('Manager').remove_permission! :log_time
1683 Role.find_by_name('Manager').remove_permission! :log_time
1684
1684
1685 get :edit, :id => 1
1685 get :edit, :id => 1
1686 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1686 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1687 end
1687 end
1688
1688
1689 def test_get_edit_with_params
1689 def test_get_edit_with_params
1690 @request.session[:user_id] = 2
1690 @request.session[:user_id] = 2
1691 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1691 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1692 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1692 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1693 assert_response :success
1693 assert_response :success
1694 assert_template 'edit'
1694 assert_template 'edit'
1695
1695
1696 issue = assigns(:issue)
1696 issue = assigns(:issue)
1697 assert_not_nil issue
1697 assert_not_nil issue
1698
1698
1699 assert_equal 5, issue.status_id
1699 assert_equal 5, issue.status_id
1700 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1700 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1701 :child => { :tag => 'option',
1701 :child => { :tag => 'option',
1702 :content => 'Closed',
1702 :content => 'Closed',
1703 :attributes => { :selected => 'selected' } }
1703 :attributes => { :selected => 'selected' } }
1704
1704
1705 assert_equal 7, issue.priority_id
1705 assert_equal 7, issue.priority_id
1706 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1706 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1707 :child => { :tag => 'option',
1707 :child => { :tag => 'option',
1708 :content => 'Urgent',
1708 :content => 'Urgent',
1709 :attributes => { :selected => 'selected' } }
1709 :attributes => { :selected => 'selected' } }
1710
1710
1711 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1711 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1712 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1712 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1713 :child => { :tag => 'option',
1713 :child => { :tag => 'option',
1714 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1714 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1715 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1715 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1716 end
1716 end
1717
1717
1718 def test_update_edit_form
1718 def test_update_edit_form
1719 @request.session[:user_id] = 2
1719 @request.session[:user_id] = 2
1720 xhr :put, :new, :project_id => 1,
1720 xhr :put, :new, :project_id => 1,
1721 :id => 1,
1721 :id => 1,
1722 :issue => {:tracker_id => 2,
1722 :issue => {:tracker_id => 2,
1723 :subject => 'This is the test_new issue',
1723 :subject => 'This is the test_new issue',
1724 :description => 'This is the description',
1724 :description => 'This is the description',
1725 :priority_id => 5}
1725 :priority_id => 5}
1726 assert_response :success
1726 assert_response :success
1727 assert_template 'attributes'
1727 assert_template 'attributes'
1728
1728
1729 issue = assigns(:issue)
1729 issue = assigns(:issue)
1730 assert_kind_of Issue, issue
1730 assert_kind_of Issue, issue
1731 assert_equal 1, issue.id
1731 assert_equal 1, issue.id
1732 assert_equal 1, issue.project_id
1732 assert_equal 1, issue.project_id
1733 assert_equal 2, issue.tracker_id
1733 assert_equal 2, issue.tracker_id
1734 assert_equal 'This is the test_new issue', issue.subject
1734 assert_equal 'This is the test_new issue', issue.subject
1735 end
1735 end
1736
1736
1737 def test_update_edit_form_with_project_change
1737 def test_update_edit_form_with_project_change
1738 @request.session[:user_id] = 2
1738 @request.session[:user_id] = 2
1739 xhr :put, :new, :project_id => 1,
1739 xhr :put, :new, :project_id => 1,
1740 :id => 1,
1740 :id => 1,
1741 :project_change => '1',
1741 :project_change => '1',
1742 :issue => {:project_id => 2,
1742 :issue => {:project_id => 2,
1743 :tracker_id => 2,
1743 :tracker_id => 2,
1744 :subject => 'This is the test_new issue',
1744 :subject => 'This is the test_new issue',
1745 :description => 'This is the description',
1745 :description => 'This is the description',
1746 :priority_id => 5}
1746 :priority_id => 5}
1747 assert_response :success
1747 assert_response :success
1748 assert_template 'form'
1748 assert_template 'form'
1749
1749
1750 issue = assigns(:issue)
1750 issue = assigns(:issue)
1751 assert_kind_of Issue, issue
1751 assert_kind_of Issue, issue
1752 assert_equal 1, issue.id
1752 assert_equal 1, issue.id
1753 assert_equal 2, issue.project_id
1753 assert_equal 2, issue.project_id
1754 assert_equal 2, issue.tracker_id
1754 assert_equal 2, issue.tracker_id
1755 assert_equal 'This is the test_new issue', issue.subject
1755 assert_equal 'This is the test_new issue', issue.subject
1756 end
1756 end
1757
1757
1758 def test_update_using_invalid_http_verbs
1758 def test_update_using_invalid_http_verbs
1759 @request.session[:user_id] = 2
1759 @request.session[:user_id] = 2
1760 subject = 'Updated by an invalid http verb'
1760 subject = 'Updated by an invalid http verb'
1761
1761
1762 get :update, :id => 1, :issue => {:subject => subject}
1762 get :update, :id => 1, :issue => {:subject => subject}
1763 assert_not_equal subject, Issue.find(1).subject
1763 assert_not_equal subject, Issue.find(1).subject
1764
1764
1765 post :update, :id => 1, :issue => {:subject => subject}
1765 post :update, :id => 1, :issue => {:subject => subject}
1766 assert_not_equal subject, Issue.find(1).subject
1766 assert_not_equal subject, Issue.find(1).subject
1767
1767
1768 delete :update, :id => 1, :issue => {:subject => subject}
1768 delete :update, :id => 1, :issue => {:subject => subject}
1769 assert_not_equal subject, Issue.find(1).subject
1769 assert_not_equal subject, Issue.find(1).subject
1770 end
1770 end
1771
1771
1772 def test_put_update_without_custom_fields_param
1772 def test_put_update_without_custom_fields_param
1773 @request.session[:user_id] = 2
1773 @request.session[:user_id] = 2
1774 ActionMailer::Base.deliveries.clear
1774 ActionMailer::Base.deliveries.clear
1775
1775
1776 issue = Issue.find(1)
1776 issue = Issue.find(1)
1777 assert_equal '125', issue.custom_value_for(2).value
1777 assert_equal '125', issue.custom_value_for(2).value
1778 old_subject = issue.subject
1778 old_subject = issue.subject
1779 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1779 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1780
1780
1781 assert_difference('Journal.count') do
1781 assert_difference('Journal.count') do
1782 assert_difference('JournalDetail.count', 2) do
1782 assert_difference('JournalDetail.count', 2) do
1783 put :update, :id => 1, :issue => {:subject => new_subject,
1783 put :update, :id => 1, :issue => {:subject => new_subject,
1784 :priority_id => '6',
1784 :priority_id => '6',
1785 :category_id => '1' # no change
1785 :category_id => '1' # no change
1786 }
1786 }
1787 end
1787 end
1788 end
1788 end
1789 assert_redirected_to :action => 'show', :id => '1'
1789 assert_redirected_to :action => 'show', :id => '1'
1790 issue.reload
1790 issue.reload
1791 assert_equal new_subject, issue.subject
1791 assert_equal new_subject, issue.subject
1792 # Make sure custom fields were not cleared
1792 # Make sure custom fields were not cleared
1793 assert_equal '125', issue.custom_value_for(2).value
1793 assert_equal '125', issue.custom_value_for(2).value
1794
1794
1795 mail = ActionMailer::Base.deliveries.last
1795 mail = ActionMailer::Base.deliveries.last
1796 assert_kind_of TMail::Mail, mail
1796 assert_kind_of TMail::Mail, mail
1797 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1797 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1798 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1798 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1799 end
1799 end
1800
1800
1801 def test_put_update_with_project_change
1801 def test_put_update_with_project_change
1802 @request.session[:user_id] = 2
1802 @request.session[:user_id] = 2
1803 ActionMailer::Base.deliveries.clear
1803 ActionMailer::Base.deliveries.clear
1804
1804
1805 assert_difference('Journal.count') do
1805 assert_difference('Journal.count') do
1806 assert_difference('JournalDetail.count', 3) do
1806 assert_difference('JournalDetail.count', 3) do
1807 put :update, :id => 1, :issue => {:project_id => '2',
1807 put :update, :id => 1, :issue => {:project_id => '2',
1808 :tracker_id => '1', # no change
1808 :tracker_id => '1', # no change
1809 :priority_id => '6',
1809 :priority_id => '6',
1810 :category_id => '3'
1810 :category_id => '3'
1811 }
1811 }
1812 end
1812 end
1813 end
1813 end
1814 assert_redirected_to :action => 'show', :id => '1'
1814 assert_redirected_to :action => 'show', :id => '1'
1815 issue = Issue.find(1)
1815 issue = Issue.find(1)
1816 assert_equal 2, issue.project_id
1816 assert_equal 2, issue.project_id
1817 assert_equal 1, issue.tracker_id
1817 assert_equal 1, issue.tracker_id
1818 assert_equal 6, issue.priority_id
1818 assert_equal 6, issue.priority_id
1819 assert_equal 3, issue.category_id
1819 assert_equal 3, issue.category_id
1820
1820
1821 mail = ActionMailer::Base.deliveries.last
1821 mail = ActionMailer::Base.deliveries.last
1822 assert_not_nil mail
1822 assert_not_nil mail
1823 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1823 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1824 assert mail.body.include?("Project changed from eCookbook to OnlineStore")
1824 assert mail.body.include?("Project changed from eCookbook to OnlineStore")
1825 end
1825 end
1826
1826
1827 def test_put_update_with_tracker_change
1827 def test_put_update_with_tracker_change
1828 @request.session[:user_id] = 2
1828 @request.session[:user_id] = 2
1829 ActionMailer::Base.deliveries.clear
1829 ActionMailer::Base.deliveries.clear
1830
1830
1831 assert_difference('Journal.count') do
1831 assert_difference('Journal.count') do
1832 assert_difference('JournalDetail.count', 2) do
1832 assert_difference('JournalDetail.count', 2) do
1833 put :update, :id => 1, :issue => {:project_id => '1',
1833 put :update, :id => 1, :issue => {:project_id => '1',
1834 :tracker_id => '2',
1834 :tracker_id => '2',
1835 :priority_id => '6'
1835 :priority_id => '6'
1836 }
1836 }
1837 end
1837 end
1838 end
1838 end
1839 assert_redirected_to :action => 'show', :id => '1'
1839 assert_redirected_to :action => 'show', :id => '1'
1840 issue = Issue.find(1)
1840 issue = Issue.find(1)
1841 assert_equal 1, issue.project_id
1841 assert_equal 1, issue.project_id
1842 assert_equal 2, issue.tracker_id
1842 assert_equal 2, issue.tracker_id
1843 assert_equal 6, issue.priority_id
1843 assert_equal 6, issue.priority_id
1844 assert_equal 1, issue.category_id
1844 assert_equal 1, issue.category_id
1845
1845
1846 mail = ActionMailer::Base.deliveries.last
1846 mail = ActionMailer::Base.deliveries.last
1847 assert_not_nil mail
1847 assert_not_nil mail
1848 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1848 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1849 assert mail.body.include?("Tracker changed from Bug to Feature request")
1849 assert mail.body.include?("Tracker changed from Bug to Feature request")
1850 end
1850 end
1851
1851
1852 def test_put_update_with_custom_field_change
1852 def test_put_update_with_custom_field_change
1853 @request.session[:user_id] = 2
1853 @request.session[:user_id] = 2
1854 issue = Issue.find(1)
1854 issue = Issue.find(1)
1855 assert_equal '125', issue.custom_value_for(2).value
1855 assert_equal '125', issue.custom_value_for(2).value
1856
1856
1857 assert_difference('Journal.count') do
1857 assert_difference('Journal.count') do
1858 assert_difference('JournalDetail.count', 3) do
1858 assert_difference('JournalDetail.count', 3) do
1859 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1859 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1860 :priority_id => '6',
1860 :priority_id => '6',
1861 :category_id => '1', # no change
1861 :category_id => '1', # no change
1862 :custom_field_values => { '2' => 'New custom value' }
1862 :custom_field_values => { '2' => 'New custom value' }
1863 }
1863 }
1864 end
1864 end
1865 end
1865 end
1866 assert_redirected_to :action => 'show', :id => '1'
1866 assert_redirected_to :action => 'show', :id => '1'
1867 issue.reload
1867 issue.reload
1868 assert_equal 'New custom value', issue.custom_value_for(2).value
1868 assert_equal 'New custom value', issue.custom_value_for(2).value
1869
1869
1870 mail = ActionMailer::Base.deliveries.last
1870 mail = ActionMailer::Base.deliveries.last
1871 assert_kind_of TMail::Mail, mail
1871 assert_kind_of TMail::Mail, mail
1872 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1872 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1873 end
1873 end
1874
1874
1875 def test_put_update_with_status_and_assignee_change
1875 def test_put_update_with_status_and_assignee_change
1876 issue = Issue.find(1)
1876 issue = Issue.find(1)
1877 assert_equal 1, issue.status_id
1877 assert_equal 1, issue.status_id
1878 @request.session[:user_id] = 2
1878 @request.session[:user_id] = 2
1879 assert_difference('TimeEntry.count', 0) do
1879 assert_difference('TimeEntry.count', 0) do
1880 put :update,
1880 put :update,
1881 :id => 1,
1881 :id => 1,
1882 :issue => { :status_id => 2, :assigned_to_id => 3 },
1882 :issue => { :status_id => 2, :assigned_to_id => 3 },
1883 :notes => 'Assigned to dlopper',
1883 :notes => 'Assigned to dlopper',
1884 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1884 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1885 end
1885 end
1886 assert_redirected_to :action => 'show', :id => '1'
1886 assert_redirected_to :action => 'show', :id => '1'
1887 issue.reload
1887 issue.reload
1888 assert_equal 2, issue.status_id
1888 assert_equal 2, issue.status_id
1889 j = Journal.find(:first, :order => 'id DESC')
1889 j = Journal.find(:first, :order => 'id DESC')
1890 assert_equal 'Assigned to dlopper', j.notes
1890 assert_equal 'Assigned to dlopper', j.notes
1891 assert_equal 2, j.details.size
1891 assert_equal 2, j.details.size
1892
1892
1893 mail = ActionMailer::Base.deliveries.last
1893 mail = ActionMailer::Base.deliveries.last
1894 assert mail.body.include?("Status changed from New to Assigned")
1894 assert mail.body.include?("Status changed from New to Assigned")
1895 # subject should contain the new status
1895 # subject should contain the new status
1896 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1896 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1897 end
1897 end
1898
1898
1899 def test_put_update_with_note_only
1899 def test_put_update_with_note_only
1900 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1900 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1901 # anonymous user
1901 # anonymous user
1902 put :update,
1902 put :update,
1903 :id => 1,
1903 :id => 1,
1904 :notes => notes
1904 :notes => notes
1905 assert_redirected_to :action => 'show', :id => '1'
1905 assert_redirected_to :action => 'show', :id => '1'
1906 j = Journal.find(:first, :order => 'id DESC')
1906 j = Journal.find(:first, :order => 'id DESC')
1907 assert_equal notes, j.notes
1907 assert_equal notes, j.notes
1908 assert_equal 0, j.details.size
1908 assert_equal 0, j.details.size
1909 assert_equal User.anonymous, j.user
1909 assert_equal User.anonymous, j.user
1910
1910
1911 mail = ActionMailer::Base.deliveries.last
1911 mail = ActionMailer::Base.deliveries.last
1912 assert mail.body.include?(notes)
1912 assert mail.body.include?(notes)
1913 end
1913 end
1914
1914
1915 def test_put_update_with_note_and_spent_time
1915 def test_put_update_with_note_and_spent_time
1916 @request.session[:user_id] = 2
1916 @request.session[:user_id] = 2
1917 spent_hours_before = Issue.find(1).spent_hours
1917 spent_hours_before = Issue.find(1).spent_hours
1918 assert_difference('TimeEntry.count') do
1918 assert_difference('TimeEntry.count') do
1919 put :update,
1919 put :update,
1920 :id => 1,
1920 :id => 1,
1921 :notes => '2.5 hours added',
1921 :notes => '2.5 hours added',
1922 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1922 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1923 end
1923 end
1924 assert_redirected_to :action => 'show', :id => '1'
1924 assert_redirected_to :action => 'show', :id => '1'
1925
1925
1926 issue = Issue.find(1)
1926 issue = Issue.find(1)
1927
1927
1928 j = Journal.find(:first, :order => 'id DESC')
1928 j = Journal.find(:first, :order => 'id DESC')
1929 assert_equal '2.5 hours added', j.notes
1929 assert_equal '2.5 hours added', j.notes
1930 assert_equal 0, j.details.size
1930 assert_equal 0, j.details.size
1931
1931
1932 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1932 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1933 assert_not_nil t
1933 assert_not_nil t
1934 assert_equal 2.5, t.hours
1934 assert_equal 2.5, t.hours
1935 assert_equal spent_hours_before + 2.5, issue.spent_hours
1935 assert_equal spent_hours_before + 2.5, issue.spent_hours
1936 end
1936 end
1937
1937
1938 def test_put_update_with_attachment_only
1938 def test_put_update_with_attachment_only
1939 set_tmp_attachments_directory
1939 set_tmp_attachments_directory
1940
1940
1941 # Delete all fixtured journals, a race condition can occur causing the wrong
1941 # Delete all fixtured journals, a race condition can occur causing the wrong
1942 # journal to get fetched in the next find.
1942 # journal to get fetched in the next find.
1943 Journal.delete_all
1943 Journal.delete_all
1944
1944
1945 # anonymous user
1945 # anonymous user
1946 assert_difference 'Attachment.count' do
1946 assert_difference 'Attachment.count' do
1947 put :update, :id => 1,
1947 put :update, :id => 1,
1948 :notes => '',
1948 :notes => '',
1949 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1949 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1950 end
1950 end
1951
1951
1952 assert_redirected_to :action => 'show', :id => '1'
1952 assert_redirected_to :action => 'show', :id => '1'
1953 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1953 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1954 assert j.notes.blank?
1954 assert j.notes.blank?
1955 assert_equal 1, j.details.size
1955 assert_equal 1, j.details.size
1956 assert_equal 'testfile.txt', j.details.first.value
1956 assert_equal 'testfile.txt', j.details.first.value
1957 assert_equal User.anonymous, j.user
1957 assert_equal User.anonymous, j.user
1958
1958
1959 attachment = Attachment.first(:order => 'id DESC')
1959 attachment = Attachment.first(:order => 'id DESC')
1960 assert_equal Issue.find(1), attachment.container
1960 assert_equal Issue.find(1), attachment.container
1961 assert_equal User.anonymous, attachment.author
1961 assert_equal User.anonymous, attachment.author
1962 assert_equal 'testfile.txt', attachment.filename
1962 assert_equal 'testfile.txt', attachment.filename
1963 assert_equal 'text/plain', attachment.content_type
1963 assert_equal 'text/plain', attachment.content_type
1964 assert_equal 'test file', attachment.description
1964 assert_equal 'test file', attachment.description
1965 assert_equal 59, attachment.filesize
1965 assert_equal 59, attachment.filesize
1966 assert File.exists?(attachment.diskfile)
1966 assert File.exists?(attachment.diskfile)
1967 assert_equal 59, File.size(attachment.diskfile)
1967 assert_equal 59, File.size(attachment.diskfile)
1968
1968
1969 mail = ActionMailer::Base.deliveries.last
1969 mail = ActionMailer::Base.deliveries.last
1970 assert mail.body.include?('testfile.txt')
1970 assert mail.body.include?('testfile.txt')
1971 end
1971 end
1972
1972
1973 def test_put_update_with_attachment_that_fails_to_save
1973 def test_put_update_with_attachment_that_fails_to_save
1974 set_tmp_attachments_directory
1974 set_tmp_attachments_directory
1975
1975
1976 # Delete all fixtured journals, a race condition can occur causing the wrong
1976 # Delete all fixtured journals, a race condition can occur causing the wrong
1977 # journal to get fetched in the next find.
1977 # journal to get fetched in the next find.
1978 Journal.delete_all
1978 Journal.delete_all
1979
1979
1980 # Mock out the unsaved attachment
1980 # Mock out the unsaved attachment
1981 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1981 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1982
1982
1983 # anonymous user
1983 # anonymous user
1984 put :update,
1984 put :update,
1985 :id => 1,
1985 :id => 1,
1986 :notes => '',
1986 :notes => '',
1987 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1987 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1988 assert_redirected_to :action => 'show', :id => '1'
1988 assert_redirected_to :action => 'show', :id => '1'
1989 assert_equal '1 file(s) could not be saved.', flash[:warning]
1989 assert_equal '1 file(s) could not be saved.', flash[:warning]
1990
1990
1991 end if Object.const_defined?(:Mocha)
1991 end if Object.const_defined?(:Mocha)
1992
1992
1993 def test_put_update_with_no_change
1993 def test_put_update_with_no_change
1994 issue = Issue.find(1)
1994 issue = Issue.find(1)
1995 issue.journals.clear
1995 issue.journals.clear
1996 ActionMailer::Base.deliveries.clear
1996 ActionMailer::Base.deliveries.clear
1997
1997
1998 put :update,
1998 put :update,
1999 :id => 1,
1999 :id => 1,
2000 :notes => ''
2000 :notes => ''
2001 assert_redirected_to :action => 'show', :id => '1'
2001 assert_redirected_to :action => 'show', :id => '1'
2002
2002
2003 issue.reload
2003 issue.reload
2004 assert issue.journals.empty?
2004 assert issue.journals.empty?
2005 # No email should be sent
2005 # No email should be sent
2006 assert ActionMailer::Base.deliveries.empty?
2006 assert ActionMailer::Base.deliveries.empty?
2007 end
2007 end
2008
2008
2009 def test_put_update_should_send_a_notification
2009 def test_put_update_should_send_a_notification
2010 @request.session[:user_id] = 2
2010 @request.session[:user_id] = 2
2011 ActionMailer::Base.deliveries.clear
2011 ActionMailer::Base.deliveries.clear
2012 issue = Issue.find(1)
2012 issue = Issue.find(1)
2013 old_subject = issue.subject
2013 old_subject = issue.subject
2014 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2014 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2015
2015
2016 put :update, :id => 1, :issue => {:subject => new_subject,
2016 put :update, :id => 1, :issue => {:subject => new_subject,
2017 :priority_id => '6',
2017 :priority_id => '6',
2018 :category_id => '1' # no change
2018 :category_id => '1' # no change
2019 }
2019 }
2020 assert_equal 1, ActionMailer::Base.deliveries.size
2020 assert_equal 1, ActionMailer::Base.deliveries.size
2021 end
2021 end
2022
2022
2023 def test_put_update_with_invalid_spent_time_hours_only
2023 def test_put_update_with_invalid_spent_time_hours_only
2024 @request.session[:user_id] = 2
2024 @request.session[:user_id] = 2
2025 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2025 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2026
2026
2027 assert_no_difference('Journal.count') do
2027 assert_no_difference('Journal.count') do
2028 put :update,
2028 put :update,
2029 :id => 1,
2029 :id => 1,
2030 :notes => notes,
2030 :notes => notes,
2031 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2031 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2032 end
2032 end
2033 assert_response :success
2033 assert_response :success
2034 assert_template 'edit'
2034 assert_template 'edit'
2035
2035
2036 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2036 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2037 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2037 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2038 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2038 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2039 end
2039 end
2040
2040
2041 def test_put_update_with_invalid_spent_time_comments_only
2041 def test_put_update_with_invalid_spent_time_comments_only
2042 @request.session[:user_id] = 2
2042 @request.session[:user_id] = 2
2043 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2043 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2044
2044
2045 assert_no_difference('Journal.count') do
2045 assert_no_difference('Journal.count') do
2046 put :update,
2046 put :update,
2047 :id => 1,
2047 :id => 1,
2048 :notes => notes,
2048 :notes => notes,
2049 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2049 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2050 end
2050 end
2051 assert_response :success
2051 assert_response :success
2052 assert_template 'edit'
2052 assert_template 'edit'
2053
2053
2054 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2054 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2055 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2055 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2056 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2056 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2057 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2057 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2058 end
2058 end
2059
2059
2060 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2060 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2061 issue = Issue.find(2)
2061 issue = Issue.find(2)
2062 @request.session[:user_id] = 2
2062 @request.session[:user_id] = 2
2063
2063
2064 put :update,
2064 put :update,
2065 :id => issue.id,
2065 :id => issue.id,
2066 :issue => {
2066 :issue => {
2067 :fixed_version_id => 4
2067 :fixed_version_id => 4
2068 }
2068 }
2069
2069
2070 assert_response :redirect
2070 assert_response :redirect
2071 issue.reload
2071 issue.reload
2072 assert_equal 4, issue.fixed_version_id
2072 assert_equal 4, issue.fixed_version_id
2073 assert_not_equal issue.project_id, issue.fixed_version.project_id
2073 assert_not_equal issue.project_id, issue.fixed_version.project_id
2074 end
2074 end
2075
2075
2076 def test_put_update_should_redirect_back_using_the_back_url_parameter
2076 def test_put_update_should_redirect_back_using_the_back_url_parameter
2077 issue = Issue.find(2)
2077 issue = Issue.find(2)
2078 @request.session[:user_id] = 2
2078 @request.session[:user_id] = 2
2079
2079
2080 put :update,
2080 put :update,
2081 :id => issue.id,
2081 :id => issue.id,
2082 :issue => {
2082 :issue => {
2083 :fixed_version_id => 4
2083 :fixed_version_id => 4
2084 },
2084 },
2085 :back_url => '/issues'
2085 :back_url => '/issues'
2086
2086
2087 assert_response :redirect
2087 assert_response :redirect
2088 assert_redirected_to '/issues'
2088 assert_redirected_to '/issues'
2089 end
2089 end
2090
2090
2091 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2091 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2092 issue = Issue.find(2)
2092 issue = Issue.find(2)
2093 @request.session[:user_id] = 2
2093 @request.session[:user_id] = 2
2094
2094
2095 put :update,
2095 put :update,
2096 :id => issue.id,
2096 :id => issue.id,
2097 :issue => {
2097 :issue => {
2098 :fixed_version_id => 4
2098 :fixed_version_id => 4
2099 },
2099 },
2100 :back_url => 'http://google.com'
2100 :back_url => 'http://google.com'
2101
2101
2102 assert_response :redirect
2102 assert_response :redirect
2103 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2103 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2104 end
2104 end
2105
2105
2106 def test_get_bulk_edit
2106 def test_get_bulk_edit
2107 @request.session[:user_id] = 2
2107 @request.session[:user_id] = 2
2108 get :bulk_edit, :ids => [1, 2]
2108 get :bulk_edit, :ids => [1, 2]
2109 assert_response :success
2109 assert_response :success
2110 assert_template 'bulk_edit'
2110 assert_template 'bulk_edit'
2111
2111
2112 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2112 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2113 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2113 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2114
2114
2115 # Project specific custom field, date type
2115 # Project specific custom field, date type
2116 field = CustomField.find(9)
2116 field = CustomField.find(9)
2117 assert !field.is_for_all?
2117 assert !field.is_for_all?
2118 assert_equal 'date', field.field_format
2118 assert_equal 'date', field.field_format
2119 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2119 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2120
2120
2121 # System wide custom field
2121 # System wide custom field
2122 assert CustomField.find(1).is_for_all?
2122 assert CustomField.find(1).is_for_all?
2123 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2123 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2124
2124
2125 # Be sure we don't display inactive IssuePriorities
2125 # Be sure we don't display inactive IssuePriorities
2126 assert ! IssuePriority.find(15).active?
2126 assert ! IssuePriority.find(15).active?
2127 assert_no_tag :option, :attributes => {:value => '15'},
2127 assert_no_tag :option, :attributes => {:value => '15'},
2128 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2128 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2129 end
2129 end
2130
2130
2131 def test_get_bulk_edit_on_different_projects
2131 def test_get_bulk_edit_on_different_projects
2132 @request.session[:user_id] = 2
2132 @request.session[:user_id] = 2
2133 get :bulk_edit, :ids => [1, 2, 6]
2133 get :bulk_edit, :ids => [1, 2, 6]
2134 assert_response :success
2134 assert_response :success
2135 assert_template 'bulk_edit'
2135 assert_template 'bulk_edit'
2136
2136
2137 # Can not set issues from different projects as children of an issue
2137 # Can not set issues from different projects as children of an issue
2138 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2138 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2139
2139
2140 # Project specific custom field, date type
2140 # Project specific custom field, date type
2141 field = CustomField.find(9)
2141 field = CustomField.find(9)
2142 assert !field.is_for_all?
2142 assert !field.is_for_all?
2143 assert !field.project_ids.include?(Issue.find(6).project_id)
2143 assert !field.project_ids.include?(Issue.find(6).project_id)
2144 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2144 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2145 end
2145 end
2146
2146
2147 def test_get_bulk_edit_with_user_custom_field
2147 def test_get_bulk_edit_with_user_custom_field
2148 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2148 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2149
2149
2150 @request.session[:user_id] = 2
2150 @request.session[:user_id] = 2
2151 get :bulk_edit, :ids => [1, 2]
2151 get :bulk_edit, :ids => [1, 2]
2152 assert_response :success
2152 assert_response :success
2153 assert_template 'bulk_edit'
2153 assert_template 'bulk_edit'
2154
2154
2155 assert_tag :select,
2155 assert_tag :select,
2156 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2156 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2157 :children => {
2157 :children => {
2158 :only => {:tag => 'option'},
2158 :only => {:tag => 'option'},
2159 :count => Project.find(1).users.count + 1
2159 :count => Project.find(1).users.count + 1
2160 }
2160 }
2161 end
2161 end
2162
2162
2163 def test_get_bulk_edit_with_version_custom_field
2163 def test_get_bulk_edit_with_version_custom_field
2164 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2164 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2165
2165
2166 @request.session[:user_id] = 2
2166 @request.session[:user_id] = 2
2167 get :bulk_edit, :ids => [1, 2]
2167 get :bulk_edit, :ids => [1, 2]
2168 assert_response :success
2168 assert_response :success
2169 assert_template 'bulk_edit'
2169 assert_template 'bulk_edit'
2170
2170
2171 assert_tag :select,
2171 assert_tag :select,
2172 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2172 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2173 :children => {
2173 :children => {
2174 :only => {:tag => 'option'},
2174 :only => {:tag => 'option'},
2175 :count => Project.find(1).shared_versions.count + 1
2175 :count => Project.find(1).shared_versions.count + 1
2176 }
2176 }
2177 end
2177 end
2178
2178
2179 def test_bulk_update
2179 def test_bulk_update
2180 @request.session[:user_id] = 2
2180 @request.session[:user_id] = 2
2181 # update issues priority
2181 # update issues priority
2182 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2182 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2183 :issue => {:priority_id => 7,
2183 :issue => {:priority_id => 7,
2184 :assigned_to_id => '',
2184 :assigned_to_id => '',
2185 :custom_field_values => {'2' => ''}}
2185 :custom_field_values => {'2' => ''}}
2186
2186
2187 assert_response 302
2187 assert_response 302
2188 # check that the issues were updated
2188 # check that the issues were updated
2189 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2189 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2190
2190
2191 issue = Issue.find(1)
2191 issue = Issue.find(1)
2192 journal = issue.journals.find(:first, :order => 'created_on DESC')
2192 journal = issue.journals.find(:first, :order => 'created_on DESC')
2193 assert_equal '125', issue.custom_value_for(2).value
2193 assert_equal '125', issue.custom_value_for(2).value
2194 assert_equal 'Bulk editing', journal.notes
2194 assert_equal 'Bulk editing', journal.notes
2195 assert_equal 1, journal.details.size
2195 assert_equal 1, journal.details.size
2196 end
2196 end
2197
2197
2198 def test_bulk_update_with_group_assignee
2198 def test_bulk_update_with_group_assignee
2199 group = Group.find(11)
2199 group = Group.find(11)
2200 project = Project.find(1)
2200 project = Project.find(1)
2201 project.members << Member.new(:principal => group, :roles => [Role.first])
2201 project.members << Member.new(:principal => group, :roles => [Role.first])
2202
2202
2203 @request.session[:user_id] = 2
2203 @request.session[:user_id] = 2
2204 # update issues assignee
2204 # update issues assignee
2205 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2205 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2206 :issue => {:priority_id => '',
2206 :issue => {:priority_id => '',
2207 :assigned_to_id => group.id,
2207 :assigned_to_id => group.id,
2208 :custom_field_values => {'2' => ''}}
2208 :custom_field_values => {'2' => ''}}
2209
2209
2210 assert_response 302
2210 assert_response 302
2211 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2211 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2212 end
2212 end
2213
2213
2214 def test_bulk_update_on_different_projects
2214 def test_bulk_update_on_different_projects
2215 @request.session[:user_id] = 2
2215 @request.session[:user_id] = 2
2216 # update issues priority
2216 # update issues priority
2217 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2217 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2218 :issue => {:priority_id => 7,
2218 :issue => {:priority_id => 7,
2219 :assigned_to_id => '',
2219 :assigned_to_id => '',
2220 :custom_field_values => {'2' => ''}}
2220 :custom_field_values => {'2' => ''}}
2221
2221
2222 assert_response 302
2222 assert_response 302
2223 # check that the issues were updated
2223 # check that the issues were updated
2224 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2224 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2225
2225
2226 issue = Issue.find(1)
2226 issue = Issue.find(1)
2227 journal = issue.journals.find(:first, :order => 'created_on DESC')
2227 journal = issue.journals.find(:first, :order => 'created_on DESC')
2228 assert_equal '125', issue.custom_value_for(2).value
2228 assert_equal '125', issue.custom_value_for(2).value
2229 assert_equal 'Bulk editing', journal.notes
2229 assert_equal 'Bulk editing', journal.notes
2230 assert_equal 1, journal.details.size
2230 assert_equal 1, journal.details.size
2231 end
2231 end
2232
2232
2233 def test_bulk_update_on_different_projects_without_rights
2233 def test_bulk_update_on_different_projects_without_rights
2234 @request.session[:user_id] = 3
2234 @request.session[:user_id] = 3
2235 user = User.find(3)
2235 user = User.find(3)
2236 action = { :controller => "issues", :action => "bulk_update" }
2236 action = { :controller => "issues", :action => "bulk_update" }
2237 assert user.allowed_to?(action, Issue.find(1).project)
2237 assert user.allowed_to?(action, Issue.find(1).project)
2238 assert ! user.allowed_to?(action, Issue.find(6).project)
2238 assert ! user.allowed_to?(action, Issue.find(6).project)
2239 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2239 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2240 :issue => {:priority_id => 7,
2240 :issue => {:priority_id => 7,
2241 :assigned_to_id => '',
2241 :assigned_to_id => '',
2242 :custom_field_values => {'2' => ''}}
2242 :custom_field_values => {'2' => ''}}
2243 assert_response 403
2243 assert_response 403
2244 assert_not_equal "Bulk should fail", Journal.last.notes
2244 assert_not_equal "Bulk should fail", Journal.last.notes
2245 end
2245 end
2246
2246
2247 def test_bullk_update_should_send_a_notification
2247 def test_bullk_update_should_send_a_notification
2248 @request.session[:user_id] = 2
2248 @request.session[:user_id] = 2
2249 ActionMailer::Base.deliveries.clear
2249 ActionMailer::Base.deliveries.clear
2250 post(:bulk_update,
2250 post(:bulk_update,
2251 {
2251 {
2252 :ids => [1, 2],
2252 :ids => [1, 2],
2253 :notes => 'Bulk editing',
2253 :notes => 'Bulk editing',
2254 :issue => {
2254 :issue => {
2255 :priority_id => 7,
2255 :priority_id => 7,
2256 :assigned_to_id => '',
2256 :assigned_to_id => '',
2257 :custom_field_values => {'2' => ''}
2257 :custom_field_values => {'2' => ''}
2258 }
2258 }
2259 })
2259 })
2260
2260
2261 assert_response 302
2261 assert_response 302
2262 assert_equal 2, ActionMailer::Base.deliveries.size
2262 assert_equal 2, ActionMailer::Base.deliveries.size
2263 end
2263 end
2264
2264
2265 def test_bulk_update_project
2265 def test_bulk_update_project
2266 @request.session[:user_id] = 2
2266 @request.session[:user_id] = 2
2267 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2267 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2268 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2268 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2269 # Issues moved to project 2
2269 # Issues moved to project 2
2270 assert_equal 2, Issue.find(1).project_id
2270 assert_equal 2, Issue.find(1).project_id
2271 assert_equal 2, Issue.find(2).project_id
2271 assert_equal 2, Issue.find(2).project_id
2272 # No tracker change
2272 # No tracker change
2273 assert_equal 1, Issue.find(1).tracker_id
2273 assert_equal 1, Issue.find(1).tracker_id
2274 assert_equal 2, Issue.find(2).tracker_id
2274 assert_equal 2, Issue.find(2).tracker_id
2275 end
2275 end
2276
2276
2277 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2277 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2278 @request.session[:user_id] = 2
2278 @request.session[:user_id] = 2
2279 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2279 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2280 assert_redirected_to '/issues/1'
2280 assert_redirected_to '/issues/1'
2281 end
2281 end
2282
2282
2283 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2283 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2284 @request.session[:user_id] = 2
2284 @request.session[:user_id] = 2
2285 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2285 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2286 assert_redirected_to '/projects/onlinestore/issues'
2286 assert_redirected_to '/projects/onlinestore/issues'
2287 end
2287 end
2288
2288
2289 def test_bulk_update_tracker
2289 def test_bulk_update_tracker
2290 @request.session[:user_id] = 2
2290 @request.session[:user_id] = 2
2291 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2291 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2292 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2292 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2293 assert_equal 2, Issue.find(1).tracker_id
2293 assert_equal 2, Issue.find(1).tracker_id
2294 assert_equal 2, Issue.find(2).tracker_id
2294 assert_equal 2, Issue.find(2).tracker_id
2295 end
2295 end
2296
2296
2297 def test_bulk_update_status
2297 def test_bulk_update_status
2298 @request.session[:user_id] = 2
2298 @request.session[:user_id] = 2
2299 # update issues priority
2299 # update issues priority
2300 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2300 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2301 :issue => {:priority_id => '',
2301 :issue => {:priority_id => '',
2302 :assigned_to_id => '',
2302 :assigned_to_id => '',
2303 :status_id => '5'}
2303 :status_id => '5'}
2304
2304
2305 assert_response 302
2305 assert_response 302
2306 issue = Issue.find(1)
2306 issue = Issue.find(1)
2307 assert issue.closed?
2307 assert issue.closed?
2308 end
2308 end
2309
2309
2310 def test_bulk_update_priority
2310 def test_bulk_update_priority
2311 @request.session[:user_id] = 2
2311 @request.session[:user_id] = 2
2312 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2312 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2313
2313
2314 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2314 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2315 assert_equal 6, Issue.find(1).priority_id
2315 assert_equal 6, Issue.find(1).priority_id
2316 assert_equal 6, Issue.find(2).priority_id
2316 assert_equal 6, Issue.find(2).priority_id
2317 end
2317 end
2318
2318
2319 def test_bulk_update_with_notes
2319 def test_bulk_update_with_notes
2320 @request.session[:user_id] = 2
2320 @request.session[:user_id] = 2
2321 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2321 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2322
2322
2323 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2323 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2324 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2324 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2325 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2325 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2326 end
2326 end
2327
2327
2328 def test_bulk_update_parent_id
2328 def test_bulk_update_parent_id
2329 @request.session[:user_id] = 2
2329 @request.session[:user_id] = 2
2330 post :bulk_update, :ids => [1, 3],
2330 post :bulk_update, :ids => [1, 3],
2331 :notes => 'Bulk editing parent',
2331 :notes => 'Bulk editing parent',
2332 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2332 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2333
2333
2334 assert_response 302
2334 assert_response 302
2335 parent = Issue.find(2)
2335 parent = Issue.find(2)
2336 assert_equal parent.id, Issue.find(1).parent_id
2336 assert_equal parent.id, Issue.find(1).parent_id
2337 assert_equal parent.id, Issue.find(3).parent_id
2337 assert_equal parent.id, Issue.find(3).parent_id
2338 assert_equal [1, 3], parent.children.collect(&:id).sort
2338 assert_equal [1, 3], parent.children.collect(&:id).sort
2339 end
2339 end
2340
2340
2341 def test_bulk_update_custom_field
2341 def test_bulk_update_custom_field
2342 @request.session[:user_id] = 2
2342 @request.session[:user_id] = 2
2343 # update issues priority
2343 # update issues priority
2344 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2344 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2345 :issue => {:priority_id => '',
2345 :issue => {:priority_id => '',
2346 :assigned_to_id => '',
2346 :assigned_to_id => '',
2347 :custom_field_values => {'2' => '777'}}
2347 :custom_field_values => {'2' => '777'}}
2348
2348
2349 assert_response 302
2349 assert_response 302
2350
2350
2351 issue = Issue.find(1)
2351 issue = Issue.find(1)
2352 journal = issue.journals.find(:first, :order => 'created_on DESC')
2352 journal = issue.journals.find(:first, :order => 'created_on DESC')
2353 assert_equal '777', issue.custom_value_for(2).value
2353 assert_equal '777', issue.custom_value_for(2).value
2354 assert_equal 1, journal.details.size
2354 assert_equal 1, journal.details.size
2355 assert_equal '125', journal.details.first.old_value
2355 assert_equal '125', journal.details.first.old_value
2356 assert_equal '777', journal.details.first.value
2356 assert_equal '777', journal.details.first.value
2357 end
2357 end
2358
2358
2359 def test_bulk_update_unassign
2359 def test_bulk_update_unassign
2360 assert_not_nil Issue.find(2).assigned_to
2360 assert_not_nil Issue.find(2).assigned_to
2361 @request.session[:user_id] = 2
2361 @request.session[:user_id] = 2
2362 # unassign issues
2362 # unassign issues
2363 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2363 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2364 assert_response 302
2364 assert_response 302
2365 # check that the issues were updated
2365 # check that the issues were updated
2366 assert_nil Issue.find(2).assigned_to
2366 assert_nil Issue.find(2).assigned_to
2367 end
2367 end
2368
2368
2369 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2369 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2370 @request.session[:user_id] = 2
2370 @request.session[:user_id] = 2
2371
2371
2372 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2372 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2373
2373
2374 assert_response :redirect
2374 assert_response :redirect
2375 issues = Issue.find([1,2])
2375 issues = Issue.find([1,2])
2376 issues.each do |issue|
2376 issues.each do |issue|
2377 assert_equal 4, issue.fixed_version_id
2377 assert_equal 4, issue.fixed_version_id
2378 assert_not_equal issue.project_id, issue.fixed_version.project_id
2378 assert_not_equal issue.project_id, issue.fixed_version.project_id
2379 end
2379 end
2380 end
2380 end
2381
2381
2382 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2382 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2383 @request.session[:user_id] = 2
2383 @request.session[:user_id] = 2
2384 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2384 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2385
2385
2386 assert_response :redirect
2386 assert_response :redirect
2387 assert_redirected_to '/issues'
2387 assert_redirected_to '/issues'
2388 end
2388 end
2389
2389
2390 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2390 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2391 @request.session[:user_id] = 2
2391 @request.session[:user_id] = 2
2392 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2392 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2393
2393
2394 assert_response :redirect
2394 assert_response :redirect
2395 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2395 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2396 end
2396 end
2397
2397
2398 def test_bulk_copy_to_another_project
2398 def test_bulk_copy_to_another_project
2399 @request.session[:user_id] = 2
2399 @request.session[:user_id] = 2
2400 assert_difference 'Issue.count', 2 do
2400 assert_difference 'Issue.count', 2 do
2401 assert_no_difference 'Project.find(1).issues.count' do
2401 assert_no_difference 'Project.find(1).issues.count' do
2402 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2402 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2403 end
2403 end
2404 end
2404 end
2405 assert_redirected_to '/projects/ecookbook/issues'
2405 assert_redirected_to '/projects/ecookbook/issues'
2406 end
2406 end
2407
2407
2408 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2408 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2409 @request.session[:user_id] = 2
2409 @request.session[:user_id] = 2
2410 issue_before_move = Issue.find(1)
2410 issue_before_move = Issue.find(1)
2411 assert_difference 'Issue.count', 1 do
2411 assert_difference 'Issue.count', 1 do
2412 assert_no_difference 'Project.find(1).issues.count' do
2412 assert_no_difference 'Project.find(1).issues.count' do
2413 post :bulk_update, :ids => [1], :copy => '1',
2413 post :bulk_update, :ids => [1], :copy => '1',
2414 :issue => {
2414 :issue => {
2415 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2415 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2416 :status_id => '', :start_date => '', :due_date => ''
2416 :status_id => '', :start_date => '', :due_date => ''
2417 }
2417 }
2418 end
2418 end
2419 end
2419 end
2420 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2420 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2421 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2421 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2422 assert_equal issue_before_move.status_id, issue_after_move.status_id
2422 assert_equal issue_before_move.status_id, issue_after_move.status_id
2423 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2423 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2424 end
2424 end
2425
2425
2426 def test_bulk_copy_should_allow_changing_the_issue_attributes
2426 def test_bulk_copy_should_allow_changing_the_issue_attributes
2427 # Fixes random test failure with Mysql
2427 # Fixes random test failure with Mysql
2428 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2428 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2429 # doesn't return the expected results
2429 # doesn't return the expected results
2430 Issue.delete_all("project_id=2")
2430 Issue.delete_all("project_id=2")
2431
2431
2432 @request.session[:user_id] = 2
2432 @request.session[:user_id] = 2
2433 assert_difference 'Issue.count', 2 do
2433 assert_difference 'Issue.count', 2 do
2434 assert_no_difference 'Project.find(1).issues.count' do
2434 assert_no_difference 'Project.find(1).issues.count' do
2435 post :bulk_update, :ids => [1, 2], :copy => '1',
2435 post :bulk_update, :ids => [1, 2], :copy => '1',
2436 :issue => {
2436 :issue => {
2437 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2437 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2438 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2438 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2439 }
2439 }
2440 end
2440 end
2441 end
2441 end
2442
2442
2443 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2443 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2444 assert_equal 2, copied_issues.size
2444 assert_equal 2, copied_issues.size
2445 copied_issues.each do |issue|
2445 copied_issues.each do |issue|
2446 assert_equal 2, issue.project_id, "Project is incorrect"
2446 assert_equal 2, issue.project_id, "Project is incorrect"
2447 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2447 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2448 assert_equal 3, issue.status_id, "Status is incorrect"
2448 assert_equal 3, issue.status_id, "Status is incorrect"
2449 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2449 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2450 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2450 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2451 end
2451 end
2452 end
2452 end
2453
2453
2454 def test_bulk_copy_should_allow_adding_a_note
2454 def test_bulk_copy_should_allow_adding_a_note
2455 @request.session[:user_id] = 2
2455 @request.session[:user_id] = 2
2456 assert_difference 'Issue.count', 1 do
2456 assert_difference 'Issue.count', 1 do
2457 post :bulk_update, :ids => [1], :copy => '1',
2457 post :bulk_update, :ids => [1], :copy => '1',
2458 :notes => 'Copying one issue',
2458 :notes => 'Copying one issue',
2459 :issue => {
2459 :issue => {
2460 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2460 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2461 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2461 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2462 }
2462 }
2463 end
2463 end
2464
2464
2465 issue = Issue.first(:order => 'id DESC')
2465 issue = Issue.first(:order => 'id DESC')
2466 assert_equal 1, issue.journals.size
2466 assert_equal 1, issue.journals.size
2467 journal = issue.journals.first
2467 journal = issue.journals.first
2468 assert_equal 0, journal.details.size
2468 assert_equal 0, journal.details.size
2469 assert_equal 'Copying one issue', journal.notes
2469 assert_equal 'Copying one issue', journal.notes
2470 end
2470 end
2471
2471
2472 def test_bulk_copy_to_another_project_should_follow_when_needed
2472 def test_bulk_copy_to_another_project_should_follow_when_needed
2473 @request.session[:user_id] = 2
2473 @request.session[:user_id] = 2
2474 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
2474 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
2475 issue = Issue.first(:order => 'id DESC')
2475 issue = Issue.first(:order => 'id DESC')
2476 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2476 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2477 end
2477 end
2478
2478
2479 def test_destroy_issue_with_no_time_entries
2479 def test_destroy_issue_with_no_time_entries
2480 assert_nil TimeEntry.find_by_issue_id(2)
2480 assert_nil TimeEntry.find_by_issue_id(2)
2481 @request.session[:user_id] = 2
2481 @request.session[:user_id] = 2
2482 delete :destroy, :id => 2
2482 delete :destroy, :id => 2
2483 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2483 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2484 assert_nil Issue.find_by_id(2)
2484 assert_nil Issue.find_by_id(2)
2485 end
2485 end
2486
2486
2487 def test_destroy_issues_with_time_entries
2487 def test_destroy_issues_with_time_entries
2488 @request.session[:user_id] = 2
2488 @request.session[:user_id] = 2
2489 delete :destroy, :ids => [1, 3]
2489 delete :destroy, :ids => [1, 3]
2490 assert_response :success
2490 assert_response :success
2491 assert_template 'destroy'
2491 assert_template 'destroy'
2492 assert_not_nil assigns(:hours)
2492 assert_not_nil assigns(:hours)
2493 assert Issue.find_by_id(1) && Issue.find_by_id(3)
2493 assert Issue.find_by_id(1) && Issue.find_by_id(3)
2494 assert_tag 'form',
2495 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
2494 end
2496 end
2495
2497
2496 def test_destroy_issues_and_destroy_time_entries
2498 def test_destroy_issues_and_destroy_time_entries
2497 @request.session[:user_id] = 2
2499 @request.session[:user_id] = 2
2498 delete :destroy, :ids => [1, 3], :todo => 'destroy'
2500 delete :destroy, :ids => [1, 3], :todo => 'destroy'
2499 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2501 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2500 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2502 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2501 assert_nil TimeEntry.find_by_id([1, 2])
2503 assert_nil TimeEntry.find_by_id([1, 2])
2502 end
2504 end
2503
2505
2504 def test_destroy_issues_and_assign_time_entries_to_project
2506 def test_destroy_issues_and_assign_time_entries_to_project
2505 @request.session[:user_id] = 2
2507 @request.session[:user_id] = 2
2506 delete :destroy, :ids => [1, 3], :todo => 'nullify'
2508 delete :destroy, :ids => [1, 3], :todo => 'nullify'
2507 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2509 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2508 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2510 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2509 assert_nil TimeEntry.find(1).issue_id
2511 assert_nil TimeEntry.find(1).issue_id
2510 assert_nil TimeEntry.find(2).issue_id
2512 assert_nil TimeEntry.find(2).issue_id
2511 end
2513 end
2512
2514
2513 def test_destroy_issues_and_reassign_time_entries_to_another_issue
2515 def test_destroy_issues_and_reassign_time_entries_to_another_issue
2514 @request.session[:user_id] = 2
2516 @request.session[:user_id] = 2
2515 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
2517 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
2516 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2518 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2517 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2519 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2518 assert_equal 2, TimeEntry.find(1).issue_id
2520 assert_equal 2, TimeEntry.find(1).issue_id
2519 assert_equal 2, TimeEntry.find(2).issue_id
2521 assert_equal 2, TimeEntry.find(2).issue_id
2520 end
2522 end
2521
2523
2522 def test_destroy_issues_from_different_projects
2524 def test_destroy_issues_from_different_projects
2523 @request.session[:user_id] = 2
2525 @request.session[:user_id] = 2
2524 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
2526 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
2525 assert_redirected_to :controller => 'issues', :action => 'index'
2527 assert_redirected_to :controller => 'issues', :action => 'index'
2526 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
2528 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
2527 end
2529 end
2528
2530
2529 def test_destroy_parent_and_child_issues
2531 def test_destroy_parent_and_child_issues
2530 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
2532 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
2531 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
2533 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
2532 assert child.is_descendant_of?(parent.reload)
2534 assert child.is_descendant_of?(parent.reload)
2533
2535
2534 @request.session[:user_id] = 2
2536 @request.session[:user_id] = 2
2535 assert_difference 'Issue.count', -2 do
2537 assert_difference 'Issue.count', -2 do
2536 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
2538 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
2537 end
2539 end
2538 assert_response 302
2540 assert_response 302
2539 end
2541 end
2540
2542
2541 def test_default_search_scope
2543 def test_default_search_scope
2542 get :index
2544 get :index
2543 assert_tag :div, :attributes => {:id => 'quick-search'},
2545 assert_tag :div, :attributes => {:id => 'quick-search'},
2544 :child => {:tag => 'form',
2546 :child => {:tag => 'form',
2545 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
2547 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
2546 end
2548 end
2547 end
2549 end
General Comments 0
You need to be logged in to leave comments. Login now