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