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