##// END OF EJS Templates
scm: filesystem: code clean up functional test....
Toshi MARUYAMA -
r5741:eb65817ff9b8
parent child
Show More
@@ -1,123 +1,122
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, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
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
35 34 @controller = RepositoriesController.new
36 35 @request = ActionController::TestRequest.new
37 36 @response = ActionController::TestResponse.new
38 37 User.current = nil
39 38 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
40 39 @repository = Repository::Filesystem.create(
41 40 :project => Project.find(PRJ_ID),
42 41 :url => REPOSITORY_PATH,
43 42 :path_encoding => ''
44 43 )
45 44 assert @repository
46 45 end
47 46
48 47 if File.directory?(REPOSITORY_PATH)
49 48 def test_browse_root
50 49 @repository.fetch_changesets
51 50 @repository.reload
52 51 get :show, :id => PRJ_ID
53 52 assert_response :success
54 53 assert_template 'show'
55 54 assert_not_nil assigns(:entries)
56 55 assert assigns(:entries).size > 0
57 56 assert_not_nil assigns(:changesets)
58 57 assert assigns(:changesets).size == 0
59 58 end
60 59
61 60 def test_show_no_extension
62 61 get :entry, :id => PRJ_ID, :path => ['test']
63 62 assert_response :success
64 63 assert_template 'entry'
65 64 assert_tag :tag => 'th',
66 65 :content => '1',
67 66 :attributes => { :class => 'line-num' },
68 67 :sibling => { :tag => 'td', :content => /TEST CAT/ }
69 68 end
70 69
71 70 def test_entry_download_no_extension
72 71 get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw'
73 72 assert_response :success
74 73 assert_equal 'application/octet-stream', @response.content_type
75 74 end
76 75
77 76 def test_show_non_ascii_contents
78 77 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
79 78 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
80 79 assert_response :success
81 80 assert_template 'entry'
82 81 assert_tag :tag => 'th',
83 82 :content => '2',
84 83 :attributes => { :class => 'line-num' },
85 84 :sibling => { :tag => 'td', :content => /japanese/ }
86 85 if @ruby19_non_utf8_pass
87 86 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
88 87 "and Encoding.default_external is not UTF-8. " +
89 88 "Current value is '#{Encoding.default_external.to_s}'"
90 89 else
91 90 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
92 91 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
93 92 assert_tag :tag => 'th',
94 93 :content => '3',
95 94 :attributes => { :class => 'line-num' },
96 95 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
97 96 end
98 97 end
99 98 end
100 99
101 100 def test_show_utf16
102 101 with_settings :repositories_encodings => 'UTF-16' do
103 102 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
104 103 assert_response :success
105 104 assert_tag :tag => 'th',
106 105 :content => '2',
107 106 :attributes => { :class => 'line-num' },
108 107 :sibling => { :tag => 'td', :content => /japanese/ }
109 108 end
110 109 end
111 110
112 111 def test_show_text_file_should_send_if_too_big
113 112 with_settings :file_max_size_displayed => 1 do
114 113 get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt']
115 114 assert_response :success
116 115 assert_equal 'text/plain', @response.content_type
117 116 end
118 117 end
119 118 else
120 119 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
121 120 def test_fake; assert true end
122 121 end
123 122 end
General Comments 0
You need to be logged in to leave comments. Login now