##// END OF EJS Templates
scm: filesystem: add functional test of destroying invalid repository (#6713, #4725)....
Toshi MARUYAMA -
r6119:fe07aee27efd
parent child
Show More
@@ -1,132 +1,153
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 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles,
26 26 :repositories, :enabled_modules
27 27
28 28 REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
29 29 PRJ_ID = 3
30 30
31 31 def setup
32 32 @ruby19_non_utf8_pass =
33 33 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
34 34 @controller = RepositoriesController.new
35 35 @request = ActionController::TestRequest.new
36 36 @response = ActionController::TestResponse.new
37 37 User.current = nil
38 38 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
39 39 @project = Project.find(PRJ_ID)
40 40 @repository = Repository::Filesystem.create(
41 41 :project => @project,
42 42 :url => REPOSITORY_PATH,
43 43 :path_encoding => ''
44 44 )
45 45 assert @repository
46 46 end
47 47
48 48 if File.directory?(REPOSITORY_PATH)
49 49 def test_browse_root
50 50 @repository.fetch_changesets
51 51 @repository.reload
52 52 get :show, :id => PRJ_ID
53 53 assert_response :success
54 54 assert_template 'show'
55 55 assert_not_nil assigns(:entries)
56 56 assert assigns(:entries).size > 0
57 57 assert_not_nil assigns(:changesets)
58 58 assert assigns(:changesets).size == 0
59 59 end
60 60
61 61 def test_show_no_extension
62 62 get :entry, :id => PRJ_ID, :path => ['test']
63 63 assert_response :success
64 64 assert_template 'entry'
65 65 assert_tag :tag => 'th',
66 66 :content => '1',
67 67 :attributes => { :class => 'line-num' },
68 68 :sibling => { :tag => 'td', :content => /TEST CAT/ }
69 69 end
70 70
71 71 def test_entry_download_no_extension
72 72 get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw'
73 73 assert_response :success
74 74 assert_equal 'application/octet-stream', @response.content_type
75 75 end
76 76
77 77 def test_show_non_ascii_contents
78 78 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
79 79 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
80 80 assert_response :success
81 81 assert_template 'entry'
82 82 assert_tag :tag => 'th',
83 83 :content => '2',
84 84 :attributes => { :class => 'line-num' },
85 85 :sibling => { :tag => 'td', :content => /japanese/ }
86 86 if @ruby19_non_utf8_pass
87 87 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
88 88 "and Encoding.default_external is not UTF-8. " +
89 89 "Current value is '#{Encoding.default_external.to_s}'"
90 90 else
91 91 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
92 92 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
93 93 assert_tag :tag => 'th',
94 94 :content => '3',
95 95 :attributes => { :class => 'line-num' },
96 96 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
97 97 end
98 98 end
99 99 end
100 100
101 101 def test_show_utf16
102 102 with_settings :repositories_encodings => 'UTF-16' do
103 103 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
104 104 assert_response :success
105 105 assert_tag :tag => 'th',
106 106 :content => '2',
107 107 :attributes => { :class => 'line-num' },
108 108 :sibling => { :tag => 'td', :content => /japanese/ }
109 109 end
110 110 end
111 111
112 112 def test_show_text_file_should_send_if_too_big
113 113 with_settings :file_max_size_displayed => 1 do
114 114 get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt']
115 115 assert_response :success
116 116 assert_equal 'text/plain', @response.content_type
117 117 end
118 118 end
119 119
120 120 def test_destroy_valid_repository
121 121 @request.session[:user_id] = 1 # admin
122 122
123 123 get :destroy, :id => PRJ_ID
124 124 assert_response 302
125 125 @project.reload
126 126 assert_nil @project.repository
127 127 end
128
129 def test_destroy_invalid_repository
130 @request.session[:user_id] = 1 # admin
131
132 get :destroy, :id => PRJ_ID
133 assert_response 302
134 @project.reload
135 assert_nil @project.repository
136
137 @repository = Repository::Filesystem.create(
138 :project => Project.find(PRJ_ID),
139 :url => "/invalid",
140 :path_encoding => ''
141 )
142 assert @repository
143
144 get :destroy, :id => PRJ_ID
145 assert_response 302
146 @project.reload
147 assert_nil @project.repository
148 end
128 149 else
129 150 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
130 151 def test_fake; assert true end
131 152 end
132 153 end
General Comments 0
You need to be logged in to leave comments. Login now