Chris@441
|
1 # Redmine - project management software
|
Chris@441
|
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
|
Chris@441
|
3 #
|
Chris@441
|
4 # This program is free software; you can redistribute it and/or
|
Chris@441
|
5 # modify it under the terms of the GNU General Public License
|
Chris@441
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@441
|
7 # of the License, or (at your option) any later version.
|
Chris@441
|
8 #
|
Chris@441
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@441
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@441
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@441
|
12 # GNU General Public License for more details.
|
Chris@441
|
13 #
|
Chris@441
|
14 # You should have received a copy of the GNU General Public License
|
Chris@441
|
15 # along with this program; if not, write to the Free Software
|
Chris@441
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@441
|
17
|
Chris@441
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@441
|
19 require 'repositories_controller'
|
Chris@441
|
20
|
Chris@441
|
21 # Re-raise errors caught by the controller.
|
Chris@441
|
22 class RepositoriesController; def rescue_action(e) raise e end; end
|
Chris@441
|
23
|
Chris@441
|
24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
|
Chris@441
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
|
Chris@441
|
26
|
Chris@441
|
27 # No '..' in the repository path
|
Chris@441
|
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
|
Chris@441
|
29 PRJ_ID = 3
|
Chris@441
|
30
|
Chris@441
|
31 def setup
|
Chris@441
|
32 @ruby19_non_utf8_pass =
|
Chris@441
|
33 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
|
Chris@441
|
34 @controller = RepositoriesController.new
|
Chris@441
|
35 @request = ActionController::TestRequest.new
|
Chris@441
|
36 @response = ActionController::TestResponse.new
|
Chris@441
|
37 User.current = nil
|
Chris@441
|
38 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
|
Chris@441
|
39 @repository = Repository::Filesystem.create(
|
Chris@441
|
40 :project => Project.find(PRJ_ID),
|
Chris@441
|
41 :url => REPOSITORY_PATH,
|
Chris@441
|
42 :path_encoding => ''
|
Chris@441
|
43 )
|
Chris@441
|
44 assert @repository
|
Chris@441
|
45 end
|
Chris@441
|
46
|
Chris@441
|
47 if File.directory?(REPOSITORY_PATH)
|
Chris@441
|
48 def test_browse_root
|
Chris@441
|
49 @repository.fetch_changesets
|
Chris@441
|
50 @repository.reload
|
Chris@441
|
51 get :show, :id => PRJ_ID
|
Chris@441
|
52 assert_response :success
|
Chris@441
|
53 assert_template 'show'
|
Chris@441
|
54 assert_not_nil assigns(:entries)
|
Chris@441
|
55 assert assigns(:entries).size > 0
|
Chris@441
|
56 assert_not_nil assigns(:changesets)
|
Chris@441
|
57 assert assigns(:changesets).size == 0
|
Chris@441
|
58 end
|
Chris@441
|
59
|
Chris@441
|
60 def test_show_no_extension
|
Chris@441
|
61 get :entry, :id => PRJ_ID, :path => ['test']
|
Chris@441
|
62 assert_response :success
|
Chris@441
|
63 assert_template 'entry'
|
Chris@441
|
64 assert_tag :tag => 'th',
|
Chris@441
|
65 :content => '1',
|
Chris@441
|
66 :attributes => { :class => 'line-num' },
|
Chris@441
|
67 :sibling => { :tag => 'td', :content => /TEST CAT/ }
|
Chris@441
|
68 end
|
Chris@441
|
69
|
Chris@441
|
70 def test_entry_download_no_extension
|
Chris@441
|
71 get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw'
|
Chris@441
|
72 assert_response :success
|
Chris@441
|
73 assert_equal 'application/octet-stream', @response.content_type
|
Chris@441
|
74 end
|
Chris@441
|
75
|
Chris@441
|
76 def test_show_non_ascii_contents
|
Chris@441
|
77 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
|
Chris@441
|
78 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
|
Chris@441
|
79 assert_response :success
|
Chris@441
|
80 assert_template 'entry'
|
Chris@441
|
81 assert_tag :tag => 'th',
|
Chris@441
|
82 :content => '2',
|
Chris@441
|
83 :attributes => { :class => 'line-num' },
|
Chris@441
|
84 :sibling => { :tag => 'td', :content => /japanese/ }
|
Chris@441
|
85 if @ruby19_non_utf8_pass
|
Chris@441
|
86 puts "TODO: show repository file contents test fails in Ruby 1.9 " +
|
Chris@441
|
87 "and Encoding.default_external is not UTF-8. " +
|
Chris@441
|
88 "Current value is '#{Encoding.default_external.to_s}'"
|
Chris@441
|
89 else
|
Chris@441
|
90 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
|
Chris@441
|
91 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
|
Chris@441
|
92 assert_tag :tag => 'th',
|
Chris@441
|
93 :content => '3',
|
Chris@441
|
94 :attributes => { :class => 'line-num' },
|
Chris@441
|
95 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
|
Chris@441
|
96 end
|
Chris@441
|
97 end
|
Chris@441
|
98 end
|
Chris@441
|
99
|
Chris@441
|
100 def test_show_utf16
|
Chris@441
|
101 with_settings :repositories_encodings => 'UTF-16' do
|
Chris@441
|
102 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
|
Chris@441
|
103 assert_response :success
|
Chris@441
|
104 assert_tag :tag => 'th',
|
Chris@441
|
105 :content => '2',
|
Chris@441
|
106 :attributes => { :class => 'line-num' },
|
Chris@441
|
107 :sibling => { :tag => 'td', :content => /japanese/ }
|
Chris@441
|
108 end
|
Chris@441
|
109 end
|
Chris@441
|
110
|
Chris@441
|
111 def test_show_text_file_should_send_if_too_big
|
Chris@441
|
112 with_settings :file_max_size_displayed => 1 do
|
Chris@441
|
113 get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt']
|
Chris@441
|
114 assert_response :success
|
Chris@441
|
115 assert_equal 'text/plain', @response.content_type
|
Chris@441
|
116 end
|
Chris@441
|
117 end
|
Chris@441
|
118 else
|
Chris@441
|
119 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
|
Chris@441
|
120 def test_fake; assert true end
|
Chris@441
|
121 end
|
Chris@441
|
122 end
|