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