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