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