##// END OF EJS Templates
Moved tracker_id param....
Jean-Philippe Lang -
r14390:9a3b8e0b1eaa
parent child
Show More
@@ -1,213 +1,215
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class IssuesTest < Redmine::IntegrationTest
20 class IssuesTest < Redmine::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users, :email_addresses,
22 :users, :email_addresses,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :trackers,
26 :trackers,
27 :projects_trackers,
27 :projects_trackers,
28 :enabled_modules,
28 :enabled_modules,
29 :issue_statuses,
29 :issue_statuses,
30 :issues,
30 :issues,
31 :enumerations,
31 :enumerations,
32 :custom_fields,
32 :custom_fields,
33 :custom_values,
33 :custom_values,
34 :custom_fields_trackers,
34 :custom_fields_trackers,
35 :attachments
35 :attachments
36
36
37 # create an issue
37 # create an issue
38 def test_add_issue
38 def test_add_issue
39 log_user('jsmith', 'jsmith')
39 log_user('jsmith', 'jsmith')
40 get '/projects/ecookbook/issues/new', :tracker_id => '1'
40
41 get '/projects/ecookbook/issues/new'
41 assert_response :success
42 assert_response :success
42 assert_template 'issues/new'
43 assert_template 'issues/new'
43
44
44 issue = new_record(Issue) do
45 issue = new_record(Issue) do
45 post '/projects/ecookbook/issues', :tracker_id => "1",
46 post '/projects/ecookbook/issues',
46 :issue => { :start_date => "2006-12-26",
47 :issue => { :tracker_id => "1",
48 :start_date => "2006-12-26",
47 :priority_id => "4",
49 :priority_id => "4",
48 :subject => "new test issue",
50 :subject => "new test issue",
49 :category_id => "",
51 :category_id => "",
50 :description => "new issue",
52 :description => "new issue",
51 :done_ratio => "0",
53 :done_ratio => "0",
52 :due_date => "",
54 :due_date => "",
53 :assigned_to_id => "" },
55 :assigned_to_id => "" },
54 :custom_fields => {'2' => 'Value for field 2'}
56 :custom_fields => {'2' => 'Value for field 2'}
55 end
57 end
56 # check redirection
58 # check redirection
57 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
59 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
58 follow_redirect!
60 follow_redirect!
59 assert_equal issue, assigns(:issue)
61 assert_equal issue, assigns(:issue)
60
62
61 # check issue attributes
63 # check issue attributes
62 assert_equal 'jsmith', issue.author.login
64 assert_equal 'jsmith', issue.author.login
63 assert_equal 1, issue.project.id
65 assert_equal 1, issue.project.id
64 assert_equal 1, issue.status.id
66 assert_equal 1, issue.status.id
65 end
67 end
66
68
67 def test_create_issue_by_anonymous_without_permission_should_fail
69 def test_create_issue_by_anonymous_without_permission_should_fail
68 Role.anonymous.remove_permission! :add_issues
70 Role.anonymous.remove_permission! :add_issues
69
71
70 assert_no_difference 'Issue.count' do
72 assert_no_difference 'Issue.count' do
71 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
73 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
72 end
74 end
73 assert_response 302
75 assert_response 302
74 end
76 end
75
77
76 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
78 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
77 Role.anonymous.remove_permission! :add_issues
79 Role.anonymous.remove_permission! :add_issues
78 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
80 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
79
81
80 issue = new_record(Issue) do
82 issue = new_record(Issue) do
81 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
83 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
82 assert_response 302
84 assert_response 302
83 end
85 end
84 assert_equal User.anonymous, issue.author
86 assert_equal User.anonymous, issue.author
85 end
87 end
86
88
87 # add then remove 2 attachments to an issue
89 # add then remove 2 attachments to an issue
88 def test_issue_attachments
90 def test_issue_attachments
89 log_user('jsmith', 'jsmith')
91 log_user('jsmith', 'jsmith')
90 set_tmp_attachments_directory
92 set_tmp_attachments_directory
91
93
92 attachment = new_record(Attachment) do
94 attachment = new_record(Attachment) do
93 put '/issues/1',
95 put '/issues/1',
94 :notes => 'Some notes',
96 :notes => 'Some notes',
95 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
97 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
96 assert_redirected_to "/issues/1"
98 assert_redirected_to "/issues/1"
97 end
99 end
98
100
99 assert_equal Issue.find(1), attachment.container
101 assert_equal Issue.find(1), attachment.container
100 assert_equal 'testfile.txt', attachment.filename
102 assert_equal 'testfile.txt', attachment.filename
101 assert_equal 'This is an attachment', attachment.description
103 assert_equal 'This is an attachment', attachment.description
102 # verify the size of the attachment stored in db
104 # verify the size of the attachment stored in db
103 #assert_equal file_data_1.length, attachment.filesize
105 #assert_equal file_data_1.length, attachment.filesize
104 # verify that the attachment was written to disk
106 # verify that the attachment was written to disk
105 assert File.exist?(attachment.diskfile)
107 assert File.exist?(attachment.diskfile)
106
108
107 # remove the attachments
109 # remove the attachments
108 Issue.find(1).attachments.each(&:destroy)
110 Issue.find(1).attachments.each(&:destroy)
109 assert_equal 0, Issue.find(1).attachments.length
111 assert_equal 0, Issue.find(1).attachments.length
110 end
112 end
111
113
112 def test_other_formats_links_on_index
114 def test_other_formats_links_on_index
113 get '/projects/ecookbook/issues'
115 get '/projects/ecookbook/issues'
114
116
115 %w(Atom PDF CSV).each do |format|
117 %w(Atom PDF CSV).each do |format|
116 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
118 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
117 end
119 end
118 end
120 end
119
121
120 def test_other_formats_links_on_index_without_project_id_in_url
122 def test_other_formats_links_on_index_without_project_id_in_url
121 get '/issues', :project_id => 'ecookbook'
123 get '/issues', :project_id => 'ecookbook'
122
124
123 %w(Atom PDF CSV).each do |format|
125 %w(Atom PDF CSV).each do |format|
124 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
126 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
125 end
127 end
126 end
128 end
127
129
128 def test_pagination_links_on_index
130 def test_pagination_links_on_index
129 with_settings :per_page_options => '2' do
131 with_settings :per_page_options => '2' do
130 get '/projects/ecookbook/issues'
132 get '/projects/ecookbook/issues'
131
133
132 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
134 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
133 end
135 end
134 end
136 end
135
137
136 def test_pagination_links_on_index_without_project_id_in_url
138 def test_pagination_links_on_index_without_project_id_in_url
137 with_settings :per_page_options => '2' do
139 with_settings :per_page_options => '2' do
138 get '/issues', :project_id => 'ecookbook'
140 get '/issues', :project_id => 'ecookbook'
139
141
140 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
142 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
141 end
143 end
142 end
144 end
143
145
144 def test_issue_with_user_custom_field
146 def test_issue_with_user_custom_field
145 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
147 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
146 Role.anonymous.add_permission! :add_issues, :edit_issues
148 Role.anonymous.add_permission! :add_issues, :edit_issues
147 users = Project.find(1).users.uniq.sort
149 users = Project.find(1).users.uniq.sort
148 tester = users.first
150 tester = users.first
149
151
150 # Issue form
152 # Issue form
151 get '/projects/ecookbook/issues/new'
153 get '/projects/ecookbook/issues/new'
152 assert_response :success
154 assert_response :success
153 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
155 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
154 assert_select 'option', users.size + 1 # +1 for blank value
156 assert_select 'option', users.size + 1 # +1 for blank value
155 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
157 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
156 end
158 end
157
159
158 # Create issue
160 # Create issue
159 issue = new_record(Issue) do
161 issue = new_record(Issue) do
160 post '/projects/ecookbook/issues',
162 post '/projects/ecookbook/issues',
161 :issue => {
163 :issue => {
162 :tracker_id => '1',
164 :tracker_id => '1',
163 :priority_id => '4',
165 :priority_id => '4',
164 :subject => 'Issue with user custom field',
166 :subject => 'Issue with user custom field',
165 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
167 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
166 }
168 }
167 assert_response 302
169 assert_response 302
168 end
170 end
169
171
170 # Issue view
172 # Issue view
171 follow_redirect!
173 follow_redirect!
172 assert_select 'th:contains("Tester:") + td', :text => tester.name
174 assert_select 'th:contains("Tester:") + td', :text => tester.name
173 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
175 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
174 assert_select 'option', users.size + 1 # +1 for blank value
176 assert_select 'option', users.size + 1 # +1 for blank value
175 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
177 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
176 end
178 end
177
179
178 new_tester = users[1]
180 new_tester = users[1]
179 with_settings :default_language => 'en' do
181 with_settings :default_language => 'en' do
180 # Update issue
182 # Update issue
181 assert_difference 'Journal.count' do
183 assert_difference 'Journal.count' do
182 put "/issues/#{issue.id}",
184 put "/issues/#{issue.id}",
183 :notes => 'Updating custom field',
185 :notes => 'Updating custom field',
184 :issue => {
186 :issue => {
185 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
187 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
186 }
188 }
187 assert_redirected_to "/issues/#{issue.id}"
189 assert_redirected_to "/issues/#{issue.id}"
188 end
190 end
189 # Issue view
191 # Issue view
190 follow_redirect!
192 follow_redirect!
191 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
193 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
192 end
194 end
193 end
195 end
194
196
195 def test_update_using_invalid_http_verbs
197 def test_update_using_invalid_http_verbs
196 subject = 'Updated by an invalid http verb'
198 subject = 'Updated by an invalid http verb'
197
199
198 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
200 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
199 assert_response 404
201 assert_response 404
200 assert_not_equal subject, Issue.find(1).subject
202 assert_not_equal subject, Issue.find(1).subject
201
203
202 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
204 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
203 assert_response 404
205 assert_response 404
204 assert_not_equal subject, Issue.find(1).subject
206 assert_not_equal subject, Issue.find(1).subject
205 end
207 end
206
208
207 def test_get_watch_should_be_invalid
209 def test_get_watch_should_be_invalid
208 assert_no_difference 'Watcher.count' do
210 assert_no_difference 'Watcher.count' do
209 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
211 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
210 assert_response 404
212 assert_response 404
211 end
213 end
212 end
214 end
213 end
215 end
General Comments 0
You need to be logged in to leave comments. Login now