##// END OF EJS Templates
Fixed that grouping issue by key/value custom field does not work (#22178)....
Jean-Philippe Lang -
r14842:e0ae0f287a5f
parent child
Show More
@@ -1,74 +1,80
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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 class CustomFieldEnumeration < ActiveRecord::Base
18 class CustomFieldEnumeration < ActiveRecord::Base
19 belongs_to :custom_field
19 belongs_to :custom_field
20 attr_accessible :name, :active, :position
20 attr_accessible :name, :active, :position
21
21
22 validates_presence_of :name, :position, :custom_field_id
22 validates_presence_of :name, :position, :custom_field_id
23 validates_length_of :name, :maximum => 60
23 validates_length_of :name, :maximum => 60
24 validates_numericality_of :position, :only_integer => true
24 validates_numericality_of :position, :only_integer => true
25 before_create :set_position
25 before_create :set_position
26
26
27 scope :active, lambda { where(:active => true) }
27 scope :active, lambda { where(:active => true) }
28
28
29 def to_s
29 def to_s
30 name.to_s
30 name.to_s
31 end
31 end
32
32
33 def objects_count
33 def objects_count
34 custom_values.count
34 custom_values.count
35 end
35 end
36
36
37 def in_use?
37 def in_use?
38 objects_count > 0
38 objects_count > 0
39 end
39 end
40
40
41 alias :destroy_without_reassign :destroy
41 alias :destroy_without_reassign :destroy
42 def destroy(reassign_to=nil)
42 def destroy(reassign_to=nil)
43 if reassign_to
43 if reassign_to
44 custom_values.update_all(:value => reassign_to.id.to_s)
44 custom_values.update_all(:value => reassign_to.id.to_s)
45 end
45 end
46 destroy_without_reassign
46 destroy_without_reassign
47 end
47 end
48
48
49 def custom_values
49 def custom_values
50 custom_field.custom_values.where(:value => id.to_s)
50 custom_field.custom_values.where(:value => id.to_s)
51 end
51 end
52
52
53 def self.update_each(custom_field, attributes)
53 def self.update_each(custom_field, attributes)
54 return unless attributes.is_a?(Hash)
54 return unless attributes.is_a?(Hash)
55 transaction do
55 transaction do
56 attributes.each do |enumeration_id, enumeration_attributes|
56 attributes.each do |enumeration_id, enumeration_attributes|
57 enumeration = custom_field.enumerations.find_by_id(enumeration_id)
57 enumeration = custom_field.enumerations.find_by_id(enumeration_id)
58 if enumeration
58 if enumeration
59 enumeration.attributes = enumeration_attributes
59 enumeration.attributes = enumeration_attributes
60 unless enumeration.save
60 unless enumeration.save
61 raise ActiveRecord::Rollback
61 raise ActiveRecord::Rollback
62 end
62 end
63 end
63 end
64 end
64 end
65 end
65 end
66 end
66 end
67
67
68 def self.fields_for_order_statement(table=nil)
69 table ||= table_name
70 columns = ['position']
71 columns.uniq.map {|field| "#{table}.#{field}"}
72 end
73
68 private
74 private
69
75
70 def set_position
76 def set_position
71 max = self.class.where(:custom_field_id => custom_field_id).maximum(:position) || 0
77 max = self.class.where(:custom_field_id => custom_field_id).maximum(:position) || 0
72 self.position = max + 1
78 self.position = max + 1
73 end
79 end
74 end
80 end
@@ -1,4494 +1,4520
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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
19
20 class IssuesControllerTest < ActionController::TestCase
20 class IssuesControllerTest < ActionController::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :users, :email_addresses,
22 :users, :email_addresses,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :issue_relations,
28 :issue_relations,
29 :versions,
29 :versions,
30 :trackers,
30 :trackers,
31 :projects_trackers,
31 :projects_trackers,
32 :issue_categories,
32 :issue_categories,
33 :enabled_modules,
33 :enabled_modules,
34 :enumerations,
34 :enumerations,
35 :attachments,
35 :attachments,
36 :workflows,
36 :workflows,
37 :custom_fields,
37 :custom_fields,
38 :custom_values,
38 :custom_values,
39 :custom_fields_projects,
39 :custom_fields_projects,
40 :custom_fields_trackers,
40 :custom_fields_trackers,
41 :time_entries,
41 :time_entries,
42 :journals,
42 :journals,
43 :journal_details,
43 :journal_details,
44 :queries,
44 :queries,
45 :repositories,
45 :repositories,
46 :changesets
46 :changesets
47
47
48 include Redmine::I18n
48 include Redmine::I18n
49
49
50 def setup
50 def setup
51 User.current = nil
51 User.current = nil
52 end
52 end
53
53
54 def test_index
54 def test_index
55 with_settings :default_language => "en" do
55 with_settings :default_language => "en" do
56 get :index
56 get :index
57 assert_response :success
57 assert_response :success
58 assert_template 'index'
58 assert_template 'index'
59 assert_not_nil assigns(:issues)
59 assert_not_nil assigns(:issues)
60 assert_nil assigns(:project)
60 assert_nil assigns(:project)
61
61
62 # links to visible issues
62 # links to visible issues
63 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
63 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
64 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
64 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
65 # private projects hidden
65 # private projects hidden
66 assert_select 'a[href="/issues/6"]', 0
66 assert_select 'a[href="/issues/6"]', 0
67 assert_select 'a[href="/issues/4"]', 0
67 assert_select 'a[href="/issues/4"]', 0
68 # project column
68 # project column
69 assert_select 'th', :text => /Project/
69 assert_select 'th', :text => /Project/
70 end
70 end
71 end
71 end
72
72
73 def test_index_should_not_list_issues_when_module_disabled
73 def test_index_should_not_list_issues_when_module_disabled
74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 get :index
75 get :index
76 assert_response :success
76 assert_response :success
77 assert_template 'index'
77 assert_template 'index'
78 assert_not_nil assigns(:issues)
78 assert_not_nil assigns(:issues)
79 assert_nil assigns(:project)
79 assert_nil assigns(:project)
80
80
81 assert_select 'a[href="/issues/1"]', 0
81 assert_select 'a[href="/issues/1"]', 0
82 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
82 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
83 end
83 end
84
84
85 def test_index_should_list_visible_issues_only
85 def test_index_should_list_visible_issues_only
86 get :index, :per_page => 100
86 get :index, :per_page => 100
87 assert_response :success
87 assert_response :success
88 assert_not_nil assigns(:issues)
88 assert_not_nil assigns(:issues)
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
90 end
90 end
91
91
92 def test_index_with_project
92 def test_index_with_project
93 Setting.display_subprojects_issues = 0
93 Setting.display_subprojects_issues = 0
94 get :index, :project_id => 1
94 get :index, :project_id => 1
95 assert_response :success
95 assert_response :success
96 assert_template 'index'
96 assert_template 'index'
97 assert_not_nil assigns(:issues)
97 assert_not_nil assigns(:issues)
98
98
99 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
99 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
100 assert_select 'a[href="/issues/5"]', 0
100 assert_select 'a[href="/issues/5"]', 0
101 end
101 end
102
102
103 def test_index_with_project_and_subprojects
103 def test_index_with_project_and_subprojects
104 Setting.display_subprojects_issues = 1
104 Setting.display_subprojects_issues = 1
105 get :index, :project_id => 1
105 get :index, :project_id => 1
106 assert_response :success
106 assert_response :success
107 assert_template 'index'
107 assert_template 'index'
108 assert_not_nil assigns(:issues)
108 assert_not_nil assigns(:issues)
109
109
110 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
110 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
111 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
111 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
112 assert_select 'a[href="/issues/6"]', 0
112 assert_select 'a[href="/issues/6"]', 0
113 end
113 end
114
114
115 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
115 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
116 @request.session[:user_id] = 2
116 @request.session[:user_id] = 2
117 Setting.display_subprojects_issues = 1
117 Setting.display_subprojects_issues = 1
118 get :index, :project_id => 1
118 get :index, :project_id => 1
119 assert_response :success
119 assert_response :success
120 assert_template 'index'
120 assert_template 'index'
121 assert_not_nil assigns(:issues)
121 assert_not_nil assigns(:issues)
122
122
123 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
123 assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
124 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
124 assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
125 assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
125 assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
126 end
126 end
127
127
128 def test_index_with_project_and_default_filter
128 def test_index_with_project_and_default_filter
129 get :index, :project_id => 1, :set_filter => 1
129 get :index, :project_id => 1, :set_filter => 1
130 assert_response :success
130 assert_response :success
131 assert_template 'index'
131 assert_template 'index'
132 assert_not_nil assigns(:issues)
132 assert_not_nil assigns(:issues)
133
133
134 query = assigns(:query)
134 query = assigns(:query)
135 assert_not_nil query
135 assert_not_nil query
136 # default filter
136 # default filter
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
138 end
138 end
139
139
140 def test_index_with_project_and_filter
140 def test_index_with_project_and_filter
141 get :index, :project_id => 1, :set_filter => 1,
141 get :index, :project_id => 1, :set_filter => 1,
142 :f => ['tracker_id'],
142 :f => ['tracker_id'],
143 :op => {'tracker_id' => '='},
143 :op => {'tracker_id' => '='},
144 :v => {'tracker_id' => ['1']}
144 :v => {'tracker_id' => ['1']}
145 assert_response :success
145 assert_response :success
146 assert_template 'index'
146 assert_template 'index'
147 assert_not_nil assigns(:issues)
147 assert_not_nil assigns(:issues)
148
148
149 query = assigns(:query)
149 query = assigns(:query)
150 assert_not_nil query
150 assert_not_nil query
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
152 end
152 end
153
153
154 def test_index_with_short_filters
154 def test_index_with_short_filters
155 to_test = {
155 to_test = {
156 'status_id' => {
156 'status_id' => {
157 'o' => { :op => 'o', :values => [''] },
157 'o' => { :op => 'o', :values => [''] },
158 'c' => { :op => 'c', :values => [''] },
158 'c' => { :op => 'c', :values => [''] },
159 '7' => { :op => '=', :values => ['7'] },
159 '7' => { :op => '=', :values => ['7'] },
160 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
160 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
161 '=7' => { :op => '=', :values => ['7'] },
161 '=7' => { :op => '=', :values => ['7'] },
162 '!3' => { :op => '!', :values => ['3'] },
162 '!3' => { :op => '!', :values => ['3'] },
163 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
163 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
164 'subject' => {
164 'subject' => {
165 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
165 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
166 'o' => { :op => '=', :values => ['o'] },
166 'o' => { :op => '=', :values => ['o'] },
167 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
167 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
168 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
168 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
169 'tracker_id' => {
169 'tracker_id' => {
170 '3' => { :op => '=', :values => ['3'] },
170 '3' => { :op => '=', :values => ['3'] },
171 '=3' => { :op => '=', :values => ['3'] }},
171 '=3' => { :op => '=', :values => ['3'] }},
172 'start_date' => {
172 'start_date' => {
173 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
173 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
174 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
174 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
175 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
175 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
176 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
176 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
177 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
177 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
178 '<t+2' => { :op => '<t+', :values => ['2'] },
178 '<t+2' => { :op => '<t+', :values => ['2'] },
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' => { :op => 't', :values => [''] },
181 't' => { :op => 't', :values => [''] },
182 'w' => { :op => 'w', :values => [''] },
182 'w' => { :op => 'w', :values => [''] },
183 '>t-2' => { :op => '>t-', :values => ['2'] },
183 '>t-2' => { :op => '>t-', :values => ['2'] },
184 '<t-2' => { :op => '<t-', :values => ['2'] },
184 '<t-2' => { :op => '<t-', :values => ['2'] },
185 't-2' => { :op => 't-', :values => ['2'] }},
185 't-2' => { :op => 't-', :values => ['2'] }},
186 'created_on' => {
186 'created_on' => {
187 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
187 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
188 '<t-2' => { :op => '<t-', :values => ['2'] },
188 '<t-2' => { :op => '<t-', :values => ['2'] },
189 '>t-2' => { :op => '>t-', :values => ['2'] },
189 '>t-2' => { :op => '>t-', :values => ['2'] },
190 't-2' => { :op => 't-', :values => ['2'] }},
190 't-2' => { :op => 't-', :values => ['2'] }},
191 'cf_1' => {
191 'cf_1' => {
192 'c' => { :op => '=', :values => ['c'] },
192 'c' => { :op => '=', :values => ['c'] },
193 '!c' => { :op => '!', :values => ['c'] },
193 '!c' => { :op => '!', :values => ['c'] },
194 '!*' => { :op => '!*', :values => [''] },
194 '!*' => { :op => '!*', :values => [''] },
195 '*' => { :op => '*', :values => [''] }},
195 '*' => { :op => '*', :values => [''] }},
196 'estimated_hours' => {
196 'estimated_hours' => {
197 '=13.4' => { :op => '=', :values => ['13.4'] },
197 '=13.4' => { :op => '=', :values => ['13.4'] },
198 '>=45' => { :op => '>=', :values => ['45'] },
198 '>=45' => { :op => '>=', :values => ['45'] },
199 '<=125' => { :op => '<=', :values => ['125'] },
199 '<=125' => { :op => '<=', :values => ['125'] },
200 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
200 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
201 '!*' => { :op => '!*', :values => [''] },
201 '!*' => { :op => '!*', :values => [''] },
202 '*' => { :op => '*', :values => [''] }}
202 '*' => { :op => '*', :values => [''] }}
203 }
203 }
204
204
205 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
205 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
206
206
207 to_test.each do |field, expression_and_expected|
207 to_test.each do |field, expression_and_expected|
208 expression_and_expected.each do |filter_expression, expected|
208 expression_and_expected.each do |filter_expression, expected|
209
209
210 get :index, :set_filter => 1, field => filter_expression
210 get :index, :set_filter => 1, field => filter_expression
211
211
212 assert_response :success
212 assert_response :success
213 assert_template 'index'
213 assert_template 'index'
214 assert_not_nil assigns(:issues)
214 assert_not_nil assigns(:issues)
215
215
216 query = assigns(:query)
216 query = assigns(:query)
217 assert_not_nil query
217 assert_not_nil query
218 assert query.has_filter?(field)
218 assert query.has_filter?(field)
219 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
219 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
220 end
220 end
221 end
221 end
222 end
222 end
223
223
224 def test_index_with_project_and_empty_filters
224 def test_index_with_project_and_empty_filters
225 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
225 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
226 assert_response :success
226 assert_response :success
227 assert_template 'index'
227 assert_template 'index'
228 assert_not_nil assigns(:issues)
228 assert_not_nil assigns(:issues)
229
229
230 query = assigns(:query)
230 query = assigns(:query)
231 assert_not_nil query
231 assert_not_nil query
232 # no filter
232 # no filter
233 assert_equal({}, query.filters)
233 assert_equal({}, query.filters)
234 end
234 end
235
235
236 def test_index_with_project_custom_field_filter
236 def test_index_with_project_custom_field_filter
237 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
237 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
238 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
238 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
239 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
239 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
240 filter_name = "project.cf_#{field.id}"
240 filter_name = "project.cf_#{field.id}"
241 @request.session[:user_id] = 1
241 @request.session[:user_id] = 1
242
242
243 get :index, :set_filter => 1,
243 get :index, :set_filter => 1,
244 :f => [filter_name],
244 :f => [filter_name],
245 :op => {filter_name => '='},
245 :op => {filter_name => '='},
246 :v => {filter_name => ['Foo']}
246 :v => {filter_name => ['Foo']}
247 assert_response :success
247 assert_response :success
248 assert_template 'index'
248 assert_template 'index'
249 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
249 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
250 end
250 end
251
251
252 def test_index_with_query
252 def test_index_with_query
253 get :index, :project_id => 1, :query_id => 5
253 get :index, :project_id => 1, :query_id => 5
254 assert_response :success
254 assert_response :success
255 assert_template 'index'
255 assert_template 'index'
256 assert_not_nil assigns(:issues)
256 assert_not_nil assigns(:issues)
257 assert_nil assigns(:issue_count_by_group)
257 assert_nil assigns(:issue_count_by_group)
258 end
258 end
259
259
260 def test_index_with_query_grouped_by_tracker
260 def test_index_with_query_grouped_by_tracker
261 get :index, :project_id => 1, :query_id => 6
261 get :index, :project_id => 1, :query_id => 6
262 assert_response :success
262 assert_response :success
263 assert_template 'index'
263 assert_template 'index'
264 assert_not_nil assigns(:issues)
264 assert_not_nil assigns(:issues)
265 assert_not_nil assigns(:issue_count_by_group)
265 assert_not_nil assigns(:issue_count_by_group)
266 end
266 end
267
267
268 def test_index_with_query_grouped_and_sorted_by_category
268 def test_index_with_query_grouped_and_sorted_by_category
269 get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
269 get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
270 assert_response :success
270 assert_response :success
271 assert_template 'index'
271 assert_template 'index'
272 assert_not_nil assigns(:issues)
272 assert_not_nil assigns(:issues)
273 assert_not_nil assigns(:issue_count_by_group)
273 assert_not_nil assigns(:issue_count_by_group)
274 end
274 end
275
275
276 def test_index_with_query_grouped_by_list_custom_field
276 def test_index_with_query_grouped_by_list_custom_field
277 get :index, :project_id => 1, :query_id => 9
277 get :index, :project_id => 1, :query_id => 9
278 assert_response :success
278 assert_response :success
279 assert_template 'index'
279 assert_template 'index'
280 assert_not_nil assigns(:issues)
280 assert_not_nil assigns(:issues)
281 assert_not_nil assigns(:issue_count_by_group)
281 assert_not_nil assigns(:issue_count_by_group)
282 end
282 end
283
283
284 def test_index_with_query_grouped_by_key_value_custom_field
285 cf = IssueCustomField.create!(:name => 'Key', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'enumeration')
286 cf.enumerations << valueb = CustomFieldEnumeration.new(:name => 'Value B', :position => 1)
287 cf.enumerations << valuea = CustomFieldEnumeration.new(:name => 'Value A', :position => 2)
288 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => valueb.id)
289 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => valueb.id)
290 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => valuea.id)
291 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
292
293 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
294 assert_response :success
295 assert_template 'index'
296 assert_not_nil assigns(:issues)
297 assert_not_nil assigns(:issue_count_by_group)
298
299 assert_select 'tr.group', 3
300 assert_select 'tr.group' do
301 assert_select 'span.name', :text => 'Value B'
302 assert_select 'span.count', :text => '2'
303 end
304 assert_select 'tr.group' do
305 assert_select 'span.name', :text => 'Value A'
306 assert_select 'span.count', :text => '1'
307 end
308 end
309
284 def test_index_with_query_grouped_by_user_custom_field
310 def test_index_with_query_grouped_by_user_custom_field
285 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
311 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
286 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
312 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
287 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
313 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
288 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
314 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
289 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
315 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
290
316
291 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
317 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
292 assert_response :success
318 assert_response :success
293
319
294 assert_select 'tr.group', 3
320 assert_select 'tr.group', 3
295 assert_select 'tr.group' do
321 assert_select 'tr.group' do
296 assert_select 'a', :text => 'John Smith'
322 assert_select 'a', :text => 'John Smith'
297 assert_select 'span.count', :text => '1'
323 assert_select 'span.count', :text => '1'
298 end
324 end
299 assert_select 'tr.group' do
325 assert_select 'tr.group' do
300 assert_select 'a', :text => 'Dave Lopper'
326 assert_select 'a', :text => 'Dave Lopper'
301 assert_select 'span.count', :text => '2'
327 assert_select 'span.count', :text => '2'
302 end
328 end
303 end
329 end
304
330
305 def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
331 def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
306 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool')
332 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool')
307 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
333 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
308 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
334 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
309 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')
335 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')
310
336
311 with_settings :default_language => 'en' do
337 with_settings :default_language => 'en' do
312 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
338 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
313 assert_response :success
339 assert_response :success
314 end
340 end
315
341
316 assert_select 'tr.group', 3
342 assert_select 'tr.group', 3
317 assert_select 'tr.group', :text => /Yes/
343 assert_select 'tr.group', :text => /Yes/
318 assert_select 'tr.group', :text => /No/
344 assert_select 'tr.group', :text => /No/
319 assert_select 'tr.group', :text => /blank/
345 assert_select 'tr.group', :text => /blank/
320 end
346 end
321
347
322 def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
348 def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
323 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool', :is_filter => true)
349 cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool', :is_filter => true)
324 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
350 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
325 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
351 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
326
352
327 with_settings :default_language => 'en' do
353 with_settings :default_language => 'en' do
328 get :index, :project_id => 1, :set_filter => 1, "cf_#{cf.id}" => "*", :group_by => "cf_#{cf.id}"
354 get :index, :project_id => 1, :set_filter => 1, "cf_#{cf.id}" => "*", :group_by => "cf_#{cf.id}"
329 assert_response :success
355 assert_response :success
330 assert_equal [1, 2], assigns(:issues).map(&:id).sort
356 assert_equal [1, 2], assigns(:issues).map(&:id).sort
331 end
357 end
332
358
333 assert_select 'tr.group', 1
359 assert_select 'tr.group', 1
334 assert_select 'tr.group', :text => /No/
360 assert_select 'tr.group', :text => /No/
335 end
361 end
336
362
337 def test_index_with_query_grouped_by_tracker_in_normal_order
363 def test_index_with_query_grouped_by_tracker_in_normal_order
338 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
364 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
339
365
340 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
366 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
341 assert_response :success
367 assert_response :success
342
368
343 trackers = assigns(:issues).map(&:tracker).uniq
369 trackers = assigns(:issues).map(&:tracker).uniq
344 assert_equal [1, 2, 3], trackers.map(&:id)
370 assert_equal [1, 2, 3], trackers.map(&:id)
345 end
371 end
346
372
347 def test_index_with_query_grouped_by_tracker_in_reverse_order
373 def test_index_with_query_grouped_by_tracker_in_reverse_order
348 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
374 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
349
375
350 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
376 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
351 assert_response :success
377 assert_response :success
352
378
353 trackers = assigns(:issues).map(&:tracker).uniq
379 trackers = assigns(:issues).map(&:tracker).uniq
354 assert_equal [3, 2, 1], trackers.map(&:id)
380 assert_equal [3, 2, 1], trackers.map(&:id)
355 end
381 end
356
382
357 def test_index_with_query_id_and_project_id_should_set_session_query
383 def test_index_with_query_id_and_project_id_should_set_session_query
358 get :index, :project_id => 1, :query_id => 4
384 get :index, :project_id => 1, :query_id => 4
359 assert_response :success
385 assert_response :success
360 assert_kind_of Hash, session[:query]
386 assert_kind_of Hash, session[:query]
361 assert_equal 4, session[:query][:id]
387 assert_equal 4, session[:query][:id]
362 assert_equal 1, session[:query][:project_id]
388 assert_equal 1, session[:query][:project_id]
363 end
389 end
364
390
365 def test_index_with_invalid_query_id_should_respond_404
391 def test_index_with_invalid_query_id_should_respond_404
366 get :index, :project_id => 1, :query_id => 999
392 get :index, :project_id => 1, :query_id => 999
367 assert_response 404
393 assert_response 404
368 end
394 end
369
395
370 def test_index_with_cross_project_query_in_session_should_show_project_issues
396 def test_index_with_cross_project_query_in_session_should_show_project_issues
371 q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
397 q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
372 @request.session[:query] = {:id => q.id, :project_id => 1}
398 @request.session[:query] = {:id => q.id, :project_id => 1}
373
399
374 with_settings :display_subprojects_issues => '0' do
400 with_settings :display_subprojects_issues => '0' do
375 get :index, :project_id => 1
401 get :index, :project_id => 1
376 end
402 end
377 assert_response :success
403 assert_response :success
378 assert_not_nil assigns(:query)
404 assert_not_nil assigns(:query)
379 assert_equal q.id, assigns(:query).id
405 assert_equal q.id, assigns(:query).id
380 assert_equal 1, assigns(:query).project_id
406 assert_equal 1, assigns(:query).project_id
381 assert_equal [1], assigns(:issues).map(&:project_id).uniq
407 assert_equal [1], assigns(:issues).map(&:project_id).uniq
382 end
408 end
383
409
384 def test_private_query_should_not_be_available_to_other_users
410 def test_private_query_should_not_be_available_to_other_users
385 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
411 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
386 @request.session[:user_id] = 3
412 @request.session[:user_id] = 3
387
413
388 get :index, :query_id => q.id
414 get :index, :query_id => q.id
389 assert_response 403
415 assert_response 403
390 end
416 end
391
417
392 def test_private_query_should_be_available_to_its_user
418 def test_private_query_should_be_available_to_its_user
393 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
419 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
394 @request.session[:user_id] = 2
420 @request.session[:user_id] = 2
395
421
396 get :index, :query_id => q.id
422 get :index, :query_id => q.id
397 assert_response :success
423 assert_response :success
398 end
424 end
399
425
400 def test_public_query_should_be_available_to_other_users
426 def test_public_query_should_be_available_to_other_users
401 q = IssueQuery.create!(:name => "public", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
427 q = IssueQuery.create!(:name => "public", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
402 @request.session[:user_id] = 3
428 @request.session[:user_id] = 3
403
429
404 get :index, :query_id => q.id
430 get :index, :query_id => q.id
405 assert_response :success
431 assert_response :success
406 end
432 end
407
433
408 def test_index_should_omit_page_param_in_export_links
434 def test_index_should_omit_page_param_in_export_links
409 get :index, :page => 2
435 get :index, :page => 2
410 assert_response :success
436 assert_response :success
411 assert_select 'a.atom[href="/issues.atom"]'
437 assert_select 'a.atom[href="/issues.atom"]'
412 assert_select 'a.csv[href="/issues.csv"]'
438 assert_select 'a.csv[href="/issues.csv"]'
413 assert_select 'a.pdf[href="/issues.pdf"]'
439 assert_select 'a.pdf[href="/issues.pdf"]'
414 assert_select 'form#csv-export-form[action="/issues.csv"]'
440 assert_select 'form#csv-export-form[action="/issues.csv"]'
415 end
441 end
416
442
417 def test_index_should_not_warn_when_not_exceeding_export_limit
443 def test_index_should_not_warn_when_not_exceeding_export_limit
418 with_settings :issues_export_limit => 200 do
444 with_settings :issues_export_limit => 200 do
419 get :index
445 get :index
420 assert_select '#csv-export-options p.icon-warning', 0
446 assert_select '#csv-export-options p.icon-warning', 0
421 end
447 end
422 end
448 end
423
449
424 def test_index_should_warn_when_exceeding_export_limit
450 def test_index_should_warn_when_exceeding_export_limit
425 with_settings :issues_export_limit => 2 do
451 with_settings :issues_export_limit => 2 do
426 get :index
452 get :index
427 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
453 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
428 end
454 end
429 end
455 end
430
456
431 def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
457 def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
432 get :index, :project_id => 1, :set_filter => "1", :tracker_id => "2", :sort => 'status', :c => ["status", "priority"]
458 get :index, :project_id => 1, :set_filter => "1", :tracker_id => "2", :sort => 'status', :c => ["status", "priority"]
433
459
434 assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
460 assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
435 assert_select '#csv-export-form[method=?]', 'get'
461 assert_select '#csv-export-form[method=?]', 'get'
436
462
437 assert_select '#csv-export-form' do
463 assert_select '#csv-export-form' do
438 assert_select 'input[name=?][value=?]', 'set_filter', '1'
464 assert_select 'input[name=?][value=?]', 'set_filter', '1'
439
465
440 assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
466 assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
441 assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
467 assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
442 assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'
468 assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'
443
469
444 assert_select 'input[name=?][value=?]', 'c[]', 'status'
470 assert_select 'input[name=?][value=?]', 'c[]', 'status'
445 assert_select 'input[name=?][value=?]', 'c[]', 'priority'
471 assert_select 'input[name=?][value=?]', 'c[]', 'priority'
446
472
447 assert_select 'input[name=?][value=?]', 'sort', 'status'
473 assert_select 'input[name=?][value=?]', 'sort', 'status'
448 end
474 end
449 end
475 end
450
476
451 def test_index_csv
477 def test_index_csv
452 get :index, :format => 'csv'
478 get :index, :format => 'csv'
453 assert_response :success
479 assert_response :success
454 assert_not_nil assigns(:issues)
480 assert_not_nil assigns(:issues)
455 assert_equal 'text/csv; header=present', @response.content_type
481 assert_equal 'text/csv; header=present', @response.content_type
456 assert @response.body.starts_with?("#,")
482 assert @response.body.starts_with?("#,")
457 lines = @response.body.chomp.split("\n")
483 lines = @response.body.chomp.split("\n")
458 assert_equal assigns(:query).columns.size, lines[0].split(',').size
484 assert_equal assigns(:query).columns.size, lines[0].split(',').size
459 end
485 end
460
486
461 def test_index_csv_with_project
487 def test_index_csv_with_project
462 get :index, :project_id => 1, :format => 'csv'
488 get :index, :project_id => 1, :format => 'csv'
463 assert_response :success
489 assert_response :success
464 assert_not_nil assigns(:issues)
490 assert_not_nil assigns(:issues)
465 assert_equal 'text/csv; header=present', @response.content_type
491 assert_equal 'text/csv; header=present', @response.content_type
466 end
492 end
467
493
468 def test_index_csv_with_description
494 def test_index_csv_with_description
469 Issue.generate!(:description => 'test_index_csv_with_description')
495 Issue.generate!(:description => 'test_index_csv_with_description')
470
496
471 with_settings :default_language => 'en' do
497 with_settings :default_language => 'en' do
472 get :index, :format => 'csv', :csv => {:description => '1'}
498 get :index, :format => 'csv', :csv => {:description => '1'}
473 assert_response :success
499 assert_response :success
474 assert_not_nil assigns(:issues)
500 assert_not_nil assigns(:issues)
475 end
501 end
476
502
477 assert_equal 'text/csv; header=present', response.content_type
503 assert_equal 'text/csv; header=present', response.content_type
478 headers = response.body.chomp.split("\n").first.split(',')
504 headers = response.body.chomp.split("\n").first.split(',')
479 assert_include 'Description', headers
505 assert_include 'Description', headers
480 assert_include 'test_index_csv_with_description', response.body
506 assert_include 'test_index_csv_with_description', response.body
481 end
507 end
482
508
483 def test_index_csv_with_spent_time_column
509 def test_index_csv_with_spent_time_column
484 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
510 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
485 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
511 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
486
512
487 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
513 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
488 assert_response :success
514 assert_response :success
489 assert_equal 'text/csv; header=present', @response.content_type
515 assert_equal 'text/csv; header=present', @response.content_type
490 lines = @response.body.chomp.split("\n")
516 lines = @response.body.chomp.split("\n")
491 assert_include "#{issue.id},#{issue.subject},7.33", lines
517 assert_include "#{issue.id},#{issue.subject},7.33", lines
492 end
518 end
493
519
494 def test_index_csv_with_all_columns
520 def test_index_csv_with_all_columns
495 get :index, :format => 'csv', :csv => {:columns => 'all'}
521 get :index, :format => 'csv', :csv => {:columns => 'all'}
496 assert_response :success
522 assert_response :success
497 assert_not_nil assigns(:issues)
523 assert_not_nil assigns(:issues)
498 assert_equal 'text/csv; header=present', @response.content_type
524 assert_equal 'text/csv; header=present', @response.content_type
499 assert_match /\A#,/, response.body
525 assert_match /\A#,/, response.body
500 lines = response.body.chomp.split("\n")
526 lines = response.body.chomp.split("\n")
501 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
527 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
502 end
528 end
503
529
504 def test_index_csv_with_multi_column_field
530 def test_index_csv_with_multi_column_field
505 CustomField.find(1).update_attribute :multiple, true
531 CustomField.find(1).update_attribute :multiple, true
506 issue = Issue.find(1)
532 issue = Issue.find(1)
507 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
533 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
508 issue.save!
534 issue.save!
509
535
510 get :index, :format => 'csv', :csv => {:columns => 'all'}
536 get :index, :format => 'csv', :csv => {:columns => 'all'}
511 assert_response :success
537 assert_response :success
512 lines = @response.body.chomp.split("\n")
538 lines = @response.body.chomp.split("\n")
513 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
539 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
514 end
540 end
515
541
516 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
542 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
517 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
543 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
518 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
544 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
519
545
520 with_settings :default_language => 'fr' do
546 with_settings :default_language => 'fr' do
521 get :index, :format => 'csv', :csv => {:columns => 'all'}
547 get :index, :format => 'csv', :csv => {:columns => 'all'}
522 assert_response :success
548 assert_response :success
523 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
549 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
524 assert_include '185,60', issue_line
550 assert_include '185,60', issue_line
525 end
551 end
526
552
527 with_settings :default_language => 'en' do
553 with_settings :default_language => 'en' do
528 get :index, :format => 'csv', :csv => {:columns => 'all'}
554 get :index, :format => 'csv', :csv => {:columns => 'all'}
529 assert_response :success
555 assert_response :success
530 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
556 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
531 assert_include '185.60', issue_line
557 assert_include '185.60', issue_line
532 end
558 end
533 end
559 end
534
560
535 def test_index_csv_should_fill_parent_column_with_parent_id
561 def test_index_csv_should_fill_parent_column_with_parent_id
536 Issue.delete_all
562 Issue.delete_all
537 parent = Issue.generate!
563 parent = Issue.generate!
538 child = Issue.generate!(:parent_issue_id => parent.id)
564 child = Issue.generate!(:parent_issue_id => parent.id)
539
565
540 with_settings :default_language => 'en' do
566 with_settings :default_language => 'en' do
541 get :index, :format => 'csv', :c => %w(parent)
567 get :index, :format => 'csv', :c => %w(parent)
542 end
568 end
543 lines = response.body.split("\n")
569 lines = response.body.split("\n")
544 assert_include "#{child.id},#{parent.id}", lines
570 assert_include "#{child.id},#{parent.id}", lines
545 end
571 end
546
572
547 def test_index_csv_big_5
573 def test_index_csv_big_5
548 with_settings :default_language => "zh-TW" do
574 with_settings :default_language => "zh-TW" do
549 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
575 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
550 str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
576 str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
551 issue = Issue.generate!(:subject => str_utf8)
577 issue = Issue.generate!(:subject => str_utf8)
552
578
553 get :index, :project_id => 1,
579 get :index, :project_id => 1,
554 :f => ['subject'],
580 :f => ['subject'],
555 :op => '=', :values => [str_utf8],
581 :op => '=', :values => [str_utf8],
556 :format => 'csv'
582 :format => 'csv'
557 assert_equal 'text/csv; header=present', @response.content_type
583 assert_equal 'text/csv; header=present', @response.content_type
558 lines = @response.body.chomp.split("\n")
584 lines = @response.body.chomp.split("\n")
559 header = lines[0]
585 header = lines[0]
560 status = "\xaa\xac\xbaA".force_encoding('Big5')
586 status = "\xaa\xac\xbaA".force_encoding('Big5')
561 assert_include status, header
587 assert_include status, header
562 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
588 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
563 assert_include str_big5, issue_line
589 assert_include str_big5, issue_line
564 end
590 end
565 end
591 end
566
592
567 def test_index_csv_cannot_convert_should_be_replaced_big_5
593 def test_index_csv_cannot_convert_should_be_replaced_big_5
568 with_settings :default_language => "zh-TW" do
594 with_settings :default_language => "zh-TW" do
569 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
595 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
570 issue = Issue.generate!(:subject => str_utf8)
596 issue = Issue.generate!(:subject => str_utf8)
571
597
572 get :index, :project_id => 1,
598 get :index, :project_id => 1,
573 :f => ['subject'],
599 :f => ['subject'],
574 :op => '=', :values => [str_utf8],
600 :op => '=', :values => [str_utf8],
575 :c => ['status', 'subject'],
601 :c => ['status', 'subject'],
576 :format => 'csv',
602 :format => 'csv',
577 :set_filter => 1
603 :set_filter => 1
578 assert_equal 'text/csv; header=present', @response.content_type
604 assert_equal 'text/csv; header=present', @response.content_type
579 lines = @response.body.chomp.split("\n")
605 lines = @response.body.chomp.split("\n")
580 header = lines[0]
606 header = lines[0]
581 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
607 issue_line = lines.find {|l| l =~ /^#{issue.id},/}
582 s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
608 s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
583 assert header.include?(s1)
609 assert header.include?(s1)
584 s2 = issue_line.split(",")[2]
610 s2 = issue_line.split(",")[2]
585 s3 = "\xa5H?".force_encoding('Big5') # subject
611 s3 = "\xa5H?".force_encoding('Big5') # subject
586 assert_equal s3, s2
612 assert_equal s3, s2
587 end
613 end
588 end
614 end
589
615
590 def test_index_csv_tw
616 def test_index_csv_tw
591 with_settings :default_language => "zh-TW" do
617 with_settings :default_language => "zh-TW" do
592 str1 = "test_index_csv_tw"
618 str1 = "test_index_csv_tw"
593 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
619 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
594
620
595 get :index, :project_id => 1,
621 get :index, :project_id => 1,
596 :f => ['subject'],
622 :f => ['subject'],
597 :op => '=', :values => [str1],
623 :op => '=', :values => [str1],
598 :c => ['estimated_hours', 'subject'],
624 :c => ['estimated_hours', 'subject'],
599 :format => 'csv',
625 :format => 'csv',
600 :set_filter => 1
626 :set_filter => 1
601 assert_equal 'text/csv; header=present', @response.content_type
627 assert_equal 'text/csv; header=present', @response.content_type
602 lines = @response.body.chomp.split("\n")
628 lines = @response.body.chomp.split("\n")
603 assert_include "#{issue.id},1234.50,#{str1}", lines
629 assert_include "#{issue.id},1234.50,#{str1}", lines
604 end
630 end
605 end
631 end
606
632
607 def test_index_csv_fr
633 def test_index_csv_fr
608 with_settings :default_language => "fr" do
634 with_settings :default_language => "fr" do
609 str1 = "test_index_csv_fr"
635 str1 = "test_index_csv_fr"
610 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
636 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
611
637
612 get :index, :project_id => 1,
638 get :index, :project_id => 1,
613 :f => ['subject'],
639 :f => ['subject'],
614 :op => '=', :values => [str1],
640 :op => '=', :values => [str1],
615 :c => ['estimated_hours', 'subject'],
641 :c => ['estimated_hours', 'subject'],
616 :format => 'csv',
642 :format => 'csv',
617 :set_filter => 1
643 :set_filter => 1
618 assert_equal 'text/csv; header=present', @response.content_type
644 assert_equal 'text/csv; header=present', @response.content_type
619 lines = @response.body.chomp.split("\n")
645 lines = @response.body.chomp.split("\n")
620 assert_include "#{issue.id};1234,50;#{str1}", lines
646 assert_include "#{issue.id};1234,50;#{str1}", lines
621 end
647 end
622 end
648 end
623
649
624 def test_index_pdf
650 def test_index_pdf
625 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
651 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
626 with_settings :default_language => lang do
652 with_settings :default_language => lang do
627
653
628 get :index
654 get :index
629 assert_response :success
655 assert_response :success
630 assert_template 'index'
656 assert_template 'index'
631
657
632 get :index, :format => 'pdf'
658 get :index, :format => 'pdf'
633 assert_response :success
659 assert_response :success
634 assert_not_nil assigns(:issues)
660 assert_not_nil assigns(:issues)
635 assert_equal 'application/pdf', @response.content_type
661 assert_equal 'application/pdf', @response.content_type
636
662
637 get :index, :project_id => 1, :format => 'pdf'
663 get :index, :project_id => 1, :format => 'pdf'
638 assert_response :success
664 assert_response :success
639 assert_not_nil assigns(:issues)
665 assert_not_nil assigns(:issues)
640 assert_equal 'application/pdf', @response.content_type
666 assert_equal 'application/pdf', @response.content_type
641
667
642 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
668 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
643 assert_response :success
669 assert_response :success
644 assert_not_nil assigns(:issues)
670 assert_not_nil assigns(:issues)
645 assert_equal 'application/pdf', @response.content_type
671 assert_equal 'application/pdf', @response.content_type
646 end
672 end
647 end
673 end
648 end
674 end
649
675
650 def test_index_pdf_with_query_grouped_by_list_custom_field
676 def test_index_pdf_with_query_grouped_by_list_custom_field
651 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
677 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
652 assert_response :success
678 assert_response :success
653 assert_not_nil assigns(:issues)
679 assert_not_nil assigns(:issues)
654 assert_not_nil assigns(:issue_count_by_group)
680 assert_not_nil assigns(:issue_count_by_group)
655 assert_equal 'application/pdf', @response.content_type
681 assert_equal 'application/pdf', @response.content_type
656 end
682 end
657
683
658 def test_index_atom
684 def test_index_atom
659 get :index, :project_id => 'ecookbook', :format => 'atom'
685 get :index, :project_id => 'ecookbook', :format => 'atom'
660 assert_response :success
686 assert_response :success
661 assert_template 'common/feed'
687 assert_template 'common/feed'
662 assert_equal 'application/atom+xml', response.content_type
688 assert_equal 'application/atom+xml', response.content_type
663
689
664 assert_select 'feed' do
690 assert_select 'feed' do
665 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
691 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
666 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
692 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
667 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
693 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
668 end
694 end
669 end
695 end
670
696
671 def test_index_sort
697 def test_index_sort
672 get :index, :sort => 'tracker,id:desc'
698 get :index, :sort => 'tracker,id:desc'
673 assert_response :success
699 assert_response :success
674
700
675 sort_params = @request.session['issues_index_sort']
701 sort_params = @request.session['issues_index_sort']
676 assert sort_params.is_a?(String)
702 assert sort_params.is_a?(String)
677 assert_equal 'tracker,id:desc', sort_params
703 assert_equal 'tracker,id:desc', sort_params
678
704
679 issues = assigns(:issues)
705 issues = assigns(:issues)
680 assert_not_nil issues
706 assert_not_nil issues
681 assert !issues.empty?
707 assert !issues.empty?
682 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
708 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
683 assert_select 'table.issues.sort-by-tracker.sort-asc'
709 assert_select 'table.issues.sort-by-tracker.sort-asc'
684 end
710 end
685
711
686 def test_index_sort_by_field_not_included_in_columns
712 def test_index_sort_by_field_not_included_in_columns
687 Setting.issue_list_default_columns = %w(subject author)
713 Setting.issue_list_default_columns = %w(subject author)
688 get :index, :sort => 'tracker'
714 get :index, :sort => 'tracker'
689 end
715 end
690
716
691 def test_index_sort_by_assigned_to
717 def test_index_sort_by_assigned_to
692 get :index, :sort => 'assigned_to'
718 get :index, :sort => 'assigned_to'
693 assert_response :success
719 assert_response :success
694 assignees = assigns(:issues).collect(&:assigned_to).compact
720 assignees = assigns(:issues).collect(&:assigned_to).compact
695 assert_equal assignees.sort, assignees
721 assert_equal assignees.sort, assignees
696 assert_select 'table.issues.sort-by-assigned-to.sort-asc'
722 assert_select 'table.issues.sort-by-assigned-to.sort-asc'
697 end
723 end
698
724
699 def test_index_sort_by_assigned_to_desc
725 def test_index_sort_by_assigned_to_desc
700 get :index, :sort => 'assigned_to:desc'
726 get :index, :sort => 'assigned_to:desc'
701 assert_response :success
727 assert_response :success
702 assignees = assigns(:issues).collect(&:assigned_to).compact
728 assignees = assigns(:issues).collect(&:assigned_to).compact
703 assert_equal assignees.sort.reverse, assignees
729 assert_equal assignees.sort.reverse, assignees
704 assert_select 'table.issues.sort-by-assigned-to.sort-desc'
730 assert_select 'table.issues.sort-by-assigned-to.sort-desc'
705 end
731 end
706
732
707 def test_index_group_by_assigned_to
733 def test_index_group_by_assigned_to
708 get :index, :group_by => 'assigned_to', :sort => 'priority'
734 get :index, :group_by => 'assigned_to', :sort => 'priority'
709 assert_response :success
735 assert_response :success
710 end
736 end
711
737
712 def test_index_sort_by_author
738 def test_index_sort_by_author
713 get :index, :sort => 'author'
739 get :index, :sort => 'author'
714 assert_response :success
740 assert_response :success
715 authors = assigns(:issues).collect(&:author)
741 authors = assigns(:issues).collect(&:author)
716 assert_equal authors.sort, authors
742 assert_equal authors.sort, authors
717 end
743 end
718
744
719 def test_index_sort_by_author_desc
745 def test_index_sort_by_author_desc
720 get :index, :sort => 'author:desc'
746 get :index, :sort => 'author:desc'
721 assert_response :success
747 assert_response :success
722 authors = assigns(:issues).collect(&:author)
748 authors = assigns(:issues).collect(&:author)
723 assert_equal authors.sort.reverse, authors
749 assert_equal authors.sort.reverse, authors
724 end
750 end
725
751
726 def test_index_group_by_author
752 def test_index_group_by_author
727 get :index, :group_by => 'author', :sort => 'priority'
753 get :index, :group_by => 'author', :sort => 'priority'
728 assert_response :success
754 assert_response :success
729 end
755 end
730
756
731 def test_index_sort_by_spent_hours
757 def test_index_sort_by_spent_hours
732 get :index, :sort => 'spent_hours:desc'
758 get :index, :sort => 'spent_hours:desc'
733 assert_response :success
759 assert_response :success
734 hours = assigns(:issues).collect(&:spent_hours)
760 hours = assigns(:issues).collect(&:spent_hours)
735 assert_equal hours.sort.reverse, hours
761 assert_equal hours.sort.reverse, hours
736 end
762 end
737
763
738 def test_index_sort_by_total_spent_hours
764 def test_index_sort_by_total_spent_hours
739 get :index, :sort => 'total_spent_hours:desc'
765 get :index, :sort => 'total_spent_hours:desc'
740 assert_response :success
766 assert_response :success
741 hours = assigns(:issues).collect(&:total_spent_hours)
767 hours = assigns(:issues).collect(&:total_spent_hours)
742 assert_equal hours.sort.reverse, hours
768 assert_equal hours.sort.reverse, hours
743 end
769 end
744
770
745 def test_index_sort_by_total_estimated_hours
771 def test_index_sort_by_total_estimated_hours
746 get :index, :sort => 'total_estimated_hours:desc'
772 get :index, :sort => 'total_estimated_hours:desc'
747 assert_response :success
773 assert_response :success
748 hours = assigns(:issues).collect(&:total_estimated_hours)
774 hours = assigns(:issues).collect(&:total_estimated_hours)
749 assert_equal hours.sort.reverse, hours
775 assert_equal hours.sort.reverse, hours
750 end
776 end
751
777
752 def test_index_sort_by_user_custom_field
778 def test_index_sort_by_user_custom_field
753 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
779 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
754 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
780 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
755 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
781 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
756 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
782 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
757 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
783 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
758
784
759 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
785 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
760 assert_response :success
786 assert_response :success
761
787
762 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
788 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
763 end
789 end
764
790
765 def test_index_with_columns
791 def test_index_with_columns
766 columns = ['tracker', 'subject', 'assigned_to']
792 columns = ['tracker', 'subject', 'assigned_to']
767 get :index, :set_filter => 1, :c => columns
793 get :index, :set_filter => 1, :c => columns
768 assert_response :success
794 assert_response :success
769
795
770 # query should use specified columns
796 # query should use specified columns
771 query = assigns(:query)
797 query = assigns(:query)
772 assert_kind_of IssueQuery, query
798 assert_kind_of IssueQuery, query
773 assert_equal columns, query.column_names.map(&:to_s)
799 assert_equal columns, query.column_names.map(&:to_s)
774
800
775 # columns should be stored in session
801 # columns should be stored in session
776 assert_kind_of Hash, session[:query]
802 assert_kind_of Hash, session[:query]
777 assert_kind_of Array, session[:query][:column_names]
803 assert_kind_of Array, session[:query][:column_names]
778 assert_equal columns, session[:query][:column_names].map(&:to_s)
804 assert_equal columns, session[:query][:column_names].map(&:to_s)
779
805
780 # ensure only these columns are kept in the selected columns list
806 # ensure only these columns are kept in the selected columns list
781 assert_select 'select#selected_columns option' do
807 assert_select 'select#selected_columns option' do
782 assert_select 'option', 3
808 assert_select 'option', 3
783 assert_select 'option[value=tracker]'
809 assert_select 'option[value=tracker]'
784 assert_select 'option[value=project]', 0
810 assert_select 'option[value=project]', 0
785 end
811 end
786 end
812 end
787
813
788 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
814 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
789 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
815 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
790 get :index, :set_filter => 1
816 get :index, :set_filter => 1
791
817
792 # query should use specified columns
818 # query should use specified columns
793 query = assigns(:query)
819 query = assigns(:query)
794 assert_kind_of IssueQuery, query
820 assert_kind_of IssueQuery, query
795 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
821 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
796 end
822 end
797
823
798 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
824 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
799 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
825 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
800 columns = ['id', 'tracker', 'subject', 'assigned_to']
826 columns = ['id', 'tracker', 'subject', 'assigned_to']
801 get :index, :set_filter => 1, :c => columns
827 get :index, :set_filter => 1, :c => columns
802
828
803 # query should use specified columns
829 # query should use specified columns
804 query = assigns(:query)
830 query = assigns(:query)
805 assert_kind_of IssueQuery, query
831 assert_kind_of IssueQuery, query
806 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
832 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
807 end
833 end
808
834
809 def test_index_with_default_columns_should_respect_default_columns_order
835 def test_index_with_default_columns_should_respect_default_columns_order
810 columns = ['assigned_to', 'subject', 'status', 'tracker']
836 columns = ['assigned_to', 'subject', 'status', 'tracker']
811 with_settings :issue_list_default_columns => columns do
837 with_settings :issue_list_default_columns => columns do
812 get :index, :project_id => 1, :set_filter => 1
838 get :index, :project_id => 1, :set_filter => 1
813
839
814 query = assigns(:query)
840 query = assigns(:query)
815 assert_equal (['id'] + columns).map(&:to_sym), query.columns.map(&:name)
841 assert_equal (['id'] + columns).map(&:to_sym), query.columns.map(&:name)
816 end
842 end
817 end
843 end
818
844
819 def test_index_with_custom_field_column
845 def test_index_with_custom_field_column
820 columns = %w(tracker subject cf_2)
846 columns = %w(tracker subject cf_2)
821 get :index, :set_filter => 1, :c => columns
847 get :index, :set_filter => 1, :c => columns
822 assert_response :success
848 assert_response :success
823
849
824 # query should use specified columns
850 # query should use specified columns
825 query = assigns(:query)
851 query = assigns(:query)
826 assert_kind_of IssueQuery, query
852 assert_kind_of IssueQuery, query
827 assert_equal columns, query.column_names.map(&:to_s)
853 assert_equal columns, query.column_names.map(&:to_s)
828
854
829 assert_select 'table.issues td.cf_2.string'
855 assert_select 'table.issues td.cf_2.string'
830 end
856 end
831
857
832 def test_index_with_multi_custom_field_column
858 def test_index_with_multi_custom_field_column
833 field = CustomField.find(1)
859 field = CustomField.find(1)
834 field.update_attribute :multiple, true
860 field.update_attribute :multiple, true
835 issue = Issue.find(1)
861 issue = Issue.find(1)
836 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
862 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
837 issue.save!
863 issue.save!
838
864
839 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
865 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
840 assert_response :success
866 assert_response :success
841
867
842 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
868 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
843 end
869 end
844
870
845 def test_index_with_multi_user_custom_field_column
871 def test_index_with_multi_user_custom_field_column
846 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
872 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
847 :tracker_ids => [1], :is_for_all => true)
873 :tracker_ids => [1], :is_for_all => true)
848 issue = Issue.find(1)
874 issue = Issue.find(1)
849 issue.custom_field_values = {field.id => ['2', '3']}
875 issue.custom_field_values = {field.id => ['2', '3']}
850 issue.save!
876 issue.save!
851
877
852 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
878 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
853 assert_response :success
879 assert_response :success
854
880
855 assert_select "table.issues td.cf_#{field.id}" do
881 assert_select "table.issues td.cf_#{field.id}" do
856 assert_select 'a', 2
882 assert_select 'a', 2
857 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
883 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
858 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
884 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
859 end
885 end
860 end
886 end
861
887
862 def test_index_with_date_column
888 def test_index_with_date_column
863 with_settings :date_format => '%d/%m/%Y' do
889 with_settings :date_format => '%d/%m/%Y' do
864 Issue.find(1).update_attribute :start_date, '1987-08-24'
890 Issue.find(1).update_attribute :start_date, '1987-08-24'
865 get :index, :set_filter => 1, :c => %w(start_date)
891 get :index, :set_filter => 1, :c => %w(start_date)
866 assert_select "table.issues td.start_date", :text => '24/08/1987'
892 assert_select "table.issues td.start_date", :text => '24/08/1987'
867 end
893 end
868 end
894 end
869
895
870 def test_index_with_done_ratio_column
896 def test_index_with_done_ratio_column
871 Issue.find(1).update_attribute :done_ratio, 40
897 Issue.find(1).update_attribute :done_ratio, 40
872 get :index, :set_filter => 1, :c => %w(done_ratio)
898 get :index, :set_filter => 1, :c => %w(done_ratio)
873 assert_select 'table.issues td.done_ratio' do
899 assert_select 'table.issues td.done_ratio' do
874 assert_select 'table.progress' do
900 assert_select 'table.progress' do
875 assert_select 'td.closed[style=?]', 'width: 40%;'
901 assert_select 'td.closed[style=?]', 'width: 40%;'
876 end
902 end
877 end
903 end
878 end
904 end
879
905
880 def test_index_with_spent_hours_column
906 def test_index_with_spent_hours_column
881 Issue.expects(:load_visible_spent_hours).once
907 Issue.expects(:load_visible_spent_hours).once
882 get :index, :set_filter => 1, :c => %w(subject spent_hours)
908 get :index, :set_filter => 1, :c => %w(subject spent_hours)
883 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
909 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
884 end
910 end
885
911
886 def test_index_with_total_spent_hours_column
912 def test_index_with_total_spent_hours_column
887 Issue.expects(:load_visible_total_spent_hours).once
913 Issue.expects(:load_visible_total_spent_hours).once
888 get :index, :set_filter => 1, :c => %w(subject total_spent_hours)
914 get :index, :set_filter => 1, :c => %w(subject total_spent_hours)
889 assert_select 'table.issues tr#issue-3 td.total_spent_hours', :text => '1.00'
915 assert_select 'table.issues tr#issue-3 td.total_spent_hours', :text => '1.00'
890 end
916 end
891
917
892 def test_index_with_total_estimated_hours_column
918 def test_index_with_total_estimated_hours_column
893 get :index, :set_filter => 1, :c => %w(subject total_estimated_hours)
919 get :index, :set_filter => 1, :c => %w(subject total_estimated_hours)
894 assert_select 'table.issues td.total_estimated_hours'
920 assert_select 'table.issues td.total_estimated_hours'
895 end
921 end
896
922
897 def test_index_should_not_show_spent_hours_column_without_permission
923 def test_index_should_not_show_spent_hours_column_without_permission
898 Role.anonymous.remove_permission! :view_time_entries
924 Role.anonymous.remove_permission! :view_time_entries
899 get :index, :set_filter => 1, :c => %w(subject spent_hours)
925 get :index, :set_filter => 1, :c => %w(subject spent_hours)
900 assert_select 'td.spent_hours', 0
926 assert_select 'td.spent_hours', 0
901 end
927 end
902
928
903 def test_index_with_fixed_version_column
929 def test_index_with_fixed_version_column
904 get :index, :set_filter => 1, :c => %w(fixed_version)
930 get :index, :set_filter => 1, :c => %w(fixed_version)
905 assert_select 'table.issues td.fixed_version' do
931 assert_select 'table.issues td.fixed_version' do
906 assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0'
932 assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0'
907 end
933 end
908 end
934 end
909
935
910 def test_index_with_relations_column
936 def test_index_with_relations_column
911 IssueRelation.delete_all
937 IssueRelation.delete_all
912 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
938 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
913 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
939 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
914 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
940 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
915 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
941 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
916
942
917 get :index, :set_filter => 1, :c => %w(subject relations)
943 get :index, :set_filter => 1, :c => %w(subject relations)
918 assert_response :success
944 assert_response :success
919 assert_select "tr#issue-1 td.relations" do
945 assert_select "tr#issue-1 td.relations" do
920 assert_select "span", 3
946 assert_select "span", 3
921 assert_select "span", :text => "Related to #7"
947 assert_select "span", :text => "Related to #7"
922 assert_select "span", :text => "Related to #8"
948 assert_select "span", :text => "Related to #8"
923 assert_select "span", :text => "Blocks #11"
949 assert_select "span", :text => "Blocks #11"
924 end
950 end
925 assert_select "tr#issue-2 td.relations" do
951 assert_select "tr#issue-2 td.relations" do
926 assert_select "span", 1
952 assert_select "span", 1
927 assert_select "span", :text => "Blocked by #12"
953 assert_select "span", :text => "Blocked by #12"
928 end
954 end
929 assert_select "tr#issue-3 td.relations" do
955 assert_select "tr#issue-3 td.relations" do
930 assert_select "span", 0
956 assert_select "span", 0
931 end
957 end
932
958
933 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
959 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
934 assert_response :success
960 assert_response :success
935 assert_equal 'text/csv; header=present', response.content_type
961 assert_equal 'text/csv; header=present', response.content_type
936 lines = response.body.chomp.split("\n")
962 lines = response.body.chomp.split("\n")
937 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
963 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
938 assert_include '2,Blocked by #12', lines
964 assert_include '2,Blocked by #12', lines
939 assert_include '3,""', lines
965 assert_include '3,""', lines
940
966
941 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
967 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
942 assert_response :success
968 assert_response :success
943 assert_equal 'application/pdf', response.content_type
969 assert_equal 'application/pdf', response.content_type
944 end
970 end
945
971
946 def test_index_with_description_column
972 def test_index_with_description_column
947 get :index, :set_filter => 1, :c => %w(subject description)
973 get :index, :set_filter => 1, :c => %w(subject description)
948
974
949 assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
975 assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
950 assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes'
976 assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes'
951
977
952 get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
978 get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
953 assert_response :success
979 assert_response :success
954 assert_equal 'application/pdf', response.content_type
980 assert_equal 'application/pdf', response.content_type
955 end
981 end
956
982
957 def test_index_with_parent_column
983 def test_index_with_parent_column
958 Issue.delete_all
984 Issue.delete_all
959 parent = Issue.generate!
985 parent = Issue.generate!
960 child = Issue.generate!(:parent_issue_id => parent.id)
986 child = Issue.generate!(:parent_issue_id => parent.id)
961
987
962 get :index, :c => %w(parent)
988 get :index, :c => %w(parent)
963
989
964 assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}"
990 assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}"
965 assert_select 'td.parent a[title=?]', parent.subject
991 assert_select 'td.parent a[title=?]', parent.subject
966 end
992 end
967
993
968 def test_index_with_estimated_hours_total
994 def test_index_with_estimated_hours_total
969 Issue.delete_all
995 Issue.delete_all
970 Issue.generate!(:estimated_hours => 5.5)
996 Issue.generate!(:estimated_hours => 5.5)
971 Issue.generate!(:estimated_hours => 1.1)
997 Issue.generate!(:estimated_hours => 1.1)
972
998
973 get :index, :t => %w(estimated_hours)
999 get :index, :t => %w(estimated_hours)
974 assert_response :success
1000 assert_response :success
975 assert_select '.query-totals'
1001 assert_select '.query-totals'
976 assert_select '.total-for-estimated-hours span.value', :text => '6.60'
1002 assert_select '.total-for-estimated-hours span.value', :text => '6.60'
977 assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
1003 assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
978 end
1004 end
979
1005
980 def test_index_with_grouped_query_and_estimated_hours_total
1006 def test_index_with_grouped_query_and_estimated_hours_total
981 Issue.delete_all
1007 Issue.delete_all
982 Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
1008 Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
983 Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
1009 Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
984 Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
1010 Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
985 Issue.generate!(:estimated_hours => 4.6)
1011 Issue.generate!(:estimated_hours => 4.6)
986
1012
987 get :index, :t => %w(estimated_hours), :group_by => 'category'
1013 get :index, :t => %w(estimated_hours), :group_by => 'category'
988 assert_response :success
1014 assert_response :success
989 assert_select '.query-totals'
1015 assert_select '.query-totals'
990 assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
1016 assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
991 assert_select 'tr.group', :text => /Printing/ do
1017 assert_select 'tr.group', :text => /Printing/ do
992 assert_select '.total-for-estimated-hours span.value', :text => '7.80'
1018 assert_select '.total-for-estimated-hours span.value', :text => '7.80'
993 end
1019 end
994 assert_select 'tr.group', :text => /Recipes/ do
1020 assert_select 'tr.group', :text => /Recipes/ do
995 assert_select '.total-for-estimated-hours span.value', :text => '1.10'
1021 assert_select '.total-for-estimated-hours span.value', :text => '1.10'
996 end
1022 end
997 assert_select 'tr.group', :text => /blank/ do
1023 assert_select 'tr.group', :text => /blank/ do
998 assert_select '.total-for-estimated-hours span.value', :text => '4.60'
1024 assert_select '.total-for-estimated-hours span.value', :text => '4.60'
999 end
1025 end
1000 end
1026 end
1001
1027
1002 def test_index_with_int_custom_field_total
1028 def test_index_with_int_custom_field_total
1003 field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
1029 field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
1004 CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
1030 CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
1005 CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')
1031 CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')
1006
1032
1007 get :index, :t => ["cf_#{field.id}"]
1033 get :index, :t => ["cf_#{field.id}"]
1008 assert_response :success
1034 assert_response :success
1009 assert_select '.query-totals'
1035 assert_select '.query-totals'
1010 assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
1036 assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
1011 end
1037 end
1012
1038
1013 def test_index_totals_should_default_to_settings
1039 def test_index_totals_should_default_to_settings
1014 with_settings :issue_list_default_totals => ['estimated_hours'] do
1040 with_settings :issue_list_default_totals => ['estimated_hours'] do
1015 get :index
1041 get :index
1016 assert_response :success
1042 assert_response :success
1017 assert_select '.total-for-estimated-hours span.value'
1043 assert_select '.total-for-estimated-hours span.value'
1018 assert_select '.query-totals>span', 1
1044 assert_select '.query-totals>span', 1
1019 end
1045 end
1020 end
1046 end
1021
1047
1022 def test_index_send_html_if_query_is_invalid
1048 def test_index_send_html_if_query_is_invalid
1023 get :index, :f => ['start_date'], :op => {:start_date => '='}
1049 get :index, :f => ['start_date'], :op => {:start_date => '='}
1024 assert_equal 'text/html', @response.content_type
1050 assert_equal 'text/html', @response.content_type
1025 assert_template 'index'
1051 assert_template 'index'
1026 end
1052 end
1027
1053
1028 def test_index_send_nothing_if_query_is_invalid
1054 def test_index_send_nothing_if_query_is_invalid
1029 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
1055 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
1030 assert_equal 'text/csv', @response.content_type
1056 assert_equal 'text/csv', @response.content_type
1031 assert @response.body.blank?
1057 assert @response.body.blank?
1032 end
1058 end
1033
1059
1034 def test_show_by_anonymous
1060 def test_show_by_anonymous
1035 get :show, :id => 1
1061 get :show, :id => 1
1036 assert_response :success
1062 assert_response :success
1037 assert_template 'show'
1063 assert_template 'show'
1038 assert_equal Issue.find(1), assigns(:issue)
1064 assert_equal Issue.find(1), assigns(:issue)
1039 assert_select 'div.issue div.description', :text => /Unable to print recipes/
1065 assert_select 'div.issue div.description', :text => /Unable to print recipes/
1040 # anonymous role is allowed to add a note
1066 # anonymous role is allowed to add a note
1041 assert_select 'form#issue-form' do
1067 assert_select 'form#issue-form' do
1042 assert_select 'fieldset' do
1068 assert_select 'fieldset' do
1043 assert_select 'legend', :text => 'Notes'
1069 assert_select 'legend', :text => 'Notes'
1044 assert_select 'textarea[name=?]', 'issue[notes]'
1070 assert_select 'textarea[name=?]', 'issue[notes]'
1045 end
1071 end
1046 end
1072 end
1047 assert_select 'title', :text => "Bug #1: Cannot print recipes - eCookbook - Redmine"
1073 assert_select 'title', :text => "Bug #1: Cannot print recipes - eCookbook - Redmine"
1048 end
1074 end
1049
1075
1050 def test_show_by_manager
1076 def test_show_by_manager
1051 @request.session[:user_id] = 2
1077 @request.session[:user_id] = 2
1052 get :show, :id => 1
1078 get :show, :id => 1
1053 assert_response :success
1079 assert_response :success
1054 assert_select 'a', :text => /Quote/
1080 assert_select 'a', :text => /Quote/
1055 assert_select 'form#issue-form' do
1081 assert_select 'form#issue-form' do
1056 assert_select 'fieldset' do
1082 assert_select 'fieldset' do
1057 assert_select 'legend', :text => 'Change properties'
1083 assert_select 'legend', :text => 'Change properties'
1058 assert_select 'input[name=?]', 'issue[subject]'
1084 assert_select 'input[name=?]', 'issue[subject]'
1059 end
1085 end
1060 assert_select 'fieldset' do
1086 assert_select 'fieldset' do
1061 assert_select 'legend', :text => 'Log time'
1087 assert_select 'legend', :text => 'Log time'
1062 assert_select 'input[name=?]', 'time_entry[hours]'
1088 assert_select 'input[name=?]', 'time_entry[hours]'
1063 end
1089 end
1064 assert_select 'fieldset' do
1090 assert_select 'fieldset' do
1065 assert_select 'legend', :text => 'Notes'
1091 assert_select 'legend', :text => 'Notes'
1066 assert_select 'textarea[name=?]', 'issue[notes]'
1092 assert_select 'textarea[name=?]', 'issue[notes]'
1067 end
1093 end
1068 end
1094 end
1069 end
1095 end
1070
1096
1071 def test_show_should_display_update_form
1097 def test_show_should_display_update_form
1072 @request.session[:user_id] = 2
1098 @request.session[:user_id] = 2
1073 get :show, :id => 1
1099 get :show, :id => 1
1074 assert_response :success
1100 assert_response :success
1075
1101
1076 assert_select 'form#issue-form' do
1102 assert_select 'form#issue-form' do
1077 assert_select 'input[name=?]', 'issue[is_private]'
1103 assert_select 'input[name=?]', 'issue[is_private]'
1078 assert_select 'select[name=?]', 'issue[project_id]'
1104 assert_select 'select[name=?]', 'issue[project_id]'
1079 assert_select 'select[name=?]', 'issue[tracker_id]'
1105 assert_select 'select[name=?]', 'issue[tracker_id]'
1080 assert_select 'input[name=?]', 'issue[subject]'
1106 assert_select 'input[name=?]', 'issue[subject]'
1081 assert_select 'textarea[name=?]', 'issue[description]'
1107 assert_select 'textarea[name=?]', 'issue[description]'
1082 assert_select 'select[name=?]', 'issue[status_id]'
1108 assert_select 'select[name=?]', 'issue[status_id]'
1083 assert_select 'select[name=?]', 'issue[priority_id]'
1109 assert_select 'select[name=?]', 'issue[priority_id]'
1084 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1110 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1085 assert_select 'select[name=?]', 'issue[category_id]'
1111 assert_select 'select[name=?]', 'issue[category_id]'
1086 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1112 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1087 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1113 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1088 assert_select 'input[name=?]', 'issue[start_date]'
1114 assert_select 'input[name=?]', 'issue[start_date]'
1089 assert_select 'input[name=?]', 'issue[due_date]'
1115 assert_select 'input[name=?]', 'issue[due_date]'
1090 assert_select 'select[name=?]', 'issue[done_ratio]'
1116 assert_select 'select[name=?]', 'issue[done_ratio]'
1091 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
1117 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
1092 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1118 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1093 assert_select 'textarea[name=?]', 'issue[notes]'
1119 assert_select 'textarea[name=?]', 'issue[notes]'
1094 end
1120 end
1095 end
1121 end
1096
1122
1097 def test_show_should_display_update_form_with_minimal_permissions
1123 def test_show_should_display_update_form_with_minimal_permissions
1098 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
1124 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
1099 WorkflowTransition.delete_all :role_id => 1
1125 WorkflowTransition.delete_all :role_id => 1
1100
1126
1101 @request.session[:user_id] = 2
1127 @request.session[:user_id] = 2
1102 get :show, :id => 1
1128 get :show, :id => 1
1103 assert_response :success
1129 assert_response :success
1104
1130
1105 assert_select 'form#issue-form' do
1131 assert_select 'form#issue-form' do
1106 assert_select 'input[name=?]', 'issue[is_private]', 0
1132 assert_select 'input[name=?]', 'issue[is_private]', 0
1107 assert_select 'select[name=?]', 'issue[project_id]', 0
1133 assert_select 'select[name=?]', 'issue[project_id]', 0
1108 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1134 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1109 assert_select 'input[name=?]', 'issue[subject]', 0
1135 assert_select 'input[name=?]', 'issue[subject]', 0
1110 assert_select 'textarea[name=?]', 'issue[description]', 0
1136 assert_select 'textarea[name=?]', 'issue[description]', 0
1111 assert_select 'select[name=?]', 'issue[status_id]', 0
1137 assert_select 'select[name=?]', 'issue[status_id]', 0
1112 assert_select 'select[name=?]', 'issue[priority_id]', 0
1138 assert_select 'select[name=?]', 'issue[priority_id]', 0
1113 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
1139 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
1114 assert_select 'select[name=?]', 'issue[category_id]', 0
1140 assert_select 'select[name=?]', 'issue[category_id]', 0
1115 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
1141 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
1116 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1142 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1117 assert_select 'input[name=?]', 'issue[start_date]', 0
1143 assert_select 'input[name=?]', 'issue[start_date]', 0
1118 assert_select 'input[name=?]', 'issue[due_date]', 0
1144 assert_select 'input[name=?]', 'issue[due_date]', 0
1119 assert_select 'select[name=?]', 'issue[done_ratio]', 0
1145 assert_select 'select[name=?]', 'issue[done_ratio]', 0
1120 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
1146 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
1121 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1147 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1122 assert_select 'textarea[name=?]', 'issue[notes]'
1148 assert_select 'textarea[name=?]', 'issue[notes]'
1123 end
1149 end
1124 end
1150 end
1125
1151
1126 def test_show_should_not_display_update_form_without_permissions
1152 def test_show_should_not_display_update_form_without_permissions
1127 Role.find(1).update_attribute :permissions, [:view_issues]
1153 Role.find(1).update_attribute :permissions, [:view_issues]
1128
1154
1129 @request.session[:user_id] = 2
1155 @request.session[:user_id] = 2
1130 get :show, :id => 1
1156 get :show, :id => 1
1131 assert_response :success
1157 assert_response :success
1132
1158
1133 assert_select 'form#issue-form', 0
1159 assert_select 'form#issue-form', 0
1134 end
1160 end
1135
1161
1136 def test_update_form_should_not_display_inactive_enumerations
1162 def test_update_form_should_not_display_inactive_enumerations
1137 assert !IssuePriority.find(15).active?
1163 assert !IssuePriority.find(15).active?
1138
1164
1139 @request.session[:user_id] = 2
1165 @request.session[:user_id] = 2
1140 get :show, :id => 1
1166 get :show, :id => 1
1141 assert_response :success
1167 assert_response :success
1142
1168
1143 assert_select 'form#issue-form' do
1169 assert_select 'form#issue-form' do
1144 assert_select 'select[name=?]', 'issue[priority_id]' do
1170 assert_select 'select[name=?]', 'issue[priority_id]' do
1145 assert_select 'option[value="4"]'
1171 assert_select 'option[value="4"]'
1146 assert_select 'option[value="15"]', 0
1172 assert_select 'option[value="15"]', 0
1147 end
1173 end
1148 end
1174 end
1149 end
1175 end
1150
1176
1151 def test_update_form_should_allow_attachment_upload
1177 def test_update_form_should_allow_attachment_upload
1152 @request.session[:user_id] = 2
1178 @request.session[:user_id] = 2
1153 get :show, :id => 1
1179 get :show, :id => 1
1154
1180
1155 assert_select 'form#issue-form[method=post][enctype="multipart/form-data"]' do
1181 assert_select 'form#issue-form[method=post][enctype="multipart/form-data"]' do
1156 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1182 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1157 end
1183 end
1158 end
1184 end
1159
1185
1160 def test_show_should_deny_anonymous_access_without_permission
1186 def test_show_should_deny_anonymous_access_without_permission
1161 Role.anonymous.remove_permission!(:view_issues)
1187 Role.anonymous.remove_permission!(:view_issues)
1162 get :show, :id => 1
1188 get :show, :id => 1
1163 assert_response :redirect
1189 assert_response :redirect
1164 end
1190 end
1165
1191
1166 def test_show_should_deny_anonymous_access_to_private_issue
1192 def test_show_should_deny_anonymous_access_to_private_issue
1167 Issue.where(:id => 1).update_all(["is_private = ?", true])
1193 Issue.where(:id => 1).update_all(["is_private = ?", true])
1168 get :show, :id => 1
1194 get :show, :id => 1
1169 assert_response :redirect
1195 assert_response :redirect
1170 end
1196 end
1171
1197
1172 def test_show_should_deny_non_member_access_without_permission
1198 def test_show_should_deny_non_member_access_without_permission
1173 Role.non_member.remove_permission!(:view_issues)
1199 Role.non_member.remove_permission!(:view_issues)
1174 @request.session[:user_id] = 9
1200 @request.session[:user_id] = 9
1175 get :show, :id => 1
1201 get :show, :id => 1
1176 assert_response 403
1202 assert_response 403
1177 end
1203 end
1178
1204
1179 def test_show_should_deny_non_member_access_to_private_issue
1205 def test_show_should_deny_non_member_access_to_private_issue
1180 Issue.where(:id => 1).update_all(["is_private = ?", true])
1206 Issue.where(:id => 1).update_all(["is_private = ?", true])
1181 @request.session[:user_id] = 9
1207 @request.session[:user_id] = 9
1182 get :show, :id => 1
1208 get :show, :id => 1
1183 assert_response 403
1209 assert_response 403
1184 end
1210 end
1185
1211
1186 def test_show_should_deny_member_access_without_permission
1212 def test_show_should_deny_member_access_without_permission
1187 Role.find(1).remove_permission!(:view_issues)
1213 Role.find(1).remove_permission!(:view_issues)
1188 @request.session[:user_id] = 2
1214 @request.session[:user_id] = 2
1189 get :show, :id => 1
1215 get :show, :id => 1
1190 assert_response 403
1216 assert_response 403
1191 end
1217 end
1192
1218
1193 def test_show_should_deny_member_access_to_private_issue_without_permission
1219 def test_show_should_deny_member_access_to_private_issue_without_permission
1194 Issue.where(:id => 1).update_all(["is_private = ?", true])
1220 Issue.where(:id => 1).update_all(["is_private = ?", true])
1195 @request.session[:user_id] = 3
1221 @request.session[:user_id] = 3
1196 get :show, :id => 1
1222 get :show, :id => 1
1197 assert_response 403
1223 assert_response 403
1198 end
1224 end
1199
1225
1200 def test_show_should_allow_author_access_to_private_issue
1226 def test_show_should_allow_author_access_to_private_issue
1201 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
1227 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
1202 @request.session[:user_id] = 3
1228 @request.session[:user_id] = 3
1203 get :show, :id => 1
1229 get :show, :id => 1
1204 assert_response :success
1230 assert_response :success
1205 end
1231 end
1206
1232
1207 def test_show_should_allow_assignee_access_to_private_issue
1233 def test_show_should_allow_assignee_access_to_private_issue
1208 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
1234 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
1209 @request.session[:user_id] = 3
1235 @request.session[:user_id] = 3
1210 get :show, :id => 1
1236 get :show, :id => 1
1211 assert_response :success
1237 assert_response :success
1212 end
1238 end
1213
1239
1214 def test_show_should_allow_member_access_to_private_issue_with_permission
1240 def test_show_should_allow_member_access_to_private_issue_with_permission
1215 Issue.where(:id => 1).update_all(["is_private = ?", true])
1241 Issue.where(:id => 1).update_all(["is_private = ?", true])
1216 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1242 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1217 @request.session[:user_id] = 3
1243 @request.session[:user_id] = 3
1218 get :show, :id => 1
1244 get :show, :id => 1
1219 assert_response :success
1245 assert_response :success
1220 end
1246 end
1221
1247
1222 def test_show_should_not_disclose_relations_to_invisible_issues
1248 def test_show_should_not_disclose_relations_to_invisible_issues
1223 Setting.cross_project_issue_relations = '1'
1249 Setting.cross_project_issue_relations = '1'
1224 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1250 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1225 # Relation to a private project issue
1251 # Relation to a private project issue
1226 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1252 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1227
1253
1228 get :show, :id => 1
1254 get :show, :id => 1
1229 assert_response :success
1255 assert_response :success
1230
1256
1231 assert_select 'div#relations' do
1257 assert_select 'div#relations' do
1232 assert_select 'a', :text => /#2$/
1258 assert_select 'a', :text => /#2$/
1233 assert_select 'a', :text => /#4$/, :count => 0
1259 assert_select 'a', :text => /#4$/, :count => 0
1234 end
1260 end
1235 end
1261 end
1236
1262
1237 def test_show_should_list_subtasks
1263 def test_show_should_list_subtasks
1238 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1264 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1239
1265
1240 get :show, :id => 1
1266 get :show, :id => 1
1241 assert_response :success
1267 assert_response :success
1242
1268
1243 assert_select 'div#issue_tree' do
1269 assert_select 'div#issue_tree' do
1244 assert_select 'td.subject', :text => /Child Issue/
1270 assert_select 'td.subject', :text => /Child Issue/
1245 end
1271 end
1246 end
1272 end
1247
1273
1248 def test_show_should_list_parents
1274 def test_show_should_list_parents
1249 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1275 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1250
1276
1251 get :show, :id => issue.id
1277 get :show, :id => issue.id
1252 assert_response :success
1278 assert_response :success
1253
1279
1254 assert_select 'div.subject' do
1280 assert_select 'div.subject' do
1255 assert_select 'h3', 'Child Issue'
1281 assert_select 'h3', 'Child Issue'
1256 assert_select 'a[href="/issues/1"]'
1282 assert_select 'a[href="/issues/1"]'
1257 end
1283 end
1258 end
1284 end
1259
1285
1260 def test_show_should_not_display_prev_next_links_without_query_in_session
1286 def test_show_should_not_display_prev_next_links_without_query_in_session
1261 get :show, :id => 1
1287 get :show, :id => 1
1262 assert_response :success
1288 assert_response :success
1263 assert_nil assigns(:prev_issue_id)
1289 assert_nil assigns(:prev_issue_id)
1264 assert_nil assigns(:next_issue_id)
1290 assert_nil assigns(:next_issue_id)
1265
1291
1266 assert_select 'div.next-prev-links', 0
1292 assert_select 'div.next-prev-links', 0
1267 end
1293 end
1268
1294
1269 def test_show_should_display_prev_next_links_with_query_in_session
1295 def test_show_should_display_prev_next_links_with_query_in_session
1270 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1296 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1271 @request.session['issues_index_sort'] = 'id'
1297 @request.session['issues_index_sort'] = 'id'
1272
1298
1273 with_settings :display_subprojects_issues => '0' do
1299 with_settings :display_subprojects_issues => '0' do
1274 get :show, :id => 3
1300 get :show, :id => 3
1275 end
1301 end
1276
1302
1277 assert_response :success
1303 assert_response :success
1278 # Previous and next issues for all projects
1304 # Previous and next issues for all projects
1279 assert_equal 2, assigns(:prev_issue_id)
1305 assert_equal 2, assigns(:prev_issue_id)
1280 assert_equal 5, assigns(:next_issue_id)
1306 assert_equal 5, assigns(:next_issue_id)
1281
1307
1282 count = Issue.open.visible.count
1308 count = Issue.open.visible.count
1283
1309
1284 assert_select 'div.next-prev-links' do
1310 assert_select 'div.next-prev-links' do
1285 assert_select 'a[href="/issues/2"]', :text => /Previous/
1311 assert_select 'a[href="/issues/2"]', :text => /Previous/
1286 assert_select 'a[href="/issues/5"]', :text => /Next/
1312 assert_select 'a[href="/issues/5"]', :text => /Next/
1287 assert_select 'span.position', :text => "3 of #{count}"
1313 assert_select 'span.position', :text => "3 of #{count}"
1288 end
1314 end
1289 end
1315 end
1290
1316
1291 def test_show_should_display_prev_next_links_with_saved_query_in_session
1317 def test_show_should_display_prev_next_links_with_saved_query_in_session
1292 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
1318 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
1293 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1319 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1294 :sort_criteria => [['id', 'asc']])
1320 :sort_criteria => [['id', 'asc']])
1295 @request.session[:query] = {:id => query.id, :project_id => nil}
1321 @request.session[:query] = {:id => query.id, :project_id => nil}
1296
1322
1297 get :show, :id => 11
1323 get :show, :id => 11
1298
1324
1299 assert_response :success
1325 assert_response :success
1300 assert_equal query, assigns(:query)
1326 assert_equal query, assigns(:query)
1301 # Previous and next issues for all projects
1327 # Previous and next issues for all projects
1302 assert_equal 8, assigns(:prev_issue_id)
1328 assert_equal 8, assigns(:prev_issue_id)
1303 assert_equal 12, assigns(:next_issue_id)
1329 assert_equal 12, assigns(:next_issue_id)
1304
1330
1305 assert_select 'div.next-prev-links' do
1331 assert_select 'div.next-prev-links' do
1306 assert_select 'a[href="/issues/8"]', :text => /Previous/
1332 assert_select 'a[href="/issues/8"]', :text => /Previous/
1307 assert_select 'a[href="/issues/12"]', :text => /Next/
1333 assert_select 'a[href="/issues/12"]', :text => /Next/
1308 end
1334 end
1309 end
1335 end
1310
1336
1311 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1337 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1312 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1338 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1313
1339
1314 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1340 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1315 @request.session['issues_index_sort'] = assoc_sort
1341 @request.session['issues_index_sort'] = assoc_sort
1316
1342
1317 get :show, :id => 3
1343 get :show, :id => 3
1318 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1344 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1319
1345
1320 assert_select 'div.next-prev-links' do
1346 assert_select 'div.next-prev-links' do
1321 assert_select 'a', :text => /(Previous|Next)/
1347 assert_select 'a', :text => /(Previous|Next)/
1322 end
1348 end
1323 end
1349 end
1324 end
1350 end
1325
1351
1326 def test_show_should_display_prev_next_links_with_project_query_in_session
1352 def test_show_should_display_prev_next_links_with_project_query_in_session
1327 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1353 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1328 @request.session['issues_index_sort'] = 'id'
1354 @request.session['issues_index_sort'] = 'id'
1329
1355
1330 with_settings :display_subprojects_issues => '0' do
1356 with_settings :display_subprojects_issues => '0' do
1331 get :show, :id => 3
1357 get :show, :id => 3
1332 end
1358 end
1333
1359
1334 assert_response :success
1360 assert_response :success
1335 # Previous and next issues inside project
1361 # Previous and next issues inside project
1336 assert_equal 2, assigns(:prev_issue_id)
1362 assert_equal 2, assigns(:prev_issue_id)
1337 assert_equal 7, assigns(:next_issue_id)
1363 assert_equal 7, assigns(:next_issue_id)
1338
1364
1339 assert_select 'div.next-prev-links' do
1365 assert_select 'div.next-prev-links' do
1340 assert_select 'a[href="/issues/2"]', :text => /Previous/
1366 assert_select 'a[href="/issues/2"]', :text => /Previous/
1341 assert_select 'a[href="/issues/7"]', :text => /Next/
1367 assert_select 'a[href="/issues/7"]', :text => /Next/
1342 end
1368 end
1343 end
1369 end
1344
1370
1345 def test_show_should_not_display_prev_link_for_first_issue
1371 def test_show_should_not_display_prev_link_for_first_issue
1346 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1372 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1347 @request.session['issues_index_sort'] = 'id'
1373 @request.session['issues_index_sort'] = 'id'
1348
1374
1349 with_settings :display_subprojects_issues => '0' do
1375 with_settings :display_subprojects_issues => '0' do
1350 get :show, :id => 1
1376 get :show, :id => 1
1351 end
1377 end
1352
1378
1353 assert_response :success
1379 assert_response :success
1354 assert_nil assigns(:prev_issue_id)
1380 assert_nil assigns(:prev_issue_id)
1355 assert_equal 2, assigns(:next_issue_id)
1381 assert_equal 2, assigns(:next_issue_id)
1356
1382
1357 assert_select 'div.next-prev-links' do
1383 assert_select 'div.next-prev-links' do
1358 assert_select 'a', :text => /Previous/, :count => 0
1384 assert_select 'a', :text => /Previous/, :count => 0
1359 assert_select 'a[href="/issues/2"]', :text => /Next/
1385 assert_select 'a[href="/issues/2"]', :text => /Next/
1360 end
1386 end
1361 end
1387 end
1362
1388
1363 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1389 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1364 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1390 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1365 @request.session['issues_index_sort'] = 'id'
1391 @request.session['issues_index_sort'] = 'id'
1366
1392
1367 get :show, :id => 1
1393 get :show, :id => 1
1368
1394
1369 assert_response :success
1395 assert_response :success
1370 assert_nil assigns(:prev_issue_id)
1396 assert_nil assigns(:prev_issue_id)
1371 assert_nil assigns(:next_issue_id)
1397 assert_nil assigns(:next_issue_id)
1372
1398
1373 assert_select 'a', :text => /Previous/, :count => 0
1399 assert_select 'a', :text => /Previous/, :count => 0
1374 assert_select 'a', :text => /Next/, :count => 0
1400 assert_select 'a', :text => /Next/, :count => 0
1375 end
1401 end
1376
1402
1377 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1403 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1378 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1404 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1379 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1405 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1380 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1406 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1381 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1407 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1382 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1408 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1383
1409
1384 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
1410 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
1385 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1411 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1386 @request.session[:query] = {:id => query.id, :project_id => nil}
1412 @request.session[:query] = {:id => query.id, :project_id => nil}
1387
1413
1388 get :show, :id => 3
1414 get :show, :id => 3
1389 assert_response :success
1415 assert_response :success
1390
1416
1391 assert_equal 2, assigns(:prev_issue_id)
1417 assert_equal 2, assigns(:prev_issue_id)
1392 assert_equal 1, assigns(:next_issue_id)
1418 assert_equal 1, assigns(:next_issue_id)
1393
1419
1394 assert_select 'div.next-prev-links' do
1420 assert_select 'div.next-prev-links' do
1395 assert_select 'a[href="/issues/2"]', :text => /Previous/
1421 assert_select 'a[href="/issues/2"]', :text => /Previous/
1396 assert_select 'a[href="/issues/1"]', :text => /Next/
1422 assert_select 'a[href="/issues/1"]', :text => /Next/
1397 end
1423 end
1398 end
1424 end
1399
1425
1400 def test_show_should_display_category_field_if_categories_are_defined
1426 def test_show_should_display_category_field_if_categories_are_defined
1401 Issue.update_all :category_id => nil
1427 Issue.update_all :category_id => nil
1402
1428
1403 get :show, :id => 1
1429 get :show, :id => 1
1404 assert_response :success
1430 assert_response :success
1405 assert_select '.attributes .category'
1431 assert_select '.attributes .category'
1406 end
1432 end
1407
1433
1408 def test_show_should_not_display_category_field_if_no_categories_are_defined
1434 def test_show_should_not_display_category_field_if_no_categories_are_defined
1409 Project.find(1).issue_categories.delete_all
1435 Project.find(1).issue_categories.delete_all
1410
1436
1411 get :show, :id => 1
1437 get :show, :id => 1
1412 assert_response :success
1438 assert_response :success
1413 assert_select 'table.attributes .category', 0
1439 assert_select 'table.attributes .category', 0
1414 end
1440 end
1415
1441
1416 def test_show_should_display_link_to_the_assignee
1442 def test_show_should_display_link_to_the_assignee
1417 get :show, :id => 2
1443 get :show, :id => 2
1418 assert_response :success
1444 assert_response :success
1419 assert_select '.assigned-to' do
1445 assert_select '.assigned-to' do
1420 assert_select 'a[href="/users/3"]'
1446 assert_select 'a[href="/users/3"]'
1421 end
1447 end
1422 end
1448 end
1423
1449
1424 def test_show_should_display_visible_changesets_from_other_projects
1450 def test_show_should_display_visible_changesets_from_other_projects
1425 project = Project.find(2)
1451 project = Project.find(2)
1426 issue = project.issues.first
1452 issue = project.issues.first
1427 issue.changeset_ids = [102]
1453 issue.changeset_ids = [102]
1428 issue.save!
1454 issue.save!
1429 # changesets from other projects should be displayed even if repository
1455 # changesets from other projects should be displayed even if repository
1430 # is disabled on issue's project
1456 # is disabled on issue's project
1431 project.disable_module! :repository
1457 project.disable_module! :repository
1432
1458
1433 @request.session[:user_id] = 2
1459 @request.session[:user_id] = 2
1434 get :show, :id => issue.id
1460 get :show, :id => issue.id
1435
1461
1436 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1462 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1437 end
1463 end
1438
1464
1439 def test_show_should_display_watchers
1465 def test_show_should_display_watchers
1440 @request.session[:user_id] = 2
1466 @request.session[:user_id] = 2
1441 Issue.find(1).add_watcher User.find(2)
1467 Issue.find(1).add_watcher User.find(2)
1442
1468
1443 get :show, :id => 1
1469 get :show, :id => 1
1444 assert_select 'div#watchers ul' do
1470 assert_select 'div#watchers ul' do
1445 assert_select 'li' do
1471 assert_select 'li' do
1446 assert_select 'a[href="/users/2"]'
1472 assert_select 'a[href="/users/2"]'
1447 assert_select 'a[class*=delete]'
1473 assert_select 'a[class*=delete]'
1448 end
1474 end
1449 end
1475 end
1450 end
1476 end
1451
1477
1452 def test_show_should_display_watchers_with_gravatars
1478 def test_show_should_display_watchers_with_gravatars
1453 @request.session[:user_id] = 2
1479 @request.session[:user_id] = 2
1454 Issue.find(1).add_watcher User.find(2)
1480 Issue.find(1).add_watcher User.find(2)
1455
1481
1456 with_settings :gravatar_enabled => '1' do
1482 with_settings :gravatar_enabled => '1' do
1457 get :show, :id => 1
1483 get :show, :id => 1
1458 end
1484 end
1459
1485
1460 assert_select 'div#watchers ul' do
1486 assert_select 'div#watchers ul' do
1461 assert_select 'li' do
1487 assert_select 'li' do
1462 assert_select 'img.gravatar'
1488 assert_select 'img.gravatar'
1463 assert_select 'a[href="/users/2"]'
1489 assert_select 'a[href="/users/2"]'
1464 assert_select 'a[class*=delete]'
1490 assert_select 'a[class*=delete]'
1465 end
1491 end
1466 end
1492 end
1467 end
1493 end
1468
1494
1469 def test_show_with_thumbnails_enabled_should_display_thumbnails
1495 def test_show_with_thumbnails_enabled_should_display_thumbnails
1470 @request.session[:user_id] = 2
1496 @request.session[:user_id] = 2
1471
1497
1472 with_settings :thumbnails_enabled => '1' do
1498 with_settings :thumbnails_enabled => '1' do
1473 get :show, :id => 14
1499 get :show, :id => 14
1474 assert_response :success
1500 assert_response :success
1475 end
1501 end
1476
1502
1477 assert_select 'div.thumbnails' do
1503 assert_select 'div.thumbnails' do
1478 assert_select 'a[href="/attachments/16/testfile.png"]' do
1504 assert_select 'a[href="/attachments/16/testfile.png"]' do
1479 assert_select 'img[src="/attachments/thumbnail/16"]'
1505 assert_select 'img[src="/attachments/thumbnail/16"]'
1480 end
1506 end
1481 end
1507 end
1482 end
1508 end
1483
1509
1484 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1510 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1485 @request.session[:user_id] = 2
1511 @request.session[:user_id] = 2
1486
1512
1487 with_settings :thumbnails_enabled => '0' do
1513 with_settings :thumbnails_enabled => '0' do
1488 get :show, :id => 14
1514 get :show, :id => 14
1489 assert_response :success
1515 assert_response :success
1490 end
1516 end
1491
1517
1492 assert_select 'div.thumbnails', 0
1518 assert_select 'div.thumbnails', 0
1493 end
1519 end
1494
1520
1495 def test_show_with_multi_custom_field
1521 def test_show_with_multi_custom_field
1496 field = CustomField.find(1)
1522 field = CustomField.find(1)
1497 field.update_attribute :multiple, true
1523 field.update_attribute :multiple, true
1498 issue = Issue.find(1)
1524 issue = Issue.find(1)
1499 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1525 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1500 issue.save!
1526 issue.save!
1501
1527
1502 get :show, :id => 1
1528 get :show, :id => 1
1503 assert_response :success
1529 assert_response :success
1504
1530
1505 assert_select ".cf_1 .value", :text => 'MySQL, Oracle'
1531 assert_select ".cf_1 .value", :text => 'MySQL, Oracle'
1506 end
1532 end
1507
1533
1508 def test_show_with_multi_user_custom_field
1534 def test_show_with_multi_user_custom_field
1509 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1535 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1510 :tracker_ids => [1], :is_for_all => true)
1536 :tracker_ids => [1], :is_for_all => true)
1511 issue = Issue.find(1)
1537 issue = Issue.find(1)
1512 issue.custom_field_values = {field.id => ['2', '3']}
1538 issue.custom_field_values = {field.id => ['2', '3']}
1513 issue.save!
1539 issue.save!
1514
1540
1515 get :show, :id => 1
1541 get :show, :id => 1
1516 assert_response :success
1542 assert_response :success
1517
1543
1518 assert_select ".cf_#{field.id} .value", :text => 'Dave Lopper, John Smith' do
1544 assert_select ".cf_#{field.id} .value", :text => 'Dave Lopper, John Smith' do
1519 assert_select 'a', :text => 'Dave Lopper'
1545 assert_select 'a', :text => 'Dave Lopper'
1520 assert_select 'a', :text => 'John Smith'
1546 assert_select 'a', :text => 'John Smith'
1521 end
1547 end
1522 end
1548 end
1523
1549
1524 def test_show_should_display_private_notes_with_permission_only
1550 def test_show_should_display_private_notes_with_permission_only
1525 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1551 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1526 @request.session[:user_id] = 2
1552 @request.session[:user_id] = 2
1527
1553
1528 get :show, :id => 2
1554 get :show, :id => 2
1529 assert_response :success
1555 assert_response :success
1530 assert_include journal, assigns(:journals)
1556 assert_include journal, assigns(:journals)
1531
1557
1532 Role.find(1).remove_permission! :view_private_notes
1558 Role.find(1).remove_permission! :view_private_notes
1533 get :show, :id => 2
1559 get :show, :id => 2
1534 assert_response :success
1560 assert_response :success
1535 assert_not_include journal, assigns(:journals)
1561 assert_not_include journal, assigns(:journals)
1536 end
1562 end
1537
1563
1538 def test_show_atom
1564 def test_show_atom
1539 get :show, :id => 2, :format => 'atom'
1565 get :show, :id => 2, :format => 'atom'
1540 assert_response :success
1566 assert_response :success
1541 assert_template 'journals/index'
1567 assert_template 'journals/index'
1542 # Inline image
1568 # Inline image
1543 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1569 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1544 end
1570 end
1545
1571
1546 def test_show_export_to_pdf
1572 def test_show_export_to_pdf
1547 issue = Issue.find(3)
1573 issue = Issue.find(3)
1548 assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
1574 assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
1549 get :show, :id => 3, :format => 'pdf'
1575 get :show, :id => 3, :format => 'pdf'
1550 assert_response :success
1576 assert_response :success
1551 assert_equal 'application/pdf', @response.content_type
1577 assert_equal 'application/pdf', @response.content_type
1552 assert @response.body.starts_with?('%PDF')
1578 assert @response.body.starts_with?('%PDF')
1553 assert_not_nil assigns(:issue)
1579 assert_not_nil assigns(:issue)
1554 end
1580 end
1555
1581
1556 def test_export_to_pdf_with_utf8_u_fffd
1582 def test_export_to_pdf_with_utf8_u_fffd
1557 # U+FFFD
1583 # U+FFFD
1558 s = "\xef\xbf\xbd"
1584 s = "\xef\xbf\xbd"
1559 s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
1585 s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
1560 issue = Issue.generate!(:subject => s)
1586 issue = Issue.generate!(:subject => s)
1561 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
1587 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
1562 with_settings :default_language => lang do
1588 with_settings :default_language => lang do
1563 get :show, :id => issue.id, :format => 'pdf'
1589 get :show, :id => issue.id, :format => 'pdf'
1564 assert_response :success
1590 assert_response :success
1565 assert_equal 'application/pdf', @response.content_type
1591 assert_equal 'application/pdf', @response.content_type
1566 assert @response.body.starts_with?('%PDF')
1592 assert @response.body.starts_with?('%PDF')
1567 assert_not_nil assigns(:issue)
1593 assert_not_nil assigns(:issue)
1568 end
1594 end
1569 end
1595 end
1570 end
1596 end
1571
1597
1572 def test_show_export_to_pdf_with_ancestors
1598 def test_show_export_to_pdf_with_ancestors
1573 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1599 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1574
1600
1575 get :show, :id => issue.id, :format => 'pdf'
1601 get :show, :id => issue.id, :format => 'pdf'
1576 assert_response :success
1602 assert_response :success
1577 assert_equal 'application/pdf', @response.content_type
1603 assert_equal 'application/pdf', @response.content_type
1578 assert @response.body.starts_with?('%PDF')
1604 assert @response.body.starts_with?('%PDF')
1579 end
1605 end
1580
1606
1581 def test_show_export_to_pdf_with_descendants
1607 def test_show_export_to_pdf_with_descendants
1582 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1608 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1583 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1609 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1584 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1610 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1585
1611
1586 get :show, :id => 1, :format => 'pdf'
1612 get :show, :id => 1, :format => 'pdf'
1587 assert_response :success
1613 assert_response :success
1588 assert_equal 'application/pdf', @response.content_type
1614 assert_equal 'application/pdf', @response.content_type
1589 assert @response.body.starts_with?('%PDF')
1615 assert @response.body.starts_with?('%PDF')
1590 end
1616 end
1591
1617
1592 def test_show_export_to_pdf_with_journals
1618 def test_show_export_to_pdf_with_journals
1593 get :show, :id => 1, :format => 'pdf'
1619 get :show, :id => 1, :format => 'pdf'
1594 assert_response :success
1620 assert_response :success
1595 assert_equal 'application/pdf', @response.content_type
1621 assert_equal 'application/pdf', @response.content_type
1596 assert @response.body.starts_with?('%PDF')
1622 assert @response.body.starts_with?('%PDF')
1597 end
1623 end
1598
1624
1599 def test_show_export_to_pdf_with_changesets
1625 def test_show_export_to_pdf_with_changesets
1600 [[100], [100, 101], [100, 101, 102]].each do |cs|
1626 [[100], [100, 101], [100, 101, 102]].each do |cs|
1601 issue1 = Issue.find(3)
1627 issue1 = Issue.find(3)
1602 issue1.changesets = Changeset.find(cs)
1628 issue1.changesets = Changeset.find(cs)
1603 issue1.save!
1629 issue1.save!
1604 issue = Issue.find(3)
1630 issue = Issue.find(3)
1605 assert_equal issue.changesets.count, cs.size
1631 assert_equal issue.changesets.count, cs.size
1606 get :show, :id => 3, :format => 'pdf'
1632 get :show, :id => 3, :format => 'pdf'
1607 assert_response :success
1633 assert_response :success
1608 assert_equal 'application/pdf', @response.content_type
1634 assert_equal 'application/pdf', @response.content_type
1609 assert @response.body.starts_with?('%PDF')
1635 assert @response.body.starts_with?('%PDF')
1610 end
1636 end
1611 end
1637 end
1612
1638
1613 def test_show_invalid_should_respond_with_404
1639 def test_show_invalid_should_respond_with_404
1614 get :show, :id => 999
1640 get :show, :id => 999
1615 assert_response 404
1641 assert_response 404
1616 end
1642 end
1617
1643
1618 def test_get_new
1644 def test_get_new
1619 @request.session[:user_id] = 2
1645 @request.session[:user_id] = 2
1620 get :new, :project_id => 1, :tracker_id => 1
1646 get :new, :project_id => 1, :tracker_id => 1
1621 assert_response :success
1647 assert_response :success
1622 assert_template 'new'
1648 assert_template 'new'
1623
1649
1624 assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues'
1650 assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues'
1625 assert_select 'form#issue-form' do
1651 assert_select 'form#issue-form' do
1626 assert_select 'input[name=?]', 'issue[is_private]'
1652 assert_select 'input[name=?]', 'issue[is_private]'
1627 assert_select 'select[name=?]', 'issue[project_id]', 0
1653 assert_select 'select[name=?]', 'issue[project_id]', 0
1628 assert_select 'select[name=?]', 'issue[tracker_id]'
1654 assert_select 'select[name=?]', 'issue[tracker_id]'
1629 assert_select 'input[name=?]', 'issue[subject]'
1655 assert_select 'input[name=?]', 'issue[subject]'
1630 assert_select 'textarea[name=?]', 'issue[description]'
1656 assert_select 'textarea[name=?]', 'issue[description]'
1631 assert_select 'select[name=?]', 'issue[status_id]'
1657 assert_select 'select[name=?]', 'issue[status_id]'
1632 assert_select 'select[name=?]', 'issue[priority_id]'
1658 assert_select 'select[name=?]', 'issue[priority_id]'
1633 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1659 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1634 assert_select 'select[name=?]', 'issue[category_id]'
1660 assert_select 'select[name=?]', 'issue[category_id]'
1635 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1661 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1636 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1662 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1637 assert_select 'input[name=?]', 'issue[start_date]'
1663 assert_select 'input[name=?]', 'issue[start_date]'
1638 assert_select 'input[name=?]', 'issue[due_date]'
1664 assert_select 'input[name=?]', 'issue[due_date]'
1639 assert_select 'select[name=?]', 'issue[done_ratio]'
1665 assert_select 'select[name=?]', 'issue[done_ratio]'
1640 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1666 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1641 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1667 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1642 end
1668 end
1643
1669
1644 # Be sure we don't display inactive IssuePriorities
1670 # Be sure we don't display inactive IssuePriorities
1645 assert ! IssuePriority.find(15).active?
1671 assert ! IssuePriority.find(15).active?
1646 assert_select 'select[name=?]', 'issue[priority_id]' do
1672 assert_select 'select[name=?]', 'issue[priority_id]' do
1647 assert_select 'option[value="15"]', 0
1673 assert_select 'option[value="15"]', 0
1648 end
1674 end
1649 end
1675 end
1650
1676
1651 def test_get_new_with_minimal_permissions
1677 def test_get_new_with_minimal_permissions
1652 Role.find(1).update_attribute :permissions, [:add_issues]
1678 Role.find(1).update_attribute :permissions, [:add_issues]
1653 WorkflowTransition.delete_all :role_id => 1
1679 WorkflowTransition.delete_all :role_id => 1
1654
1680
1655 @request.session[:user_id] = 2
1681 @request.session[:user_id] = 2
1656 get :new, :project_id => 1, :tracker_id => 1
1682 get :new, :project_id => 1, :tracker_id => 1
1657 assert_response :success
1683 assert_response :success
1658 assert_template 'new'
1684 assert_template 'new'
1659
1685
1660 assert_select 'form#issue-form' do
1686 assert_select 'form#issue-form' do
1661 assert_select 'input[name=?]', 'issue[is_private]', 0
1687 assert_select 'input[name=?]', 'issue[is_private]', 0
1662 assert_select 'select[name=?]', 'issue[project_id]', 0
1688 assert_select 'select[name=?]', 'issue[project_id]', 0
1663 assert_select 'select[name=?]', 'issue[tracker_id]'
1689 assert_select 'select[name=?]', 'issue[tracker_id]'
1664 assert_select 'input[name=?]', 'issue[subject]'
1690 assert_select 'input[name=?]', 'issue[subject]'
1665 assert_select 'textarea[name=?]', 'issue[description]'
1691 assert_select 'textarea[name=?]', 'issue[description]'
1666 assert_select 'select[name=?]', 'issue[status_id]'
1692 assert_select 'select[name=?]', 'issue[status_id]'
1667 assert_select 'select[name=?]', 'issue[priority_id]'
1693 assert_select 'select[name=?]', 'issue[priority_id]'
1668 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1694 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1669 assert_select 'select[name=?]', 'issue[category_id]'
1695 assert_select 'select[name=?]', 'issue[category_id]'
1670 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1696 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1671 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1697 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1672 assert_select 'input[name=?]', 'issue[start_date]'
1698 assert_select 'input[name=?]', 'issue[start_date]'
1673 assert_select 'input[name=?]', 'issue[due_date]'
1699 assert_select 'input[name=?]', 'issue[due_date]'
1674 assert_select 'select[name=?]', 'issue[done_ratio]'
1700 assert_select 'select[name=?]', 'issue[done_ratio]'
1675 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1701 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1676 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1702 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1677 end
1703 end
1678 end
1704 end
1679
1705
1680 def test_new_without_project_id
1706 def test_new_without_project_id
1681 @request.session[:user_id] = 2
1707 @request.session[:user_id] = 2
1682 get :new
1708 get :new
1683 assert_response :success
1709 assert_response :success
1684 assert_template 'new'
1710 assert_template 'new'
1685
1711
1686 assert_select 'form#issue-form[action=?]', '/issues'
1712 assert_select 'form#issue-form[action=?]', '/issues'
1687 assert_select 'form#issue-form' do
1713 assert_select 'form#issue-form' do
1688 assert_select 'select[name=?]', 'issue[project_id]'
1714 assert_select 'select[name=?]', 'issue[project_id]'
1689 end
1715 end
1690
1716
1691 assert_nil assigns(:project)
1717 assert_nil assigns(:project)
1692 assert_not_nil assigns(:issue)
1718 assert_not_nil assigns(:issue)
1693 end
1719 end
1694
1720
1695 def test_new_should_select_default_status
1721 def test_new_should_select_default_status
1696 @request.session[:user_id] = 2
1722 @request.session[:user_id] = 2
1697
1723
1698 get :new, :project_id => 1
1724 get :new, :project_id => 1
1699 assert_response :success
1725 assert_response :success
1700 assert_template 'new'
1726 assert_template 'new'
1701 assert_select 'select[name=?]', 'issue[status_id]' do
1727 assert_select 'select[name=?]', 'issue[status_id]' do
1702 assert_select 'option[value="1"][selected=selected]'
1728 assert_select 'option[value="1"][selected=selected]'
1703 end
1729 end
1704 assert_select 'input[name=was_default_status][value="1"]'
1730 assert_select 'input[name=was_default_status][value="1"]'
1705 end
1731 end
1706
1732
1707 def test_new_should_propose_allowed_statuses
1733 def test_new_should_propose_allowed_statuses
1708 WorkflowTransition.delete_all
1734 WorkflowTransition.delete_all
1709 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 1)
1735 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 1)
1710 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 3)
1736 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 3)
1711 @request.session[:user_id] = 2
1737 @request.session[:user_id] = 2
1712
1738
1713 get :new, :project_id => 1
1739 get :new, :project_id => 1
1714 assert_response :success
1740 assert_response :success
1715 assert_select 'select[name=?]', 'issue[status_id]' do
1741 assert_select 'select[name=?]', 'issue[status_id]' do
1716 assert_select 'option[value="1"]'
1742 assert_select 'option[value="1"]'
1717 assert_select 'option[value="3"]'
1743 assert_select 'option[value="3"]'
1718 assert_select 'option', 2
1744 assert_select 'option', 2
1719 assert_select 'option[value="1"][selected=selected]'
1745 assert_select 'option[value="1"][selected=selected]'
1720 end
1746 end
1721 end
1747 end
1722
1748
1723 def test_new_should_propose_allowed_statuses_without_default_status_allowed
1749 def test_new_should_propose_allowed_statuses_without_default_status_allowed
1724 WorkflowTransition.delete_all
1750 WorkflowTransition.delete_all
1725 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 2)
1751 WorkflowTransition.create!(:tracker_id => 1, :role_id => 1, :old_status_id => 0, :new_status_id => 2)
1726 assert_equal 1, Tracker.find(1).default_status_id
1752 assert_equal 1, Tracker.find(1).default_status_id
1727 @request.session[:user_id] = 2
1753 @request.session[:user_id] = 2
1728
1754
1729 get :new, :project_id => 1
1755 get :new, :project_id => 1
1730 assert_response :success
1756 assert_response :success
1731 assert_select 'select[name=?]', 'issue[status_id]' do
1757 assert_select 'select[name=?]', 'issue[status_id]' do
1732 assert_select 'option[value="2"]'
1758 assert_select 'option[value="2"]'
1733 assert_select 'option', 1
1759 assert_select 'option', 1
1734 assert_select 'option[value="2"][selected=selected]'
1760 assert_select 'option[value="2"][selected=selected]'
1735 end
1761 end
1736 end
1762 end
1737
1763
1738 def test_new_should_preselect_default_version
1764 def test_new_should_preselect_default_version
1739 version = Version.generate!(:project_id => 1)
1765 version = Version.generate!(:project_id => 1)
1740 Project.find(1).update_attribute :default_version_id, version.id
1766 Project.find(1).update_attribute :default_version_id, version.id
1741 @request.session[:user_id] = 2
1767 @request.session[:user_id] = 2
1742
1768
1743 get :new, :project_id => 1
1769 get :new, :project_id => 1
1744 assert_response :success
1770 assert_response :success
1745 assert_equal version, assigns(:issue).fixed_version
1771 assert_equal version, assigns(:issue).fixed_version
1746 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
1772 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
1747 assert_select 'option[value=?][selected=selected]', version.id.to_s
1773 assert_select 'option[value=?][selected=selected]', version.id.to_s
1748 end
1774 end
1749 end
1775 end
1750
1776
1751 def test_get_new_with_list_custom_field
1777 def test_get_new_with_list_custom_field
1752 @request.session[:user_id] = 2
1778 @request.session[:user_id] = 2
1753 get :new, :project_id => 1, :tracker_id => 1
1779 get :new, :project_id => 1, :tracker_id => 1
1754 assert_response :success
1780 assert_response :success
1755 assert_template 'new'
1781 assert_template 'new'
1756
1782
1757 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1783 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1758 assert_select 'option', 4
1784 assert_select 'option', 4
1759 assert_select 'option[value=MySQL]', :text => 'MySQL'
1785 assert_select 'option[value=MySQL]', :text => 'MySQL'
1760 end
1786 end
1761 end
1787 end
1762
1788
1763 def test_get_new_with_multi_custom_field
1789 def test_get_new_with_multi_custom_field
1764 field = IssueCustomField.find(1)
1790 field = IssueCustomField.find(1)
1765 field.update_attribute :multiple, true
1791 field.update_attribute :multiple, true
1766
1792
1767 @request.session[:user_id] = 2
1793 @request.session[:user_id] = 2
1768 get :new, :project_id => 1, :tracker_id => 1
1794 get :new, :project_id => 1, :tracker_id => 1
1769 assert_response :success
1795 assert_response :success
1770 assert_template 'new'
1796 assert_template 'new'
1771
1797
1772 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1798 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1773 assert_select 'option', 3
1799 assert_select 'option', 3
1774 assert_select 'option[value=MySQL]', :text => 'MySQL'
1800 assert_select 'option[value=MySQL]', :text => 'MySQL'
1775 end
1801 end
1776 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1802 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1777 end
1803 end
1778
1804
1779 def test_get_new_with_multi_user_custom_field
1805 def test_get_new_with_multi_user_custom_field
1780 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1806 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1781 :tracker_ids => [1], :is_for_all => true)
1807 :tracker_ids => [1], :is_for_all => true)
1782
1808
1783 @request.session[:user_id] = 2
1809 @request.session[:user_id] = 2
1784 get :new, :project_id => 1, :tracker_id => 1
1810 get :new, :project_id => 1, :tracker_id => 1
1785 assert_response :success
1811 assert_response :success
1786 assert_template 'new'
1812 assert_template 'new'
1787
1813
1788 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1814 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1789 assert_select 'option', Project.find(1).users.count
1815 assert_select 'option', Project.find(1).users.count
1790 assert_select 'option[value="2"]', :text => 'John Smith'
1816 assert_select 'option[value="2"]', :text => 'John Smith'
1791 end
1817 end
1792 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1818 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1793 end
1819 end
1794
1820
1795 def test_get_new_with_date_custom_field
1821 def test_get_new_with_date_custom_field
1796 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1822 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1797
1823
1798 @request.session[:user_id] = 2
1824 @request.session[:user_id] = 2
1799 get :new, :project_id => 1, :tracker_id => 1
1825 get :new, :project_id => 1, :tracker_id => 1
1800 assert_response :success
1826 assert_response :success
1801
1827
1802 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1828 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1803 end
1829 end
1804
1830
1805 def test_get_new_with_text_custom_field
1831 def test_get_new_with_text_custom_field
1806 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1832 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1807
1833
1808 @request.session[:user_id] = 2
1834 @request.session[:user_id] = 2
1809 get :new, :project_id => 1, :tracker_id => 1
1835 get :new, :project_id => 1, :tracker_id => 1
1810 assert_response :success
1836 assert_response :success
1811
1837
1812 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1838 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1813 end
1839 end
1814
1840
1815 def test_get_new_without_default_start_date_is_creation_date
1841 def test_get_new_without_default_start_date_is_creation_date
1816 with_settings :default_issue_start_date_to_creation_date => 0 do
1842 with_settings :default_issue_start_date_to_creation_date => 0 do
1817 @request.session[:user_id] = 2
1843 @request.session[:user_id] = 2
1818 get :new, :project_id => 1, :tracker_id => 1
1844 get :new, :project_id => 1, :tracker_id => 1
1819 assert_response :success
1845 assert_response :success
1820 assert_template 'new'
1846 assert_template 'new'
1821 assert_select 'input[name=?]', 'issue[start_date]'
1847 assert_select 'input[name=?]', 'issue[start_date]'
1822 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1848 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1823 end
1849 end
1824 end
1850 end
1825
1851
1826 def test_get_new_with_default_start_date_is_creation_date
1852 def test_get_new_with_default_start_date_is_creation_date
1827 with_settings :default_issue_start_date_to_creation_date => 1 do
1853 with_settings :default_issue_start_date_to_creation_date => 1 do
1828 @request.session[:user_id] = 2
1854 @request.session[:user_id] = 2
1829 get :new, :project_id => 1, :tracker_id => 1
1855 get :new, :project_id => 1, :tracker_id => 1
1830 assert_response :success
1856 assert_response :success
1831 assert_template 'new'
1857 assert_template 'new'
1832 assert_select 'input[name=?][value=?]', 'issue[start_date]',
1858 assert_select 'input[name=?][value=?]', 'issue[start_date]',
1833 Date.today.to_s
1859 Date.today.to_s
1834 end
1860 end
1835 end
1861 end
1836
1862
1837 def test_get_new_form_should_allow_attachment_upload
1863 def test_get_new_form_should_allow_attachment_upload
1838 @request.session[:user_id] = 2
1864 @request.session[:user_id] = 2
1839 get :new, :project_id => 1, :tracker_id => 1
1865 get :new, :project_id => 1, :tracker_id => 1
1840
1866
1841 assert_select 'form[id=issue-form][method=post][enctype="multipart/form-data"]' do
1867 assert_select 'form[id=issue-form][method=post][enctype="multipart/form-data"]' do
1842 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1868 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1843 end
1869 end
1844 end
1870 end
1845
1871
1846 def test_get_new_should_prefill_the_form_from_params
1872 def test_get_new_should_prefill_the_form_from_params
1847 @request.session[:user_id] = 2
1873 @request.session[:user_id] = 2
1848 get :new, :project_id => 1,
1874 get :new, :project_id => 1,
1849 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1875 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1850
1876
1851 issue = assigns(:issue)
1877 issue = assigns(:issue)
1852 assert_equal 3, issue.tracker_id
1878 assert_equal 3, issue.tracker_id
1853 assert_equal 'Prefilled', issue.description
1879 assert_equal 'Prefilled', issue.description
1854 assert_equal 'Custom field value', issue.custom_field_value(2)
1880 assert_equal 'Custom field value', issue.custom_field_value(2)
1855
1881
1856 assert_select 'select[name=?]', 'issue[tracker_id]' do
1882 assert_select 'select[name=?]', 'issue[tracker_id]' do
1857 assert_select 'option[value="3"][selected=selected]'
1883 assert_select 'option[value="3"][selected=selected]'
1858 end
1884 end
1859 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1885 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1860 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1886 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1861 end
1887 end
1862
1888
1863 def test_get_new_should_mark_required_fields
1889 def test_get_new_should_mark_required_fields
1864 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1890 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1865 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1891 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1866 WorkflowPermission.delete_all
1892 WorkflowPermission.delete_all
1867 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1893 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1868 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1894 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1869 @request.session[:user_id] = 2
1895 @request.session[:user_id] = 2
1870
1896
1871 get :new, :project_id => 1
1897 get :new, :project_id => 1
1872 assert_response :success
1898 assert_response :success
1873 assert_template 'new'
1899 assert_template 'new'
1874
1900
1875 assert_select 'label[for=issue_start_date]' do
1901 assert_select 'label[for=issue_start_date]' do
1876 assert_select 'span[class=required]', 0
1902 assert_select 'span[class=required]', 0
1877 end
1903 end
1878 assert_select 'label[for=issue_due_date]' do
1904 assert_select 'label[for=issue_due_date]' do
1879 assert_select 'span[class=required]'
1905 assert_select 'span[class=required]'
1880 end
1906 end
1881 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1907 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1882 assert_select 'span[class=required]', 0
1908 assert_select 'span[class=required]', 0
1883 end
1909 end
1884 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1910 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1885 assert_select 'span[class=required]'
1911 assert_select 'span[class=required]'
1886 end
1912 end
1887 end
1913 end
1888
1914
1889 def test_get_new_should_not_display_readonly_fields
1915 def test_get_new_should_not_display_readonly_fields
1890 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1916 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1891 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1917 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1892 WorkflowPermission.delete_all
1918 WorkflowPermission.delete_all
1893 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1919 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1894 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1920 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1895 @request.session[:user_id] = 2
1921 @request.session[:user_id] = 2
1896
1922
1897 get :new, :project_id => 1
1923 get :new, :project_id => 1
1898 assert_response :success
1924 assert_response :success
1899 assert_template 'new'
1925 assert_template 'new'
1900
1926
1901 assert_select 'input[name=?]', 'issue[start_date]'
1927 assert_select 'input[name=?]', 'issue[start_date]'
1902 assert_select 'input[name=?]', 'issue[due_date]', 0
1928 assert_select 'input[name=?]', 'issue[due_date]', 0
1903 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1929 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1904 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1930 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1905 end
1931 end
1906
1932
1907 def test_new_with_tracker_set_as_readonly_should_accept_status
1933 def test_new_with_tracker_set_as_readonly_should_accept_status
1908 WorkflowPermission.delete_all
1934 WorkflowPermission.delete_all
1909 [1, 2].each do |status_id|
1935 [1, 2].each do |status_id|
1910 WorkflowPermission.create!(:tracker_id => 1, :old_status_id => status_id, :role_id => 1, :field_name => 'tracker_id', :rule => 'readonly')
1936 WorkflowPermission.create!(:tracker_id => 1, :old_status_id => status_id, :role_id => 1, :field_name => 'tracker_id', :rule => 'readonly')
1911 end
1937 end
1912 @request.session[:user_id] = 2
1938 @request.session[:user_id] = 2
1913
1939
1914 get :new, :project_id => 1, :issue => {:status_id => 2}
1940 get :new, :project_id => 1, :issue => {:status_id => 2}
1915 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1941 assert_select 'select[name=?]', 'issue[tracker_id]', 0
1916 assert_equal 2, assigns(:issue).status_id
1942 assert_equal 2, assigns(:issue).status_id
1917 end
1943 end
1918
1944
1919 def test_get_new_without_tracker_id
1945 def test_get_new_without_tracker_id
1920 @request.session[:user_id] = 2
1946 @request.session[:user_id] = 2
1921 get :new, :project_id => 1
1947 get :new, :project_id => 1
1922 assert_response :success
1948 assert_response :success
1923 assert_template 'new'
1949 assert_template 'new'
1924
1950
1925 issue = assigns(:issue)
1951 issue = assigns(:issue)
1926 assert_not_nil issue
1952 assert_not_nil issue
1927 assert_equal Project.find(1).trackers.first, issue.tracker
1953 assert_equal Project.find(1).trackers.first, issue.tracker
1928 end
1954 end
1929
1955
1930 def test_get_new_with_no_default_status_should_display_an_error
1956 def test_get_new_with_no_default_status_should_display_an_error
1931 @request.session[:user_id] = 2
1957 @request.session[:user_id] = 2
1932 IssueStatus.delete_all
1958 IssueStatus.delete_all
1933
1959
1934 get :new, :project_id => 1
1960 get :new, :project_id => 1
1935 assert_response 500
1961 assert_response 500
1936 assert_select_error /No default issue/
1962 assert_select_error /No default issue/
1937 end
1963 end
1938
1964
1939 def test_get_new_with_no_tracker_should_display_an_error
1965 def test_get_new_with_no_tracker_should_display_an_error
1940 @request.session[:user_id] = 2
1966 @request.session[:user_id] = 2
1941 Tracker.delete_all
1967 Tracker.delete_all
1942
1968
1943 get :new, :project_id => 1
1969 get :new, :project_id => 1
1944 assert_response 500
1970 assert_response 500
1945 assert_select_error /No tracker/
1971 assert_select_error /No tracker/
1946 end
1972 end
1947
1973
1948 def test_new_with_invalid_project_id
1974 def test_new_with_invalid_project_id
1949 @request.session[:user_id] = 1
1975 @request.session[:user_id] = 1
1950 get :new, :project_id => 'invalid'
1976 get :new, :project_id => 'invalid'
1951 assert_response 404
1977 assert_response 404
1952 end
1978 end
1953
1979
1954 def test_update_form_for_new_issue
1980 def test_update_form_for_new_issue
1955 @request.session[:user_id] = 2
1981 @request.session[:user_id] = 2
1956 xhr :post, :new, :project_id => 1,
1982 xhr :post, :new, :project_id => 1,
1957 :issue => {:tracker_id => 2,
1983 :issue => {:tracker_id => 2,
1958 :subject => 'This is the test_new issue',
1984 :subject => 'This is the test_new issue',
1959 :description => 'This is the description',
1985 :description => 'This is the description',
1960 :priority_id => 5}
1986 :priority_id => 5}
1961 assert_response :success
1987 assert_response :success
1962 assert_template 'new'
1988 assert_template 'new'
1963 assert_template :partial => '_form'
1989 assert_template :partial => '_form'
1964 assert_equal 'text/javascript', response.content_type
1990 assert_equal 'text/javascript', response.content_type
1965
1991
1966 issue = assigns(:issue)
1992 issue = assigns(:issue)
1967 assert_kind_of Issue, issue
1993 assert_kind_of Issue, issue
1968 assert_equal 1, issue.project_id
1994 assert_equal 1, issue.project_id
1969 assert_equal 2, issue.tracker_id
1995 assert_equal 2, issue.tracker_id
1970 assert_equal 'This is the test_new issue', issue.subject
1996 assert_equal 'This is the test_new issue', issue.subject
1971 end
1997 end
1972
1998
1973 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1999 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1974 @request.session[:user_id] = 2
2000 @request.session[:user_id] = 2
1975 WorkflowTransition.delete_all
2001 WorkflowTransition.delete_all
1976 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 2)
2002 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 2)
1977 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 5)
2003 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 5)
1978 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
2004 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1979
2005
1980 xhr :post, :new, :project_id => 1,
2006 xhr :post, :new, :project_id => 1,
1981 :issue => {:tracker_id => 1,
2007 :issue => {:tracker_id => 1,
1982 :status_id => 5,
2008 :status_id => 5,
1983 :subject => 'This is an issue'}
2009 :subject => 'This is an issue'}
1984
2010
1985 assert_equal 5, assigns(:issue).status_id
2011 assert_equal 5, assigns(:issue).status_id
1986 assert_equal [2,5], assigns(:allowed_statuses).map(&:id).sort
2012 assert_equal [2,5], assigns(:allowed_statuses).map(&:id).sort
1987 end
2013 end
1988
2014
1989 def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals
2015 def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals
1990 @request.session[:user_id] = 2
2016 @request.session[:user_id] = 2
1991 tracker = Tracker.find(2)
2017 tracker = Tracker.find(2)
1992 tracker.update! :default_status_id => 2
2018 tracker.update! :default_status_id => 2
1993 tracker.generate_transitions! 2, 1, :clear => true
2019 tracker.generate_transitions! 2, 1, :clear => true
1994
2020
1995 xhr :post, :new, :project_id => 1,
2021 xhr :post, :new, :project_id => 1,
1996 :issue => {:tracker_id => 2,
2022 :issue => {:tracker_id => 2,
1997 :status_id => 1},
2023 :status_id => 1},
1998 :was_default_status => 1
2024 :was_default_status => 1
1999
2025
2000 assert_equal 2, assigns(:issue).status_id
2026 assert_equal 2, assigns(:issue).status_id
2001 end
2027 end
2002
2028
2003 def test_update_form_for_new_issue_should_ignore_version_when_changing_project
2029 def test_update_form_for_new_issue_should_ignore_version_when_changing_project
2004 version = Version.generate!(:project_id => 1)
2030 version = Version.generate!(:project_id => 1)
2005 Project.find(1).update_attribute :default_version_id, version.id
2031 Project.find(1).update_attribute :default_version_id, version.id
2006 @request.session[:user_id] = 2
2032 @request.session[:user_id] = 2
2007
2033
2008 xhr :post, :new, :issue => {:project_id => 1,
2034 xhr :post, :new, :issue => {:project_id => 1,
2009 :fixed_version_id => ''},
2035 :fixed_version_id => ''},
2010 :form_update_triggered_by => 'issue_project_id'
2036 :form_update_triggered_by => 'issue_project_id'
2011 assert_response :success
2037 assert_response :success
2012 assert_template 'new'
2038 assert_template 'new'
2013
2039
2014 issue = assigns(:issue)
2040 issue = assigns(:issue)
2015 assert_equal 1, issue.project_id
2041 assert_equal 1, issue.project_id
2016 assert_equal version, issue.fixed_version
2042 assert_equal version, issue.fixed_version
2017 end
2043 end
2018
2044
2019 def test_post_create
2045 def test_post_create
2020 @request.session[:user_id] = 2
2046 @request.session[:user_id] = 2
2021 assert_difference 'Issue.count' do
2047 assert_difference 'Issue.count' do
2022 assert_no_difference 'Journal.count' do
2048 assert_no_difference 'Journal.count' do
2023 post :create, :project_id => 1,
2049 post :create, :project_id => 1,
2024 :issue => {:tracker_id => 3,
2050 :issue => {:tracker_id => 3,
2025 :status_id => 2,
2051 :status_id => 2,
2026 :subject => 'This is the test_new issue',
2052 :subject => 'This is the test_new issue',
2027 :description => 'This is the description',
2053 :description => 'This is the description',
2028 :priority_id => 5,
2054 :priority_id => 5,
2029 :start_date => '2010-11-07',
2055 :start_date => '2010-11-07',
2030 :estimated_hours => '',
2056 :estimated_hours => '',
2031 :custom_field_values => {'2' => 'Value for field 2'}}
2057 :custom_field_values => {'2' => 'Value for field 2'}}
2032 end
2058 end
2033 end
2059 end
2034 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2060 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2035
2061
2036 issue = Issue.find_by_subject('This is the test_new issue')
2062 issue = Issue.find_by_subject('This is the test_new issue')
2037 assert_not_nil issue
2063 assert_not_nil issue
2038 assert_equal 2, issue.author_id
2064 assert_equal 2, issue.author_id
2039 assert_equal 3, issue.tracker_id
2065 assert_equal 3, issue.tracker_id
2040 assert_equal 2, issue.status_id
2066 assert_equal 2, issue.status_id
2041 assert_equal Date.parse('2010-11-07'), issue.start_date
2067 assert_equal Date.parse('2010-11-07'), issue.start_date
2042 assert_nil issue.estimated_hours
2068 assert_nil issue.estimated_hours
2043 v = issue.custom_values.where(:custom_field_id => 2).first
2069 v = issue.custom_values.where(:custom_field_id => 2).first
2044 assert_not_nil v
2070 assert_not_nil v
2045 assert_equal 'Value for field 2', v.value
2071 assert_equal 'Value for field 2', v.value
2046 end
2072 end
2047
2073
2048 def test_post_new_with_group_assignment
2074 def test_post_new_with_group_assignment
2049 group = Group.find(11)
2075 group = Group.find(11)
2050 project = Project.find(1)
2076 project = Project.find(1)
2051 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2077 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2052
2078
2053 with_settings :issue_group_assignment => '1' do
2079 with_settings :issue_group_assignment => '1' do
2054 @request.session[:user_id] = 2
2080 @request.session[:user_id] = 2
2055 assert_difference 'Issue.count' do
2081 assert_difference 'Issue.count' do
2056 post :create, :project_id => project.id,
2082 post :create, :project_id => project.id,
2057 :issue => {:tracker_id => 3,
2083 :issue => {:tracker_id => 3,
2058 :status_id => 1,
2084 :status_id => 1,
2059 :subject => 'This is the test_new_with_group_assignment issue',
2085 :subject => 'This is the test_new_with_group_assignment issue',
2060 :assigned_to_id => group.id}
2086 :assigned_to_id => group.id}
2061 end
2087 end
2062 end
2088 end
2063 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2089 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2064
2090
2065 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
2091 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
2066 assert_not_nil issue
2092 assert_not_nil issue
2067 assert_equal group, issue.assigned_to
2093 assert_equal group, issue.assigned_to
2068 end
2094 end
2069
2095
2070 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
2096 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
2071 with_settings :default_issue_start_date_to_creation_date => 0 do
2097 with_settings :default_issue_start_date_to_creation_date => 0 do
2072 @request.session[:user_id] = 2
2098 @request.session[:user_id] = 2
2073 assert_difference 'Issue.count' do
2099 assert_difference 'Issue.count' do
2074 post :create, :project_id => 1,
2100 post :create, :project_id => 1,
2075 :issue => {:tracker_id => 3,
2101 :issue => {:tracker_id => 3,
2076 :status_id => 2,
2102 :status_id => 2,
2077 :subject => 'This is the test_new issue',
2103 :subject => 'This is the test_new issue',
2078 :description => 'This is the description',
2104 :description => 'This is the description',
2079 :priority_id => 5,
2105 :priority_id => 5,
2080 :estimated_hours => '',
2106 :estimated_hours => '',
2081 :custom_field_values => {'2' => 'Value for field 2'}}
2107 :custom_field_values => {'2' => 'Value for field 2'}}
2082 end
2108 end
2083 assert_redirected_to :controller => 'issues', :action => 'show',
2109 assert_redirected_to :controller => 'issues', :action => 'show',
2084 :id => Issue.last.id
2110 :id => Issue.last.id
2085 issue = Issue.find_by_subject('This is the test_new issue')
2111 issue = Issue.find_by_subject('This is the test_new issue')
2086 assert_not_nil issue
2112 assert_not_nil issue
2087 assert_nil issue.start_date
2113 assert_nil issue.start_date
2088 end
2114 end
2089 end
2115 end
2090
2116
2091 def test_post_create_without_start_date_and_default_start_date_is_creation_date
2117 def test_post_create_without_start_date_and_default_start_date_is_creation_date
2092 with_settings :default_issue_start_date_to_creation_date => 1 do
2118 with_settings :default_issue_start_date_to_creation_date => 1 do
2093 @request.session[:user_id] = 2
2119 @request.session[:user_id] = 2
2094 assert_difference 'Issue.count' do
2120 assert_difference 'Issue.count' do
2095 post :create, :project_id => 1,
2121 post :create, :project_id => 1,
2096 :issue => {:tracker_id => 3,
2122 :issue => {:tracker_id => 3,
2097 :status_id => 2,
2123 :status_id => 2,
2098 :subject => 'This is the test_new issue',
2124 :subject => 'This is the test_new issue',
2099 :description => 'This is the description',
2125 :description => 'This is the description',
2100 :priority_id => 5,
2126 :priority_id => 5,
2101 :estimated_hours => '',
2127 :estimated_hours => '',
2102 :custom_field_values => {'2' => 'Value for field 2'}}
2128 :custom_field_values => {'2' => 'Value for field 2'}}
2103 end
2129 end
2104 assert_redirected_to :controller => 'issues', :action => 'show',
2130 assert_redirected_to :controller => 'issues', :action => 'show',
2105 :id => Issue.last.id
2131 :id => Issue.last.id
2106 issue = Issue.find_by_subject('This is the test_new issue')
2132 issue = Issue.find_by_subject('This is the test_new issue')
2107 assert_not_nil issue
2133 assert_not_nil issue
2108 assert_equal Date.today, issue.start_date
2134 assert_equal Date.today, issue.start_date
2109 end
2135 end
2110 end
2136 end
2111
2137
2112 def test_post_create_and_continue
2138 def test_post_create_and_continue
2113 @request.session[:user_id] = 2
2139 @request.session[:user_id] = 2
2114 assert_difference 'Issue.count' do
2140 assert_difference 'Issue.count' do
2115 post :create, :project_id => 1,
2141 post :create, :project_id => 1,
2116 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
2142 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
2117 :continue => ''
2143 :continue => ''
2118 end
2144 end
2119
2145
2120 issue = Issue.order('id DESC').first
2146 issue = Issue.order('id DESC').first
2121 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
2147 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
2122 assert_not_nil flash[:notice], "flash was not set"
2148 assert_not_nil flash[:notice], "flash was not set"
2123 assert_select_in flash[:notice],
2149 assert_select_in flash[:notice],
2124 'a[href=?][title=?]', "/issues/#{issue.id}", "This is first issue", :text => "##{issue.id}"
2150 'a[href=?][title=?]', "/issues/#{issue.id}", "This is first issue", :text => "##{issue.id}"
2125 end
2151 end
2126
2152
2127 def test_post_create_without_custom_fields_param
2153 def test_post_create_without_custom_fields_param
2128 @request.session[:user_id] = 2
2154 @request.session[:user_id] = 2
2129 assert_difference 'Issue.count' do
2155 assert_difference 'Issue.count' do
2130 post :create, :project_id => 1,
2156 post :create, :project_id => 1,
2131 :issue => {:tracker_id => 1,
2157 :issue => {:tracker_id => 1,
2132 :subject => 'This is the test_new issue',
2158 :subject => 'This is the test_new issue',
2133 :description => 'This is the description',
2159 :description => 'This is the description',
2134 :priority_id => 5}
2160 :priority_id => 5}
2135 end
2161 end
2136 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2162 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2137 end
2163 end
2138
2164
2139 def test_post_create_with_multi_custom_field
2165 def test_post_create_with_multi_custom_field
2140 field = IssueCustomField.find_by_name('Database')
2166 field = IssueCustomField.find_by_name('Database')
2141 field.update_attribute(:multiple, true)
2167 field.update_attribute(:multiple, true)
2142
2168
2143 @request.session[:user_id] = 2
2169 @request.session[:user_id] = 2
2144 assert_difference 'Issue.count' do
2170 assert_difference 'Issue.count' do
2145 post :create, :project_id => 1,
2171 post :create, :project_id => 1,
2146 :issue => {:tracker_id => 1,
2172 :issue => {:tracker_id => 1,
2147 :subject => 'This is the test_new issue',
2173 :subject => 'This is the test_new issue',
2148 :description => 'This is the description',
2174 :description => 'This is the description',
2149 :priority_id => 5,
2175 :priority_id => 5,
2150 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
2176 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
2151 end
2177 end
2152 assert_response 302
2178 assert_response 302
2153 issue = Issue.order('id DESC').first
2179 issue = Issue.order('id DESC').first
2154 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
2180 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
2155 end
2181 end
2156
2182
2157 def test_post_create_with_empty_multi_custom_field
2183 def test_post_create_with_empty_multi_custom_field
2158 field = IssueCustomField.find_by_name('Database')
2184 field = IssueCustomField.find_by_name('Database')
2159 field.update_attribute(:multiple, true)
2185 field.update_attribute(:multiple, true)
2160
2186
2161 @request.session[:user_id] = 2
2187 @request.session[:user_id] = 2
2162 assert_difference 'Issue.count' do
2188 assert_difference 'Issue.count' do
2163 post :create, :project_id => 1,
2189 post :create, :project_id => 1,
2164 :issue => {:tracker_id => 1,
2190 :issue => {:tracker_id => 1,
2165 :subject => 'This is the test_new issue',
2191 :subject => 'This is the test_new issue',
2166 :description => 'This is the description',
2192 :description => 'This is the description',
2167 :priority_id => 5,
2193 :priority_id => 5,
2168 :custom_field_values => {'1' => ['']}}
2194 :custom_field_values => {'1' => ['']}}
2169 end
2195 end
2170 assert_response 302
2196 assert_response 302
2171 issue = Issue.order('id DESC').first
2197 issue = Issue.order('id DESC').first
2172 assert_equal [''], issue.custom_field_value(1).sort
2198 assert_equal [''], issue.custom_field_value(1).sort
2173 end
2199 end
2174
2200
2175 def test_post_create_with_multi_user_custom_field
2201 def test_post_create_with_multi_user_custom_field
2176 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
2202 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
2177 :tracker_ids => [1], :is_for_all => true)
2203 :tracker_ids => [1], :is_for_all => true)
2178
2204
2179 @request.session[:user_id] = 2
2205 @request.session[:user_id] = 2
2180 assert_difference 'Issue.count' do
2206 assert_difference 'Issue.count' do
2181 post :create, :project_id => 1,
2207 post :create, :project_id => 1,
2182 :issue => {:tracker_id => 1,
2208 :issue => {:tracker_id => 1,
2183 :subject => 'This is the test_new issue',
2209 :subject => 'This is the test_new issue',
2184 :description => 'This is the description',
2210 :description => 'This is the description',
2185 :priority_id => 5,
2211 :priority_id => 5,
2186 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
2212 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
2187 end
2213 end
2188 assert_response 302
2214 assert_response 302
2189 issue = Issue.order('id DESC').first
2215 issue = Issue.order('id DESC').first
2190 assert_equal ['2', '3'], issue.custom_field_value(field).sort
2216 assert_equal ['2', '3'], issue.custom_field_value(field).sort
2191 end
2217 end
2192
2218
2193 def test_post_create_with_required_custom_field_and_without_custom_fields_param
2219 def test_post_create_with_required_custom_field_and_without_custom_fields_param
2194 field = IssueCustomField.find_by_name('Database')
2220 field = IssueCustomField.find_by_name('Database')
2195 field.update_attribute(:is_required, true)
2221 field.update_attribute(:is_required, true)
2196
2222
2197 @request.session[:user_id] = 2
2223 @request.session[:user_id] = 2
2198 assert_no_difference 'Issue.count' do
2224 assert_no_difference 'Issue.count' do
2199 post :create, :project_id => 1,
2225 post :create, :project_id => 1,
2200 :issue => {:tracker_id => 1,
2226 :issue => {:tracker_id => 1,
2201 :subject => 'This is the test_new issue',
2227 :subject => 'This is the test_new issue',
2202 :description => 'This is the description',
2228 :description => 'This is the description',
2203 :priority_id => 5}
2229 :priority_id => 5}
2204 end
2230 end
2205 assert_response :success
2231 assert_response :success
2206 assert_template 'new'
2232 assert_template 'new'
2207 issue = assigns(:issue)
2233 issue = assigns(:issue)
2208 assert_not_nil issue
2234 assert_not_nil issue
2209 assert_select_error /Database cannot be blank/
2235 assert_select_error /Database cannot be blank/
2210 end
2236 end
2211
2237
2212 def test_create_should_validate_required_fields
2238 def test_create_should_validate_required_fields
2213 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2239 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2214 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2240 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2215 WorkflowPermission.delete_all
2241 WorkflowPermission.delete_all
2216 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
2242 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
2217 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2243 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2218 @request.session[:user_id] = 2
2244 @request.session[:user_id] = 2
2219
2245
2220 assert_no_difference 'Issue.count' do
2246 assert_no_difference 'Issue.count' do
2221 post :create, :project_id => 1, :issue => {
2247 post :create, :project_id => 1, :issue => {
2222 :tracker_id => 2,
2248 :tracker_id => 2,
2223 :status_id => 1,
2249 :status_id => 1,
2224 :subject => 'Test',
2250 :subject => 'Test',
2225 :start_date => '',
2251 :start_date => '',
2226 :due_date => '',
2252 :due_date => '',
2227 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
2253 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
2228 }
2254 }
2229 assert_response :success
2255 assert_response :success
2230 assert_template 'new'
2256 assert_template 'new'
2231 end
2257 end
2232
2258
2233 assert_select_error /Due date cannot be blank/i
2259 assert_select_error /Due date cannot be blank/i
2234 assert_select_error /Bar cannot be blank/i
2260 assert_select_error /Bar cannot be blank/i
2235 end
2261 end
2236
2262
2237 def test_create_should_validate_required_list_fields
2263 def test_create_should_validate_required_list_fields
2238 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
2264 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
2239 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
2265 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
2240 WorkflowPermission.delete_all
2266 WorkflowPermission.delete_all
2241 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
2267 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
2242 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2268 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2243 @request.session[:user_id] = 2
2269 @request.session[:user_id] = 2
2244
2270
2245 assert_no_difference 'Issue.count' do
2271 assert_no_difference 'Issue.count' do
2246 post :create, :project_id => 1, :issue => {
2272 post :create, :project_id => 1, :issue => {
2247 :tracker_id => 2,
2273 :tracker_id => 2,
2248 :status_id => 1,
2274 :status_id => 1,
2249 :subject => 'Test',
2275 :subject => 'Test',
2250 :start_date => '',
2276 :start_date => '',
2251 :due_date => '',
2277 :due_date => '',
2252 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
2278 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
2253 }
2279 }
2254 assert_response :success
2280 assert_response :success
2255 assert_template 'new'
2281 assert_template 'new'
2256 end
2282 end
2257
2283
2258 assert_select_error /Foo cannot be blank/i
2284 assert_select_error /Foo cannot be blank/i
2259 assert_select_error /Bar cannot be blank/i
2285 assert_select_error /Bar cannot be blank/i
2260 end
2286 end
2261
2287
2262 def test_create_should_ignore_readonly_fields
2288 def test_create_should_ignore_readonly_fields
2263 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2289 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2264 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2290 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2265 WorkflowPermission.delete_all
2291 WorkflowPermission.delete_all
2266 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
2292 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
2267 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
2293 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
2268 @request.session[:user_id] = 2
2294 @request.session[:user_id] = 2
2269
2295
2270 assert_difference 'Issue.count' do
2296 assert_difference 'Issue.count' do
2271 post :create, :project_id => 1, :issue => {
2297 post :create, :project_id => 1, :issue => {
2272 :tracker_id => 2,
2298 :tracker_id => 2,
2273 :status_id => 1,
2299 :status_id => 1,
2274 :subject => 'Test',
2300 :subject => 'Test',
2275 :start_date => '2012-07-14',
2301 :start_date => '2012-07-14',
2276 :due_date => '2012-07-16',
2302 :due_date => '2012-07-16',
2277 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
2303 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
2278 }
2304 }
2279 assert_response 302
2305 assert_response 302
2280 end
2306 end
2281
2307
2282 issue = Issue.order('id DESC').first
2308 issue = Issue.order('id DESC').first
2283 assert_equal Date.parse('2012-07-14'), issue.start_date
2309 assert_equal Date.parse('2012-07-14'), issue.start_date
2284 assert_nil issue.due_date
2310 assert_nil issue.due_date
2285 assert_equal 'value1', issue.custom_field_value(cf1)
2311 assert_equal 'value1', issue.custom_field_value(cf1)
2286 assert_nil issue.custom_field_value(cf2)
2312 assert_nil issue.custom_field_value(cf2)
2287 end
2313 end
2288
2314
2289 def test_post_create_with_watchers
2315 def test_post_create_with_watchers
2290 @request.session[:user_id] = 2
2316 @request.session[:user_id] = 2
2291 ActionMailer::Base.deliveries.clear
2317 ActionMailer::Base.deliveries.clear
2292
2318
2293 with_settings :notified_events => %w(issue_added) do
2319 with_settings :notified_events => %w(issue_added) do
2294 assert_difference 'Watcher.count', 2 do
2320 assert_difference 'Watcher.count', 2 do
2295 post :create, :project_id => 1,
2321 post :create, :project_id => 1,
2296 :issue => {:tracker_id => 1,
2322 :issue => {:tracker_id => 1,
2297 :subject => 'This is a new issue with watchers',
2323 :subject => 'This is a new issue with watchers',
2298 :description => 'This is the description',
2324 :description => 'This is the description',
2299 :priority_id => 5,
2325 :priority_id => 5,
2300 :watcher_user_ids => ['2', '3']}
2326 :watcher_user_ids => ['2', '3']}
2301 end
2327 end
2302 end
2328 end
2303 issue = Issue.find_by_subject('This is a new issue with watchers')
2329 issue = Issue.find_by_subject('This is a new issue with watchers')
2304 assert_not_nil issue
2330 assert_not_nil issue
2305 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2331 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2306
2332
2307 # Watchers added
2333 # Watchers added
2308 assert_equal [2, 3], issue.watcher_user_ids.sort
2334 assert_equal [2, 3], issue.watcher_user_ids.sort
2309 assert issue.watched_by?(User.find(3))
2335 assert issue.watched_by?(User.find(3))
2310 # Watchers notified
2336 # Watchers notified
2311 mail = ActionMailer::Base.deliveries.last
2337 mail = ActionMailer::Base.deliveries.last
2312 assert_not_nil mail
2338 assert_not_nil mail
2313 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
2339 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
2314 end
2340 end
2315
2341
2316 def test_post_create_subissue
2342 def test_post_create_subissue
2317 @request.session[:user_id] = 2
2343 @request.session[:user_id] = 2
2318
2344
2319 assert_difference 'Issue.count' do
2345 assert_difference 'Issue.count' do
2320 post :create, :project_id => 1,
2346 post :create, :project_id => 1,
2321 :issue => {:tracker_id => 1,
2347 :issue => {:tracker_id => 1,
2322 :subject => 'This is a child issue',
2348 :subject => 'This is a child issue',
2323 :parent_issue_id => '2'}
2349 :parent_issue_id => '2'}
2324 assert_response 302
2350 assert_response 302
2325 end
2351 end
2326 issue = Issue.order('id DESC').first
2352 issue = Issue.order('id DESC').first
2327 assert_equal Issue.find(2), issue.parent
2353 assert_equal Issue.find(2), issue.parent
2328 end
2354 end
2329
2355
2330 def test_post_create_subissue_with_sharp_parent_id
2356 def test_post_create_subissue_with_sharp_parent_id
2331 @request.session[:user_id] = 2
2357 @request.session[:user_id] = 2
2332
2358
2333 assert_difference 'Issue.count' do
2359 assert_difference 'Issue.count' do
2334 post :create, :project_id => 1,
2360 post :create, :project_id => 1,
2335 :issue => {:tracker_id => 1,
2361 :issue => {:tracker_id => 1,
2336 :subject => 'This is a child issue',
2362 :subject => 'This is a child issue',
2337 :parent_issue_id => '#2'}
2363 :parent_issue_id => '#2'}
2338 assert_response 302
2364 assert_response 302
2339 end
2365 end
2340 issue = Issue.order('id DESC').first
2366 issue = Issue.order('id DESC').first
2341 assert_equal Issue.find(2), issue.parent
2367 assert_equal Issue.find(2), issue.parent
2342 end
2368 end
2343
2369
2344 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
2370 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
2345 @request.session[:user_id] = 2
2371 @request.session[:user_id] = 2
2346
2372
2347 assert_no_difference 'Issue.count' do
2373 assert_no_difference 'Issue.count' do
2348 post :create, :project_id => 1,
2374 post :create, :project_id => 1,
2349 :issue => {:tracker_id => 1,
2375 :issue => {:tracker_id => 1,
2350 :subject => 'This is a child issue',
2376 :subject => 'This is a child issue',
2351 :parent_issue_id => '4'}
2377 :parent_issue_id => '4'}
2352
2378
2353 assert_response :success
2379 assert_response :success
2354 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
2380 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
2355 assert_select_error /Parent task is invalid/i
2381 assert_select_error /Parent task is invalid/i
2356 end
2382 end
2357 end
2383 end
2358
2384
2359 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
2385 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
2360 @request.session[:user_id] = 2
2386 @request.session[:user_id] = 2
2361
2387
2362 assert_no_difference 'Issue.count' do
2388 assert_no_difference 'Issue.count' do
2363 post :create, :project_id => 1,
2389 post :create, :project_id => 1,
2364 :issue => {:tracker_id => 1,
2390 :issue => {:tracker_id => 1,
2365 :subject => 'This is a child issue',
2391 :subject => 'This is a child issue',
2366 :parent_issue_id => '01ABC'}
2392 :parent_issue_id => '01ABC'}
2367
2393
2368 assert_response :success
2394 assert_response :success
2369 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2395 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2370 assert_select_error /Parent task is invalid/i
2396 assert_select_error /Parent task is invalid/i
2371 end
2397 end
2372 end
2398 end
2373
2399
2374 def test_post_create_private
2400 def test_post_create_private
2375 @request.session[:user_id] = 2
2401 @request.session[:user_id] = 2
2376
2402
2377 assert_difference 'Issue.count' do
2403 assert_difference 'Issue.count' do
2378 post :create, :project_id => 1,
2404 post :create, :project_id => 1,
2379 :issue => {:tracker_id => 1,
2405 :issue => {:tracker_id => 1,
2380 :subject => 'This is a private issue',
2406 :subject => 'This is a private issue',
2381 :is_private => '1'}
2407 :is_private => '1'}
2382 end
2408 end
2383 issue = Issue.order('id DESC').first
2409 issue = Issue.order('id DESC').first
2384 assert issue.is_private?
2410 assert issue.is_private?
2385 end
2411 end
2386
2412
2387 def test_post_create_private_with_set_own_issues_private_permission
2413 def test_post_create_private_with_set_own_issues_private_permission
2388 role = Role.find(1)
2414 role = Role.find(1)
2389 role.remove_permission! :set_issues_private
2415 role.remove_permission! :set_issues_private
2390 role.add_permission! :set_own_issues_private
2416 role.add_permission! :set_own_issues_private
2391
2417
2392 @request.session[:user_id] = 2
2418 @request.session[:user_id] = 2
2393
2419
2394 assert_difference 'Issue.count' do
2420 assert_difference 'Issue.count' do
2395 post :create, :project_id => 1,
2421 post :create, :project_id => 1,
2396 :issue => {:tracker_id => 1,
2422 :issue => {:tracker_id => 1,
2397 :subject => 'This is a private issue',
2423 :subject => 'This is a private issue',
2398 :is_private => '1'}
2424 :is_private => '1'}
2399 end
2425 end
2400 issue = Issue.order('id DESC').first
2426 issue = Issue.order('id DESC').first
2401 assert issue.is_private?
2427 assert issue.is_private?
2402 end
2428 end
2403
2429
2404 def test_create_without_project_id
2430 def test_create_without_project_id
2405 @request.session[:user_id] = 2
2431 @request.session[:user_id] = 2
2406
2432
2407 assert_difference 'Issue.count' do
2433 assert_difference 'Issue.count' do
2408 post :create,
2434 post :create,
2409 :issue => {:project_id => 3,
2435 :issue => {:project_id => 3,
2410 :tracker_id => 2,
2436 :tracker_id => 2,
2411 :subject => 'Foo'}
2437 :subject => 'Foo'}
2412 assert_response 302
2438 assert_response 302
2413 end
2439 end
2414 issue = Issue.order('id DESC').first
2440 issue = Issue.order('id DESC').first
2415 assert_equal 3, issue.project_id
2441 assert_equal 3, issue.project_id
2416 assert_equal 2, issue.tracker_id
2442 assert_equal 2, issue.tracker_id
2417 end
2443 end
2418
2444
2419 def test_create_without_project_id_and_continue_should_redirect_without_project_id
2445 def test_create_without_project_id_and_continue_should_redirect_without_project_id
2420 @request.session[:user_id] = 2
2446 @request.session[:user_id] = 2
2421
2447
2422 assert_difference 'Issue.count' do
2448 assert_difference 'Issue.count' do
2423 post :create,
2449 post :create,
2424 :issue => {:project_id => 3,
2450 :issue => {:project_id => 3,
2425 :tracker_id => 2,
2451 :tracker_id => 2,
2426 :subject => 'Foo'},
2452 :subject => 'Foo'},
2427 :continue => '1'
2453 :continue => '1'
2428 assert_redirected_to '/issues/new?issue%5Bproject_id%5D=3&issue%5Btracker_id%5D=2'
2454 assert_redirected_to '/issues/new?issue%5Bproject_id%5D=3&issue%5Btracker_id%5D=2'
2429 end
2455 end
2430 end
2456 end
2431
2457
2432 def test_create_without_project_id_should_be_denied_without_permission
2458 def test_create_without_project_id_should_be_denied_without_permission
2433 Role.non_member.remove_permission! :add_issues
2459 Role.non_member.remove_permission! :add_issues
2434 Role.anonymous.remove_permission! :add_issues
2460 Role.anonymous.remove_permission! :add_issues
2435 @request.session[:user_id] = 2
2461 @request.session[:user_id] = 2
2436
2462
2437 assert_no_difference 'Issue.count' do
2463 assert_no_difference 'Issue.count' do
2438 post :create,
2464 post :create,
2439 :issue => {:project_id => 3,
2465 :issue => {:project_id => 3,
2440 :tracker_id => 2,
2466 :tracker_id => 2,
2441 :subject => 'Foo'}
2467 :subject => 'Foo'}
2442 assert_response 422
2468 assert_response 422
2443 end
2469 end
2444 end
2470 end
2445
2471
2446 def test_create_without_project_id_with_failure
2472 def test_create_without_project_id_with_failure
2447 @request.session[:user_id] = 2
2473 @request.session[:user_id] = 2
2448
2474
2449 post :create,
2475 post :create,
2450 :issue => {:project_id => 3,
2476 :issue => {:project_id => 3,
2451 :tracker_id => 2,
2477 :tracker_id => 2,
2452 :subject => ''}
2478 :subject => ''}
2453 assert_response :success
2479 assert_response :success
2454 assert_nil assigns(:project)
2480 assert_nil assigns(:project)
2455 end
2481 end
2456
2482
2457 def test_post_create_should_send_a_notification
2483 def test_post_create_should_send_a_notification
2458 ActionMailer::Base.deliveries.clear
2484 ActionMailer::Base.deliveries.clear
2459 @request.session[:user_id] = 2
2485 @request.session[:user_id] = 2
2460 with_settings :notified_events => %w(issue_added) do
2486 with_settings :notified_events => %w(issue_added) do
2461 assert_difference 'Issue.count' do
2487 assert_difference 'Issue.count' do
2462 post :create, :project_id => 1,
2488 post :create, :project_id => 1,
2463 :issue => {:tracker_id => 3,
2489 :issue => {:tracker_id => 3,
2464 :subject => 'This is the test_new issue',
2490 :subject => 'This is the test_new issue',
2465 :description => 'This is the description',
2491 :description => 'This is the description',
2466 :priority_id => 5,
2492 :priority_id => 5,
2467 :estimated_hours => '',
2493 :estimated_hours => '',
2468 :custom_field_values => {'2' => 'Value for field 2'}}
2494 :custom_field_values => {'2' => 'Value for field 2'}}
2469 end
2495 end
2470 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2496 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2471
2497
2472 assert_equal 1, ActionMailer::Base.deliveries.size
2498 assert_equal 1, ActionMailer::Base.deliveries.size
2473 end
2499 end
2474 end
2500 end
2475
2501
2476 def test_post_create_should_preserve_fields_values_on_validation_failure
2502 def test_post_create_should_preserve_fields_values_on_validation_failure
2477 @request.session[:user_id] = 2
2503 @request.session[:user_id] = 2
2478 post :create, :project_id => 1,
2504 post :create, :project_id => 1,
2479 :issue => {:tracker_id => 1,
2505 :issue => {:tracker_id => 1,
2480 # empty subject
2506 # empty subject
2481 :subject => '',
2507 :subject => '',
2482 :description => 'This is a description',
2508 :description => 'This is a description',
2483 :priority_id => 6,
2509 :priority_id => 6,
2484 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2510 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2485 assert_response :success
2511 assert_response :success
2486 assert_template 'new'
2512 assert_template 'new'
2487
2513
2488 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2514 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2489 assert_select 'select[name=?]', 'issue[priority_id]' do
2515 assert_select 'select[name=?]', 'issue[priority_id]' do
2490 assert_select 'option[value="6"][selected=selected]', :text => 'High'
2516 assert_select 'option[value="6"][selected=selected]', :text => 'High'
2491 end
2517 end
2492 # Custom fields
2518 # Custom fields
2493 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2519 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2494 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2520 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2495 end
2521 end
2496 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
2522 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
2497 end
2523 end
2498
2524
2499 def test_post_create_with_failure_should_preserve_watchers
2525 def test_post_create_with_failure_should_preserve_watchers
2500 assert !User.find(8).member_of?(Project.find(1))
2526 assert !User.find(8).member_of?(Project.find(1))
2501
2527
2502 @request.session[:user_id] = 2
2528 @request.session[:user_id] = 2
2503 post :create, :project_id => 1,
2529 post :create, :project_id => 1,
2504 :issue => {:tracker_id => 1,
2530 :issue => {:tracker_id => 1,
2505 :watcher_user_ids => ['3', '8']}
2531 :watcher_user_ids => ['3', '8']}
2506 assert_response :success
2532 assert_response :success
2507 assert_template 'new'
2533 assert_template 'new'
2508
2534
2509 assert_select 'input[name=?][value="2"]:not(checked)', 'issue[watcher_user_ids][]'
2535 assert_select 'input[name=?][value="2"]:not(checked)', 'issue[watcher_user_ids][]'
2510 assert_select 'input[name=?][value="3"][checked=checked]', 'issue[watcher_user_ids][]'
2536 assert_select 'input[name=?][value="3"][checked=checked]', 'issue[watcher_user_ids][]'
2511 assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]'
2537 assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]'
2512 end
2538 end
2513
2539
2514 def test_post_create_should_ignore_non_safe_attributes
2540 def test_post_create_should_ignore_non_safe_attributes
2515 @request.session[:user_id] = 2
2541 @request.session[:user_id] = 2
2516 assert_nothing_raised do
2542 assert_nothing_raised do
2517 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2543 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2518 end
2544 end
2519 end
2545 end
2520
2546
2521 def test_post_create_with_attachment
2547 def test_post_create_with_attachment
2522 set_tmp_attachments_directory
2548 set_tmp_attachments_directory
2523 @request.session[:user_id] = 2
2549 @request.session[:user_id] = 2
2524
2550
2525 assert_difference 'Issue.count' do
2551 assert_difference 'Issue.count' do
2526 assert_difference 'Attachment.count' do
2552 assert_difference 'Attachment.count' do
2527 assert_no_difference 'Journal.count' do
2553 assert_no_difference 'Journal.count' do
2528 post :create, :project_id => 1,
2554 post :create, :project_id => 1,
2529 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2555 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2530 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2556 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2531 end
2557 end
2532 end
2558 end
2533 end
2559 end
2534
2560
2535 issue = Issue.order('id DESC').first
2561 issue = Issue.order('id DESC').first
2536 attachment = Attachment.order('id DESC').first
2562 attachment = Attachment.order('id DESC').first
2537
2563
2538 assert_equal issue, attachment.container
2564 assert_equal issue, attachment.container
2539 assert_equal 2, attachment.author_id
2565 assert_equal 2, attachment.author_id
2540 assert_equal 'testfile.txt', attachment.filename
2566 assert_equal 'testfile.txt', attachment.filename
2541 assert_equal 'text/plain', attachment.content_type
2567 assert_equal 'text/plain', attachment.content_type
2542 assert_equal 'test file', attachment.description
2568 assert_equal 'test file', attachment.description
2543 assert_equal 59, attachment.filesize
2569 assert_equal 59, attachment.filesize
2544 assert File.exists?(attachment.diskfile)
2570 assert File.exists?(attachment.diskfile)
2545 assert_equal 59, File.size(attachment.diskfile)
2571 assert_equal 59, File.size(attachment.diskfile)
2546 end
2572 end
2547
2573
2548 def test_post_create_with_attachment_should_notify_with_attachments
2574 def test_post_create_with_attachment_should_notify_with_attachments
2549 ActionMailer::Base.deliveries.clear
2575 ActionMailer::Base.deliveries.clear
2550 set_tmp_attachments_directory
2576 set_tmp_attachments_directory
2551 @request.session[:user_id] = 2
2577 @request.session[:user_id] = 2
2552
2578
2553 with_settings :host_name => 'mydomain.foo', :protocol => 'http', :notified_events => %w(issue_added) do
2579 with_settings :host_name => 'mydomain.foo', :protocol => 'http', :notified_events => %w(issue_added) do
2554 assert_difference 'Issue.count' do
2580 assert_difference 'Issue.count' do
2555 post :create, :project_id => 1,
2581 post :create, :project_id => 1,
2556 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2582 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2557 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2583 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2558 end
2584 end
2559 end
2585 end
2560
2586
2561 assert_not_nil ActionMailer::Base.deliveries.last
2587 assert_not_nil ActionMailer::Base.deliveries.last
2562 assert_select_email do
2588 assert_select_email do
2563 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
2589 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
2564 end
2590 end
2565 end
2591 end
2566
2592
2567 def test_post_create_with_failure_should_save_attachments
2593 def test_post_create_with_failure_should_save_attachments
2568 set_tmp_attachments_directory
2594 set_tmp_attachments_directory
2569 @request.session[:user_id] = 2
2595 @request.session[:user_id] = 2
2570
2596
2571 assert_no_difference 'Issue.count' do
2597 assert_no_difference 'Issue.count' do
2572 assert_difference 'Attachment.count' do
2598 assert_difference 'Attachment.count' do
2573 post :create, :project_id => 1,
2599 post :create, :project_id => 1,
2574 :issue => { :tracker_id => '1', :subject => '' },
2600 :issue => { :tracker_id => '1', :subject => '' },
2575 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2601 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2576 assert_response :success
2602 assert_response :success
2577 assert_template 'new'
2603 assert_template 'new'
2578 end
2604 end
2579 end
2605 end
2580
2606
2581 attachment = Attachment.order('id DESC').first
2607 attachment = Attachment.order('id DESC').first
2582 assert_equal 'testfile.txt', attachment.filename
2608 assert_equal 'testfile.txt', attachment.filename
2583 assert File.exists?(attachment.diskfile)
2609 assert File.exists?(attachment.diskfile)
2584 assert_nil attachment.container
2610 assert_nil attachment.container
2585
2611
2586 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2612 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2587 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2613 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2588 end
2614 end
2589
2615
2590 def test_post_create_with_failure_should_keep_saved_attachments
2616 def test_post_create_with_failure_should_keep_saved_attachments
2591 set_tmp_attachments_directory
2617 set_tmp_attachments_directory
2592 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2618 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2593 @request.session[:user_id] = 2
2619 @request.session[:user_id] = 2
2594
2620
2595 assert_no_difference 'Issue.count' do
2621 assert_no_difference 'Issue.count' do
2596 assert_no_difference 'Attachment.count' do
2622 assert_no_difference 'Attachment.count' do
2597 post :create, :project_id => 1,
2623 post :create, :project_id => 1,
2598 :issue => { :tracker_id => '1', :subject => '' },
2624 :issue => { :tracker_id => '1', :subject => '' },
2599 :attachments => {'p0' => {'token' => attachment.token}}
2625 :attachments => {'p0' => {'token' => attachment.token}}
2600 assert_response :success
2626 assert_response :success
2601 assert_template 'new'
2627 assert_template 'new'
2602 end
2628 end
2603 end
2629 end
2604
2630
2605 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2631 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2606 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2632 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2607 end
2633 end
2608
2634
2609 def test_post_create_should_attach_saved_attachments
2635 def test_post_create_should_attach_saved_attachments
2610 set_tmp_attachments_directory
2636 set_tmp_attachments_directory
2611 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2637 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2612 @request.session[:user_id] = 2
2638 @request.session[:user_id] = 2
2613
2639
2614 assert_difference 'Issue.count' do
2640 assert_difference 'Issue.count' do
2615 assert_no_difference 'Attachment.count' do
2641 assert_no_difference 'Attachment.count' do
2616 post :create, :project_id => 1,
2642 post :create, :project_id => 1,
2617 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2643 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2618 :attachments => {'p0' => {'token' => attachment.token}}
2644 :attachments => {'p0' => {'token' => attachment.token}}
2619 assert_response 302
2645 assert_response 302
2620 end
2646 end
2621 end
2647 end
2622
2648
2623 issue = Issue.order('id DESC').first
2649 issue = Issue.order('id DESC').first
2624 assert_equal 1, issue.attachments.count
2650 assert_equal 1, issue.attachments.count
2625
2651
2626 attachment.reload
2652 attachment.reload
2627 assert_equal issue, attachment.container
2653 assert_equal issue, attachment.container
2628 end
2654 end
2629
2655
2630 def setup_without_workflow_privilege
2656 def setup_without_workflow_privilege
2631 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2657 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2632 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2658 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2633 end
2659 end
2634 private :setup_without_workflow_privilege
2660 private :setup_without_workflow_privilege
2635
2661
2636 test "without workflow privilege #new should propose default status only" do
2662 test "without workflow privilege #new should propose default status only" do
2637 setup_without_workflow_privilege
2663 setup_without_workflow_privilege
2638 get :new, :project_id => 1
2664 get :new, :project_id => 1
2639 assert_response :success
2665 assert_response :success
2640 assert_template 'new'
2666 assert_template 'new'
2641
2667
2642 issue = assigns(:issue)
2668 issue = assigns(:issue)
2643 assert_not_nil issue.default_status
2669 assert_not_nil issue.default_status
2644
2670
2645 assert_select 'select[name=?]', 'issue[status_id]' do
2671 assert_select 'select[name=?]', 'issue[status_id]' do
2646 assert_select 'option', 1
2672 assert_select 'option', 1
2647 assert_select 'option[value=?]', issue.default_status.id.to_s
2673 assert_select 'option[value=?]', issue.default_status.id.to_s
2648 end
2674 end
2649 end
2675 end
2650
2676
2651 test "without workflow privilege #create should accept default status" do
2677 test "without workflow privilege #create should accept default status" do
2652 setup_without_workflow_privilege
2678 setup_without_workflow_privilege
2653 assert_difference 'Issue.count' do
2679 assert_difference 'Issue.count' do
2654 post :create, :project_id => 1,
2680 post :create, :project_id => 1,
2655 :issue => {:tracker_id => 1,
2681 :issue => {:tracker_id => 1,
2656 :subject => 'This is an issue',
2682 :subject => 'This is an issue',
2657 :status_id => 1}
2683 :status_id => 1}
2658 end
2684 end
2659 issue = Issue.order('id').last
2685 issue = Issue.order('id').last
2660 assert_not_nil issue.default_status
2686 assert_not_nil issue.default_status
2661 assert_equal issue.default_status, issue.status
2687 assert_equal issue.default_status, issue.status
2662 end
2688 end
2663
2689
2664 test "without workflow privilege #create should ignore unauthorized status" do
2690 test "without workflow privilege #create should ignore unauthorized status" do
2665 setup_without_workflow_privilege
2691 setup_without_workflow_privilege
2666 assert_difference 'Issue.count' do
2692 assert_difference 'Issue.count' do
2667 post :create, :project_id => 1,
2693 post :create, :project_id => 1,
2668 :issue => {:tracker_id => 1,
2694 :issue => {:tracker_id => 1,
2669 :subject => 'This is an issue',
2695 :subject => 'This is an issue',
2670 :status_id => 3}
2696 :status_id => 3}
2671 end
2697 end
2672 issue = Issue.order('id').last
2698 issue = Issue.order('id').last
2673 assert_not_nil issue.default_status
2699 assert_not_nil issue.default_status
2674 assert_equal issue.default_status, issue.status
2700 assert_equal issue.default_status, issue.status
2675 end
2701 end
2676
2702
2677 test "without workflow privilege #update should ignore status change" do
2703 test "without workflow privilege #update should ignore status change" do
2678 setup_without_workflow_privilege
2704 setup_without_workflow_privilege
2679 assert_difference 'Journal.count' do
2705 assert_difference 'Journal.count' do
2680 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2706 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2681 end
2707 end
2682 assert_equal 1, Issue.find(1).status_id
2708 assert_equal 1, Issue.find(1).status_id
2683 end
2709 end
2684
2710
2685 test "without workflow privilege #update ignore attributes changes" do
2711 test "without workflow privilege #update ignore attributes changes" do
2686 setup_without_workflow_privilege
2712 setup_without_workflow_privilege
2687 assert_difference 'Journal.count' do
2713 assert_difference 'Journal.count' do
2688 put :update, :id => 1,
2714 put :update, :id => 1,
2689 :issue => {:subject => 'changed', :assigned_to_id => 2,
2715 :issue => {:subject => 'changed', :assigned_to_id => 2,
2690 :notes => 'just trying'}
2716 :notes => 'just trying'}
2691 end
2717 end
2692 issue = Issue.find(1)
2718 issue = Issue.find(1)
2693 assert_equal "Cannot print recipes", issue.subject
2719 assert_equal "Cannot print recipes", issue.subject
2694 assert_nil issue.assigned_to
2720 assert_nil issue.assigned_to
2695 end
2721 end
2696
2722
2697 def setup_with_workflow_privilege
2723 def setup_with_workflow_privilege
2698 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2724 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2699 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2725 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2700 :old_status_id => 1, :new_status_id => 3)
2726 :old_status_id => 1, :new_status_id => 3)
2701 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2727 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2702 :old_status_id => 1, :new_status_id => 4)
2728 :old_status_id => 1, :new_status_id => 4)
2703 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2729 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2704 end
2730 end
2705 private :setup_with_workflow_privilege
2731 private :setup_with_workflow_privilege
2706
2732
2707 def setup_with_workflow_privilege_and_edit_issues_permission
2733 def setup_with_workflow_privilege_and_edit_issues_permission
2708 setup_with_workflow_privilege
2734 setup_with_workflow_privilege
2709 Role.anonymous.add_permission! :add_issues, :edit_issues
2735 Role.anonymous.add_permission! :add_issues, :edit_issues
2710 end
2736 end
2711 private :setup_with_workflow_privilege_and_edit_issues_permission
2737 private :setup_with_workflow_privilege_and_edit_issues_permission
2712
2738
2713 test "with workflow privilege and :edit_issues permission should accept authorized status" do
2739 test "with workflow privilege and :edit_issues permission should accept authorized status" do
2714 setup_with_workflow_privilege_and_edit_issues_permission
2740 setup_with_workflow_privilege_and_edit_issues_permission
2715 assert_difference 'Journal.count' do
2741 assert_difference 'Journal.count' do
2716 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2742 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2717 end
2743 end
2718 assert_equal 3, Issue.find(1).status_id
2744 assert_equal 3, Issue.find(1).status_id
2719 end
2745 end
2720
2746
2721 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
2747 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
2722 setup_with_workflow_privilege_and_edit_issues_permission
2748 setup_with_workflow_privilege_and_edit_issues_permission
2723 assert_difference 'Journal.count' do
2749 assert_difference 'Journal.count' do
2724 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2750 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2725 end
2751 end
2726 assert_equal 1, Issue.find(1).status_id
2752 assert_equal 1, Issue.find(1).status_id
2727 end
2753 end
2728
2754
2729 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
2755 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
2730 setup_with_workflow_privilege_and_edit_issues_permission
2756 setup_with_workflow_privilege_and_edit_issues_permission
2731 assert_difference 'Journal.count' do
2757 assert_difference 'Journal.count' do
2732 put :update, :id => 1,
2758 put :update, :id => 1,
2733 :issue => {:subject => 'changed', :assigned_to_id => 2,
2759 :issue => {:subject => 'changed', :assigned_to_id => 2,
2734 :notes => 'just trying'}
2760 :notes => 'just trying'}
2735 end
2761 end
2736 issue = Issue.find(1)
2762 issue = Issue.find(1)
2737 assert_equal "changed", issue.subject
2763 assert_equal "changed", issue.subject
2738 assert_equal 2, issue.assigned_to_id
2764 assert_equal 2, issue.assigned_to_id
2739 end
2765 end
2740
2766
2741 def test_new_as_copy
2767 def test_new_as_copy
2742 @request.session[:user_id] = 2
2768 @request.session[:user_id] = 2
2743 get :new, :project_id => 1, :copy_from => 1
2769 get :new, :project_id => 1, :copy_from => 1
2744
2770
2745 assert_response :success
2771 assert_response :success
2746 assert_template 'new'
2772 assert_template 'new'
2747
2773
2748 assert_not_nil assigns(:issue)
2774 assert_not_nil assigns(:issue)
2749 orig = Issue.find(1)
2775 orig = Issue.find(1)
2750 assert_equal 1, assigns(:issue).project_id
2776 assert_equal 1, assigns(:issue).project_id
2751 assert_equal orig.subject, assigns(:issue).subject
2777 assert_equal orig.subject, assigns(:issue).subject
2752 assert assigns(:issue).copy?
2778 assert assigns(:issue).copy?
2753
2779
2754 assert_select 'form[id=issue-form][action="/projects/ecookbook/issues"]' do
2780 assert_select 'form[id=issue-form][action="/projects/ecookbook/issues"]' do
2755 assert_select 'select[name=?]', 'issue[project_id]' do
2781 assert_select 'select[name=?]', 'issue[project_id]' do
2756 assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook'
2782 assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook'
2757 assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore'
2783 assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore'
2758 end
2784 end
2759 assert_select 'input[name=copy_from][value="1"]'
2785 assert_select 'input[name=copy_from][value="1"]'
2760 end
2786 end
2761
2787
2762 # "New issue" menu item should not link to copy
2788 # "New issue" menu item should not link to copy
2763 assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]'
2789 assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]'
2764 end
2790 end
2765
2791
2766 def test_new_as_copy_without_add_issues_permission_should_not_propose_current_project_as_target
2792 def test_new_as_copy_without_add_issues_permission_should_not_propose_current_project_as_target
2767 user = setup_user_with_copy_but_not_add_permission
2793 user = setup_user_with_copy_but_not_add_permission
2768
2794
2769 @request.session[:user_id] = user.id
2795 @request.session[:user_id] = user.id
2770 get :new, :project_id => 1, :copy_from => 1
2796 get :new, :project_id => 1, :copy_from => 1
2771
2797
2772 assert_response :success
2798 assert_response :success
2773 assert_template 'new'
2799 assert_template 'new'
2774 assert_select 'select[name=?]', 'issue[project_id]' do
2800 assert_select 'select[name=?]', 'issue[project_id]' do
2775 assert_select 'option[value="1"]', 0
2801 assert_select 'option[value="1"]', 0
2776 assert_select 'option[value="2"]', :text => 'OnlineStore'
2802 assert_select 'option[value="2"]', :text => 'OnlineStore'
2777 end
2803 end
2778 end
2804 end
2779
2805
2780 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2806 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2781 @request.session[:user_id] = 2
2807 @request.session[:user_id] = 2
2782 issue = Issue.find(3)
2808 issue = Issue.find(3)
2783 assert issue.attachments.count > 0
2809 assert issue.attachments.count > 0
2784 get :new, :project_id => 1, :copy_from => 3
2810 get :new, :project_id => 1, :copy_from => 3
2785
2811
2786 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value="1"]'
2812 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value="1"]'
2787 end
2813 end
2788
2814
2789 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2815 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2790 @request.session[:user_id] = 2
2816 @request.session[:user_id] = 2
2791 issue = Issue.find(3)
2817 issue = Issue.find(3)
2792 issue.attachments.delete_all
2818 issue.attachments.delete_all
2793 get :new, :project_id => 1, :copy_from => 3
2819 get :new, :project_id => 1, :copy_from => 3
2794
2820
2795 assert_select 'input[name=copy_attachments]', 0
2821 assert_select 'input[name=copy_attachments]', 0
2796 end
2822 end
2797
2823
2798 def test_new_as_copy_should_preserve_parent_id
2824 def test_new_as_copy_should_preserve_parent_id
2799 @request.session[:user_id] = 2
2825 @request.session[:user_id] = 2
2800 issue = Issue.generate!(:parent_issue_id => 2)
2826 issue = Issue.generate!(:parent_issue_id => 2)
2801 get :new, :project_id => 1, :copy_from => issue.id
2827 get :new, :project_id => 1, :copy_from => issue.id
2802
2828
2803 assert_select 'input[name=?][value="2"]', 'issue[parent_issue_id]'
2829 assert_select 'input[name=?][value="2"]', 'issue[parent_issue_id]'
2804 end
2830 end
2805
2831
2806 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2832 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2807 @request.session[:user_id] = 2
2833 @request.session[:user_id] = 2
2808 issue = Issue.generate_with_descendants!
2834 issue = Issue.generate_with_descendants!
2809 get :new, :project_id => 1, :copy_from => issue.id
2835 get :new, :project_id => 1, :copy_from => issue.id
2810
2836
2811 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]'
2837 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]'
2812 end
2838 end
2813
2839
2814 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2840 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2815 @request.session[:user_id] = 2
2841 @request.session[:user_id] = 2
2816 get :new, :project_id => 1, :copy_from => 99999
2842 get :new, :project_id => 1, :copy_from => 99999
2817 assert_response 404
2843 assert_response 404
2818 end
2844 end
2819
2845
2820 def test_create_as_copy_on_different_project
2846 def test_create_as_copy_on_different_project
2821 @request.session[:user_id] = 2
2847 @request.session[:user_id] = 2
2822 assert_difference 'Issue.count' do
2848 assert_difference 'Issue.count' do
2823 post :create, :project_id => 1, :copy_from => 1,
2849 post :create, :project_id => 1, :copy_from => 1,
2824 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2850 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2825
2851
2826 assert_not_nil assigns(:issue)
2852 assert_not_nil assigns(:issue)
2827 assert assigns(:issue).copy?
2853 assert assigns(:issue).copy?
2828 end
2854 end
2829 issue = Issue.order('id DESC').first
2855 issue = Issue.order('id DESC').first
2830 assert_redirected_to "/issues/#{issue.id}"
2856 assert_redirected_to "/issues/#{issue.id}"
2831
2857
2832 assert_equal 2, issue.project_id
2858 assert_equal 2, issue.project_id
2833 assert_equal 3, issue.tracker_id
2859 assert_equal 3, issue.tracker_id
2834 assert_equal 'Copy', issue.subject
2860 assert_equal 'Copy', issue.subject
2835 end
2861 end
2836
2862
2837 def test_create_as_copy_should_allow_status_to_be_set_to_default
2863 def test_create_as_copy_should_allow_status_to_be_set_to_default
2838 copied = Issue.generate! :status_id => 2
2864 copied = Issue.generate! :status_id => 2
2839 assert_equal 2, copied.reload.status_id
2865 assert_equal 2, copied.reload.status_id
2840
2866
2841 @request.session[:user_id] = 2
2867 @request.session[:user_id] = 2
2842 assert_difference 'Issue.count' do
2868 assert_difference 'Issue.count' do
2843 post :create, :project_id => 1, :copy_from => copied.id,
2869 post :create, :project_id => 1, :copy_from => copied.id,
2844 :issue => {:project_id => '1', :tracker_id => '1', :status_id => '1'},
2870 :issue => {:project_id => '1', :tracker_id => '1', :status_id => '1'},
2845 :was_default_status => '1'
2871 :was_default_status => '1'
2846 end
2872 end
2847 issue = Issue.order('id DESC').first
2873 issue = Issue.order('id DESC').first
2848 assert_equal 1, issue.status_id
2874 assert_equal 1, issue.status_id
2849 end
2875 end
2850
2876
2851 def test_create_as_copy_should_copy_attachments
2877 def test_create_as_copy_should_copy_attachments
2852 @request.session[:user_id] = 2
2878 @request.session[:user_id] = 2
2853 issue = Issue.find(3)
2879 issue = Issue.find(3)
2854 count = issue.attachments.count
2880 count = issue.attachments.count
2855 assert count > 0
2881 assert count > 0
2856 assert_difference 'Issue.count' do
2882 assert_difference 'Issue.count' do
2857 assert_difference 'Attachment.count', count do
2883 assert_difference 'Attachment.count', count do
2858 post :create, :project_id => 1, :copy_from => 3,
2884 post :create, :project_id => 1, :copy_from => 3,
2859 :issue => {:project_id => '1', :tracker_id => '3',
2885 :issue => {:project_id => '1', :tracker_id => '3',
2860 :status_id => '1', :subject => 'Copy with attachments'},
2886 :status_id => '1', :subject => 'Copy with attachments'},
2861 :copy_attachments => '1'
2887 :copy_attachments => '1'
2862 end
2888 end
2863 end
2889 end
2864 copy = Issue.order('id DESC').first
2890 copy = Issue.order('id DESC').first
2865 assert_equal count, copy.attachments.count
2891 assert_equal count, copy.attachments.count
2866 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2892 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2867 end
2893 end
2868
2894
2869 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2895 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2870 @request.session[:user_id] = 2
2896 @request.session[:user_id] = 2
2871 issue = Issue.find(3)
2897 issue = Issue.find(3)
2872 count = issue.attachments.count
2898 count = issue.attachments.count
2873 assert count > 0
2899 assert count > 0
2874 assert_difference 'Issue.count' do
2900 assert_difference 'Issue.count' do
2875 assert_no_difference 'Attachment.count' do
2901 assert_no_difference 'Attachment.count' do
2876 post :create, :project_id => 1, :copy_from => 3,
2902 post :create, :project_id => 1, :copy_from => 3,
2877 :issue => {:project_id => '1', :tracker_id => '3',
2903 :issue => {:project_id => '1', :tracker_id => '3',
2878 :status_id => '1', :subject => 'Copy with attachments'}
2904 :status_id => '1', :subject => 'Copy with attachments'}
2879 end
2905 end
2880 end
2906 end
2881 copy = Issue.order('id DESC').first
2907 copy = Issue.order('id DESC').first
2882 assert_equal 0, copy.attachments.count
2908 assert_equal 0, copy.attachments.count
2883 end
2909 end
2884
2910
2885 def test_create_as_copy_with_attachments_should_also_add_new_files
2911 def test_create_as_copy_with_attachments_should_also_add_new_files
2886 @request.session[:user_id] = 2
2912 @request.session[:user_id] = 2
2887 issue = Issue.find(3)
2913 issue = Issue.find(3)
2888 count = issue.attachments.count
2914 count = issue.attachments.count
2889 assert count > 0
2915 assert count > 0
2890 assert_difference 'Issue.count' do
2916 assert_difference 'Issue.count' do
2891 assert_difference 'Attachment.count', count + 1 do
2917 assert_difference 'Attachment.count', count + 1 do
2892 post :create, :project_id => 1, :copy_from => 3,
2918 post :create, :project_id => 1, :copy_from => 3,
2893 :issue => {:project_id => '1', :tracker_id => '3',
2919 :issue => {:project_id => '1', :tracker_id => '3',
2894 :status_id => '1', :subject => 'Copy with attachments'},
2920 :status_id => '1', :subject => 'Copy with attachments'},
2895 :copy_attachments => '1',
2921 :copy_attachments => '1',
2896 :attachments => {'1' =>
2922 :attachments => {'1' =>
2897 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2923 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2898 'description' => 'test file'}}
2924 'description' => 'test file'}}
2899 end
2925 end
2900 end
2926 end
2901 copy = Issue.order('id DESC').first
2927 copy = Issue.order('id DESC').first
2902 assert_equal count + 1, copy.attachments.count
2928 assert_equal count + 1, copy.attachments.count
2903 end
2929 end
2904
2930
2905 def test_create_as_copy_should_add_relation_with_copied_issue
2931 def test_create_as_copy_should_add_relation_with_copied_issue
2906 @request.session[:user_id] = 2
2932 @request.session[:user_id] = 2
2907 assert_difference 'Issue.count' do
2933 assert_difference 'Issue.count' do
2908 assert_difference 'IssueRelation.count' do
2934 assert_difference 'IssueRelation.count' do
2909 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2935 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2910 :issue => {:project_id => '1', :tracker_id => '3',
2936 :issue => {:project_id => '1', :tracker_id => '3',
2911 :status_id => '1', :subject => 'Copy'}
2937 :status_id => '1', :subject => 'Copy'}
2912 end
2938 end
2913 end
2939 end
2914 copy = Issue.order('id DESC').first
2940 copy = Issue.order('id DESC').first
2915 assert_equal 1, copy.relations.size
2941 assert_equal 1, copy.relations.size
2916 end
2942 end
2917
2943
2918 def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue
2944 def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue
2919 @request.session[:user_id] = 2
2945 @request.session[:user_id] = 2
2920 assert_difference 'Issue.count' do
2946 assert_difference 'Issue.count' do
2921 assert_no_difference 'IssueRelation.count' do
2947 assert_no_difference 'IssueRelation.count' do
2922 post :create, :project_id => 1, :copy_from => 1,
2948 post :create, :project_id => 1, :copy_from => 1,
2923 :issue => {:subject => 'Copy'}
2949 :issue => {:subject => 'Copy'}
2924 end
2950 end
2925 end
2951 end
2926 end
2952 end
2927
2953
2928 def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting
2954 def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting
2929 with_settings :link_copied_issue => 'yes' do
2955 with_settings :link_copied_issue => 'yes' do
2930 @request.session[:user_id] = 2
2956 @request.session[:user_id] = 2
2931 assert_difference 'Issue.count' do
2957 assert_difference 'Issue.count' do
2932 assert_difference 'IssueRelation.count' do
2958 assert_difference 'IssueRelation.count' do
2933 post :create, :project_id => 1, :copy_from => 1,
2959 post :create, :project_id => 1, :copy_from => 1,
2934 :issue => {:subject => 'Copy'}
2960 :issue => {:subject => 'Copy'}
2935 end
2961 end
2936 end
2962 end
2937 end
2963 end
2938 end
2964 end
2939
2965
2940 def test_create_as_copy_should_never_add_relation_with_copied_issue_by_setting
2966 def test_create_as_copy_should_never_add_relation_with_copied_issue_by_setting
2941 with_settings :link_copied_issue => 'no' do
2967 with_settings :link_copied_issue => 'no' do
2942 @request.session[:user_id] = 2
2968 @request.session[:user_id] = 2
2943 assert_difference 'Issue.count' do
2969 assert_difference 'Issue.count' do
2944 assert_no_difference 'IssueRelation.count' do
2970 assert_no_difference 'IssueRelation.count' do
2945 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2971 post :create, :project_id => 1, :copy_from => 1, :link_copy => '1',
2946 :issue => {:subject => 'Copy'}
2972 :issue => {:subject => 'Copy'}
2947 end
2973 end
2948 end
2974 end
2949 end
2975 end
2950 end
2976 end
2951
2977
2952 def test_create_as_copy_should_copy_subtasks
2978 def test_create_as_copy_should_copy_subtasks
2953 @request.session[:user_id] = 2
2979 @request.session[:user_id] = 2
2954 issue = Issue.generate_with_descendants!
2980 issue = Issue.generate_with_descendants!
2955 count = issue.descendants.count
2981 count = issue.descendants.count
2956 assert_difference 'Issue.count', count + 1 do
2982 assert_difference 'Issue.count', count + 1 do
2957 post :create, :project_id => 1, :copy_from => issue.id,
2983 post :create, :project_id => 1, :copy_from => issue.id,
2958 :issue => {:project_id => '1', :tracker_id => '3',
2984 :issue => {:project_id => '1', :tracker_id => '3',
2959 :status_id => '1', :subject => 'Copy with subtasks'},
2985 :status_id => '1', :subject => 'Copy with subtasks'},
2960 :copy_subtasks => '1'
2986 :copy_subtasks => '1'
2961 end
2987 end
2962 copy = Issue.where(:parent_id => nil).order('id DESC').first
2988 copy = Issue.where(:parent_id => nil).order('id DESC').first
2963 assert_equal count, copy.descendants.count
2989 assert_equal count, copy.descendants.count
2964 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2990 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2965 end
2991 end
2966
2992
2967 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2993 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2968 @request.session[:user_id] = 2
2994 @request.session[:user_id] = 2
2969 issue = Issue.generate_with_descendants!
2995 issue = Issue.generate_with_descendants!
2970 assert_difference 'Issue.count', 1 do
2996 assert_difference 'Issue.count', 1 do
2971 post :create, :project_id => 1, :copy_from => 3,
2997 post :create, :project_id => 1, :copy_from => 3,
2972 :issue => {:project_id => '1', :tracker_id => '3',
2998 :issue => {:project_id => '1', :tracker_id => '3',
2973 :status_id => '1', :subject => 'Copy with subtasks'}
2999 :status_id => '1', :subject => 'Copy with subtasks'}
2974 end
3000 end
2975 copy = Issue.where(:parent_id => nil).order('id DESC').first
3001 copy = Issue.where(:parent_id => nil).order('id DESC').first
2976 assert_equal 0, copy.descendants.count
3002 assert_equal 0, copy.descendants.count
2977 end
3003 end
2978
3004
2979 def test_create_as_copy_with_failure
3005 def test_create_as_copy_with_failure
2980 @request.session[:user_id] = 2
3006 @request.session[:user_id] = 2
2981 post :create, :project_id => 1, :copy_from => 1,
3007 post :create, :project_id => 1, :copy_from => 1,
2982 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
3008 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2983
3009
2984 assert_response :success
3010 assert_response :success
2985 assert_template 'new'
3011 assert_template 'new'
2986
3012
2987 assert_not_nil assigns(:issue)
3013 assert_not_nil assigns(:issue)
2988 assert assigns(:issue).copy?
3014 assert assigns(:issue).copy?
2989
3015
2990 assert_select 'form#issue-form[action="/projects/ecookbook/issues"]' do
3016 assert_select 'form#issue-form[action="/projects/ecookbook/issues"]' do
2991 assert_select 'select[name=?]', 'issue[project_id]' do
3017 assert_select 'select[name=?]', 'issue[project_id]' do
2992 assert_select 'option[value="1"]:not([selected])', :text => 'eCookbook'
3018 assert_select 'option[value="1"]:not([selected])', :text => 'eCookbook'
2993 assert_select 'option[value="2"][selected=selected]', :text => 'OnlineStore'
3019 assert_select 'option[value="2"][selected=selected]', :text => 'OnlineStore'
2994 end
3020 end
2995 assert_select 'input[name=copy_from][value="1"]'
3021 assert_select 'input[name=copy_from][value="1"]'
2996 end
3022 end
2997 end
3023 end
2998
3024
2999 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
3025 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
3000 @request.session[:user_id] = 2
3026 @request.session[:user_id] = 2
3001 assert !User.find(2).member_of?(Project.find(4))
3027 assert !User.find(2).member_of?(Project.find(4))
3002
3028
3003 assert_difference 'Issue.count' do
3029 assert_difference 'Issue.count' do
3004 post :create, :project_id => 1, :copy_from => 1,
3030 post :create, :project_id => 1, :copy_from => 1,
3005 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
3031 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
3006 end
3032 end
3007 issue = Issue.order('id DESC').first
3033 issue = Issue.order('id DESC').first
3008 assert_equal 1, issue.project_id
3034 assert_equal 1, issue.project_id
3009 end
3035 end
3010
3036
3011 def test_get_edit
3037 def test_get_edit
3012 @request.session[:user_id] = 2
3038 @request.session[:user_id] = 2
3013 get :edit, :id => 1
3039 get :edit, :id => 1
3014 assert_response :success
3040 assert_response :success
3015 assert_template 'edit'
3041 assert_template 'edit'
3016 assert_not_nil assigns(:issue)
3042 assert_not_nil assigns(:issue)
3017 assert_equal Issue.find(1), assigns(:issue)
3043 assert_equal Issue.find(1), assigns(:issue)
3018
3044
3019 # Be sure we don't display inactive IssuePriorities
3045 # Be sure we don't display inactive IssuePriorities
3020 assert ! IssuePriority.find(15).active?
3046 assert ! IssuePriority.find(15).active?
3021 assert_select 'select[name=?]', 'issue[priority_id]' do
3047 assert_select 'select[name=?]', 'issue[priority_id]' do
3022 assert_select 'option[value="15"]', 0
3048 assert_select 'option[value="15"]', 0
3023 end
3049 end
3024 end
3050 end
3025
3051
3026 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
3052 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
3027 @request.session[:user_id] = 2
3053 @request.session[:user_id] = 2
3028 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
3054 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
3029
3055
3030 get :edit, :id => 1
3056 get :edit, :id => 1
3031 assert_select 'input[name=?]', 'time_entry[hours]'
3057 assert_select 'input[name=?]', 'time_entry[hours]'
3032 end
3058 end
3033
3059
3034 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
3060 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
3035 @request.session[:user_id] = 2
3061 @request.session[:user_id] = 2
3036 Role.find_by_name('Manager').remove_permission! :log_time
3062 Role.find_by_name('Manager').remove_permission! :log_time
3037
3063
3038 get :edit, :id => 1
3064 get :edit, :id => 1
3039 assert_select 'input[name=?]', 'time_entry[hours]', 0
3065 assert_select 'input[name=?]', 'time_entry[hours]', 0
3040 end
3066 end
3041
3067
3042 def test_get_edit_with_params
3068 def test_get_edit_with_params
3043 @request.session[:user_id] = 2
3069 @request.session[:user_id] = 2
3044 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
3070 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
3045 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
3071 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
3046 assert_response :success
3072 assert_response :success
3047 assert_template 'edit'
3073 assert_template 'edit'
3048
3074
3049 issue = assigns(:issue)
3075 issue = assigns(:issue)
3050 assert_not_nil issue
3076 assert_not_nil issue
3051
3077
3052 assert_equal 5, issue.status_id
3078 assert_equal 5, issue.status_id
3053 assert_select 'select[name=?]', 'issue[status_id]' do
3079 assert_select 'select[name=?]', 'issue[status_id]' do
3054 assert_select 'option[value="5"][selected=selected]', :text => 'Closed'
3080 assert_select 'option[value="5"][selected=selected]', :text => 'Closed'
3055 end
3081 end
3056
3082
3057 assert_equal 7, issue.priority_id
3083 assert_equal 7, issue.priority_id
3058 assert_select 'select[name=?]', 'issue[priority_id]' do
3084 assert_select 'select[name=?]', 'issue[priority_id]' do
3059 assert_select 'option[value="7"][selected=selected]', :text => 'Urgent'
3085 assert_select 'option[value="7"][selected=selected]', :text => 'Urgent'
3060 end
3086 end
3061
3087
3062 assert_select 'input[name=?][value="2.5"]', 'time_entry[hours]'
3088 assert_select 'input[name=?][value="2.5"]', 'time_entry[hours]'
3063 assert_select 'select[name=?]', 'time_entry[activity_id]' do
3089 assert_select 'select[name=?]', 'time_entry[activity_id]' do
3064 assert_select 'option[value="10"][selected=selected]', :text => 'Development'
3090 assert_select 'option[value="10"][selected=selected]', :text => 'Development'
3065 end
3091 end
3066 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
3092 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
3067 end
3093 end
3068
3094
3069 def test_get_edit_with_multi_custom_field
3095 def test_get_edit_with_multi_custom_field
3070 field = CustomField.find(1)
3096 field = CustomField.find(1)
3071 field.update_attribute :multiple, true
3097 field.update_attribute :multiple, true
3072 issue = Issue.find(1)
3098 issue = Issue.find(1)
3073 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3099 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3074 issue.save!
3100 issue.save!
3075
3101
3076 @request.session[:user_id] = 2
3102 @request.session[:user_id] = 2
3077 get :edit, :id => 1
3103 get :edit, :id => 1
3078 assert_response :success
3104 assert_response :success
3079 assert_template 'edit'
3105 assert_template 'edit'
3080
3106
3081 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
3107 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
3082 assert_select 'option', 3
3108 assert_select 'option', 3
3083 assert_select 'option[value=MySQL][selected=selected]'
3109 assert_select 'option[value=MySQL][selected=selected]'
3084 assert_select 'option[value=Oracle][selected=selected]'
3110 assert_select 'option[value=Oracle][selected=selected]'
3085 assert_select 'option[value=PostgreSQL]:not([selected])'
3111 assert_select 'option[value=PostgreSQL]:not([selected])'
3086 end
3112 end
3087 end
3113 end
3088
3114
3089 def test_update_form_for_existing_issue
3115 def test_update_form_for_existing_issue
3090 @request.session[:user_id] = 2
3116 @request.session[:user_id] = 2
3091 xhr :patch, :edit, :id => 1,
3117 xhr :patch, :edit, :id => 1,
3092 :issue => {:tracker_id => 2,
3118 :issue => {:tracker_id => 2,
3093 :subject => 'This is the test_new issue',
3119 :subject => 'This is the test_new issue',
3094 :description => 'This is the description',
3120 :description => 'This is the description',
3095 :priority_id => 5}
3121 :priority_id => 5}
3096 assert_response :success
3122 assert_response :success
3097 assert_equal 'text/javascript', response.content_type
3123 assert_equal 'text/javascript', response.content_type
3098 assert_template 'edit'
3124 assert_template 'edit'
3099 assert_template :partial => '_form'
3125 assert_template :partial => '_form'
3100
3126
3101 issue = assigns(:issue)
3127 issue = assigns(:issue)
3102 assert_kind_of Issue, issue
3128 assert_kind_of Issue, issue
3103 assert_equal 1, issue.id
3129 assert_equal 1, issue.id
3104 assert_equal 1, issue.project_id
3130 assert_equal 1, issue.project_id
3105 assert_equal 2, issue.tracker_id
3131 assert_equal 2, issue.tracker_id
3106 assert_equal 'This is the test_new issue', issue.subject
3132 assert_equal 'This is the test_new issue', issue.subject
3107 end
3133 end
3108
3134
3109 def test_update_form_for_existing_issue_should_keep_issue_author
3135 def test_update_form_for_existing_issue_should_keep_issue_author
3110 @request.session[:user_id] = 3
3136 @request.session[:user_id] = 3
3111 xhr :patch, :edit, :id => 1, :issue => {:subject => 'Changed'}
3137 xhr :patch, :edit, :id => 1, :issue => {:subject => 'Changed'}
3112 assert_response :success
3138 assert_response :success
3113 assert_equal 'text/javascript', response.content_type
3139 assert_equal 'text/javascript', response.content_type
3114
3140
3115 issue = assigns(:issue)
3141 issue = assigns(:issue)
3116 assert_equal User.find(2), issue.author
3142 assert_equal User.find(2), issue.author
3117 assert_equal 2, issue.author_id
3143 assert_equal 2, issue.author_id
3118 assert_not_equal User.current, issue.author
3144 assert_not_equal User.current, issue.author
3119 end
3145 end
3120
3146
3121 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
3147 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
3122 @request.session[:user_id] = 2
3148 @request.session[:user_id] = 2
3123 WorkflowTransition.delete_all
3149 WorkflowTransition.delete_all
3124 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3150 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3125 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3151 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3126 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
3152 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
3127
3153
3128 xhr :patch, :edit, :id => 2,
3154 xhr :patch, :edit, :id => 2,
3129 :issue => {:tracker_id => 2,
3155 :issue => {:tracker_id => 2,
3130 :status_id => 5,
3156 :status_id => 5,
3131 :subject => 'This is an issue'}
3157 :subject => 'This is an issue'}
3132
3158
3133 assert_equal 5, assigns(:issue).status_id
3159 assert_equal 5, assigns(:issue).status_id
3134 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
3160 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
3135 end
3161 end
3136
3162
3137 def test_update_form_for_existing_issue_with_project_change
3163 def test_update_form_for_existing_issue_with_project_change
3138 @request.session[:user_id] = 2
3164 @request.session[:user_id] = 2
3139 xhr :patch, :edit, :id => 1,
3165 xhr :patch, :edit, :id => 1,
3140 :issue => {:project_id => 2,
3166 :issue => {:project_id => 2,
3141 :tracker_id => 2,
3167 :tracker_id => 2,
3142 :subject => 'This is the test_new issue',
3168 :subject => 'This is the test_new issue',
3143 :description => 'This is the description',
3169 :description => 'This is the description',
3144 :priority_id => 5}
3170 :priority_id => 5}
3145 assert_response :success
3171 assert_response :success
3146 assert_template :partial => '_form'
3172 assert_template :partial => '_form'
3147
3173
3148 issue = assigns(:issue)
3174 issue = assigns(:issue)
3149 assert_kind_of Issue, issue
3175 assert_kind_of Issue, issue
3150 assert_equal 1, issue.id
3176 assert_equal 1, issue.id
3151 assert_equal 2, issue.project_id
3177 assert_equal 2, issue.project_id
3152 assert_equal 2, issue.tracker_id
3178 assert_equal 2, issue.tracker_id
3153 assert_equal 'This is the test_new issue', issue.subject
3179 assert_equal 'This is the test_new issue', issue.subject
3154 end
3180 end
3155
3181
3156 def test_update_form_should_keep_category_with_same_when_changing_project
3182 def test_update_form_should_keep_category_with_same_when_changing_project
3157 source = Project.generate!
3183 source = Project.generate!
3158 target = Project.generate!
3184 target = Project.generate!
3159 source_category = IssueCategory.create!(:name => 'Foo', :project => source)
3185 source_category = IssueCategory.create!(:name => 'Foo', :project => source)
3160 target_category = IssueCategory.create!(:name => 'Foo', :project => target)
3186 target_category = IssueCategory.create!(:name => 'Foo', :project => target)
3161 issue = Issue.generate!(:project => source, :category => source_category)
3187 issue = Issue.generate!(:project => source, :category => source_category)
3162
3188
3163 @request.session[:user_id] = 1
3189 @request.session[:user_id] = 1
3164 patch :edit, :id => issue.id,
3190 patch :edit, :id => issue.id,
3165 :issue => {:project_id => target.id, :category_id => source_category.id}
3191 :issue => {:project_id => target.id, :category_id => source_category.id}
3166 assert_response :success
3192 assert_response :success
3167
3193
3168 issue = assigns(:issue)
3194 issue = assigns(:issue)
3169 assert_equal target_category, issue.category
3195 assert_equal target_category, issue.category
3170 end
3196 end
3171
3197
3172 def test_update_form_should_propose_default_status_for_existing_issue
3198 def test_update_form_should_propose_default_status_for_existing_issue
3173 @request.session[:user_id] = 2
3199 @request.session[:user_id] = 2
3174 WorkflowTransition.delete_all
3200 WorkflowTransition.delete_all
3175 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3201 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3176
3202
3177 xhr :patch, :edit, :id => 2
3203 xhr :patch, :edit, :id => 2
3178 assert_response :success
3204 assert_response :success
3179 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
3205 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
3180 end
3206 end
3181
3207
3182 def test_put_update_without_custom_fields_param
3208 def test_put_update_without_custom_fields_param
3183 @request.session[:user_id] = 2
3209 @request.session[:user_id] = 2
3184
3210
3185 issue = Issue.find(1)
3211 issue = Issue.find(1)
3186 assert_equal '125', issue.custom_value_for(2).value
3212 assert_equal '125', issue.custom_value_for(2).value
3187
3213
3188 assert_difference('Journal.count') do
3214 assert_difference('Journal.count') do
3189 assert_difference('JournalDetail.count') do
3215 assert_difference('JournalDetail.count') do
3190 put :update, :id => 1, :issue => {:subject => 'New subject'}
3216 put :update, :id => 1, :issue => {:subject => 'New subject'}
3191 end
3217 end
3192 end
3218 end
3193 assert_redirected_to :action => 'show', :id => '1'
3219 assert_redirected_to :action => 'show', :id => '1'
3194 issue.reload
3220 issue.reload
3195 assert_equal 'New subject', issue.subject
3221 assert_equal 'New subject', issue.subject
3196 # Make sure custom fields were not cleared
3222 # Make sure custom fields were not cleared
3197 assert_equal '125', issue.custom_value_for(2).value
3223 assert_equal '125', issue.custom_value_for(2).value
3198 end
3224 end
3199
3225
3200 def test_put_update_with_project_change
3226 def test_put_update_with_project_change
3201 @request.session[:user_id] = 2
3227 @request.session[:user_id] = 2
3202 ActionMailer::Base.deliveries.clear
3228 ActionMailer::Base.deliveries.clear
3203
3229
3204 with_settings :notified_events => %w(issue_updated) do
3230 with_settings :notified_events => %w(issue_updated) do
3205 assert_difference('Journal.count') do
3231 assert_difference('Journal.count') do
3206 assert_difference('JournalDetail.count', 3) do
3232 assert_difference('JournalDetail.count', 3) do
3207 put :update, :id => 1, :issue => {:project_id => '2',
3233 put :update, :id => 1, :issue => {:project_id => '2',
3208 :tracker_id => '1', # no change
3234 :tracker_id => '1', # no change
3209 :priority_id => '6',
3235 :priority_id => '6',
3210 :category_id => '3'
3236 :category_id => '3'
3211 }
3237 }
3212 end
3238 end
3213 end
3239 end
3214 end
3240 end
3215 assert_redirected_to :action => 'show', :id => '1'
3241 assert_redirected_to :action => 'show', :id => '1'
3216 issue = Issue.find(1)
3242 issue = Issue.find(1)
3217 assert_equal 2, issue.project_id
3243 assert_equal 2, issue.project_id
3218 assert_equal 1, issue.tracker_id
3244 assert_equal 1, issue.tracker_id
3219 assert_equal 6, issue.priority_id
3245 assert_equal 6, issue.priority_id
3220 assert_equal 3, issue.category_id
3246 assert_equal 3, issue.category_id
3221
3247
3222 mail = ActionMailer::Base.deliveries.last
3248 mail = ActionMailer::Base.deliveries.last
3223 assert_not_nil mail
3249 assert_not_nil mail
3224 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3250 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3225 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
3251 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
3226 end
3252 end
3227
3253
3228 def test_put_update_trying_to_move_issue_to_project_without_tracker_should_not_error
3254 def test_put_update_trying_to_move_issue_to_project_without_tracker_should_not_error
3229 target = Project.generate!(:tracker_ids => [])
3255 target = Project.generate!(:tracker_ids => [])
3230 assert target.trackers.empty?
3256 assert target.trackers.empty?
3231 issue = Issue.generate!
3257 issue = Issue.generate!
3232 @request.session[:user_id] = 1
3258 @request.session[:user_id] = 1
3233
3259
3234 put :update, :id => issue.id, :issue => {:project_id => target.id}
3260 put :update, :id => issue.id, :issue => {:project_id => target.id}
3235 assert_response 302
3261 assert_response 302
3236 end
3262 end
3237
3263
3238 def test_put_update_with_tracker_change
3264 def test_put_update_with_tracker_change
3239 @request.session[:user_id] = 2
3265 @request.session[:user_id] = 2
3240 ActionMailer::Base.deliveries.clear
3266 ActionMailer::Base.deliveries.clear
3241
3267
3242 with_settings :notified_events => %w(issue_updated) do
3268 with_settings :notified_events => %w(issue_updated) do
3243 assert_difference('Journal.count') do
3269 assert_difference('Journal.count') do
3244 assert_difference('JournalDetail.count', 2) do
3270 assert_difference('JournalDetail.count', 2) do
3245 put :update, :id => 1, :issue => {:project_id => '1',
3271 put :update, :id => 1, :issue => {:project_id => '1',
3246 :tracker_id => '2',
3272 :tracker_id => '2',
3247 :priority_id => '6'
3273 :priority_id => '6'
3248 }
3274 }
3249 end
3275 end
3250 end
3276 end
3251 end
3277 end
3252 assert_redirected_to :action => 'show', :id => '1'
3278 assert_redirected_to :action => 'show', :id => '1'
3253 issue = Issue.find(1)
3279 issue = Issue.find(1)
3254 assert_equal 1, issue.project_id
3280 assert_equal 1, issue.project_id
3255 assert_equal 2, issue.tracker_id
3281 assert_equal 2, issue.tracker_id
3256 assert_equal 6, issue.priority_id
3282 assert_equal 6, issue.priority_id
3257 assert_equal 1, issue.category_id
3283 assert_equal 1, issue.category_id
3258
3284
3259 mail = ActionMailer::Base.deliveries.last
3285 mail = ActionMailer::Base.deliveries.last
3260 assert_not_nil mail
3286 assert_not_nil mail
3261 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3287 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
3262 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
3288 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
3263 end
3289 end
3264
3290
3265 def test_put_update_with_custom_field_change
3291 def test_put_update_with_custom_field_change
3266 @request.session[:user_id] = 2
3292 @request.session[:user_id] = 2
3267 issue = Issue.find(1)
3293 issue = Issue.find(1)
3268 assert_equal '125', issue.custom_value_for(2).value
3294 assert_equal '125', issue.custom_value_for(2).value
3269
3295
3270 with_settings :notified_events => %w(issue_updated) do
3296 with_settings :notified_events => %w(issue_updated) do
3271 assert_difference('Journal.count') do
3297 assert_difference('Journal.count') do
3272 assert_difference('JournalDetail.count', 3) do
3298 assert_difference('JournalDetail.count', 3) do
3273 put :update, :id => 1, :issue => {:subject => 'Custom field change',
3299 put :update, :id => 1, :issue => {:subject => 'Custom field change',
3274 :priority_id => '6',
3300 :priority_id => '6',
3275 :category_id => '1', # no change
3301 :category_id => '1', # no change
3276 :custom_field_values => { '2' => 'New custom value' }
3302 :custom_field_values => { '2' => 'New custom value' }
3277 }
3303 }
3278 end
3304 end
3279 end
3305 end
3280 end
3306 end
3281 assert_redirected_to :action => 'show', :id => '1'
3307 assert_redirected_to :action => 'show', :id => '1'
3282 issue.reload
3308 issue.reload
3283 assert_equal 'New custom value', issue.custom_value_for(2).value
3309 assert_equal 'New custom value', issue.custom_value_for(2).value
3284
3310
3285 mail = ActionMailer::Base.deliveries.last
3311 mail = ActionMailer::Base.deliveries.last
3286 assert_not_nil mail
3312 assert_not_nil mail
3287 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
3313 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
3288 end
3314 end
3289
3315
3290 def test_put_update_with_multi_custom_field_change
3316 def test_put_update_with_multi_custom_field_change
3291 field = CustomField.find(1)
3317 field = CustomField.find(1)
3292 field.update_attribute :multiple, true
3318 field.update_attribute :multiple, true
3293 issue = Issue.find(1)
3319 issue = Issue.find(1)
3294 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3320 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
3295 issue.save!
3321 issue.save!
3296
3322
3297 @request.session[:user_id] = 2
3323 @request.session[:user_id] = 2
3298 assert_difference('Journal.count') do
3324 assert_difference('Journal.count') do
3299 assert_difference('JournalDetail.count', 3) do
3325 assert_difference('JournalDetail.count', 3) do
3300 put :update, :id => 1,
3326 put :update, :id => 1,
3301 :issue => {
3327 :issue => {
3302 :subject => 'Custom field change',
3328 :subject => 'Custom field change',
3303 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
3329 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
3304 }
3330 }
3305 end
3331 end
3306 end
3332 end
3307 assert_redirected_to :action => 'show', :id => '1'
3333 assert_redirected_to :action => 'show', :id => '1'
3308 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
3334 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
3309 end
3335 end
3310
3336
3311 def test_put_update_with_status_and_assignee_change
3337 def test_put_update_with_status_and_assignee_change
3312 issue = Issue.find(1)
3338 issue = Issue.find(1)
3313 assert_equal 1, issue.status_id
3339 assert_equal 1, issue.status_id
3314 @request.session[:user_id] = 2
3340 @request.session[:user_id] = 2
3315
3341
3316 with_settings :notified_events => %w(issue_updated) do
3342 with_settings :notified_events => %w(issue_updated) do
3317 assert_difference('TimeEntry.count', 0) do
3343 assert_difference('TimeEntry.count', 0) do
3318 put :update,
3344 put :update,
3319 :id => 1,
3345 :id => 1,
3320 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
3346 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
3321 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
3347 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
3322 end
3348 end
3323 end
3349 end
3324 assert_redirected_to :action => 'show', :id => '1'
3350 assert_redirected_to :action => 'show', :id => '1'
3325 issue.reload
3351 issue.reload
3326 assert_equal 2, issue.status_id
3352 assert_equal 2, issue.status_id
3327 j = Journal.order('id DESC').first
3353 j = Journal.order('id DESC').first
3328 assert_equal 'Assigned to dlopper', j.notes
3354 assert_equal 'Assigned to dlopper', j.notes
3329 assert_equal 2, j.details.size
3355 assert_equal 2, j.details.size
3330
3356
3331 mail = ActionMailer::Base.deliveries.last
3357 mail = ActionMailer::Base.deliveries.last
3332 assert_mail_body_match "Status changed from New to Assigned", mail
3358 assert_mail_body_match "Status changed from New to Assigned", mail
3333 # subject should contain the new status
3359 # subject should contain the new status
3334 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
3360 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
3335 end
3361 end
3336
3362
3337 def test_put_update_with_note_only
3363 def test_put_update_with_note_only
3338 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
3364 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
3339
3365
3340 with_settings :notified_events => %w(issue_updated) do
3366 with_settings :notified_events => %w(issue_updated) do
3341 # anonymous user
3367 # anonymous user
3342 put :update,
3368 put :update,
3343 :id => 1,
3369 :id => 1,
3344 :issue => { :notes => notes }
3370 :issue => { :notes => notes }
3345 end
3371 end
3346 assert_redirected_to :action => 'show', :id => '1'
3372 assert_redirected_to :action => 'show', :id => '1'
3347 j = Journal.order('id DESC').first
3373 j = Journal.order('id DESC').first
3348 assert_equal notes, j.notes
3374 assert_equal notes, j.notes
3349 assert_equal 0, j.details.size
3375 assert_equal 0, j.details.size
3350 assert_equal User.anonymous, j.user
3376 assert_equal User.anonymous, j.user
3351
3377
3352 mail = ActionMailer::Base.deliveries.last
3378 mail = ActionMailer::Base.deliveries.last
3353 assert_mail_body_match notes, mail
3379 assert_mail_body_match notes, mail
3354 end
3380 end
3355
3381
3356 def test_put_update_with_private_note_only
3382 def test_put_update_with_private_note_only
3357 notes = 'Private note'
3383 notes = 'Private note'
3358 @request.session[:user_id] = 2
3384 @request.session[:user_id] = 2
3359
3385
3360 assert_difference 'Journal.count' do
3386 assert_difference 'Journal.count' do
3361 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
3387 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
3362 assert_redirected_to :action => 'show', :id => '1'
3388 assert_redirected_to :action => 'show', :id => '1'
3363 end
3389 end
3364
3390
3365 j = Journal.order('id DESC').first
3391 j = Journal.order('id DESC').first
3366 assert_equal notes, j.notes
3392 assert_equal notes, j.notes
3367 assert_equal true, j.private_notes
3393 assert_equal true, j.private_notes
3368 end
3394 end
3369
3395
3370 def test_put_update_with_private_note_and_changes
3396 def test_put_update_with_private_note_and_changes
3371 notes = 'Private note'
3397 notes = 'Private note'
3372 @request.session[:user_id] = 2
3398 @request.session[:user_id] = 2
3373
3399
3374 assert_difference 'Journal.count', 2 do
3400 assert_difference 'Journal.count', 2 do
3375 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
3401 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
3376 assert_redirected_to :action => 'show', :id => '1'
3402 assert_redirected_to :action => 'show', :id => '1'
3377 end
3403 end
3378
3404
3379 j = Journal.order('id DESC').first
3405 j = Journal.order('id DESC').first
3380 assert_equal notes, j.notes
3406 assert_equal notes, j.notes
3381 assert_equal true, j.private_notes
3407 assert_equal true, j.private_notes
3382 assert_equal 0, j.details.count
3408 assert_equal 0, j.details.count
3383
3409
3384 j = Journal.order('id DESC').offset(1).first
3410 j = Journal.order('id DESC').offset(1).first
3385 assert_nil j.notes
3411 assert_nil j.notes
3386 assert_equal false, j.private_notes
3412 assert_equal false, j.private_notes
3387 assert_equal 1, j.details.count
3413 assert_equal 1, j.details.count
3388 end
3414 end
3389
3415
3390 def test_put_update_with_note_and_spent_time
3416 def test_put_update_with_note_and_spent_time
3391 @request.session[:user_id] = 2
3417 @request.session[:user_id] = 2
3392 spent_hours_before = Issue.find(1).spent_hours
3418 spent_hours_before = Issue.find(1).spent_hours
3393 assert_difference('TimeEntry.count') do
3419 assert_difference('TimeEntry.count') do
3394 put :update,
3420 put :update,
3395 :id => 1,
3421 :id => 1,
3396 :issue => { :notes => '2.5 hours added' },
3422 :issue => { :notes => '2.5 hours added' },
3397 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
3423 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
3398 end
3424 end
3399 assert_redirected_to :action => 'show', :id => '1'
3425 assert_redirected_to :action => 'show', :id => '1'
3400
3426
3401 issue = Issue.find(1)
3427 issue = Issue.find(1)
3402
3428
3403 j = Journal.order('id DESC').first
3429 j = Journal.order('id DESC').first
3404 assert_equal '2.5 hours added', j.notes
3430 assert_equal '2.5 hours added', j.notes
3405 assert_equal 0, j.details.size
3431 assert_equal 0, j.details.size
3406
3432
3407 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
3433 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
3408 assert_not_nil t
3434 assert_not_nil t
3409 assert_equal 2.5, t.hours
3435 assert_equal 2.5, t.hours
3410 assert_equal spent_hours_before + 2.5, issue.spent_hours
3436 assert_equal spent_hours_before + 2.5, issue.spent_hours
3411 end
3437 end
3412
3438
3413 def test_put_update_should_preserve_parent_issue_even_if_not_visible
3439 def test_put_update_should_preserve_parent_issue_even_if_not_visible
3414 parent = Issue.generate!(:project_id => 1, :is_private => true)
3440 parent = Issue.generate!(:project_id => 1, :is_private => true)
3415 issue = Issue.generate!(:parent_issue_id => parent.id)
3441 issue = Issue.generate!(:parent_issue_id => parent.id)
3416 assert !parent.visible?(User.find(3))
3442 assert !parent.visible?(User.find(3))
3417 @request.session[:user_id] = 3
3443 @request.session[:user_id] = 3
3418
3444
3419 get :edit, :id => issue.id
3445 get :edit, :id => issue.id
3420 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
3446 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
3421
3447
3422 put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s}
3448 put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s}
3423 assert_response 302
3449 assert_response 302
3424 assert_equal parent, issue.parent
3450 assert_equal parent, issue.parent
3425 end
3451 end
3426
3452
3427 def test_put_update_with_attachment_only
3453 def test_put_update_with_attachment_only
3428 set_tmp_attachments_directory
3454 set_tmp_attachments_directory
3429
3455
3430 # Delete all fixtured journals, a race condition can occur causing the wrong
3456 # Delete all fixtured journals, a race condition can occur causing the wrong
3431 # journal to get fetched in the next find.
3457 # journal to get fetched in the next find.
3432 Journal.delete_all
3458 Journal.delete_all
3433
3459
3434 with_settings :notified_events => %w(issue_updated) do
3460 with_settings :notified_events => %w(issue_updated) do
3435 # anonymous user
3461 # anonymous user
3436 assert_difference 'Attachment.count' do
3462 assert_difference 'Attachment.count' do
3437 put :update, :id => 1,
3463 put :update, :id => 1,
3438 :issue => {:notes => ''},
3464 :issue => {:notes => ''},
3439 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3465 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3440 end
3466 end
3441 end
3467 end
3442
3468
3443 assert_redirected_to :action => 'show', :id => '1'
3469 assert_redirected_to :action => 'show', :id => '1'
3444 j = Issue.find(1).journals.reorder('id DESC').first
3470 j = Issue.find(1).journals.reorder('id DESC').first
3445 assert j.notes.blank?
3471 assert j.notes.blank?
3446 assert_equal 1, j.details.size
3472 assert_equal 1, j.details.size
3447 assert_equal 'testfile.txt', j.details.first.value
3473 assert_equal 'testfile.txt', j.details.first.value
3448 assert_equal User.anonymous, j.user
3474 assert_equal User.anonymous, j.user
3449
3475
3450 attachment = Attachment.order('id DESC').first
3476 attachment = Attachment.order('id DESC').first
3451 assert_equal Issue.find(1), attachment.container
3477 assert_equal Issue.find(1), attachment.container
3452 assert_equal User.anonymous, attachment.author
3478 assert_equal User.anonymous, attachment.author
3453 assert_equal 'testfile.txt', attachment.filename
3479 assert_equal 'testfile.txt', attachment.filename
3454 assert_equal 'text/plain', attachment.content_type
3480 assert_equal 'text/plain', attachment.content_type
3455 assert_equal 'test file', attachment.description
3481 assert_equal 'test file', attachment.description
3456 assert_equal 59, attachment.filesize
3482 assert_equal 59, attachment.filesize
3457 assert File.exists?(attachment.diskfile)
3483 assert File.exists?(attachment.diskfile)
3458 assert_equal 59, File.size(attachment.diskfile)
3484 assert_equal 59, File.size(attachment.diskfile)
3459
3485
3460 mail = ActionMailer::Base.deliveries.last
3486 mail = ActionMailer::Base.deliveries.last
3461 assert_mail_body_match 'testfile.txt', mail
3487 assert_mail_body_match 'testfile.txt', mail
3462 end
3488 end
3463
3489
3464 def test_put_update_with_failure_should_save_attachments
3490 def test_put_update_with_failure_should_save_attachments
3465 set_tmp_attachments_directory
3491 set_tmp_attachments_directory
3466 @request.session[:user_id] = 2
3492 @request.session[:user_id] = 2
3467
3493
3468 assert_no_difference 'Journal.count' do
3494 assert_no_difference 'Journal.count' do
3469 assert_difference 'Attachment.count' do
3495 assert_difference 'Attachment.count' do
3470 put :update, :id => 1,
3496 put :update, :id => 1,
3471 :issue => { :subject => '' },
3497 :issue => { :subject => '' },
3472 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3498 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
3473 assert_response :success
3499 assert_response :success
3474 assert_template 'edit'
3500 assert_template 'edit'
3475 end
3501 end
3476 end
3502 end
3477
3503
3478 attachment = Attachment.order('id DESC').first
3504 attachment = Attachment.order('id DESC').first
3479 assert_equal 'testfile.txt', attachment.filename
3505 assert_equal 'testfile.txt', attachment.filename
3480 assert File.exists?(attachment.diskfile)
3506 assert File.exists?(attachment.diskfile)
3481 assert_nil attachment.container
3507 assert_nil attachment.container
3482
3508
3483 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3509 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3484 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3510 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3485 end
3511 end
3486
3512
3487 def test_put_update_with_failure_should_keep_saved_attachments
3513 def test_put_update_with_failure_should_keep_saved_attachments
3488 set_tmp_attachments_directory
3514 set_tmp_attachments_directory
3489 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3515 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3490 @request.session[:user_id] = 2
3516 @request.session[:user_id] = 2
3491
3517
3492 assert_no_difference 'Journal.count' do
3518 assert_no_difference 'Journal.count' do
3493 assert_no_difference 'Attachment.count' do
3519 assert_no_difference 'Attachment.count' do
3494 put :update, :id => 1,
3520 put :update, :id => 1,
3495 :issue => { :subject => '' },
3521 :issue => { :subject => '' },
3496 :attachments => {'p0' => {'token' => attachment.token}}
3522 :attachments => {'p0' => {'token' => attachment.token}}
3497 assert_response :success
3523 assert_response :success
3498 assert_template 'edit'
3524 assert_template 'edit'
3499 end
3525 end
3500 end
3526 end
3501
3527
3502 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3528 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3503 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3529 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3504 end
3530 end
3505
3531
3506 def test_put_update_should_attach_saved_attachments
3532 def test_put_update_should_attach_saved_attachments
3507 set_tmp_attachments_directory
3533 set_tmp_attachments_directory
3508 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3534 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3509 @request.session[:user_id] = 2
3535 @request.session[:user_id] = 2
3510
3536
3511 assert_difference 'Journal.count' do
3537 assert_difference 'Journal.count' do
3512 assert_difference 'JournalDetail.count' do
3538 assert_difference 'JournalDetail.count' do
3513 assert_no_difference 'Attachment.count' do
3539 assert_no_difference 'Attachment.count' do
3514 put :update, :id => 1,
3540 put :update, :id => 1,
3515 :issue => {:notes => 'Attachment added'},
3541 :issue => {:notes => 'Attachment added'},
3516 :attachments => {'p0' => {'token' => attachment.token}}
3542 :attachments => {'p0' => {'token' => attachment.token}}
3517 assert_redirected_to '/issues/1'
3543 assert_redirected_to '/issues/1'
3518 end
3544 end
3519 end
3545 end
3520 end
3546 end
3521
3547
3522 attachment.reload
3548 attachment.reload
3523 assert_equal Issue.find(1), attachment.container
3549 assert_equal Issue.find(1), attachment.container
3524
3550
3525 journal = Journal.order('id DESC').first
3551 journal = Journal.order('id DESC').first
3526 assert_equal 1, journal.details.size
3552 assert_equal 1, journal.details.size
3527 assert_equal 'testfile.txt', journal.details.first.value
3553 assert_equal 'testfile.txt', journal.details.first.value
3528 end
3554 end
3529
3555
3530 def test_put_update_with_attachment_that_fails_to_save
3556 def test_put_update_with_attachment_that_fails_to_save
3531 set_tmp_attachments_directory
3557 set_tmp_attachments_directory
3532
3558
3533 # anonymous user
3559 # anonymous user
3534 with_settings :attachment_max_size => 0 do
3560 with_settings :attachment_max_size => 0 do
3535 put :update,
3561 put :update,
3536 :id => 1,
3562 :id => 1,
3537 :issue => {:notes => ''},
3563 :issue => {:notes => ''},
3538 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3564 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3539 assert_redirected_to :action => 'show', :id => '1'
3565 assert_redirected_to :action => 'show', :id => '1'
3540 assert_equal '1 file(s) could not be saved.', flash[:warning]
3566 assert_equal '1 file(s) could not be saved.', flash[:warning]
3541 end
3567 end
3542 end
3568 end
3543
3569
3544 def test_put_update_with_no_change
3570 def test_put_update_with_no_change
3545 issue = Issue.find(1)
3571 issue = Issue.find(1)
3546 issue.journals.clear
3572 issue.journals.clear
3547 ActionMailer::Base.deliveries.clear
3573 ActionMailer::Base.deliveries.clear
3548
3574
3549 put :update,
3575 put :update,
3550 :id => 1,
3576 :id => 1,
3551 :issue => {:notes => ''}
3577 :issue => {:notes => ''}
3552 assert_redirected_to :action => 'show', :id => '1'
3578 assert_redirected_to :action => 'show', :id => '1'
3553
3579
3554 issue.reload
3580 issue.reload
3555 assert issue.journals.empty?
3581 assert issue.journals.empty?
3556 # No email should be sent
3582 # No email should be sent
3557 assert ActionMailer::Base.deliveries.empty?
3583 assert ActionMailer::Base.deliveries.empty?
3558 end
3584 end
3559
3585
3560 def test_put_update_should_send_a_notification
3586 def test_put_update_should_send_a_notification
3561 @request.session[:user_id] = 2
3587 @request.session[:user_id] = 2
3562 ActionMailer::Base.deliveries.clear
3588 ActionMailer::Base.deliveries.clear
3563 issue = Issue.find(1)
3589 issue = Issue.find(1)
3564 old_subject = issue.subject
3590 old_subject = issue.subject
3565 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3591 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3566
3592
3567 with_settings :notified_events => %w(issue_updated) do
3593 with_settings :notified_events => %w(issue_updated) do
3568 put :update, :id => 1, :issue => {:subject => new_subject,
3594 put :update, :id => 1, :issue => {:subject => new_subject,
3569 :priority_id => '6',
3595 :priority_id => '6',
3570 :category_id => '1' # no change
3596 :category_id => '1' # no change
3571 }
3597 }
3572 assert_equal 1, ActionMailer::Base.deliveries.size
3598 assert_equal 1, ActionMailer::Base.deliveries.size
3573 end
3599 end
3574 end
3600 end
3575
3601
3576 def test_put_update_with_invalid_spent_time_hours_only
3602 def test_put_update_with_invalid_spent_time_hours_only
3577 @request.session[:user_id] = 2
3603 @request.session[:user_id] = 2
3578 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3604 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3579
3605
3580 assert_no_difference('Journal.count') do
3606 assert_no_difference('Journal.count') do
3581 put :update,
3607 put :update,
3582 :id => 1,
3608 :id => 1,
3583 :issue => {:notes => notes},
3609 :issue => {:notes => notes},
3584 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3610 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3585 end
3611 end
3586 assert_response :success
3612 assert_response :success
3587 assert_template 'edit'
3613 assert_template 'edit'
3588
3614
3589 assert_select_error /Activity cannot be blank/
3615 assert_select_error /Activity cannot be blank/
3590 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3616 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3591 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3617 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3592 end
3618 end
3593
3619
3594 def test_put_update_with_invalid_spent_time_comments_only
3620 def test_put_update_with_invalid_spent_time_comments_only
3595 @request.session[:user_id] = 2
3621 @request.session[:user_id] = 2
3596 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3622 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3597
3623
3598 assert_no_difference('Journal.count') do
3624 assert_no_difference('Journal.count') do
3599 put :update,
3625 put :update,
3600 :id => 1,
3626 :id => 1,
3601 :issue => {:notes => notes},
3627 :issue => {:notes => notes},
3602 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3628 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3603 end
3629 end
3604 assert_response :success
3630 assert_response :success
3605 assert_template 'edit'
3631 assert_template 'edit'
3606
3632
3607 assert_select_error /Activity cannot be blank/
3633 assert_select_error /Activity cannot be blank/
3608 assert_select_error /Hours cannot be blank/
3634 assert_select_error /Hours cannot be blank/
3609 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3635 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3610 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3636 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3611 end
3637 end
3612
3638
3613 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3639 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3614 issue = Issue.find(2)
3640 issue = Issue.find(2)
3615 @request.session[:user_id] = 2
3641 @request.session[:user_id] = 2
3616
3642
3617 put :update,
3643 put :update,
3618 :id => issue.id,
3644 :id => issue.id,
3619 :issue => {
3645 :issue => {
3620 :fixed_version_id => 4
3646 :fixed_version_id => 4
3621 }
3647 }
3622
3648
3623 assert_response :redirect
3649 assert_response :redirect
3624 issue.reload
3650 issue.reload
3625 assert_equal 4, issue.fixed_version_id
3651 assert_equal 4, issue.fixed_version_id
3626 assert_not_equal issue.project_id, issue.fixed_version.project_id
3652 assert_not_equal issue.project_id, issue.fixed_version.project_id
3627 end
3653 end
3628
3654
3629 def test_put_update_should_redirect_back_using_the_back_url_parameter
3655 def test_put_update_should_redirect_back_using_the_back_url_parameter
3630 issue = Issue.find(2)
3656 issue = Issue.find(2)
3631 @request.session[:user_id] = 2
3657 @request.session[:user_id] = 2
3632
3658
3633 put :update,
3659 put :update,
3634 :id => issue.id,
3660 :id => issue.id,
3635 :issue => {
3661 :issue => {
3636 :fixed_version_id => 4
3662 :fixed_version_id => 4
3637 },
3663 },
3638 :back_url => '/issues'
3664 :back_url => '/issues'
3639
3665
3640 assert_response :redirect
3666 assert_response :redirect
3641 assert_redirected_to '/issues'
3667 assert_redirected_to '/issues'
3642 end
3668 end
3643
3669
3644 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3670 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3645 issue = Issue.find(2)
3671 issue = Issue.find(2)
3646 @request.session[:user_id] = 2
3672 @request.session[:user_id] = 2
3647
3673
3648 put :update,
3674 put :update,
3649 :id => issue.id,
3675 :id => issue.id,
3650 :issue => {
3676 :issue => {
3651 :fixed_version_id => 4
3677 :fixed_version_id => 4
3652 },
3678 },
3653 :back_url => 'http://google.com'
3679 :back_url => 'http://google.com'
3654
3680
3655 assert_response :redirect
3681 assert_response :redirect
3656 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3682 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3657 end
3683 end
3658
3684
3659 def test_get_bulk_edit
3685 def test_get_bulk_edit
3660 @request.session[:user_id] = 2
3686 @request.session[:user_id] = 2
3661 get :bulk_edit, :ids => [1, 3]
3687 get :bulk_edit, :ids => [1, 3]
3662 assert_response :success
3688 assert_response :success
3663 assert_template 'bulk_edit'
3689 assert_template 'bulk_edit'
3664
3690
3665 assert_select 'ul#bulk-selection' do
3691 assert_select 'ul#bulk-selection' do
3666 assert_select 'li', 2
3692 assert_select 'li', 2
3667 assert_select 'li a', :text => 'Bug #1'
3693 assert_select 'li a', :text => 'Bug #1'
3668 end
3694 end
3669
3695
3670 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3696 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3671 assert_select 'input[name=?]', 'ids[]', 2
3697 assert_select 'input[name=?]', 'ids[]', 2
3672 assert_select 'input[name=?][value="1"][type=hidden]', 'ids[]'
3698 assert_select 'input[name=?][value="1"][type=hidden]', 'ids[]'
3673
3699
3674 assert_select 'select[name=?]', 'issue[project_id]'
3700 assert_select 'select[name=?]', 'issue[project_id]'
3675 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3701 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3676
3702
3677 # Project specific custom field, date type
3703 # Project specific custom field, date type
3678 field = CustomField.find(9)
3704 field = CustomField.find(9)
3679 assert !field.is_for_all?
3705 assert !field.is_for_all?
3680 assert_equal 'date', field.field_format
3706 assert_equal 'date', field.field_format
3681 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3707 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3682
3708
3683 # System wide custom field
3709 # System wide custom field
3684 assert CustomField.find(1).is_for_all?
3710 assert CustomField.find(1).is_for_all?
3685 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3711 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3686
3712
3687 # Be sure we don't display inactive IssuePriorities
3713 # Be sure we don't display inactive IssuePriorities
3688 assert ! IssuePriority.find(15).active?
3714 assert ! IssuePriority.find(15).active?
3689 assert_select 'select[name=?]', 'issue[priority_id]' do
3715 assert_select 'select[name=?]', 'issue[priority_id]' do
3690 assert_select 'option[value="15"]', 0
3716 assert_select 'option[value="15"]', 0
3691 end
3717 end
3692 end
3718 end
3693 end
3719 end
3694
3720
3695 def test_get_bulk_edit_on_different_projects
3721 def test_get_bulk_edit_on_different_projects
3696 @request.session[:user_id] = 2
3722 @request.session[:user_id] = 2
3697 get :bulk_edit, :ids => [1, 2, 6]
3723 get :bulk_edit, :ids => [1, 2, 6]
3698 assert_response :success
3724 assert_response :success
3699 assert_template 'bulk_edit'
3725 assert_template 'bulk_edit'
3700
3726
3701 # Can not set issues from different projects as children of an issue
3727 # Can not set issues from different projects as children of an issue
3702 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3728 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3703
3729
3704 # Project specific custom field, date type
3730 # Project specific custom field, date type
3705 field = CustomField.find(9)
3731 field = CustomField.find(9)
3706 assert !field.is_for_all?
3732 assert !field.is_for_all?
3707 assert !field.project_ids.include?(Issue.find(6).project_id)
3733 assert !field.project_ids.include?(Issue.find(6).project_id)
3708 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3734 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3709 end
3735 end
3710
3736
3711 def test_get_bulk_edit_with_user_custom_field
3737 def test_get_bulk_edit_with_user_custom_field
3712 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :tracker_ids => [1,2,3])
3738 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :tracker_ids => [1,2,3])
3713
3739
3714 @request.session[:user_id] = 2
3740 @request.session[:user_id] = 2
3715 get :bulk_edit, :ids => [1, 2]
3741 get :bulk_edit, :ids => [1, 2]
3716 assert_response :success
3742 assert_response :success
3717 assert_template 'bulk_edit'
3743 assert_template 'bulk_edit'
3718
3744
3719 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3745 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3720 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3746 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3721 end
3747 end
3722 end
3748 end
3723
3749
3724 def test_get_bulk_edit_with_version_custom_field
3750 def test_get_bulk_edit_with_version_custom_field
3725 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
3751 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
3726
3752
3727 @request.session[:user_id] = 2
3753 @request.session[:user_id] = 2
3728 get :bulk_edit, :ids => [1, 2]
3754 get :bulk_edit, :ids => [1, 2]
3729 assert_response :success
3755 assert_response :success
3730 assert_template 'bulk_edit'
3756 assert_template 'bulk_edit'
3731
3757
3732 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3758 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3733 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3759 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3734 end
3760 end
3735 end
3761 end
3736
3762
3737 def test_get_bulk_edit_with_multi_custom_field
3763 def test_get_bulk_edit_with_multi_custom_field
3738 field = CustomField.find(1)
3764 field = CustomField.find(1)
3739 field.update_attribute :multiple, true
3765 field.update_attribute :multiple, true
3740
3766
3741 @request.session[:user_id] = 2
3767 @request.session[:user_id] = 2
3742 get :bulk_edit, :ids => [1, 3]
3768 get :bulk_edit, :ids => [1, 3]
3743 assert_response :success
3769 assert_response :success
3744 assert_template 'bulk_edit'
3770 assert_template 'bulk_edit'
3745
3771
3746 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3772 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3747 assert_select 'option', field.possible_values.size + 1 # "none" options
3773 assert_select 'option', field.possible_values.size + 1 # "none" options
3748 end
3774 end
3749 end
3775 end
3750
3776
3751 def test_bulk_edit_should_propose_to_clear_text_custom_fields
3777 def test_bulk_edit_should_propose_to_clear_text_custom_fields
3752 @request.session[:user_id] = 2
3778 @request.session[:user_id] = 2
3753 get :bulk_edit, :ids => [1, 3]
3779 get :bulk_edit, :ids => [1, 3]
3754 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
3780 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
3755 end
3781 end
3756
3782
3757 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3783 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3758 WorkflowTransition.delete_all
3784 WorkflowTransition.delete_all
3759 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3785 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3760 :old_status_id => 1, :new_status_id => 1)
3786 :old_status_id => 1, :new_status_id => 1)
3761 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3787 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3762 :old_status_id => 1, :new_status_id => 3)
3788 :old_status_id => 1, :new_status_id => 3)
3763 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3789 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3764 :old_status_id => 1, :new_status_id => 4)
3790 :old_status_id => 1, :new_status_id => 4)
3765 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3791 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3766 :old_status_id => 2, :new_status_id => 1)
3792 :old_status_id => 2, :new_status_id => 1)
3767 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3793 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3768 :old_status_id => 2, :new_status_id => 3)
3794 :old_status_id => 2, :new_status_id => 3)
3769 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3795 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3770 :old_status_id => 2, :new_status_id => 5)
3796 :old_status_id => 2, :new_status_id => 5)
3771 @request.session[:user_id] = 2
3797 @request.session[:user_id] = 2
3772 get :bulk_edit, :ids => [1, 2]
3798 get :bulk_edit, :ids => [1, 2]
3773
3799
3774 assert_response :success
3800 assert_response :success
3775 statuses = assigns(:available_statuses)
3801 statuses = assigns(:available_statuses)
3776 assert_not_nil statuses
3802 assert_not_nil statuses
3777 assert_equal [1, 3], statuses.map(&:id).sort
3803 assert_equal [1, 3], statuses.map(&:id).sort
3778
3804
3779 assert_select 'select[name=?]', 'issue[status_id]' do
3805 assert_select 'select[name=?]', 'issue[status_id]' do
3780 assert_select 'option', 3 # 2 statuses + "no change" option
3806 assert_select 'option', 3 # 2 statuses + "no change" option
3781 end
3807 end
3782 end
3808 end
3783
3809
3784 def test_bulk_edit_should_propose_target_project_open_shared_versions
3810 def test_bulk_edit_should_propose_target_project_open_shared_versions
3785 @request.session[:user_id] = 2
3811 @request.session[:user_id] = 2
3786 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3812 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3787 assert_response :success
3813 assert_response :success
3788 assert_template 'bulk_edit'
3814 assert_template 'bulk_edit'
3789 assert_equal Project.find(1).shared_versions.open.to_a.sort, assigns(:versions).sort
3815 assert_equal Project.find(1).shared_versions.open.to_a.sort, assigns(:versions).sort
3790
3816
3791 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3817 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3792 assert_select 'option', :text => '2.0'
3818 assert_select 'option', :text => '2.0'
3793 end
3819 end
3794 end
3820 end
3795
3821
3796 def test_bulk_edit_should_propose_target_project_categories
3822 def test_bulk_edit_should_propose_target_project_categories
3797 @request.session[:user_id] = 2
3823 @request.session[:user_id] = 2
3798 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3824 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3799 assert_response :success
3825 assert_response :success
3800 assert_template 'bulk_edit'
3826 assert_template 'bulk_edit'
3801 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3827 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3802
3828
3803 assert_select 'select[name=?]', 'issue[category_id]' do
3829 assert_select 'select[name=?]', 'issue[category_id]' do
3804 assert_select 'option', :text => 'Recipes'
3830 assert_select 'option', :text => 'Recipes'
3805 end
3831 end
3806 end
3832 end
3807
3833
3808 def test_bulk_edit_should_only_propose_issues_trackers_custom_fields
3834 def test_bulk_edit_should_only_propose_issues_trackers_custom_fields
3809 IssueCustomField.delete_all
3835 IssueCustomField.delete_all
3810 field = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
3836 field = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
3811 IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
3837 IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
3812 @request.session[:user_id] = 2
3838 @request.session[:user_id] = 2
3813
3839
3814 issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
3840 issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
3815 get :bulk_edit, :ids => issue_ids
3841 get :bulk_edit, :ids => issue_ids
3816 assert_equal [field], assigns(:custom_fields)
3842 assert_equal [field], assigns(:custom_fields)
3817 end
3843 end
3818
3844
3819 def test_bulk_update
3845 def test_bulk_update
3820 @request.session[:user_id] = 2
3846 @request.session[:user_id] = 2
3821 # update issues priority
3847 # update issues priority
3822 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3848 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3823 :issue => {:priority_id => 7,
3849 :issue => {:priority_id => 7,
3824 :assigned_to_id => '',
3850 :assigned_to_id => '',
3825 :custom_field_values => {'2' => ''}}
3851 :custom_field_values => {'2' => ''}}
3826
3852
3827 assert_response 302
3853 assert_response 302
3828 # check that the issues were updated
3854 # check that the issues were updated
3829 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
3855 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
3830
3856
3831 issue = Issue.find(1)
3857 issue = Issue.find(1)
3832 journal = issue.journals.reorder('created_on DESC').first
3858 journal = issue.journals.reorder('created_on DESC').first
3833 assert_equal '125', issue.custom_value_for(2).value
3859 assert_equal '125', issue.custom_value_for(2).value
3834 assert_equal 'Bulk editing', journal.notes
3860 assert_equal 'Bulk editing', journal.notes
3835 assert_equal 1, journal.details.size
3861 assert_equal 1, journal.details.size
3836 end
3862 end
3837
3863
3838 def test_bulk_update_with_group_assignee
3864 def test_bulk_update_with_group_assignee
3839 group = Group.find(11)
3865 group = Group.find(11)
3840 project = Project.find(1)
3866 project = Project.find(1)
3841 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3867 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3842
3868
3843 @request.session[:user_id] = 2
3869 @request.session[:user_id] = 2
3844 # update issues assignee
3870 # update issues assignee
3845 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3871 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3846 :issue => {:priority_id => '',
3872 :issue => {:priority_id => '',
3847 :assigned_to_id => group.id,
3873 :assigned_to_id => group.id,
3848 :custom_field_values => {'2' => ''}}
3874 :custom_field_values => {'2' => ''}}
3849
3875
3850 assert_response 302
3876 assert_response 302
3851 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
3877 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
3852 end
3878 end
3853
3879
3854 def test_bulk_update_on_different_projects
3880 def test_bulk_update_on_different_projects
3855 @request.session[:user_id] = 2
3881 @request.session[:user_id] = 2
3856 # update issues priority
3882 # update issues priority
3857 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3883 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3858 :issue => {:priority_id => 7,
3884 :issue => {:priority_id => 7,
3859 :assigned_to_id => '',
3885 :assigned_to_id => '',
3860 :custom_field_values => {'2' => ''}}
3886 :custom_field_values => {'2' => ''}}
3861
3887
3862 assert_response 302
3888 assert_response 302
3863 # check that the issues were updated
3889 # check that the issues were updated
3864 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3890 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3865
3891
3866 issue = Issue.find(1)
3892 issue = Issue.find(1)
3867 journal = issue.journals.reorder('created_on DESC').first
3893 journal = issue.journals.reorder('created_on DESC').first
3868 assert_equal '125', issue.custom_value_for(2).value
3894 assert_equal '125', issue.custom_value_for(2).value
3869 assert_equal 'Bulk editing', journal.notes
3895 assert_equal 'Bulk editing', journal.notes
3870 assert_equal 1, journal.details.size
3896 assert_equal 1, journal.details.size
3871 end
3897 end
3872
3898
3873 def test_bulk_update_on_different_projects_without_rights
3899 def test_bulk_update_on_different_projects_without_rights
3874 @request.session[:user_id] = 3
3900 @request.session[:user_id] = 3
3875 user = User.find(3)
3901 user = User.find(3)
3876 action = { :controller => "issues", :action => "bulk_update" }
3902 action = { :controller => "issues", :action => "bulk_update" }
3877 assert user.allowed_to?(action, Issue.find(1).project)
3903 assert user.allowed_to?(action, Issue.find(1).project)
3878 assert ! user.allowed_to?(action, Issue.find(6).project)
3904 assert ! user.allowed_to?(action, Issue.find(6).project)
3879 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3905 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3880 :issue => {:priority_id => 7,
3906 :issue => {:priority_id => 7,
3881 :assigned_to_id => '',
3907 :assigned_to_id => '',
3882 :custom_field_values => {'2' => ''}}
3908 :custom_field_values => {'2' => ''}}
3883 assert_response 403
3909 assert_response 403
3884 assert_not_equal "Bulk should fail", Journal.last.notes
3910 assert_not_equal "Bulk should fail", Journal.last.notes
3885 end
3911 end
3886
3912
3887 def test_bullk_update_should_send_a_notification
3913 def test_bullk_update_should_send_a_notification
3888 @request.session[:user_id] = 2
3914 @request.session[:user_id] = 2
3889 ActionMailer::Base.deliveries.clear
3915 ActionMailer::Base.deliveries.clear
3890 with_settings :notified_events => %w(issue_updated) do
3916 with_settings :notified_events => %w(issue_updated) do
3891 post(:bulk_update,
3917 post(:bulk_update,
3892 {
3918 {
3893 :ids => [1, 2],
3919 :ids => [1, 2],
3894 :notes => 'Bulk editing',
3920 :notes => 'Bulk editing',
3895 :issue => {
3921 :issue => {
3896 :priority_id => 7,
3922 :priority_id => 7,
3897 :assigned_to_id => '',
3923 :assigned_to_id => '',
3898 :custom_field_values => {'2' => ''}
3924 :custom_field_values => {'2' => ''}
3899 }
3925 }
3900 })
3926 })
3901 assert_response 302
3927 assert_response 302
3902 assert_equal 2, ActionMailer::Base.deliveries.size
3928 assert_equal 2, ActionMailer::Base.deliveries.size
3903 end
3929 end
3904 end
3930 end
3905
3931
3906 def test_bulk_update_project
3932 def test_bulk_update_project
3907 @request.session[:user_id] = 2
3933 @request.session[:user_id] = 2
3908 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3934 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3909 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3935 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3910 # Issues moved to project 2
3936 # Issues moved to project 2
3911 assert_equal 2, Issue.find(1).project_id
3937 assert_equal 2, Issue.find(1).project_id
3912 assert_equal 2, Issue.find(2).project_id
3938 assert_equal 2, Issue.find(2).project_id
3913 # No tracker change
3939 # No tracker change
3914 assert_equal 1, Issue.find(1).tracker_id
3940 assert_equal 1, Issue.find(1).tracker_id
3915 assert_equal 2, Issue.find(2).tracker_id
3941 assert_equal 2, Issue.find(2).tracker_id
3916 end
3942 end
3917
3943
3918 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3944 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3919 @request.session[:user_id] = 2
3945 @request.session[:user_id] = 2
3920 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3946 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3921 assert_redirected_to '/issues/1'
3947 assert_redirected_to '/issues/1'
3922 end
3948 end
3923
3949
3924 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3950 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3925 @request.session[:user_id] = 2
3951 @request.session[:user_id] = 2
3926 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3952 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3927 assert_redirected_to '/projects/onlinestore/issues'
3953 assert_redirected_to '/projects/onlinestore/issues'
3928 end
3954 end
3929
3955
3930 def test_bulk_update_tracker
3956 def test_bulk_update_tracker
3931 @request.session[:user_id] = 2
3957 @request.session[:user_id] = 2
3932 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3958 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3933 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3959 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3934 assert_equal 2, Issue.find(1).tracker_id
3960 assert_equal 2, Issue.find(1).tracker_id
3935 assert_equal 2, Issue.find(2).tracker_id
3961 assert_equal 2, Issue.find(2).tracker_id
3936 end
3962 end
3937
3963
3938 def test_bulk_update_status
3964 def test_bulk_update_status
3939 @request.session[:user_id] = 2
3965 @request.session[:user_id] = 2
3940 # update issues priority
3966 # update issues priority
3941 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3967 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3942 :issue => {:priority_id => '',
3968 :issue => {:priority_id => '',
3943 :assigned_to_id => '',
3969 :assigned_to_id => '',
3944 :status_id => '5'}
3970 :status_id => '5'}
3945
3971
3946 assert_response 302
3972 assert_response 302
3947 issue = Issue.find(1)
3973 issue = Issue.find(1)
3948 assert issue.closed?
3974 assert issue.closed?
3949 end
3975 end
3950
3976
3951 def test_bulk_update_priority
3977 def test_bulk_update_priority
3952 @request.session[:user_id] = 2
3978 @request.session[:user_id] = 2
3953 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3979 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3954
3980
3955 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3981 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3956 assert_equal 6, Issue.find(1).priority_id
3982 assert_equal 6, Issue.find(1).priority_id
3957 assert_equal 6, Issue.find(2).priority_id
3983 assert_equal 6, Issue.find(2).priority_id
3958 end
3984 end
3959
3985
3960 def test_bulk_update_with_notes
3986 def test_bulk_update_with_notes
3961 @request.session[:user_id] = 2
3987 @request.session[:user_id] = 2
3962 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3988 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3963
3989
3964 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3990 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3965 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3991 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3966 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3992 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3967 end
3993 end
3968
3994
3969 def test_bulk_update_parent_id
3995 def test_bulk_update_parent_id
3970 IssueRelation.delete_all
3996 IssueRelation.delete_all
3971 @request.session[:user_id] = 2
3997 @request.session[:user_id] = 2
3972 post :bulk_update, :ids => [1, 3],
3998 post :bulk_update, :ids => [1, 3],
3973 :notes => 'Bulk editing parent',
3999 :notes => 'Bulk editing parent',
3974 :issue => {:priority_id => '', :assigned_to_id => '',
4000 :issue => {:priority_id => '', :assigned_to_id => '',
3975 :status_id => '', :parent_issue_id => '2'}
4001 :status_id => '', :parent_issue_id => '2'}
3976 assert_response 302
4002 assert_response 302
3977 parent = Issue.find(2)
4003 parent = Issue.find(2)
3978 assert_equal parent.id, Issue.find(1).parent_id
4004 assert_equal parent.id, Issue.find(1).parent_id
3979 assert_equal parent.id, Issue.find(3).parent_id
4005 assert_equal parent.id, Issue.find(3).parent_id
3980 assert_equal [1, 3], parent.children.collect(&:id).sort
4006 assert_equal [1, 3], parent.children.collect(&:id).sort
3981 end
4007 end
3982
4008
3983 def test_bulk_update_custom_field
4009 def test_bulk_update_custom_field
3984 @request.session[:user_id] = 2
4010 @request.session[:user_id] = 2
3985 # update issues priority
4011 # update issues priority
3986 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
4012 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3987 :issue => {:priority_id => '',
4013 :issue => {:priority_id => '',
3988 :assigned_to_id => '',
4014 :assigned_to_id => '',
3989 :custom_field_values => {'2' => '777'}}
4015 :custom_field_values => {'2' => '777'}}
3990
4016
3991 assert_response 302
4017 assert_response 302
3992
4018
3993 issue = Issue.find(1)
4019 issue = Issue.find(1)
3994 journal = issue.journals.reorder('created_on DESC').first
4020 journal = issue.journals.reorder('created_on DESC').first
3995 assert_equal '777', issue.custom_value_for(2).value
4021 assert_equal '777', issue.custom_value_for(2).value
3996 assert_equal 1, journal.details.size
4022 assert_equal 1, journal.details.size
3997 assert_equal '125', journal.details.first.old_value
4023 assert_equal '125', journal.details.first.old_value
3998 assert_equal '777', journal.details.first.value
4024 assert_equal '777', journal.details.first.value
3999 end
4025 end
4000
4026
4001 def test_bulk_update_custom_field_to_blank
4027 def test_bulk_update_custom_field_to_blank
4002 @request.session[:user_id] = 2
4028 @request.session[:user_id] = 2
4003 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
4029 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
4004 :issue => {:priority_id => '',
4030 :issue => {:priority_id => '',
4005 :assigned_to_id => '',
4031 :assigned_to_id => '',
4006 :custom_field_values => {'1' => '__none__'}}
4032 :custom_field_values => {'1' => '__none__'}}
4007 assert_response 302
4033 assert_response 302
4008 assert_equal '', Issue.find(1).custom_field_value(1)
4034 assert_equal '', Issue.find(1).custom_field_value(1)
4009 assert_equal '', Issue.find(3).custom_field_value(1)
4035 assert_equal '', Issue.find(3).custom_field_value(1)
4010 end
4036 end
4011
4037
4012 def test_bulk_update_multi_custom_field
4038 def test_bulk_update_multi_custom_field
4013 field = CustomField.find(1)
4039 field = CustomField.find(1)
4014 field.update_attribute :multiple, true
4040 field.update_attribute :multiple, true
4015
4041
4016 @request.session[:user_id] = 2
4042 @request.session[:user_id] = 2
4017 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
4043 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
4018 :issue => {:priority_id => '',
4044 :issue => {:priority_id => '',
4019 :assigned_to_id => '',
4045 :assigned_to_id => '',
4020 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
4046 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
4021
4047
4022 assert_response 302
4048 assert_response 302
4023
4049
4024 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
4050 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
4025 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
4051 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
4026 # the custom field is not associated with the issue tracker
4052 # the custom field is not associated with the issue tracker
4027 assert_nil Issue.find(2).custom_field_value(1)
4053 assert_nil Issue.find(2).custom_field_value(1)
4028 end
4054 end
4029
4055
4030 def test_bulk_update_multi_custom_field_to_blank
4056 def test_bulk_update_multi_custom_field_to_blank
4031 field = CustomField.find(1)
4057 field = CustomField.find(1)
4032 field.update_attribute :multiple, true
4058 field.update_attribute :multiple, true
4033
4059
4034 @request.session[:user_id] = 2
4060 @request.session[:user_id] = 2
4035 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
4061 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
4036 :issue => {:priority_id => '',
4062 :issue => {:priority_id => '',
4037 :assigned_to_id => '',
4063 :assigned_to_id => '',
4038 :custom_field_values => {'1' => ['__none__']}}
4064 :custom_field_values => {'1' => ['__none__']}}
4039 assert_response 302
4065 assert_response 302
4040 assert_equal [''], Issue.find(1).custom_field_value(1)
4066 assert_equal [''], Issue.find(1).custom_field_value(1)
4041 assert_equal [''], Issue.find(3).custom_field_value(1)
4067 assert_equal [''], Issue.find(3).custom_field_value(1)
4042 end
4068 end
4043
4069
4044 def test_bulk_update_unassign
4070 def test_bulk_update_unassign
4045 assert_not_nil Issue.find(2).assigned_to
4071 assert_not_nil Issue.find(2).assigned_to
4046 @request.session[:user_id] = 2
4072 @request.session[:user_id] = 2
4047 # unassign issues
4073 # unassign issues
4048 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
4074 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
4049 assert_response 302
4075 assert_response 302
4050 # check that the issues were updated
4076 # check that the issues were updated
4051 assert_nil Issue.find(2).assigned_to
4077 assert_nil Issue.find(2).assigned_to
4052 end
4078 end
4053
4079
4054 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
4080 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
4055 @request.session[:user_id] = 2
4081 @request.session[:user_id] = 2
4056
4082
4057 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
4083 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
4058
4084
4059 assert_response :redirect
4085 assert_response :redirect
4060 issues = Issue.find([1,2])
4086 issues = Issue.find([1,2])
4061 issues.each do |issue|
4087 issues.each do |issue|
4062 assert_equal 4, issue.fixed_version_id
4088 assert_equal 4, issue.fixed_version_id
4063 assert_not_equal issue.project_id, issue.fixed_version.project_id
4089 assert_not_equal issue.project_id, issue.fixed_version.project_id
4064 end
4090 end
4065 end
4091 end
4066
4092
4067 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
4093 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
4068 @request.session[:user_id] = 2
4094 @request.session[:user_id] = 2
4069 post :bulk_update, :ids => [1,2], :back_url => '/issues'
4095 post :bulk_update, :ids => [1,2], :back_url => '/issues'
4070
4096
4071 assert_response :redirect
4097 assert_response :redirect
4072 assert_redirected_to '/issues'
4098 assert_redirected_to '/issues'
4073 end
4099 end
4074
4100
4075 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
4101 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
4076 @request.session[:user_id] = 2
4102 @request.session[:user_id] = 2
4077 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
4103 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
4078
4104
4079 assert_response :redirect
4105 assert_response :redirect
4080 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
4106 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
4081 end
4107 end
4082
4108
4083 def test_bulk_update_with_all_failures_should_show_errors
4109 def test_bulk_update_with_all_failures_should_show_errors
4084 @request.session[:user_id] = 2
4110 @request.session[:user_id] = 2
4085 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
4111 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
4086
4112
4087 assert_response :success
4113 assert_response :success
4088 assert_template 'bulk_edit'
4114 assert_template 'bulk_edit'
4089 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
4115 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
4090 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
4116 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
4091
4117
4092 assert_equal [1, 2], assigns[:issues].map(&:id)
4118 assert_equal [1, 2], assigns[:issues].map(&:id)
4093 end
4119 end
4094
4120
4095 def test_bulk_update_with_some_failures_should_show_errors
4121 def test_bulk_update_with_some_failures_should_show_errors
4096 issue1 = Issue.generate!(:start_date => '2013-05-12')
4122 issue1 = Issue.generate!(:start_date => '2013-05-12')
4097 issue2 = Issue.generate!(:start_date => '2013-05-15')
4123 issue2 = Issue.generate!(:start_date => '2013-05-15')
4098 issue3 = Issue.generate!
4124 issue3 = Issue.generate!
4099 @request.session[:user_id] = 2
4125 @request.session[:user_id] = 2
4100 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
4126 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
4101 :issue => {:due_date => '2013-05-01'}
4127 :issue => {:due_date => '2013-05-01'}
4102 assert_response :success
4128 assert_response :success
4103 assert_template 'bulk_edit'
4129 assert_template 'bulk_edit'
4104 assert_select '#errorExplanation span',
4130 assert_select '#errorExplanation span',
4105 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
4131 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
4106 assert_select '#errorExplanation ul li',
4132 assert_select '#errorExplanation ul li',
4107 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
4133 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
4108 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
4134 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
4109 end
4135 end
4110
4136
4111 def test_bulk_update_with_failure_should_preserved_form_values
4137 def test_bulk_update_with_failure_should_preserved_form_values
4112 @request.session[:user_id] = 2
4138 @request.session[:user_id] = 2
4113 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
4139 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
4114
4140
4115 assert_response :success
4141 assert_response :success
4116 assert_template 'bulk_edit'
4142 assert_template 'bulk_edit'
4117 assert_select 'select[name=?]', 'issue[tracker_id]' do
4143 assert_select 'select[name=?]', 'issue[tracker_id]' do
4118 assert_select 'option[value="2"][selected=selected]'
4144 assert_select 'option[value="2"][selected=selected]'
4119 end
4145 end
4120 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
4146 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
4121 end
4147 end
4122
4148
4123 def test_get_bulk_copy
4149 def test_get_bulk_copy
4124 @request.session[:user_id] = 2
4150 @request.session[:user_id] = 2
4125 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4151 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4126 assert_response :success
4152 assert_response :success
4127 assert_template 'bulk_edit'
4153 assert_template 'bulk_edit'
4128
4154
4129 issues = assigns(:issues)
4155 issues = assigns(:issues)
4130 assert_not_nil issues
4156 assert_not_nil issues
4131 assert_equal [1, 2, 3], issues.map(&:id).sort
4157 assert_equal [1, 2, 3], issues.map(&:id).sort
4132
4158
4133 assert_select 'select[name=?]', 'issue[project_id]' do
4159 assert_select 'select[name=?]', 'issue[project_id]' do
4134 assert_select 'option[value=""]'
4160 assert_select 'option[value=""]'
4135 end
4161 end
4136 assert_select 'input[name=copy_attachments]'
4162 assert_select 'input[name=copy_attachments]'
4137 end
4163 end
4138
4164
4139 def test_get_bulk_copy_without_add_issues_permission_should_not_propose_current_project_as_target
4165 def test_get_bulk_copy_without_add_issues_permission_should_not_propose_current_project_as_target
4140 user = setup_user_with_copy_but_not_add_permission
4166 user = setup_user_with_copy_but_not_add_permission
4141 @request.session[:user_id] = user.id
4167 @request.session[:user_id] = user.id
4142
4168
4143 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4169 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
4144 assert_response :success
4170 assert_response :success
4145 assert_template 'bulk_edit'
4171 assert_template 'bulk_edit'
4146
4172
4147 assert_select 'select[name=?]', 'issue[project_id]' do
4173 assert_select 'select[name=?]', 'issue[project_id]' do
4148 assert_select 'option[value=""]', 0
4174 assert_select 'option[value=""]', 0
4149 assert_select 'option[value="2"]'
4175 assert_select 'option[value="2"]'
4150 end
4176 end
4151 end
4177 end
4152
4178
4153 def test_bulk_copy_to_another_project
4179 def test_bulk_copy_to_another_project
4154 @request.session[:user_id] = 2
4180 @request.session[:user_id] = 2
4155 assert_difference 'Issue.count', 2 do
4181 assert_difference 'Issue.count', 2 do
4156 assert_no_difference 'Project.find(1).issues.count' do
4182 assert_no_difference 'Project.find(1).issues.count' do
4157 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
4183 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
4158 end
4184 end
4159 end
4185 end
4160 assert_redirected_to '/projects/ecookbook/issues'
4186 assert_redirected_to '/projects/ecookbook/issues'
4161
4187
4162 copies = Issue.order('id DESC').limit(issues.size)
4188 copies = Issue.order('id DESC').limit(issues.size)
4163 copies.each do |copy|
4189 copies.each do |copy|
4164 assert_equal 2, copy.project_id
4190 assert_equal 2, copy.project_id
4165 end
4191 end
4166 end
4192 end
4167
4193
4168 def test_bulk_copy_without_add_issues_permission_should_be_allowed_on_project_with_permission
4194 def test_bulk_copy_without_add_issues_permission_should_be_allowed_on_project_with_permission
4169 user = setup_user_with_copy_but_not_add_permission
4195 user = setup_user_with_copy_but_not_add_permission
4170 @request.session[:user_id] = user.id
4196 @request.session[:user_id] = user.id
4171
4197
4172 assert_difference 'Issue.count', 3 do
4198 assert_difference 'Issue.count', 3 do
4173 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '2'}, :copy => '1'
4199 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '2'}, :copy => '1'
4174 assert_response 302
4200 assert_response 302
4175 end
4201 end
4176 end
4202 end
4177
4203
4178 def test_bulk_copy_on_same_project_without_add_issues_permission_should_be_denied
4204 def test_bulk_copy_on_same_project_without_add_issues_permission_should_be_denied
4179 user = setup_user_with_copy_but_not_add_permission
4205 user = setup_user_with_copy_but_not_add_permission
4180 @request.session[:user_id] = user.id
4206 @request.session[:user_id] = user.id
4181
4207
4182 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => ''}, :copy => '1'
4208 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => ''}, :copy => '1'
4183 assert_response 403
4209 assert_response 403
4184 end
4210 end
4185
4211
4186 def test_bulk_copy_on_different_project_without_add_issues_permission_should_be_denied
4212 def test_bulk_copy_on_different_project_without_add_issues_permission_should_be_denied
4187 user = setup_user_with_copy_but_not_add_permission
4213 user = setup_user_with_copy_but_not_add_permission
4188 @request.session[:user_id] = user.id
4214 @request.session[:user_id] = user.id
4189
4215
4190 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '1'}, :copy => '1'
4216 post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '1'}, :copy => '1'
4191 assert_response 403
4217 assert_response 403
4192 end
4218 end
4193
4219
4194 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
4220 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
4195 @request.session[:user_id] = 2
4221 @request.session[:user_id] = 2
4196 issues = [
4222 issues = [
4197 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
4223 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
4198 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
4224 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
4199 :assigned_to_id => nil),
4225 :assigned_to_id => nil),
4200 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
4226 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
4201 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
4227 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
4202 :assigned_to_id => 3)
4228 :assigned_to_id => 3)
4203 ]
4229 ]
4204 assert_difference 'Issue.count', issues.size do
4230 assert_difference 'Issue.count', issues.size do
4205 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
4231 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
4206 :issue => {
4232 :issue => {
4207 :project_id => '', :tracker_id => '', :assigned_to_id => '',
4233 :project_id => '', :tracker_id => '', :assigned_to_id => '',
4208 :status_id => '', :start_date => '', :due_date => ''
4234 :status_id => '', :start_date => '', :due_date => ''
4209 }
4235 }
4210 end
4236 end
4211
4237
4212 copies = Issue.order('id DESC').limit(issues.size)
4238 copies = Issue.order('id DESC').limit(issues.size)
4213 issues.each do |orig|
4239 issues.each do |orig|
4214 copy = copies.detect {|c| c.subject == orig.subject}
4240 copy = copies.detect {|c| c.subject == orig.subject}
4215 assert_not_nil copy
4241 assert_not_nil copy
4216 assert_equal orig.project_id, copy.project_id
4242 assert_equal orig.project_id, copy.project_id
4217 assert_equal orig.tracker_id, copy.tracker_id
4243 assert_equal orig.tracker_id, copy.tracker_id
4218 assert_equal orig.status_id, copy.status_id
4244 assert_equal orig.status_id, copy.status_id
4219 assert_equal orig.assigned_to_id, copy.assigned_to_id
4245 assert_equal orig.assigned_to_id, copy.assigned_to_id
4220 assert_equal orig.priority_id, copy.priority_id
4246 assert_equal orig.priority_id, copy.priority_id
4221 end
4247 end
4222 end
4248 end
4223
4249
4224 def test_bulk_copy_should_allow_changing_the_issue_attributes
4250 def test_bulk_copy_should_allow_changing_the_issue_attributes
4225 # Fixes random test failure with Mysql
4251 # Fixes random test failure with Mysql
4226 # where Issue.where(:project_id => 2).limit(2).order('id desc')
4252 # where Issue.where(:project_id => 2).limit(2).order('id desc')
4227 # doesn't return the expected results
4253 # doesn't return the expected results
4228 Issue.delete_all("project_id=2")
4254 Issue.delete_all("project_id=2")
4229
4255
4230 @request.session[:user_id] = 2
4256 @request.session[:user_id] = 2
4231 assert_difference 'Issue.count', 2 do
4257 assert_difference 'Issue.count', 2 do
4232 assert_no_difference 'Project.find(1).issues.count' do
4258 assert_no_difference 'Project.find(1).issues.count' do
4233 post :bulk_update, :ids => [1, 2], :copy => '1',
4259 post :bulk_update, :ids => [1, 2], :copy => '1',
4234 :issue => {
4260 :issue => {
4235 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
4261 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
4236 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
4262 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
4237 }
4263 }
4238 end
4264 end
4239 end
4265 end
4240
4266
4241 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
4267 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
4242 assert_equal 2, copied_issues.size
4268 assert_equal 2, copied_issues.size
4243 copied_issues.each do |issue|
4269 copied_issues.each do |issue|
4244 assert_equal 2, issue.project_id, "Project is incorrect"
4270 assert_equal 2, issue.project_id, "Project is incorrect"
4245 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
4271 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
4246 assert_equal 1, issue.status_id, "Status is incorrect"
4272 assert_equal 1, issue.status_id, "Status is incorrect"
4247 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
4273 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
4248 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
4274 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
4249 end
4275 end
4250 end
4276 end
4251
4277
4252 def test_bulk_copy_should_allow_adding_a_note
4278 def test_bulk_copy_should_allow_adding_a_note
4253 @request.session[:user_id] = 2
4279 @request.session[:user_id] = 2
4254 assert_difference 'Issue.count', 1 do
4280 assert_difference 'Issue.count', 1 do
4255 post :bulk_update, :ids => [1], :copy => '1',
4281 post :bulk_update, :ids => [1], :copy => '1',
4256 :notes => 'Copying one issue',
4282 :notes => 'Copying one issue',
4257 :issue => {
4283 :issue => {
4258 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
4284 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
4259 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
4285 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
4260 }
4286 }
4261 end
4287 end
4262 issue = Issue.order('id DESC').first
4288 issue = Issue.order('id DESC').first
4263 assert_equal 1, issue.journals.size
4289 assert_equal 1, issue.journals.size
4264 journal = issue.journals.first
4290 journal = issue.journals.first
4265 assert_equal 'Copying one issue', journal.notes
4291 assert_equal 'Copying one issue', journal.notes
4266 end
4292 end
4267
4293
4268 def test_bulk_copy_should_allow_not_copying_the_attachments
4294 def test_bulk_copy_should_allow_not_copying_the_attachments
4269 attachment_count = Issue.find(3).attachments.size
4295 attachment_count = Issue.find(3).attachments.size
4270 assert attachment_count > 0
4296 assert attachment_count > 0
4271 @request.session[:user_id] = 2
4297 @request.session[:user_id] = 2
4272
4298
4273 assert_difference 'Issue.count', 1 do
4299 assert_difference 'Issue.count', 1 do
4274 assert_no_difference 'Attachment.count' do
4300 assert_no_difference 'Attachment.count' do
4275 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '0',
4301 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '0',
4276 :issue => {
4302 :issue => {
4277 :project_id => ''
4303 :project_id => ''
4278 }
4304 }
4279 end
4305 end
4280 end
4306 end
4281 end
4307 end
4282
4308
4283 def test_bulk_copy_should_allow_copying_the_attachments
4309 def test_bulk_copy_should_allow_copying_the_attachments
4284 attachment_count = Issue.find(3).attachments.size
4310 attachment_count = Issue.find(3).attachments.size
4285 assert attachment_count > 0
4311 assert attachment_count > 0
4286 @request.session[:user_id] = 2
4312 @request.session[:user_id] = 2
4287
4313
4288 assert_difference 'Issue.count', 1 do
4314 assert_difference 'Issue.count', 1 do
4289 assert_difference 'Attachment.count', attachment_count do
4315 assert_difference 'Attachment.count', attachment_count do
4290 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
4316 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
4291 :issue => {
4317 :issue => {
4292 :project_id => ''
4318 :project_id => ''
4293 }
4319 }
4294 end
4320 end
4295 end
4321 end
4296 end
4322 end
4297
4323
4298 def test_bulk_copy_should_add_relations_with_copied_issues
4324 def test_bulk_copy_should_add_relations_with_copied_issues
4299 @request.session[:user_id] = 2
4325 @request.session[:user_id] = 2
4300
4326
4301 assert_difference 'Issue.count', 2 do
4327 assert_difference 'Issue.count', 2 do
4302 assert_difference 'IssueRelation.count', 2 do
4328 assert_difference 'IssueRelation.count', 2 do
4303 post :bulk_update, :ids => [1, 3], :copy => '1', :link_copy => '1',
4329 post :bulk_update, :ids => [1, 3], :copy => '1', :link_copy => '1',
4304 :issue => {
4330 :issue => {
4305 :project_id => '1'
4331 :project_id => '1'
4306 }
4332 }
4307 end
4333 end
4308 end
4334 end
4309 end
4335 end
4310
4336
4311 def test_bulk_copy_should_allow_not_copying_the_subtasks
4337 def test_bulk_copy_should_allow_not_copying_the_subtasks
4312 issue = Issue.generate_with_descendants!
4338 issue = Issue.generate_with_descendants!
4313 @request.session[:user_id] = 2
4339 @request.session[:user_id] = 2
4314
4340
4315 assert_difference 'Issue.count', 1 do
4341 assert_difference 'Issue.count', 1 do
4316 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '0',
4342 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '0',
4317 :issue => {
4343 :issue => {
4318 :project_id => ''
4344 :project_id => ''
4319 }
4345 }
4320 end
4346 end
4321 end
4347 end
4322
4348
4323 def test_bulk_copy_should_allow_copying_the_subtasks
4349 def test_bulk_copy_should_allow_copying_the_subtasks
4324 issue = Issue.generate_with_descendants!
4350 issue = Issue.generate_with_descendants!
4325 count = issue.descendants.count
4351 count = issue.descendants.count
4326 @request.session[:user_id] = 2
4352 @request.session[:user_id] = 2
4327
4353
4328 assert_difference 'Issue.count', count+1 do
4354 assert_difference 'Issue.count', count+1 do
4329 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
4355 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
4330 :issue => {
4356 :issue => {
4331 :project_id => ''
4357 :project_id => ''
4332 }
4358 }
4333 end
4359 end
4334 copy = Issue.where(:parent_id => nil).order("id DESC").first
4360 copy = Issue.where(:parent_id => nil).order("id DESC").first
4335 assert_equal count, copy.descendants.count
4361 assert_equal count, copy.descendants.count
4336 end
4362 end
4337
4363
4338 def test_bulk_copy_should_not_copy_selected_subtasks_twice
4364 def test_bulk_copy_should_not_copy_selected_subtasks_twice
4339 issue = Issue.generate_with_descendants!
4365 issue = Issue.generate_with_descendants!
4340 count = issue.descendants.count
4366 count = issue.descendants.count
4341 @request.session[:user_id] = 2
4367 @request.session[:user_id] = 2
4342
4368
4343 assert_difference 'Issue.count', count+1 do
4369 assert_difference 'Issue.count', count+1 do
4344 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
4370 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
4345 :issue => {
4371 :issue => {
4346 :project_id => ''
4372 :project_id => ''
4347 }
4373 }
4348 end
4374 end
4349 copy = Issue.where(:parent_id => nil).order("id DESC").first
4375 copy = Issue.where(:parent_id => nil).order("id DESC").first
4350 assert_equal count, copy.descendants.count
4376 assert_equal count, copy.descendants.count
4351 end
4377 end
4352
4378
4353 def test_bulk_copy_to_another_project_should_follow_when_needed
4379 def test_bulk_copy_to_another_project_should_follow_when_needed
4354 @request.session[:user_id] = 2
4380 @request.session[:user_id] = 2
4355 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
4381 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
4356 issue = Issue.order('id DESC').first
4382 issue = Issue.order('id DESC').first
4357 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
4383 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
4358 end
4384 end
4359
4385
4360 def test_bulk_copy_with_all_failures_should_display_errors
4386 def test_bulk_copy_with_all_failures_should_display_errors
4361 @request.session[:user_id] = 2
4387 @request.session[:user_id] = 2
4362 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
4388 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
4363
4389
4364 assert_response :success
4390 assert_response :success
4365 end
4391 end
4366
4392
4367 def test_destroy_issue_with_no_time_entries
4393 def test_destroy_issue_with_no_time_entries
4368 assert_nil TimeEntry.find_by_issue_id(2)
4394 assert_nil TimeEntry.find_by_issue_id(2)
4369 @request.session[:user_id] = 2
4395 @request.session[:user_id] = 2
4370
4396
4371 assert_difference 'Issue.count', -1 do
4397 assert_difference 'Issue.count', -1 do
4372 delete :destroy, :id => 2
4398 delete :destroy, :id => 2
4373 end
4399 end
4374 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4400 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4375 assert_nil Issue.find_by_id(2)
4401 assert_nil Issue.find_by_id(2)
4376 end
4402 end
4377
4403
4378 def test_destroy_issues_with_time_entries
4404 def test_destroy_issues_with_time_entries
4379 @request.session[:user_id] = 2
4405 @request.session[:user_id] = 2
4380
4406
4381 assert_no_difference 'Issue.count' do
4407 assert_no_difference 'Issue.count' do
4382 delete :destroy, :ids => [1, 3]
4408 delete :destroy, :ids => [1, 3]
4383 end
4409 end
4384 assert_response :success
4410 assert_response :success
4385 assert_template 'destroy'
4411 assert_template 'destroy'
4386 assert_not_nil assigns(:hours)
4412 assert_not_nil assigns(:hours)
4387 assert Issue.find_by_id(1) && Issue.find_by_id(3)
4413 assert Issue.find_by_id(1) && Issue.find_by_id(3)
4388
4414
4389 assert_select 'form' do
4415 assert_select 'form' do
4390 assert_select 'input[name=_method][value=delete]'
4416 assert_select 'input[name=_method][value=delete]'
4391 end
4417 end
4392 end
4418 end
4393
4419
4394 def test_destroy_issues_and_destroy_time_entries
4420 def test_destroy_issues_and_destroy_time_entries
4395 @request.session[:user_id] = 2
4421 @request.session[:user_id] = 2
4396
4422
4397 assert_difference 'Issue.count', -2 do
4423 assert_difference 'Issue.count', -2 do
4398 assert_difference 'TimeEntry.count', -3 do
4424 assert_difference 'TimeEntry.count', -3 do
4399 delete :destroy, :ids => [1, 3], :todo => 'destroy'
4425 delete :destroy, :ids => [1, 3], :todo => 'destroy'
4400 end
4426 end
4401 end
4427 end
4402 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4428 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4403 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4429 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4404 assert_nil TimeEntry.find_by_id([1, 2])
4430 assert_nil TimeEntry.find_by_id([1, 2])
4405 end
4431 end
4406
4432
4407 def test_destroy_issues_and_assign_time_entries_to_project
4433 def test_destroy_issues_and_assign_time_entries_to_project
4408 @request.session[:user_id] = 2
4434 @request.session[:user_id] = 2
4409
4435
4410 assert_difference 'Issue.count', -2 do
4436 assert_difference 'Issue.count', -2 do
4411 assert_no_difference 'TimeEntry.count' do
4437 assert_no_difference 'TimeEntry.count' do
4412 delete :destroy, :ids => [1, 3], :todo => 'nullify'
4438 delete :destroy, :ids => [1, 3], :todo => 'nullify'
4413 end
4439 end
4414 end
4440 end
4415 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4441 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4416 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4442 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4417 assert_nil TimeEntry.find(1).issue_id
4443 assert_nil TimeEntry.find(1).issue_id
4418 assert_nil TimeEntry.find(2).issue_id
4444 assert_nil TimeEntry.find(2).issue_id
4419 end
4445 end
4420
4446
4421 def test_destroy_issues_and_reassign_time_entries_to_another_issue
4447 def test_destroy_issues_and_reassign_time_entries_to_another_issue
4422 @request.session[:user_id] = 2
4448 @request.session[:user_id] = 2
4423
4449
4424 assert_difference 'Issue.count', -2 do
4450 assert_difference 'Issue.count', -2 do
4425 assert_no_difference 'TimeEntry.count' do
4451 assert_no_difference 'TimeEntry.count' do
4426 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
4452 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
4427 end
4453 end
4428 end
4454 end
4429 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4455 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
4430 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4456 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
4431 assert_equal 2, TimeEntry.find(1).issue_id
4457 assert_equal 2, TimeEntry.find(1).issue_id
4432 assert_equal 2, TimeEntry.find(2).issue_id
4458 assert_equal 2, TimeEntry.find(2).issue_id
4433 end
4459 end
4434
4460
4435 def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
4461 def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
4436 @request.session[:user_id] = 2
4462 @request.session[:user_id] = 2
4437
4463
4438 assert_no_difference 'Issue.count' do
4464 assert_no_difference 'Issue.count' do
4439 assert_no_difference 'TimeEntry.count' do
4465 assert_no_difference 'TimeEntry.count' do
4440 # try to reassign time to an issue of another project
4466 # try to reassign time to an issue of another project
4441 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 4
4467 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 4
4442 end
4468 end
4443 end
4469 end
4444 assert_response :success
4470 assert_response :success
4445 assert_template 'destroy'
4471 assert_template 'destroy'
4446 end
4472 end
4447
4473
4448 def test_destroy_issues_from_different_projects
4474 def test_destroy_issues_from_different_projects
4449 @request.session[:user_id] = 2
4475 @request.session[:user_id] = 2
4450
4476
4451 assert_difference 'Issue.count', -3 do
4477 assert_difference 'Issue.count', -3 do
4452 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
4478 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
4453 end
4479 end
4454 assert_redirected_to :controller => 'issues', :action => 'index'
4480 assert_redirected_to :controller => 'issues', :action => 'index'
4455 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
4481 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
4456 end
4482 end
4457
4483
4458 def test_destroy_parent_and_child_issues
4484 def test_destroy_parent_and_child_issues
4459 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
4485 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
4460 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
4486 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
4461 assert child.is_descendant_of?(parent.reload)
4487 assert child.is_descendant_of?(parent.reload)
4462
4488
4463 @request.session[:user_id] = 2
4489 @request.session[:user_id] = 2
4464 assert_difference 'Issue.count', -2 do
4490 assert_difference 'Issue.count', -2 do
4465 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
4491 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
4466 end
4492 end
4467 assert_response 302
4493 assert_response 302
4468 end
4494 end
4469
4495
4470 def test_destroy_invalid_should_respond_with_404
4496 def test_destroy_invalid_should_respond_with_404
4471 @request.session[:user_id] = 2
4497 @request.session[:user_id] = 2
4472 assert_no_difference 'Issue.count' do
4498 assert_no_difference 'Issue.count' do
4473 delete :destroy, :id => 999
4499 delete :destroy, :id => 999
4474 end
4500 end
4475 assert_response 404
4501 assert_response 404
4476 end
4502 end
4477
4503
4478 def test_default_search_scope
4504 def test_default_search_scope
4479 get :index
4505 get :index
4480
4506
4481 assert_select 'div#quick-search form' do
4507 assert_select 'div#quick-search form' do
4482 assert_select 'input[name=issues][value="1"][type=hidden]'
4508 assert_select 'input[name=issues][value="1"][type=hidden]'
4483 end
4509 end
4484 end
4510 end
4485
4511
4486 def setup_user_with_copy_but_not_add_permission
4512 def setup_user_with_copy_but_not_add_permission
4487 Role.all.each {|r| r.remove_permission! :add_issues}
4513 Role.all.each {|r| r.remove_permission! :add_issues}
4488 Role.find_by_name('Manager').add_permission! :add_issues
4514 Role.find_by_name('Manager').add_permission! :add_issues
4489 user = User.generate!
4515 user = User.generate!
4490 User.add_to_project(user, Project.find(1), Role.find_by_name('Developer'))
4516 User.add_to_project(user, Project.find(1), Role.find_by_name('Developer'))
4491 User.add_to_project(user, Project.find(2), Role.find_by_name('Manager'))
4517 User.add_to_project(user, Project.find(2), Role.find_by_name('Manager'))
4492 user
4518 user
4493 end
4519 end
4494 end
4520 end
General Comments 0
You need to be logged in to leave comments. Login now