comparison test/functional/.svn/text-base/attachments_controller_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 8661b858af72
children 753f1380d6bc
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
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__)
25 25
26 26
27 class AttachmentsControllerTest < ActionController::TestCase 27 class AttachmentsControllerTest < ActionController::TestCase
28 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,
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 get :show, :id => 14 # 060719210727_changeset_utf8.diff
41 assert_response :success 41 assert_response :success
42 assert_template 'diff' 42 assert_template 'diff'
43 assert_equal 'text/html', @response.content_type 43 assert_equal 'text/html', @response.content_type
44 44
45 assert_tag 'th', 45 assert_tag 'th',
46 :attributes => {:class => /filename/}, 46 :attributes => {:class => /filename/},
47 :content => /issues_controller.rb\t\(révision 1484\)/ 47 :content => /issues_controller.rb\t\(révision 1484\)/
48 assert_tag 'td', 48 assert_tag 'td',
49 :attributes => {:class => /line-code/}, 49 :attributes => {:class => /line-code/},
50 :content => /Demande créée avec succès/ 50 :content => /Demande créée avec succès/
51 end 51 end
52 52
53 def test_show_diff_should_strip_non_utf8_content 53 def test_show_diff_should_strip_non_utf8_content
54 get :show, :id => 5 # 060719210727_changeset_iso8859-1.diff 54 get :show, :id => 5 # 060719210727_changeset_iso8859-1.diff
55 assert_response :success 55 assert_response :success
56 assert_template 'diff' 56 assert_template 'diff'
57 assert_equal 'text/html', @response.content_type 57 assert_equal 'text/html', @response.content_type
58 58
59 assert_tag 'th', 59 assert_tag 'th',
60 :attributes => {:class => /filename/}, 60 :attributes => {:class => /filename/},
61 :content => /issues_controller.rb\t\(rvision 1484\)/ 61 :content => /issues_controller.rb\t\(rvision 1484\)/
62 assert_tag 'td', 62 assert_tag 'td',
63 :attributes => {:class => /line-code/}, 63 :attributes => {:class => /line-code/},
64 :content => /Demande cre avec succs/ 64 :content => /Demande cre avec succs/
65 end 65 end
66 66
67 def test_show_text_file 67 def test_show_text_file
68 get :show, :id => 4 68 get :show, :id => 4
69 assert_response :success 69 assert_response :success
70 assert_template 'file' 70 assert_template 'file'
71 assert_equal 'text/html', @response.content_type 71 assert_equal 'text/html', @response.content_type
72 end 72 end
73 73
74 def test_show_text_file_should_send_if_too_big 74 def test_show_text_file_should_send_if_too_big
75 Setting.file_max_size_displayed = 512 75 Setting.file_max_size_displayed = 512
76 Attachment.find(4).update_attribute :filesize, 754.kilobyte 76 Attachment.find(4).update_attribute :filesize, 754.kilobyte
77 77
78 get :show, :id => 4 78 get :show, :id => 4
79 assert_response :success 79 assert_response :success
80 assert_equal 'application/x-ruby', @response.content_type 80 assert_equal 'application/x-ruby', @response.content_type
81 end 81 end
82 82
83 def test_show_other 83 def test_show_other
84 get :show, :id => 6 84 get :show, :id => 6
85 assert_response :success 85 assert_response :success
86 assert_equal 'application/octet-stream', @response.content_type 86 assert_equal 'application/octet-stream', @response.content_type
87 end 87 end
88 88
89 def test_show_file_from_private_issue_without_permission
90 get :show, :id => 15
91 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
92 end
93
94 def test_show_file_from_private_issue_with_permission
95 @request.session[:user_id] = 2
96 get :show, :id => 15
97 assert_response :success
98 assert_tag 'h2', :content => /private.diff/
99 end
100
89 def test_download_text_file 101 def test_download_text_file
90 get :download, :id => 4 102 get :download, :id => 4
91 assert_response :success 103 assert_response :success
92 assert_equal 'application/x-ruby', @response.content_type 104 assert_equal 'application/x-ruby', @response.content_type
93 end 105 end
94 106
95 def test_download_should_assign_content_type_if_blank 107 def test_download_should_assign_content_type_if_blank
96 Attachment.find(4).update_attribute(:content_type, '') 108 Attachment.find(4).update_attribute(:content_type, '')
97 109
98 get :download, :id => 4 110 get :download, :id => 4
99 assert_response :success 111 assert_response :success
100 assert_equal 'text/x-ruby', @response.content_type 112 assert_equal 'text/x-ruby', @response.content_type
101 end 113 end
102 114
103 def test_download_missing_file 115 def test_download_missing_file
104 get :download, :id => 2 116 get :download, :id => 2
105 assert_response 404 117 assert_response 404
106 end 118 end
107 119
108 def test_anonymous_on_private_private 120 def test_anonymous_on_private_private
109 get :download, :id => 7 121 get :download, :id => 7
110 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7' 122 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
111 end 123 end
112 124
113 def test_destroy_issue_attachment 125 def test_destroy_issue_attachment
114 issue = Issue.find(3) 126 issue = Issue.find(3)
115 @request.session[:user_id] = 2 127 @request.session[:user_id] = 2
116 128
117 assert_difference 'issue.attachments.count', -1 do 129 assert_difference 'issue.attachments.count', -1 do
118 post :destroy, :id => 1 130 post :destroy, :id => 1
119 end 131 end
120 # no referrer 132 # no referrer
121 assert_redirected_to '/projects/ecookbook' 133 assert_redirected_to '/projects/ecookbook'
123 j = issue.journals.find(:first, :order => 'created_on DESC') 135 j = issue.journals.find(:first, :order => 'created_on DESC')
124 assert_equal 'attachment', j.details.first.property 136 assert_equal 'attachment', j.details.first.property
125 assert_equal '1', j.details.first.prop_key 137 assert_equal '1', j.details.first.prop_key
126 assert_equal 'error281.txt', j.details.first.old_value 138 assert_equal 'error281.txt', j.details.first.old_value
127 end 139 end
128 140
129 def test_destroy_wiki_page_attachment 141 def test_destroy_wiki_page_attachment
130 @request.session[:user_id] = 2 142 @request.session[:user_id] = 2
131 assert_difference 'Attachment.count', -1 do 143 assert_difference 'Attachment.count', -1 do
132 post :destroy, :id => 3 144 post :destroy, :id => 3
133 assert_response 302 145 assert_response 302
134 end 146 end
135 end 147 end
136 148
137 def test_destroy_project_attachment 149 def test_destroy_project_attachment
138 @request.session[:user_id] = 2 150 @request.session[:user_id] = 2
139 assert_difference 'Attachment.count', -1 do 151 assert_difference 'Attachment.count', -1 do
140 post :destroy, :id => 8 152 post :destroy, :id => 8
141 assert_response 302 153 assert_response 302
142 end 154 end
143 end 155 end
144 156
145 def test_destroy_version_attachment 157 def test_destroy_version_attachment
146 @request.session[:user_id] = 2 158 @request.session[:user_id] = 2
147 assert_difference 'Attachment.count', -1 do 159 assert_difference 'Attachment.count', -1 do
148 post :destroy, :id => 9 160 post :destroy, :id => 9
149 assert_response 302 161 assert_response 302
150 end 162 end
151 end 163 end
152 164
153 def test_destroy_without_permission 165 def test_destroy_without_permission
154 post :destroy, :id => 3 166 post :destroy, :id => 3
155 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3' 167 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
156 assert Attachment.find_by_id(3) 168 assert Attachment.find_by_id(3)
157 end 169 end