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