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