##// END OF EJS Templates
Merged r13390 (#17163)....
Jean-Philippe Lang -
r13034:198e92d26b49
parent child
Show More
@@ -1,290 +1,294
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 class Version < ActiveRecord::Base
19 19 include Redmine::SafeAttributes
20 20 after_update :update_issues_from_sharing_change
21 21 belongs_to :project
22 22 has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
23 23 acts_as_customizable
24 24 acts_as_attachable :view_permission => :view_files,
25 25 :delete_permission => :manage_files
26 26
27 27 VERSION_STATUSES = %w(open locked closed)
28 28 VERSION_SHARINGS = %w(none descendants hierarchy tree system)
29 29
30 30 validates_presence_of :name
31 31 validates_uniqueness_of :name, :scope => [:project_id]
32 32 validates_length_of :name, :maximum => 60
33 33 validates :effective_date, :date => true
34 34 validates_inclusion_of :status, :in => VERSION_STATUSES
35 35 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
36 36
37 37 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
38 38 scope :open, lambda { where(:status => 'open') }
39 39 scope :visible, lambda {|*args|
40 40 includes(:project).where(Project.allowed_to_condition(args.first || User.current, :view_issues))
41 41 }
42 42
43 43 safe_attributes 'name',
44 44 'description',
45 45 'effective_date',
46 46 'due_date',
47 47 'wiki_page_title',
48 48 'status',
49 49 'sharing',
50 50 'custom_field_values',
51 51 'custom_fields'
52 52
53 53 # Returns true if +user+ or current user is allowed to view the version
54 54 def visible?(user=User.current)
55 55 user.allowed_to?(:view_issues, self.project)
56 56 end
57 57
58 58 # Version files have same visibility as project files
59 59 def attachments_visible?(*args)
60 60 project.present? && project.attachments_visible?(*args)
61 61 end
62 62
63 def attachments_deletable?(usr=User.current)
64 project.present? && project.attachments_deletable?(usr)
65 end
66
63 67 def start_date
64 68 @start_date ||= fixed_issues.minimum('start_date')
65 69 end
66 70
67 71 def due_date
68 72 effective_date
69 73 end
70 74
71 75 def due_date=(arg)
72 76 self.effective_date=(arg)
73 77 end
74 78
75 79 # Returns the total estimated time for this version
76 80 # (sum of leaves estimated_hours)
77 81 def estimated_hours
78 82 @estimated_hours ||= fixed_issues.leaves.sum(:estimated_hours).to_f
79 83 end
80 84
81 85 # Returns the total reported time for this version
82 86 def spent_hours
83 87 @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
84 88 end
85 89
86 90 def closed?
87 91 status == 'closed'
88 92 end
89 93
90 94 def open?
91 95 status == 'open'
92 96 end
93 97
94 98 # Returns true if the version is completed: due date reached and no open issues
95 99 def completed?
96 100 effective_date && (effective_date < Date.today) && (open_issues_count == 0)
97 101 end
98 102
99 103 def behind_schedule?
100 104 if completed_percent == 100
101 105 return false
102 106 elsif due_date && start_date
103 107 done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor
104 108 return done_date <= Date.today
105 109 else
106 110 false # No issues so it's not late
107 111 end
108 112 end
109 113
110 114 # Returns the completion percentage of this version based on the amount of open/closed issues
111 115 # and the time spent on the open issues.
112 116 def completed_percent
113 117 if issues_count == 0
114 118 0
115 119 elsif open_issues_count == 0
116 120 100
117 121 else
118 122 issues_progress(false) + issues_progress(true)
119 123 end
120 124 end
121 125
122 126 # TODO: remove in Redmine 3.0
123 127 def completed_pourcent
124 128 ActiveSupport::Deprecation.warn "Version#completed_pourcent is deprecated and will be removed in Redmine 3.0. Please use #completed_percent instead."
125 129 completed_percent
126 130 end
127 131
128 132 # Returns the percentage of issues that have been marked as 'closed'.
129 133 def closed_percent
130 134 if issues_count == 0
131 135 0
132 136 else
133 137 issues_progress(false)
134 138 end
135 139 end
136 140
137 141 # TODO: remove in Redmine 3.0
138 142 def closed_pourcent
139 143 ActiveSupport::Deprecation.warn "Version#closed_pourcent is deprecated and will be removed in Redmine 3.0. Please use #closed_percent instead."
140 144 closed_percent
141 145 end
142 146
143 147 # Returns true if the version is overdue: due date reached and some open issues
144 148 def overdue?
145 149 effective_date && (effective_date < Date.today) && (open_issues_count > 0)
146 150 end
147 151
148 152 # Returns assigned issues count
149 153 def issues_count
150 154 load_issue_counts
151 155 @issue_count
152 156 end
153 157
154 158 # Returns the total amount of open issues for this version.
155 159 def open_issues_count
156 160 load_issue_counts
157 161 @open_issues_count
158 162 end
159 163
160 164 # Returns the total amount of closed issues for this version.
161 165 def closed_issues_count
162 166 load_issue_counts
163 167 @closed_issues_count
164 168 end
165 169
166 170 def wiki_page
167 171 if project.wiki && !wiki_page_title.blank?
168 172 @wiki_page ||= project.wiki.find_page(wiki_page_title)
169 173 end
170 174 @wiki_page
171 175 end
172 176
173 177 def to_s; name end
174 178
175 179 def to_s_with_project
176 180 "#{project} - #{name}"
177 181 end
178 182
179 183 # Versions are sorted by effective_date and name
180 184 # Those with no effective_date are at the end, sorted by name
181 185 def <=>(version)
182 186 if self.effective_date
183 187 if version.effective_date
184 188 if self.effective_date == version.effective_date
185 189 name == version.name ? id <=> version.id : name <=> version.name
186 190 else
187 191 self.effective_date <=> version.effective_date
188 192 end
189 193 else
190 194 -1
191 195 end
192 196 else
193 197 if version.effective_date
194 198 1
195 199 else
196 200 name == version.name ? id <=> version.id : name <=> version.name
197 201 end
198 202 end
199 203 end
200 204
201 205 def self.fields_for_order_statement(table=nil)
202 206 table ||= table_name
203 207 ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"]
204 208 end
205 209
206 210 scope :sorted, lambda { order(fields_for_order_statement) }
207 211
208 212 # Returns the sharings that +user+ can set the version to
209 213 def allowed_sharings(user = User.current)
210 214 VERSION_SHARINGS.select do |s|
211 215 if sharing == s
212 216 true
213 217 else
214 218 case s
215 219 when 'system'
216 220 # Only admin users can set a systemwide sharing
217 221 user.admin?
218 222 when 'hierarchy', 'tree'
219 223 # Only users allowed to manage versions of the root project can
220 224 # set sharing to hierarchy or tree
221 225 project.nil? || user.allowed_to?(:manage_versions, project.root)
222 226 else
223 227 true
224 228 end
225 229 end
226 230 end
227 231 end
228 232
229 233 private
230 234
231 235 def load_issue_counts
232 236 unless @issue_count
233 237 @open_issues_count = 0
234 238 @closed_issues_count = 0
235 239 fixed_issues.group(:status).count.each do |status, count|
236 240 if status.is_closed?
237 241 @closed_issues_count += count
238 242 else
239 243 @open_issues_count += count
240 244 end
241 245 end
242 246 @issue_count = @open_issues_count + @closed_issues_count
243 247 end
244 248 end
245 249
246 250 # Update the issue's fixed versions. Used if a version's sharing changes.
247 251 def update_issues_from_sharing_change
248 252 if sharing_changed?
249 253 if VERSION_SHARINGS.index(sharing_was).nil? ||
250 254 VERSION_SHARINGS.index(sharing).nil? ||
251 255 VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
252 256 Issue.update_versions_from_sharing_change self
253 257 end
254 258 end
255 259 end
256 260
257 261 # Returns the average estimated time of assigned issues
258 262 # or 1 if no issue has an estimated time
259 263 # Used to weigth unestimated issues in progress calculation
260 264 def estimated_average
261 265 if @estimated_average.nil?
262 266 average = fixed_issues.average(:estimated_hours).to_f
263 267 if average == 0
264 268 average = 1
265 269 end
266 270 @estimated_average = average
267 271 end
268 272 @estimated_average
269 273 end
270 274
271 275 # Returns the total progress of open or closed issues. The returned percentage takes into account
272 276 # the amount of estimated time set for this version.
273 277 #
274 278 # Examples:
275 279 # issues_progress(true) => returns the progress percentage for open issues.
276 280 # issues_progress(false) => returns the progress percentage for closed issues.
277 281 def issues_progress(open)
278 282 @issues_progress ||= {}
279 283 @issues_progress[open] ||= begin
280 284 progress = 0
281 285 if issues_count > 0
282 286 ratio = open ? 'done_ratio' : 100
283 287
284 288 done = fixed_issues.open(open).sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}").to_f
285 289 progress = done / (estimated_average * issues_count)
286 290 end
287 291 progress
288 292 end
289 293 end
290 294 end
@@ -1,385 +1,395
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class AttachmentsControllerTest < ActionController::TestCase
23 23 fixtures :users, :projects, :roles, :members, :member_roles,
24 24 :enabled_modules, :issues, :trackers, :attachments,
25 25 :versions, :wiki_pages, :wikis, :documents
26 26
27 27 def setup
28 28 User.current = nil
29 29 set_fixtures_attachments_directory
30 30 end
31 31
32 32 def teardown
33 33 set_tmp_attachments_directory
34 34 end
35 35
36 36 def test_show_diff
37 37 ['inline', 'sbs'].each do |dt|
38 38 # 060719210727_changeset_utf8.diff
39 39 get :show, :id => 14, :type => dt
40 40 assert_response :success
41 41 assert_template 'diff'
42 42 assert_equal 'text/html', @response.content_type
43 43 assert_tag 'th',
44 44 :attributes => {:class => /filename/},
45 45 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
46 46 assert_tag 'td',
47 47 :attributes => {:class => /line-code/},
48 48 :content => /Demande créée avec succès/
49 49 end
50 50 set_tmp_attachments_directory
51 51 end
52 52
53 53 def test_show_diff_replace_cannot_convert_content
54 54 with_settings :repositories_encodings => 'UTF-8' do
55 55 ['inline', 'sbs'].each do |dt|
56 56 # 060719210727_changeset_iso8859-1.diff
57 57 get :show, :id => 5, :type => dt
58 58 assert_response :success
59 59 assert_template 'diff'
60 60 assert_equal 'text/html', @response.content_type
61 61 assert_tag 'th',
62 62 :attributes => {:class => "filename"},
63 63 :content => /issues_controller.rb\t\(r\?vision 1484\)/
64 64 assert_tag 'td',
65 65 :attributes => {:class => /line-code/},
66 66 :content => /Demande cr\?\?e avec succ\?s/
67 67 end
68 68 end
69 69 set_tmp_attachments_directory
70 70 end
71 71
72 72 def test_show_diff_latin_1
73 73 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
74 74 ['inline', 'sbs'].each do |dt|
75 75 # 060719210727_changeset_iso8859-1.diff
76 76 get :show, :id => 5, :type => dt
77 77 assert_response :success
78 78 assert_template 'diff'
79 79 assert_equal 'text/html', @response.content_type
80 80 assert_tag 'th',
81 81 :attributes => {:class => "filename"},
82 82 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
83 83 assert_tag 'td',
84 84 :attributes => {:class => /line-code/},
85 85 :content => /Demande créée avec succès/
86 86 end
87 87 end
88 88 set_tmp_attachments_directory
89 89 end
90 90
91 91 def test_save_diff_type
92 92 user1 = User.find(1)
93 93 user1.pref[:diff_type] = nil
94 94 user1.preference.save
95 95 user = User.find(1)
96 96 assert_nil user.pref[:diff_type]
97 97
98 98 @request.session[:user_id] = 1 # admin
99 99 get :show, :id => 5
100 100 assert_response :success
101 101 assert_template 'diff'
102 102 user.reload
103 103 assert_equal "inline", user.pref[:diff_type]
104 104 get :show, :id => 5, :type => 'sbs'
105 105 assert_response :success
106 106 assert_template 'diff'
107 107 user.reload
108 108 assert_equal "sbs", user.pref[:diff_type]
109 109 end
110 110
111 111 def test_diff_show_filename_in_mercurial_export
112 112 set_tmp_attachments_directory
113 113 a = Attachment.new(:container => Issue.find(1),
114 114 :file => uploaded_test_file("hg-export.diff", "text/plain"),
115 115 :author => User.find(1))
116 116 assert a.save
117 117 assert_equal 'hg-export.diff', a.filename
118 118
119 119 get :show, :id => a.id, :type => 'inline'
120 120 assert_response :success
121 121 assert_template 'diff'
122 122 assert_equal 'text/html', @response.content_type
123 123 assert_select 'th.filename', :text => 'test1.txt'
124 124 end
125 125
126 126 def test_show_text_file
127 127 get :show, :id => 4
128 128 assert_response :success
129 129 assert_template 'file'
130 130 assert_equal 'text/html', @response.content_type
131 131 set_tmp_attachments_directory
132 132 end
133 133
134 134 def test_show_text_file_utf_8
135 135 set_tmp_attachments_directory
136 136 a = Attachment.new(:container => Issue.find(1),
137 137 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
138 138 :author => User.find(1))
139 139 assert a.save
140 140 assert_equal 'japanese-utf-8.txt', a.filename
141 141
142 142 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
143 143 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
144 144
145 145 get :show, :id => a.id
146 146 assert_response :success
147 147 assert_template 'file'
148 148 assert_equal 'text/html', @response.content_type
149 149 assert_tag :tag => 'th',
150 150 :content => '1',
151 151 :attributes => { :class => 'line-num' },
152 152 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
153 153 end
154 154
155 155 def test_show_text_file_replace_cannot_convert_content
156 156 set_tmp_attachments_directory
157 157 with_settings :repositories_encodings => 'UTF-8' do
158 158 a = Attachment.new(:container => Issue.find(1),
159 159 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
160 160 :author => User.find(1))
161 161 assert a.save
162 162 assert_equal 'iso8859-1.txt', a.filename
163 163
164 164 get :show, :id => a.id
165 165 assert_response :success
166 166 assert_template 'file'
167 167 assert_equal 'text/html', @response.content_type
168 168 assert_tag :tag => 'th',
169 169 :content => '7',
170 170 :attributes => { :class => 'line-num' },
171 171 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
172 172 end
173 173 end
174 174
175 175 def test_show_text_file_latin_1
176 176 set_tmp_attachments_directory
177 177 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
178 178 a = Attachment.new(:container => Issue.find(1),
179 179 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
180 180 :author => User.find(1))
181 181 assert a.save
182 182 assert_equal 'iso8859-1.txt', a.filename
183 183
184 184 get :show, :id => a.id
185 185 assert_response :success
186 186 assert_template 'file'
187 187 assert_equal 'text/html', @response.content_type
188 188 assert_tag :tag => 'th',
189 189 :content => '7',
190 190 :attributes => { :class => 'line-num' },
191 191 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
192 192 end
193 193 end
194 194
195 195 def test_show_text_file_should_send_if_too_big
196 196 Setting.file_max_size_displayed = 512
197 197 Attachment.find(4).update_attribute :filesize, 754.kilobyte
198 198
199 199 get :show, :id => 4
200 200 assert_response :success
201 201 assert_equal 'application/x-ruby', @response.content_type
202 202 set_tmp_attachments_directory
203 203 end
204 204
205 205 def test_show_other
206 206 get :show, :id => 6
207 207 assert_response :success
208 208 assert_equal 'application/octet-stream', @response.content_type
209 209 set_tmp_attachments_directory
210 210 end
211 211
212 212 def test_show_file_from_private_issue_without_permission
213 213 get :show, :id => 15
214 214 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
215 215 set_tmp_attachments_directory
216 216 end
217 217
218 218 def test_show_file_from_private_issue_with_permission
219 219 @request.session[:user_id] = 2
220 220 get :show, :id => 15
221 221 assert_response :success
222 222 assert_tag 'h2', :content => /private.diff/
223 223 set_tmp_attachments_directory
224 224 end
225 225
226 226 def test_show_file_without_container_should_be_allowed_to_author
227 227 set_tmp_attachments_directory
228 228 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
229 229
230 230 @request.session[:user_id] = 2
231 231 get :show, :id => attachment.id
232 232 assert_response 200
233 233 end
234 234
235 235 def test_show_file_without_container_should_be_denied_to_other_users
236 236 set_tmp_attachments_directory
237 237 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
238 238
239 239 @request.session[:user_id] = 3
240 240 get :show, :id => attachment.id
241 241 assert_response 403
242 242 end
243 243
244 244 def test_show_invalid_should_respond_with_404
245 245 get :show, :id => 999
246 246 assert_response 404
247 247 end
248 248
249 249 def test_download_text_file
250 250 get :download, :id => 4
251 251 assert_response :success
252 252 assert_equal 'application/x-ruby', @response.content_type
253 253 set_tmp_attachments_directory
254 254 end
255 255
256 256 def test_download_version_file_with_issue_tracking_disabled
257 257 Project.find(1).disable_module! :issue_tracking
258 258 get :download, :id => 9
259 259 assert_response :success
260 260 end
261 261
262 262 def test_download_should_assign_content_type_if_blank
263 263 Attachment.find(4).update_attribute(:content_type, '')
264 264
265 265 get :download, :id => 4
266 266 assert_response :success
267 267 assert_equal 'text/x-ruby', @response.content_type
268 268 set_tmp_attachments_directory
269 269 end
270 270
271 271 def test_download_missing_file
272 272 get :download, :id => 2
273 273 assert_response 404
274 274 set_tmp_attachments_directory
275 275 end
276 276
277 277 def test_download_should_be_denied_without_permission
278 278 get :download, :id => 7
279 279 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
280 280 set_tmp_attachments_directory
281 281 end
282 282
283 283 if convert_installed?
284 284 def test_thumbnail
285 285 Attachment.clear_thumbnails
286 286 @request.session[:user_id] = 2
287 287
288 288 get :thumbnail, :id => 16
289 289 assert_response :success
290 290 assert_equal 'image/png', response.content_type
291 291 end
292 292
293 293 def test_thumbnail_should_not_exceed_maximum_size
294 294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
295 295
296 296 @request.session[:user_id] = 2
297 297 get :thumbnail, :id => 16, :size => 2000
298 298 end
299 299
300 300 def test_thumbnail_should_round_size
301 301 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
302 302
303 303 @request.session[:user_id] = 2
304 304 get :thumbnail, :id => 16, :size => 260
305 305 end
306 306
307 307 def test_thumbnail_should_return_404_for_non_image_attachment
308 308 @request.session[:user_id] = 2
309 309
310 310 get :thumbnail, :id => 15
311 311 assert_response 404
312 312 end
313 313
314 314 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
315 315 Attachment.any_instance.stubs(:thumbnail).returns(nil)
316 316 @request.session[:user_id] = 2
317 317
318 318 get :thumbnail, :id => 16
319 319 assert_response 404
320 320 end
321 321
322 322 def test_thumbnail_should_be_denied_without_permission
323 323 get :thumbnail, :id => 16
324 324 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
325 325 end
326 326 else
327 327 puts '(ImageMagick convert not available)'
328 328 end
329 329
330 330 def test_destroy_issue_attachment
331 331 set_tmp_attachments_directory
332 332 issue = Issue.find(3)
333 333 @request.session[:user_id] = 2
334 334
335 335 assert_difference 'issue.attachments.count', -1 do
336 336 assert_difference 'Journal.count' do
337 337 delete :destroy, :id => 1
338 338 assert_redirected_to '/projects/ecookbook'
339 339 end
340 340 end
341 341 assert_nil Attachment.find_by_id(1)
342 342 j = Journal.order('id DESC').first
343 343 assert_equal issue, j.journalized
344 344 assert_equal 'attachment', j.details.first.property
345 345 assert_equal '1', j.details.first.prop_key
346 346 assert_equal 'error281.txt', j.details.first.old_value
347 347 assert_equal User.find(2), j.user
348 348 end
349 349
350 350 def test_destroy_wiki_page_attachment
351 351 set_tmp_attachments_directory
352 352 @request.session[:user_id] = 2
353 353 assert_difference 'Attachment.count', -1 do
354 354 delete :destroy, :id => 3
355 355 assert_response 302
356 356 end
357 357 end
358 358
359 359 def test_destroy_project_attachment
360 360 set_tmp_attachments_directory
361 361 @request.session[:user_id] = 2
362 362 assert_difference 'Attachment.count', -1 do
363 363 delete :destroy, :id => 8
364 364 assert_response 302
365 365 end
366 366 end
367 367
368 368 def test_destroy_version_attachment
369 369 set_tmp_attachments_directory
370 370 @request.session[:user_id] = 2
371 371 assert_difference 'Attachment.count', -1 do
372 372 delete :destroy, :id => 9
373 373 assert_response 302
374 374 end
375 375 end
376 376
377 def test_destroy_version_attachment_with_issue_tracking_disabled
378 Project.find(1).disable_module! :issue_tracking
379 set_tmp_attachments_directory
380 @request.session[:user_id] = 2
381 assert_difference 'Attachment.count', -1 do
382 delete :destroy, :id => 9
383 assert_response 302
384 end
385 end
386
377 387 def test_destroy_without_permission
378 388 set_tmp_attachments_directory
379 389 assert_no_difference 'Attachment.count' do
380 390 delete :destroy, :id => 3
381 391 end
382 392 assert_response 302
383 393 assert Attachment.find_by_id(3)
384 394 end
385 395 end
General Comments 0
You need to be logged in to leave comments. Login now