##// END OF EJS Templates
Fixed: version files in Files module cannot be downloaded if issue tracking is disabled (#9055)....
Jean-Philippe Lang -
r7864:d92c204ed389
parent child
Show More
@@ -1,234 +1,239
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 after_update :update_issues_from_sharing_change
20 20 belongs_to :project
21 21 has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
22 22 acts_as_customizable
23 23 acts_as_attachable :view_permission => :view_files,
24 24 :delete_permission => :manage_files
25 25
26 26 VERSION_STATUSES = %w(open locked closed)
27 27 VERSION_SHARINGS = %w(none descendants hierarchy tree system)
28 28
29 29 validates_presence_of :name
30 30 validates_uniqueness_of :name, :scope => [:project_id]
31 31 validates_length_of :name, :maximum => 60
32 32 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
33 33 validates_inclusion_of :status, :in => VERSION_STATUSES
34 34 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
35 35
36 36 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
37 37 named_scope :open, :conditions => {:status => 'open'}
38 38 named_scope :visible, lambda {|*args| { :include => :project,
39 39 :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
40 40
41 41 # Returns true if +user+ or current user is allowed to view the version
42 42 def visible?(user=User.current)
43 43 user.allowed_to?(:view_issues, self.project)
44 44 end
45 45
46 # Version files have same visibility as project files
47 def attachments_visible?(*args)
48 project.present? && project.attachments_visible?(*args)
49 end
50
46 51 def start_date
47 52 @start_date ||= fixed_issues.minimum('start_date')
48 53 end
49 54
50 55 def due_date
51 56 effective_date
52 57 end
53 58
54 59 # Returns the total estimated time for this version
55 60 # (sum of leaves estimated_hours)
56 61 def estimated_hours
57 62 @estimated_hours ||= fixed_issues.leaves.sum(:estimated_hours).to_f
58 63 end
59 64
60 65 # Returns the total reported time for this version
61 66 def spent_hours
62 67 @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
63 68 end
64 69
65 70 def closed?
66 71 status == 'closed'
67 72 end
68 73
69 74 def open?
70 75 status == 'open'
71 76 end
72 77
73 78 # Returns true if the version is completed: due date reached and no open issues
74 79 def completed?
75 80 effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
76 81 end
77 82
78 83 def behind_schedule?
79 84 if completed_pourcent == 100
80 85 return false
81 86 elsif due_date && start_date
82 87 done_date = start_date + ((due_date - start_date+1)* completed_pourcent/100).floor
83 88 return done_date <= Date.today
84 89 else
85 90 false # No issues so it's not late
86 91 end
87 92 end
88 93
89 94 # Returns the completion percentage of this version based on the amount of open/closed issues
90 95 # and the time spent on the open issues.
91 96 def completed_pourcent
92 97 if issues_count == 0
93 98 0
94 99 elsif open_issues_count == 0
95 100 100
96 101 else
97 102 issues_progress(false) + issues_progress(true)
98 103 end
99 104 end
100 105
101 106 # Returns the percentage of issues that have been marked as 'closed'.
102 107 def closed_pourcent
103 108 if issues_count == 0
104 109 0
105 110 else
106 111 issues_progress(false)
107 112 end
108 113 end
109 114
110 115 # Returns true if the version is overdue: due date reached and some open issues
111 116 def overdue?
112 117 effective_date && (effective_date < Date.today) && (open_issues_count > 0)
113 118 end
114 119
115 120 # Returns assigned issues count
116 121 def issues_count
117 122 @issue_count ||= fixed_issues.count
118 123 end
119 124
120 125 # Returns the total amount of open issues for this version.
121 126 def open_issues_count
122 127 @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status)
123 128 end
124 129
125 130 # Returns the total amount of closed issues for this version.
126 131 def closed_issues_count
127 132 @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status)
128 133 end
129 134
130 135 def wiki_page
131 136 if project.wiki && !wiki_page_title.blank?
132 137 @wiki_page ||= project.wiki.find_page(wiki_page_title)
133 138 end
134 139 @wiki_page
135 140 end
136 141
137 142 def to_s; name end
138 143
139 144 def to_s_with_project
140 145 "#{project} - #{name}"
141 146 end
142 147
143 148 # Versions are sorted by effective_date and "Project Name - Version name"
144 149 # Those with no effective_date are at the end, sorted by "Project Name - Version name"
145 150 def <=>(version)
146 151 if self.effective_date
147 152 if version.effective_date
148 153 if self.effective_date == version.effective_date
149 154 "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}"
150 155 else
151 156 self.effective_date <=> version.effective_date
152 157 end
153 158 else
154 159 -1
155 160 end
156 161 else
157 162 if version.effective_date
158 163 1
159 164 else
160 165 "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}"
161 166 end
162 167 end
163 168 end
164 169
165 170 # Returns the sharings that +user+ can set the version to
166 171 def allowed_sharings(user = User.current)
167 172 VERSION_SHARINGS.select do |s|
168 173 if sharing == s
169 174 true
170 175 else
171 176 case s
172 177 when 'system'
173 178 # Only admin users can set a systemwide sharing
174 179 user.admin?
175 180 when 'hierarchy', 'tree'
176 181 # Only users allowed to manage versions of the root project can
177 182 # set sharing to hierarchy or tree
178 183 project.nil? || user.allowed_to?(:manage_versions, project.root)
179 184 else
180 185 true
181 186 end
182 187 end
183 188 end
184 189 end
185 190
186 191 private
187 192
188 193 # Update the issue's fixed versions. Used if a version's sharing changes.
189 194 def update_issues_from_sharing_change
190 195 if sharing_changed?
191 196 if VERSION_SHARINGS.index(sharing_was).nil? ||
192 197 VERSION_SHARINGS.index(sharing).nil? ||
193 198 VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing)
194 199 Issue.update_versions_from_sharing_change self
195 200 end
196 201 end
197 202 end
198 203
199 204 # Returns the average estimated time of assigned issues
200 205 # or 1 if no issue has an estimated time
201 206 # Used to weigth unestimated issues in progress calculation
202 207 def estimated_average
203 208 if @estimated_average.nil?
204 209 average = fixed_issues.average(:estimated_hours).to_f
205 210 if average == 0
206 211 average = 1
207 212 end
208 213 @estimated_average = average
209 214 end
210 215 @estimated_average
211 216 end
212 217
213 218 # Returns the total progress of open or closed issues. The returned percentage takes into account
214 219 # the amount of estimated time set for this version.
215 220 #
216 221 # Examples:
217 222 # issues_progress(true) => returns the progress percentage for open issues.
218 223 # issues_progress(false) => returns the progress percentage for closed issues.
219 224 def issues_progress(open)
220 225 @issues_progress ||= {}
221 226 @issues_progress[open] ||= begin
222 227 progress = 0
223 228 if issues_count > 0
224 229 ratio = open ? 'done_ratio' : 100
225 230
226 231 done = fixed_issues.sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}",
227 232 :include => :status,
228 233 :conditions => ["is_closed = ?", !open]).to_f
229 234 progress = done / (estimated_average * issues_count)
230 235 end
231 236 progress
232 237 end
233 238 end
234 239 end
@@ -1,236 +1,236
1 1 ---
2 2 attachments_001:
3 3 created_on: 2006-07-19 21:07:27 +02:00
4 4 downloads: 0
5 5 content_type: text/plain
6 6 disk_filename: 060719210727_error281.txt
7 7 container_id: 3
8 8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 9 id: 1
10 10 container_type: Issue
11 11 filesize: 28
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 15 created_on: 2007-01-27 15:08:27 +01:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
19 19 container_id: 1
20 20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 21 id: 2
22 22 container_type: Document
23 23 filesize: 28
24 24 filename: document.txt
25 25 author_id: 2
26 26 attachments_003:
27 27 created_on: 2006-07-19 21:07:27 +02:00
28 28 downloads: 0
29 29 content_type: image/gif
30 30 disk_filename: 060719210727_logo.gif
31 31 container_id: 4
32 32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 33 id: 3
34 34 container_type: WikiPage
35 35 filesize: 280
36 36 filename: logo.gif
37 37 description: This is a logo
38 38 author_id: 2
39 39 attachments_004:
40 40 created_on: 2006-07-19 21:07:27 +02:00
41 41 container_type: Issue
42 42 container_id: 3
43 43 downloads: 0
44 44 disk_filename: 060719210727_source.rb
45 45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 46 id: 4
47 47 filesize: 153
48 48 filename: source.rb
49 49 author_id: 2
50 50 description: This is a Ruby source file
51 51 content_type: application/x-ruby
52 52 attachments_005:
53 53 created_on: 2006-07-19 21:07:27 +02:00
54 54 container_type: Issue
55 55 container_id: 3
56 56 downloads: 0
57 57 disk_filename: 060719210727_changeset_iso8859-1.diff
58 58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 59 id: 5
60 60 filesize: 687
61 61 filename: changeset_iso8859-1.diff
62 62 author_id: 2
63 63 content_type: text/x-diff
64 64 attachments_006:
65 65 created_on: 2006-07-19 21:07:27 +02:00
66 66 container_type: Issue
67 67 container_id: 3
68 68 downloads: 0
69 69 disk_filename: 060719210727_archive.zip
70 70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 71 id: 6
72 72 filesize: 157
73 73 filename: archive.zip
74 74 author_id: 2
75 75 content_type: application/octet-stream
76 76 attachments_007:
77 77 created_on: 2006-07-19 21:07:27 +02:00
78 78 container_type: Issue
79 79 container_id: 4
80 80 downloads: 0
81 81 disk_filename: 060719210727_archive.zip
82 82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 83 id: 7
84 84 filesize: 157
85 85 filename: archive.zip
86 86 author_id: 1
87 87 content_type: application/octet-stream
88 88 attachments_008:
89 89 created_on: 2006-07-19 21:07:27 +02:00
90 90 container_type: Project
91 91 container_id: 1
92 92 downloads: 0
93 93 disk_filename: 060719210727_project_file.zip
94 94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
95 95 id: 8
96 96 filesize: 320
97 97 filename: project_file.zip
98 98 author_id: 2
99 99 content_type: application/octet-stream
100 100 attachments_009:
101 101 created_on: 2006-07-19 21:07:27 +02:00
102 102 container_type: Version
103 103 container_id: 1
104 104 downloads: 0
105 disk_filename: 060719210727_version_file.zip
105 disk_filename: 060719210727_archive.zip
106 106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
107 107 id: 9
108 108 filesize: 452
109 109 filename: version_file.zip
110 110 author_id: 2
111 111 content_type: application/octet-stream
112 112 attachments_010:
113 113 created_on: 2006-07-19 21:07:27 +02:00
114 114 container_type: Issue
115 115 container_id: 2
116 116 downloads: 0
117 117 disk_filename: 060719210727_picture.jpg
118 118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
119 119 id: 10
120 120 filesize: 452
121 121 filename: picture.jpg
122 122 author_id: 2
123 123 content_type: image/jpeg
124 124 attachments_011:
125 125 created_on: 2007-02-12 15:08:27 +01:00
126 126 container_type: Document
127 127 container_id: 1
128 128 downloads: 0
129 129 disk_filename: 060719210727_picture.jpg
130 130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
131 131 id: 11
132 132 filesize: 452
133 133 filename: picture.jpg
134 134 author_id: 2
135 135 content_type: image/jpeg
136 136 attachments_012:
137 137 created_on: 2006-07-19 21:07:27 +02:00
138 138 container_type: Version
139 139 container_id: 1
140 140 downloads: 0
141 141 disk_filename: 060719210727_version_file.zip
142 142 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
143 143 id: 12
144 144 filesize: 452
145 145 filename: version_file.zip
146 146 author_id: 2
147 147 content_type: application/octet-stream
148 148 attachments_013:
149 149 created_on: 2006-07-19 21:07:27 +02:00
150 150 container_type: Message
151 151 container_id: 1
152 152 downloads: 0
153 153 disk_filename: 060719210727_foo.zip
154 154 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
155 155 id: 13
156 156 filesize: 452
157 157 filename: foo.zip
158 158 author_id: 2
159 159 content_type: application/octet-stream
160 160 attachments_014:
161 161 created_on: 2006-07-19 21:07:27 +02:00
162 162 container_type: Issue
163 163 container_id: 3
164 164 downloads: 0
165 165 disk_filename: 060719210727_changeset_utf8.diff
166 166 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
167 167 id: 14
168 168 filesize: 687
169 169 filename: changeset_utf8.diff
170 170 author_id: 2
171 171 content_type: text/x-diff
172 172 attachments_015:
173 173 id: 15
174 174 created_on: 2010-07-19 21:07:27 +02:00
175 175 container_type: Issue
176 176 container_id: 14
177 177 downloads: 0
178 178 disk_filename: 060719210727_changeset_utf8.diff
179 179 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
180 180 filesize: 687
181 181 filename: private.diff
182 182 author_id: 2
183 183 content_type: text/x-diff
184 184 description: attachement of a private issue
185 185 attachments_016:
186 186 content_type: image/png
187 187 downloads: 0
188 188 created_on: 2010-11-23 16:14:50 +09:00
189 189 disk_filename: 101123161450_testfile_1.png
190 190 container_id: 14
191 191 digest: 8e0294de2441577c529f170b6fb8f638
192 192 id: 16
193 193 container_type: Issue
194 194 description: ""
195 195 filename: testfile.png
196 196 filesize: 2654
197 197 author_id: 2
198 198 attachments_017:
199 199 content_type: image/png
200 200 downloads: 0
201 201 created_on: 2010-12-23 16:14:50 +09:00
202 202 disk_filename: 101223161450_testfile_2.png
203 203 container_id: 14
204 204 digest: 6bc2963e8d7ea0d3e68d12d1fba3d6ca
205 205 id: 17
206 206 container_type: Issue
207 207 description: ""
208 208 filename: testfile.PNG
209 209 filesize: 3582
210 210 author_id: 2
211 211 attachments_018:
212 212 content_type: image/png
213 213 downloads: 0
214 214 created_on: 2011-01-23 16:14:50 +09:00
215 215 disk_filename: 101123161450_testfile_1.png
216 216 container_id: 14
217 217 digest: 8e0294de2441577c529f170b6fb8f638
218 218 id: 18
219 219 container_type: Issue
220 220 description: ""
221 221 filename: testγƒ†γ‚Ήγƒˆ.png
222 222 filesize: 2654
223 223 author_id: 2
224 224 attachments_019:
225 225 content_type: image/png
226 226 downloads: 0
227 227 created_on: 2011-02-23 16:14:50 +09:00
228 228 disk_filename: 101223161450_testfile_2.png
229 229 container_id: 14
230 230 digest: 6bc2963e8d7ea0d3e68d12d1fba3d6ca
231 231 id: 19
232 232 container_type: Issue
233 233 description: ""
234 234 filename: Testγƒ†γ‚Ήγƒˆ.PNG
235 235 filesize: 3582
236 236 author_id: 2
@@ -1,274 +1,280
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 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 require 'attachments_controller'
22 22
23 23 # Re-raise errors caught by the controller.
24 24 class AttachmentsController; def rescue_action(e) raise e end; end
25 25
26 26 class AttachmentsControllerTest < ActionController::TestCase
27 27 fixtures :users, :projects, :roles, :members, :member_roles,
28 28 :enabled_modules, :issues, :trackers, :attachments,
29 29 :versions, :wiki_pages, :wikis, :documents
30 30
31 31 def setup
32 32 @controller = AttachmentsController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
36 36 User.current = nil
37 37 end
38 38
39 39 def test_show_diff
40 40 ['inline', 'sbs'].each do |dt|
41 41 # 060719210727_changeset_utf8.diff
42 42 get :show, :id => 14, :type => dt
43 43 assert_response :success
44 44 assert_template 'diff'
45 45 assert_equal 'text/html', @response.content_type
46 46 assert_tag 'th',
47 47 :attributes => {:class => /filename/},
48 48 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
49 49 assert_tag 'td',
50 50 :attributes => {:class => /line-code/},
51 51 :content => /Demande créée avec succès/
52 52 end
53 53 set_tmp_attachments_directory
54 54 end
55 55
56 56 def test_show_diff_replcace_cannot_convert_content
57 57 with_settings :repositories_encodings => 'UTF-8' do
58 58 ['inline', 'sbs'].each do |dt|
59 59 # 060719210727_changeset_iso8859-1.diff
60 60 get :show, :id => 5, :type => dt
61 61 assert_response :success
62 62 assert_template 'diff'
63 63 assert_equal 'text/html', @response.content_type
64 64 assert_tag 'th',
65 65 :attributes => {:class => "filename"},
66 66 :content => /issues_controller.rb\t\(r\?vision 1484\)/
67 67 assert_tag 'td',
68 68 :attributes => {:class => /line-code/},
69 69 :content => /Demande cr\?\?e avec succ\?s/
70 70 end
71 71 end
72 72 set_tmp_attachments_directory
73 73 end
74 74
75 75 def test_show_diff_latin_1
76 76 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
77 77 ['inline', 'sbs'].each do |dt|
78 78 # 060719210727_changeset_iso8859-1.diff
79 79 get :show, :id => 5, :type => dt
80 80 assert_response :success
81 81 assert_template 'diff'
82 82 assert_equal 'text/html', @response.content_type
83 83 assert_tag 'th',
84 84 :attributes => {:class => "filename"},
85 85 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
86 86 assert_tag 'td',
87 87 :attributes => {:class => /line-code/},
88 88 :content => /Demande créée avec succès/
89 89 end
90 90 end
91 91 set_tmp_attachments_directory
92 92 end
93 93
94 94 def test_show_text_file
95 95 get :show, :id => 4
96 96 assert_response :success
97 97 assert_template 'file'
98 98 assert_equal 'text/html', @response.content_type
99 99 set_tmp_attachments_directory
100 100 end
101 101
102 102 def test_show_text_file_utf_8
103 103 set_tmp_attachments_directory
104 104 a = Attachment.new(:container => Issue.find(1),
105 105 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
106 106 :author => User.find(1))
107 107 assert a.save
108 108 assert_equal 'japanese-utf-8.txt', a.filename
109 109
110 110 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
111 111 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
112 112
113 113 get :show, :id => a.id
114 114 assert_response :success
115 115 assert_template 'file'
116 116 assert_equal 'text/html', @response.content_type
117 117 assert_tag :tag => 'th',
118 118 :content => '1',
119 119 :attributes => { :class => 'line-num' },
120 120 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
121 121 end
122 122
123 123 def test_show_text_file_replcace_cannot_convert_content
124 124 set_tmp_attachments_directory
125 125 with_settings :repositories_encodings => 'UTF-8' do
126 126 a = Attachment.new(:container => Issue.find(1),
127 127 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
128 128 :author => User.find(1))
129 129 assert a.save
130 130 assert_equal 'iso8859-1.txt', a.filename
131 131
132 132 get :show, :id => a.id
133 133 assert_response :success
134 134 assert_template 'file'
135 135 assert_equal 'text/html', @response.content_type
136 136 assert_tag :tag => 'th',
137 137 :content => '7',
138 138 :attributes => { :class => 'line-num' },
139 139 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
140 140 end
141 141 end
142 142
143 143 def test_show_text_file_latin_1
144 144 set_tmp_attachments_directory
145 145 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
146 146 a = Attachment.new(:container => Issue.find(1),
147 147 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
148 148 :author => User.find(1))
149 149 assert a.save
150 150 assert_equal 'iso8859-1.txt', a.filename
151 151
152 152 get :show, :id => a.id
153 153 assert_response :success
154 154 assert_template 'file'
155 155 assert_equal 'text/html', @response.content_type
156 156 assert_tag :tag => 'th',
157 157 :content => '7',
158 158 :attributes => { :class => 'line-num' },
159 159 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
160 160 end
161 161 end
162 162
163 163 def test_show_text_file_should_send_if_too_big
164 164 Setting.file_max_size_displayed = 512
165 165 Attachment.find(4).update_attribute :filesize, 754.kilobyte
166 166
167 167 get :show, :id => 4
168 168 assert_response :success
169 169 assert_equal 'application/x-ruby', @response.content_type
170 170 set_tmp_attachments_directory
171 171 end
172 172
173 173 def test_show_other
174 174 get :show, :id => 6
175 175 assert_response :success
176 176 assert_equal 'application/octet-stream', @response.content_type
177 177 set_tmp_attachments_directory
178 178 end
179 179
180 180 def test_show_file_from_private_issue_without_permission
181 181 get :show, :id => 15
182 182 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
183 183 set_tmp_attachments_directory
184 184 end
185 185
186 186 def test_show_file_from_private_issue_with_permission
187 187 @request.session[:user_id] = 2
188 188 get :show, :id => 15
189 189 assert_response :success
190 190 assert_tag 'h2', :content => /private.diff/
191 191 set_tmp_attachments_directory
192 192 end
193 193
194 194 def test_download_text_file
195 195 get :download, :id => 4
196 196 assert_response :success
197 197 assert_equal 'application/x-ruby', @response.content_type
198 198 set_tmp_attachments_directory
199 199 end
200 200
201 def test_download_version_file_with_issue_tracking_disabled
202 Project.find(1).disable_module! :issue_tracking
203 get :download, :id => 9
204 assert_response :success
205 end
206
201 207 def test_download_should_assign_content_type_if_blank
202 208 Attachment.find(4).update_attribute(:content_type, '')
203 209
204 210 get :download, :id => 4
205 211 assert_response :success
206 212 assert_equal 'text/x-ruby', @response.content_type
207 213 set_tmp_attachments_directory
208 214 end
209 215
210 216 def test_download_missing_file
211 217 get :download, :id => 2
212 218 assert_response 404
213 219 set_tmp_attachments_directory
214 220 end
215 221
216 222 def test_anonymous_on_private_private
217 223 get :download, :id => 7
218 224 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
219 225 set_tmp_attachments_directory
220 226 end
221 227
222 228 def test_destroy_issue_attachment
223 229 set_tmp_attachments_directory
224 230 issue = Issue.find(3)
225 231 @request.session[:user_id] = 2
226 232
227 233 assert_difference 'issue.attachments.count', -1 do
228 234 delete :destroy, :id => 1
229 235 end
230 236 # no referrer
231 237 assert_redirected_to '/projects/ecookbook'
232 238 assert_nil Attachment.find_by_id(1)
233 239 j = issue.journals.find(:first, :order => 'created_on DESC')
234 240 assert_equal 'attachment', j.details.first.property
235 241 assert_equal '1', j.details.first.prop_key
236 242 assert_equal 'error281.txt', j.details.first.old_value
237 243 end
238 244
239 245 def test_destroy_wiki_page_attachment
240 246 set_tmp_attachments_directory
241 247 @request.session[:user_id] = 2
242 248 assert_difference 'Attachment.count', -1 do
243 249 delete :destroy, :id => 3
244 250 assert_response 302
245 251 end
246 252 end
247 253
248 254 def test_destroy_project_attachment
249 255 set_tmp_attachments_directory
250 256 @request.session[:user_id] = 2
251 257 assert_difference 'Attachment.count', -1 do
252 258 delete :destroy, :id => 8
253 259 assert_response 302
254 260 end
255 261 end
256 262
257 263 def test_destroy_version_attachment
258 264 set_tmp_attachments_directory
259 265 @request.session[:user_id] = 2
260 266 assert_difference 'Attachment.count', -1 do
261 267 delete :destroy, :id => 9
262 268 assert_response 302
263 269 end
264 270 end
265 271
266 272 def test_destroy_without_permission
267 273 set_tmp_attachments_directory
268 274 assert_no_difference 'Attachment.count' do
269 275 delete :destroy, :id => 3
270 276 end
271 277 assert_response 302
272 278 assert Attachment.find_by_id(3)
273 279 end
274 280 end
General Comments 0
You need to be logged in to leave comments. Login now