##// END OF EJS Templates
Strip non utf8 content when displaying diff (ruby1.9 compatibility)....
Jean-Philippe Lang -
r4484:488285e12321
parent child
Show More
@@ -0,0 +1,13
1 Index: trunk/app/controllers/issues_controller.rb
2 ===================================================================
3 --- trunk/app/controllers/issues_controller.rb (révision 1483)
4 +++ trunk/app/controllers/issues_controller.rb (révision 1484)
5 @@ -149,7 +149,7 @@
6 attach_files(@issue, params[:attachments])
7 flash[:notice] = 'Demande créée avec succès'
8 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
9 - redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project
10 + redirect_to :controller => 'issues', :action => 'show', :id => @issue
11 return
12 end
13 end
@@ -1,34 +1,40
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 AttachmentsHelper
18 module AttachmentsHelper
19 # Displays view/delete links to the attachments of the given object
19 # Displays view/delete links to the attachments of the given object
20 # Options:
20 # Options:
21 # :author -- author names are not displayed if set to false
21 # :author -- author names are not displayed if set to false
22 def link_to_attachments(container, options = {})
22 def link_to_attachments(container, options = {})
23 options.assert_valid_keys(:author)
23 options.assert_valid_keys(:author)
24
24
25 if container.attachments.any?
25 if container.attachments.any?
26 options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
26 options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
27 render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
27 render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
28 end
28 end
29 end
29 end
30
30
31 def to_utf8(str)
31 def to_utf8(str)
32 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
33 begin
34 Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
35 rescue Iconv::InvalidEncoding
36 # "UTF-8//IGNORE" is not supported on some OS
32 str
37 str
33 end
38 end
34 end
39 end
40 end
@@ -1,67 +1,67
1 <% diff = Redmine::UnifiedDiff.new(diff, :type => diff_type, :max_lines => Setting.diff_max_lines_displayed.to_i) -%>
1 <% diff = Redmine::UnifiedDiff.new(diff, :type => diff_type, :max_lines => Setting.diff_max_lines_displayed.to_i) -%>
2 <% diff.each do |table_file| -%>
2 <% diff.each do |table_file| -%>
3 <div class="autoscroll">
3 <div class="autoscroll">
4 <% if diff_type == 'sbs' -%>
4 <% if diff_type == 'sbs' -%>
5 <table class="filecontent">
5 <table class="filecontent">
6 <thead>
6 <thead>
7 <tr><th colspan="4" class="filename"><%= table_file.file_name %></th></tr>
7 <tr><th colspan="4" class="filename"><%=to_utf8 table_file.file_name %></th></tr>
8 </thead>
8 </thead>
9 <tbody>
9 <tbody>
10 <% prev_line_left, prev_line_right = nil, nil -%>
10 <% prev_line_left, prev_line_right = nil, nil -%>
11 <% table_file.keys.sort.each do |key| -%>
11 <% table_file.keys.sort.each do |key| -%>
12 <% if prev_line_left && prev_line_right && (table_file[key].nb_line_left != prev_line_left+1) && (table_file[key].nb_line_right != prev_line_right+1) -%>
12 <% if prev_line_left && prev_line_right && (table_file[key].nb_line_left != prev_line_left+1) && (table_file[key].nb_line_right != prev_line_right+1) -%>
13 <tr class="spacing">
13 <tr class="spacing">
14 <th class="line-num">...</th><td></td><th class="line-num">...</th><td></td>
14 <th class="line-num">...</th><td></td><th class="line-num">...</th><td></td>
15 <% end -%>
15 <% end -%>
16 <tr>
16 <tr>
17 <th class="line-num"><%= table_file[key].nb_line_left %></th>
17 <th class="line-num"><%= table_file[key].nb_line_left %></th>
18 <td class="line-code <%= table_file[key].type_diff_left %>">
18 <td class="line-code <%= table_file[key].type_diff_left %>">
19 <pre><%=to_utf8 table_file[key].line_left %></pre>
19 <pre><%=to_utf8 table_file[key].line_left %></pre>
20 </td>
20 </td>
21 <th class="line-num"><%= table_file[key].nb_line_right %></th>
21 <th class="line-num"><%= table_file[key].nb_line_right %></th>
22 <td class="line-code <%= table_file[key].type_diff_right %>">
22 <td class="line-code <%= table_file[key].type_diff_right %>">
23 <pre><%=to_utf8 table_file[key].line_right %></pre>
23 <pre><%=to_utf8 table_file[key].line_right %></pre>
24 </td>
24 </td>
25 </tr>
25 </tr>
26 <% prev_line_left, prev_line_right = table_file[key].nb_line_left.to_i, table_file[key].nb_line_right.to_i -%>
26 <% prev_line_left, prev_line_right = table_file[key].nb_line_left.to_i, table_file[key].nb_line_right.to_i -%>
27 <% end -%>
27 <% end -%>
28 </tbody>
28 </tbody>
29 </table>
29 </table>
30
30
31 <% else -%>
31 <% else -%>
32 <table class="filecontent syntaxhl">
32 <table class="filecontent syntaxhl">
33 <thead>
33 <thead>
34 <tr><th colspan="3" class="filename"><%= table_file.file_name %></th></tr>
34 <tr><th colspan="3" class="filename"><%=to_utf8 table_file.file_name %></th></tr>
35 </thead>
35 </thead>
36 <tbody>
36 <tbody>
37 <% prev_line_left, prev_line_right = nil, nil -%>
37 <% prev_line_left, prev_line_right = nil, nil -%>
38 <% table_file.keys.sort.each do |key, line| %>
38 <% table_file.keys.sort.each do |key, line| %>
39 <% if prev_line_left && prev_line_right && (table_file[key].nb_line_left != prev_line_left+1) && (table_file[key].nb_line_right != prev_line_right+1) -%>
39 <% if prev_line_left && prev_line_right && (table_file[key].nb_line_left != prev_line_left+1) && (table_file[key].nb_line_right != prev_line_right+1) -%>
40 <tr class="spacing">
40 <tr class="spacing">
41 <th class="line-num">...</th><th class="line-num">...</th><td></td>
41 <th class="line-num">...</th><th class="line-num">...</th><td></td>
42 </tr>
42 </tr>
43 <% end -%>
43 <% end -%>
44 <tr>
44 <tr>
45 <th class="line-num"><%= table_file[key].nb_line_left %></th>
45 <th class="line-num"><%= table_file[key].nb_line_left %></th>
46 <th class="line-num"><%= table_file[key].nb_line_right %></th>
46 <th class="line-num"><%= table_file[key].nb_line_right %></th>
47 <% if table_file[key].line_left.empty? -%>
47 <% if table_file[key].line_left.empty? -%>
48 <td class="line-code <%= table_file[key].type_diff_right %>">
48 <td class="line-code <%= table_file[key].type_diff_right %>">
49 <pre><%=to_utf8 table_file[key].line_right %></pre>
49 <pre><%=to_utf8 table_file[key].line_right %></pre>
50 </td>
50 </td>
51 <% else -%>
51 <% else -%>
52 <td class="line-code <%= table_file[key].type_diff_left %>">
52 <td class="line-code <%= table_file[key].type_diff_left %>">
53 <pre><%=to_utf8 table_file[key].line_left %></pre>
53 <pre><%=to_utf8 table_file[key].line_left %></pre>
54 </td>
54 </td>
55 <% end -%>
55 <% end -%>
56 </tr>
56 </tr>
57 <% prev_line_left = table_file[key].nb_line_left.to_i if table_file[key].nb_line_left.to_i > 0 -%>
57 <% prev_line_left = table_file[key].nb_line_left.to_i if table_file[key].nb_line_left.to_i > 0 -%>
58 <% prev_line_right = table_file[key].nb_line_right.to_i if table_file[key].nb_line_right.to_i > 0 -%>
58 <% prev_line_right = table_file[key].nb_line_right.to_i if table_file[key].nb_line_right.to_i > 0 -%>
59 <% end -%>
59 <% end -%>
60 </tbody>
60 </tbody>
61 </table>
61 </table>
62 <% end -%>
62 <% end -%>
63
63
64 </div>
64 </div>
65 <% end -%>
65 <% end -%>
66
66
67 <%= l(:text_diff_truncated) if diff.truncated? %>
67 <%= l(:text_diff_truncated) if diff.truncated? %>
@@ -1,159 +1,171
1 ---
1 ---
2 attachments_001:
2 attachments_001:
3 created_on: 2006-07-19 21:07:27 +02:00
3 created_on: 2006-07-19 21:07:27 +02:00
4 downloads: 0
4 downloads: 0
5 content_type: text/plain
5 content_type: text/plain
6 disk_filename: 060719210727_error281.txt
6 disk_filename: 060719210727_error281.txt
7 container_id: 3
7 container_id: 3
8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 id: 1
9 id: 1
10 container_type: Issue
10 container_type: Issue
11 filesize: 28
11 filesize: 28
12 filename: error281.txt
12 filename: error281.txt
13 author_id: 2
13 author_id: 2
14 attachments_002:
14 attachments_002:
15 created_on: 2007-01-27 15:08:27 +01:00
15 created_on: 2007-01-27 15:08:27 +01:00
16 downloads: 0
16 downloads: 0
17 content_type: text/plain
17 content_type: text/plain
18 disk_filename: 060719210727_document.txt
18 disk_filename: 060719210727_document.txt
19 container_id: 1
19 container_id: 1
20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 id: 2
21 id: 2
22 container_type: Document
22 container_type: Document
23 filesize: 28
23 filesize: 28
24 filename: document.txt
24 filename: document.txt
25 author_id: 2
25 author_id: 2
26 attachments_003:
26 attachments_003:
27 created_on: 2006-07-19 21:07:27 +02:00
27 created_on: 2006-07-19 21:07:27 +02:00
28 downloads: 0
28 downloads: 0
29 content_type: image/gif
29 content_type: image/gif
30 disk_filename: 060719210727_logo.gif
30 disk_filename: 060719210727_logo.gif
31 container_id: 4
31 container_id: 4
32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 id: 3
33 id: 3
34 container_type: WikiPage
34 container_type: WikiPage
35 filesize: 280
35 filesize: 280
36 filename: logo.gif
36 filename: logo.gif
37 description: This is a logo
37 description: This is a logo
38 author_id: 2
38 author_id: 2
39 attachments_004:
39 attachments_004:
40 created_on: 2006-07-19 21:07:27 +02:00
40 created_on: 2006-07-19 21:07:27 +02:00
41 container_type: Issue
41 container_type: Issue
42 container_id: 3
42 container_id: 3
43 downloads: 0
43 downloads: 0
44 disk_filename: 060719210727_source.rb
44 disk_filename: 060719210727_source.rb
45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 id: 4
46 id: 4
47 filesize: 153
47 filesize: 153
48 filename: source.rb
48 filename: source.rb
49 author_id: 2
49 author_id: 2
50 description: This is a Ruby source file
50 description: This is a Ruby source file
51 content_type: application/x-ruby
51 content_type: application/x-ruby
52 attachments_005:
52 attachments_005:
53 created_on: 2006-07-19 21:07:27 +02:00
53 created_on: 2006-07-19 21:07:27 +02:00
54 container_type: Issue
54 container_type: Issue
55 container_id: 3
55 container_id: 3
56 downloads: 0
56 downloads: 0
57 disk_filename: 060719210727_changeset.diff
57 disk_filename: 060719210727_changeset_iso8859-1.diff
58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 id: 5
59 id: 5
60 filesize: 687
60 filesize: 687
61 filename: changeset.diff
61 filename: changeset_iso8859-1.diff
62 author_id: 2
62 author_id: 2
63 content_type: text/x-diff
63 content_type: text/x-diff
64 attachments_006:
64 attachments_006:
65 created_on: 2006-07-19 21:07:27 +02:00
65 created_on: 2006-07-19 21:07:27 +02:00
66 container_type: Issue
66 container_type: Issue
67 container_id: 3
67 container_id: 3
68 downloads: 0
68 downloads: 0
69 disk_filename: 060719210727_archive.zip
69 disk_filename: 060719210727_archive.zip
70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 id: 6
71 id: 6
72 filesize: 157
72 filesize: 157
73 filename: archive.zip
73 filename: archive.zip
74 author_id: 2
74 author_id: 2
75 content_type: application/octet-stream
75 content_type: application/octet-stream
76 attachments_007:
76 attachments_007:
77 created_on: 2006-07-19 21:07:27 +02:00
77 created_on: 2006-07-19 21:07:27 +02:00
78 container_type: Issue
78 container_type: Issue
79 container_id: 4
79 container_id: 4
80 downloads: 0
80 downloads: 0
81 disk_filename: 060719210727_archive.zip
81 disk_filename: 060719210727_archive.zip
82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 id: 7
83 id: 7
84 filesize: 157
84 filesize: 157
85 filename: archive.zip
85 filename: archive.zip
86 author_id: 1
86 author_id: 1
87 content_type: application/octet-stream
87 content_type: application/octet-stream
88 attachments_008:
88 attachments_008:
89 created_on: 2006-07-19 21:07:27 +02:00
89 created_on: 2006-07-19 21:07:27 +02:00
90 container_type: Project
90 container_type: Project
91 container_id: 1
91 container_id: 1
92 downloads: 0
92 downloads: 0
93 disk_filename: 060719210727_project_file.zip
93 disk_filename: 060719210727_project_file.zip
94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
95 id: 8
95 id: 8
96 filesize: 320
96 filesize: 320
97 filename: project_file.zip
97 filename: project_file.zip
98 author_id: 2
98 author_id: 2
99 content_type: application/octet-stream
99 content_type: application/octet-stream
100 attachments_009:
100 attachments_009:
101 created_on: 2006-07-19 21:07:27 +02:00
101 created_on: 2006-07-19 21:07:27 +02:00
102 container_type: Version
102 container_type: Version
103 container_id: 1
103 container_id: 1
104 downloads: 0
104 downloads: 0
105 disk_filename: 060719210727_version_file.zip
105 disk_filename: 060719210727_version_file.zip
106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
107 id: 9
107 id: 9
108 filesize: 452
108 filesize: 452
109 filename: version_file.zip
109 filename: version_file.zip
110 author_id: 2
110 author_id: 2
111 content_type: application/octet-stream
111 content_type: application/octet-stream
112 attachments_010:
112 attachments_010:
113 created_on: 2006-07-19 21:07:27 +02:00
113 created_on: 2006-07-19 21:07:27 +02:00
114 container_type: Issue
114 container_type: Issue
115 container_id: 2
115 container_id: 2
116 downloads: 0
116 downloads: 0
117 disk_filename: 060719210727_picture.jpg
117 disk_filename: 060719210727_picture.jpg
118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
119 id: 10
119 id: 10
120 filesize: 452
120 filesize: 452
121 filename: picture.jpg
121 filename: picture.jpg
122 author_id: 2
122 author_id: 2
123 content_type: image/jpeg
123 content_type: image/jpeg
124 attachments_011:
124 attachments_011:
125 created_on: 2007-02-12 15:08:27 +01:00
125 created_on: 2007-02-12 15:08:27 +01:00
126 container_type: Document
126 container_type: Document
127 container_id: 1
127 container_id: 1
128 downloads: 0
128 downloads: 0
129 disk_filename: 060719210727_picture.jpg
129 disk_filename: 060719210727_picture.jpg
130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
131 id: 11
131 id: 11
132 filesize: 452
132 filesize: 452
133 filename: picture.jpg
133 filename: picture.jpg
134 author_id: 2
134 author_id: 2
135 content_type: image/jpeg
135 content_type: image/jpeg
136 attachments_012:
136 attachments_012:
137 created_on: 2006-07-19 21:07:27 +02:00
137 created_on: 2006-07-19 21:07:27 +02:00
138 container_type: Version
138 container_type: Version
139 container_id: 1
139 container_id: 1
140 downloads: 0
140 downloads: 0
141 disk_filename: 060719210727_version_file.zip
141 disk_filename: 060719210727_version_file.zip
142 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
142 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
143 id: 12
143 id: 12
144 filesize: 452
144 filesize: 452
145 filename: version_file.zip
145 filename: version_file.zip
146 author_id: 2
146 author_id: 2
147 content_type: application/octet-stream
147 content_type: application/octet-stream
148 attachments_013:
148 attachments_013:
149 created_on: 2006-07-19 21:07:27 +02:00
149 created_on: 2006-07-19 21:07:27 +02:00
150 container_type: Message
150 container_type: Message
151 container_id: 1
151 container_id: 1
152 downloads: 0
152 downloads: 0
153 disk_filename: 060719210727_foo.zip
153 disk_filename: 060719210727_foo.zip
154 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
154 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
155 id: 13
155 id: 13
156 filesize: 452
156 filesize: 452
157 filename: foo.zip
157 filename: foo.zip
158 author_id: 2
158 author_id: 2
159 content_type: application/octet-stream
159 content_type: application/octet-stream
160 attachments_014:
161 created_on: 2006-07-19 21:07:27 +02:00
162 container_type: Issue
163 container_id: 3
164 downloads: 0
165 disk_filename: 060719210727_changeset_utf8.diff
166 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
167 id: 14
168 filesize: 687
169 filename: changeset_utf8.diff
170 author_id: 2
171 content_type: text/x-diff
@@ -1,13 +1,13
1 Index: trunk/app/controllers/issues_controller.rb
1 Index: trunk/app/controllers/issues_controller.rb
2 ===================================================================
2 ===================================================================
3 --- trunk/app/controllers/issues_controller.rb (r�vision 1483)
3 --- trunk/app/controllers/issues_controller.rb (r�vision 1483)
4 +++ trunk/app/controllers/issues_controller.rb (r�vision 1484)
4 +++ trunk/app/controllers/issues_controller.rb (r�vision 1484)
5 @@ -149,7 +149,7 @@
5 @@ -149,7 +149,7 @@
6 attach_files(@issue, params[:attachments])
6 attach_files(@issue, params[:attachments])
7 flash[:notice] = l(:notice_successful_create)
7 flash[:notice] = 'Demande cr��e avec succ�s'
8 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
8 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
9 - redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project
9 - redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project
10 + redirect_to :controller => 'issues', :action => 'show', :id => @issue
10 + redirect_to :controller => 'issues', :action => 'show', :id => @issue
11 return
11 return
12 end
12 end
13 end
13 end
@@ -1,135 +1,158
1 # redMine - project management software
1 # encoding: utf-8
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 #
3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
5 #
4 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
8 #
10 #
9 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # GNU General Public License for more details.
13 #
15 #
14 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
19
18 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
19 require 'attachments_controller'
21 require 'attachments_controller'
20
22
21 # Re-raise errors caught by the controller.
23 # Re-raise errors caught by the controller.
22 class AttachmentsController; def rescue_action(e) raise e end; end
24 class AttachmentsController; def rescue_action(e) raise e end; end
23
25
24
26
25 class AttachmentsControllerTest < ActionController::TestCase
27 class AttachmentsControllerTest < ActionController::TestCase
26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
28 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
27 :versions, :wiki_pages, :wikis, :documents
29 :versions, :wiki_pages, :wikis, :documents
28
30
29 def setup
31 def setup
30 @controller = AttachmentsController.new
32 @controller = AttachmentsController.new
31 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
35 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
34 User.current = nil
36 User.current = nil
35 end
37 end
36
38
37 def test_show_diff
39 def test_show_diff
38 get :show, :id => 5
40 get :show, :id => 14 # 060719210727_changeset_utf8.diff
41 assert_response :success
42 assert_template 'diff'
43 assert_equal 'text/html', @response.content_type
44
45 assert_tag 'th',
46 :attributes => {:class => /filename/},
47 :content => /issues_controller.rb\t\(révision 1484\)/
48 assert_tag 'td',
49 :attributes => {:class => /line-code/},
50 :content => /Demande créée avec succès/
51 end
52
53 def test_show_diff_should_strip_non_utf8_content
54 get :show, :id => 5 # 060719210727_changeset_iso8859-1.diff
39 assert_response :success
55 assert_response :success
40 assert_template 'diff'
56 assert_template 'diff'
41 assert_equal 'text/html', @response.content_type
57 assert_equal 'text/html', @response.content_type
58
59 assert_tag 'th',
60 :attributes => {:class => /filename/},
61 :content => /issues_controller.rb\t\(rvision 1484\)/
62 assert_tag 'td',
63 :attributes => {:class => /line-code/},
64 :content => /Demande cre avec succs/
42 end
65 end
43
66
44 def test_show_text_file
67 def test_show_text_file
45 get :show, :id => 4
68 get :show, :id => 4
46 assert_response :success
69 assert_response :success
47 assert_template 'file'
70 assert_template 'file'
48 assert_equal 'text/html', @response.content_type
71 assert_equal 'text/html', @response.content_type
49 end
72 end
50
73
51 def test_show_text_file_should_send_if_too_big
74 def test_show_text_file_should_send_if_too_big
52 Setting.file_max_size_displayed = 512
75 Setting.file_max_size_displayed = 512
53 Attachment.find(4).update_attribute :filesize, 754.kilobyte
76 Attachment.find(4).update_attribute :filesize, 754.kilobyte
54
77
55 get :show, :id => 4
78 get :show, :id => 4
56 assert_response :success
79 assert_response :success
57 assert_equal 'application/x-ruby', @response.content_type
80 assert_equal 'application/x-ruby', @response.content_type
58 end
81 end
59
82
60 def test_show_other
83 def test_show_other
61 get :show, :id => 6
84 get :show, :id => 6
62 assert_response :success
85 assert_response :success
63 assert_equal 'application/octet-stream', @response.content_type
86 assert_equal 'application/octet-stream', @response.content_type
64 end
87 end
65
88
66 def test_download_text_file
89 def test_download_text_file
67 get :download, :id => 4
90 get :download, :id => 4
68 assert_response :success
91 assert_response :success
69 assert_equal 'application/x-ruby', @response.content_type
92 assert_equal 'application/x-ruby', @response.content_type
70 end
93 end
71
94
72 def test_download_should_assign_content_type_if_blank
95 def test_download_should_assign_content_type_if_blank
73 Attachment.find(4).update_attribute(:content_type, '')
96 Attachment.find(4).update_attribute(:content_type, '')
74
97
75 get :download, :id => 4
98 get :download, :id => 4
76 assert_response :success
99 assert_response :success
77 assert_equal 'text/x-ruby', @response.content_type
100 assert_equal 'text/x-ruby', @response.content_type
78 end
101 end
79
102
80 def test_download_missing_file
103 def test_download_missing_file
81 get :download, :id => 2
104 get :download, :id => 2
82 assert_response 404
105 assert_response 404
83 end
106 end
84
107
85 def test_anonymous_on_private_private
108 def test_anonymous_on_private_private
86 get :download, :id => 7
109 get :download, :id => 7
87 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
110 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
88 end
111 end
89
112
90 def test_destroy_issue_attachment
113 def test_destroy_issue_attachment
91 issue = Issue.find(3)
114 issue = Issue.find(3)
92 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
93
116
94 assert_difference 'issue.attachments.count', -1 do
117 assert_difference 'issue.attachments.count', -1 do
95 post :destroy, :id => 1
118 post :destroy, :id => 1
96 end
119 end
97 # no referrer
120 # no referrer
98 assert_redirected_to '/projects/ecookbook'
121 assert_redirected_to '/projects/ecookbook'
99 assert_nil Attachment.find_by_id(1)
122 assert_nil Attachment.find_by_id(1)
100 j = issue.journals.find(:first, :order => 'created_on DESC')
123 j = issue.journals.find(:first, :order => 'created_on DESC')
101 assert_equal 'attachment', j.details.first.property
124 assert_equal 'attachment', j.details.first.property
102 assert_equal '1', j.details.first.prop_key
125 assert_equal '1', j.details.first.prop_key
103 assert_equal 'error281.txt', j.details.first.old_value
126 assert_equal 'error281.txt', j.details.first.old_value
104 end
127 end
105
128
106 def test_destroy_wiki_page_attachment
129 def test_destroy_wiki_page_attachment
107 @request.session[:user_id] = 2
130 @request.session[:user_id] = 2
108 assert_difference 'Attachment.count', -1 do
131 assert_difference 'Attachment.count', -1 do
109 post :destroy, :id => 3
132 post :destroy, :id => 3
110 assert_response 302
133 assert_response 302
111 end
134 end
112 end
135 end
113
136
114 def test_destroy_project_attachment
137 def test_destroy_project_attachment
115 @request.session[:user_id] = 2
138 @request.session[:user_id] = 2
116 assert_difference 'Attachment.count', -1 do
139 assert_difference 'Attachment.count', -1 do
117 post :destroy, :id => 8
140 post :destroy, :id => 8
118 assert_response 302
141 assert_response 302
119 end
142 end
120 end
143 end
121
144
122 def test_destroy_version_attachment
145 def test_destroy_version_attachment
123 @request.session[:user_id] = 2
146 @request.session[:user_id] = 2
124 assert_difference 'Attachment.count', -1 do
147 assert_difference 'Attachment.count', -1 do
125 post :destroy, :id => 9
148 post :destroy, :id => 9
126 assert_response 302
149 assert_response 302
127 end
150 end
128 end
151 end
129
152
130 def test_destroy_without_permission
153 def test_destroy_without_permission
131 post :destroy, :id => 3
154 post :destroy, :id => 3
132 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
155 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
133 assert Attachment.find_by_id(3)
156 assert Attachment.find_by_id(3)
134 end
157 end
135 end
158 end
General Comments 0
You need to be logged in to leave comments. Login now