##// END OF EJS Templates
attachment: update functional tests to switch "side by side" and "inline" for patches (#9612)...
Toshi MARUYAMA -
r7741:00f9581380ea
parent child
Show More
@@ -1,209 +1,213
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # 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,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # 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
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # 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.
19
19
20 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21 require 'attachments_controller'
21 require 'attachments_controller'
22
22
23 # Re-raise errors caught by the controller.
23 # Re-raise errors caught by the controller.
24 class AttachmentsController; def rescue_action(e) raise e end; end
24 class AttachmentsController; def rescue_action(e) raise e end; end
25
25
26 class AttachmentsControllerTest < ActionController::TestCase
26 class AttachmentsControllerTest < ActionController::TestCase
27 fixtures :users, :projects, :roles, :members, :member_roles,
27 fixtures :users, :projects, :roles, :members, :member_roles,
28 :enabled_modules, :issues, :trackers, :attachments,
28 :enabled_modules, :issues, :trackers, :attachments,
29 :versions, :wiki_pages, :wikis, :documents
29 :versions, :wiki_pages, :wikis, :documents
30
30
31 def setup
31 def setup
32 @controller = AttachmentsController.new
32 @controller = AttachmentsController.new
33 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
36 User.current = nil
36 User.current = nil
37 end
37 end
38
38
39 def test_show_diff
39 def test_show_diff
40 get :show, :id => 14 # 060719210727_changeset_utf8.diff
40 ['inline', 'sbs'].each do |dt|
41 # 060719210727_changeset_utf8.diff
42 get :show, :id => 14, :type => dt
41 assert_response :success
43 assert_response :success
42 assert_template 'diff'
44 assert_template 'diff'
43 assert_equal 'text/html', @response.content_type
45 assert_equal 'text/html', @response.content_type
44
45 assert_tag 'th',
46 assert_tag 'th',
46 :attributes => {:class => /filename/},
47 :attributes => {:class => /filename/},
47 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
48 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
48 assert_tag 'td',
49 assert_tag 'td',
49 :attributes => {:class => /line-code/},
50 :attributes => {:class => /line-code/},
50 :content => /Demande créée avec succès/
51 :content => /Demande créée avec succès/
51 end
52 end
53 end
52
54
53 def test_show_diff_should_strip_non_utf8_content
55 def test_show_diff_should_strip_non_utf8_content
54 get :show, :id => 5 # 060719210727_changeset_iso8859-1.diff
56 ['inline', 'sbs'].each do |dt|
57 # 060719210727_changeset_iso8859-1.diff
58 get :show, :id => 5, :type => dt
55 assert_response :success
59 assert_response :success
56 assert_template 'diff'
60 assert_template 'diff'
57 assert_equal 'text/html', @response.content_type
61 assert_equal 'text/html', @response.content_type
58
59 assert_tag 'th',
62 assert_tag 'th',
60 :attributes => {:class => /filename/},
63 :attributes => {:class => /filename/},
61 :content => /issues_controller.rb\t\(rvision 1484\)/
64 :content => /issues_controller.rb\t\(rvision 1484\)/
62 assert_tag 'td',
65 assert_tag 'td',
63 :attributes => {:class => /line-code/},
66 :attributes => {:class => /line-code/},
64 :content => /Demande cre avec succs/
67 :content => /Demande cre avec succs/
65 end
68 end
69 end
66
70
67 def test_show_text_file
71 def test_show_text_file
68 get :show, :id => 4
72 get :show, :id => 4
69 assert_response :success
73 assert_response :success
70 assert_template 'file'
74 assert_template 'file'
71 assert_equal 'text/html', @response.content_type
75 assert_equal 'text/html', @response.content_type
72 end
76 end
73
77
74 def test_show_text_file_utf_8
78 def test_show_text_file_utf_8
75 set_tmp_attachments_directory
79 set_tmp_attachments_directory
76 a = Attachment.new(:container => Issue.find(1),
80 a = Attachment.new(:container => Issue.find(1),
77 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
81 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
78 :author => User.find(1))
82 :author => User.find(1))
79 assert a.save
83 assert a.save
80 assert_equal 'japanese-utf-8.txt', a.filename
84 assert_equal 'japanese-utf-8.txt', a.filename
81
85
82 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
86 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
83 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
87 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
84
88
85 get :show, :id => a.id
89 get :show, :id => a.id
86 assert_response :success
90 assert_response :success
87 assert_template 'file'
91 assert_template 'file'
88 assert_equal 'text/html', @response.content_type
92 assert_equal 'text/html', @response.content_type
89 assert_tag :tag => 'th',
93 assert_tag :tag => 'th',
90 :content => '1',
94 :content => '1',
91 :attributes => { :class => 'line-num' },
95 :attributes => { :class => 'line-num' },
92 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
96 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
93 end
97 end
94
98
95 def test_show_text_file_should_strip_non_utf8_content
99 def test_show_text_file_should_strip_non_utf8_content
96 set_tmp_attachments_directory
100 set_tmp_attachments_directory
97 a = Attachment.new(:container => Issue.find(1),
101 a = Attachment.new(:container => Issue.find(1),
98 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
102 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
99 :author => User.find(1))
103 :author => User.find(1))
100 assert a.save
104 assert a.save
101 assert_equal 'iso8859-1.txt', a.filename
105 assert_equal 'iso8859-1.txt', a.filename
102
106
103 get :show, :id => a.id
107 get :show, :id => a.id
104 assert_response :success
108 assert_response :success
105 assert_template 'file'
109 assert_template 'file'
106 assert_equal 'text/html', @response.content_type
110 assert_equal 'text/html', @response.content_type
107 assert_tag :tag => 'th',
111 assert_tag :tag => 'th',
108 :content => '7',
112 :content => '7',
109 :attributes => { :class => 'line-num' },
113 :attributes => { :class => 'line-num' },
110 :sibling => { :tag => 'td', :content => /Demande cre avec succs/ }
114 :sibling => { :tag => 'td', :content => /Demande cre avec succs/ }
111 end
115 end
112
116
113 def test_show_text_file_should_send_if_too_big
117 def test_show_text_file_should_send_if_too_big
114 Setting.file_max_size_displayed = 512
118 Setting.file_max_size_displayed = 512
115 Attachment.find(4).update_attribute :filesize, 754.kilobyte
119 Attachment.find(4).update_attribute :filesize, 754.kilobyte
116
120
117 get :show, :id => 4
121 get :show, :id => 4
118 assert_response :success
122 assert_response :success
119 assert_equal 'application/x-ruby', @response.content_type
123 assert_equal 'application/x-ruby', @response.content_type
120 end
124 end
121
125
122 def test_show_other
126 def test_show_other
123 get :show, :id => 6
127 get :show, :id => 6
124 assert_response :success
128 assert_response :success
125 assert_equal 'application/octet-stream', @response.content_type
129 assert_equal 'application/octet-stream', @response.content_type
126 end
130 end
127
131
128 def test_show_file_from_private_issue_without_permission
132 def test_show_file_from_private_issue_without_permission
129 get :show, :id => 15
133 get :show, :id => 15
130 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
134 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
131 end
135 end
132
136
133 def test_show_file_from_private_issue_with_permission
137 def test_show_file_from_private_issue_with_permission
134 @request.session[:user_id] = 2
138 @request.session[:user_id] = 2
135 get :show, :id => 15
139 get :show, :id => 15
136 assert_response :success
140 assert_response :success
137 assert_tag 'h2', :content => /private.diff/
141 assert_tag 'h2', :content => /private.diff/
138 end
142 end
139
143
140 def test_download_text_file
144 def test_download_text_file
141 get :download, :id => 4
145 get :download, :id => 4
142 assert_response :success
146 assert_response :success
143 assert_equal 'application/x-ruby', @response.content_type
147 assert_equal 'application/x-ruby', @response.content_type
144 end
148 end
145
149
146 def test_download_should_assign_content_type_if_blank
150 def test_download_should_assign_content_type_if_blank
147 Attachment.find(4).update_attribute(:content_type, '')
151 Attachment.find(4).update_attribute(:content_type, '')
148
152
149 get :download, :id => 4
153 get :download, :id => 4
150 assert_response :success
154 assert_response :success
151 assert_equal 'text/x-ruby', @response.content_type
155 assert_equal 'text/x-ruby', @response.content_type
152 end
156 end
153
157
154 def test_download_missing_file
158 def test_download_missing_file
155 get :download, :id => 2
159 get :download, :id => 2
156 assert_response 404
160 assert_response 404
157 end
161 end
158
162
159 def test_anonymous_on_private_private
163 def test_anonymous_on_private_private
160 get :download, :id => 7
164 get :download, :id => 7
161 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
165 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
162 end
166 end
163
167
164 def test_destroy_issue_attachment
168 def test_destroy_issue_attachment
165 issue = Issue.find(3)
169 issue = Issue.find(3)
166 @request.session[:user_id] = 2
170 @request.session[:user_id] = 2
167
171
168 assert_difference 'issue.attachments.count', -1 do
172 assert_difference 'issue.attachments.count', -1 do
169 post :destroy, :id => 1
173 post :destroy, :id => 1
170 end
174 end
171 # no referrer
175 # no referrer
172 assert_redirected_to '/projects/ecookbook'
176 assert_redirected_to '/projects/ecookbook'
173 assert_nil Attachment.find_by_id(1)
177 assert_nil Attachment.find_by_id(1)
174 j = issue.journals.find(:first, :order => 'created_on DESC')
178 j = issue.journals.find(:first, :order => 'created_on DESC')
175 assert_equal 'attachment', j.details.first.property
179 assert_equal 'attachment', j.details.first.property
176 assert_equal '1', j.details.first.prop_key
180 assert_equal '1', j.details.first.prop_key
177 assert_equal 'error281.txt', j.details.first.old_value
181 assert_equal 'error281.txt', j.details.first.old_value
178 end
182 end
179
183
180 def test_destroy_wiki_page_attachment
184 def test_destroy_wiki_page_attachment
181 @request.session[:user_id] = 2
185 @request.session[:user_id] = 2
182 assert_difference 'Attachment.count', -1 do
186 assert_difference 'Attachment.count', -1 do
183 post :destroy, :id => 3
187 post :destroy, :id => 3
184 assert_response 302
188 assert_response 302
185 end
189 end
186 end
190 end
187
191
188 def test_destroy_project_attachment
192 def test_destroy_project_attachment
189 @request.session[:user_id] = 2
193 @request.session[:user_id] = 2
190 assert_difference 'Attachment.count', -1 do
194 assert_difference 'Attachment.count', -1 do
191 post :destroy, :id => 8
195 post :destroy, :id => 8
192 assert_response 302
196 assert_response 302
193 end
197 end
194 end
198 end
195
199
196 def test_destroy_version_attachment
200 def test_destroy_version_attachment
197 @request.session[:user_id] = 2
201 @request.session[:user_id] = 2
198 assert_difference 'Attachment.count', -1 do
202 assert_difference 'Attachment.count', -1 do
199 post :destroy, :id => 9
203 post :destroy, :id => 9
200 assert_response 302
204 assert_response 302
201 end
205 end
202 end
206 end
203
207
204 def test_destroy_without_permission
208 def test_destroy_without_permission
205 post :destroy, :id => 3
209 post :destroy, :id => 3
206 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
210 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
207 assert Attachment.find_by_id(3)
211 assert Attachment.find_by_id(3)
208 end
212 end
209 end
213 end
General Comments 0
You need to be logged in to leave comments. Login now