##// END OF EJS Templates
Merged r4713 from trunk....
Toshi MARUYAMA -
r4597:b8f365f2a178
parent child
Show More
@@ -1,203 +1,203
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 RepositoriesGitControllerTest < ActionController::TestCase
24 class RepositoriesGitControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26
26
27 # No '..' in the repository path
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30
30
31 def setup
31 def setup
32 @controller = RepositoriesController.new
32 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
35 User.current = nil
35 User.current = nil
36 @repository = Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 @repository = Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
37 assert @repository
37 assert @repository
38 end
38 end
39
39
40 if File.directory?(REPOSITORY_PATH)
40 if File.directory?(REPOSITORY_PATH)
41 def test_show
41 def test_show
42 get :show, :id => 3
42 get :show, :id => 3
43 assert_response :success
43 assert_response :success
44 assert_template 'show'
44 assert_template 'show'
45 assert_not_nil assigns(:entries)
45 assert_not_nil assigns(:entries)
46 assert_not_nil assigns(:changesets)
46 assert_not_nil assigns(:changesets)
47 end
47 end
48
48
49 def test_browse_root
49 def test_browse_root
50 get :show, :id => 3
50 get :show, :id => 3
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_not_nil assigns(:entries)
53 assert_not_nil assigns(:entries)
54 assert_equal 9, assigns(:entries).size
54 assert_equal 9, assigns(:entries).size
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
58 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
58 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
59 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
59 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
60 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
60 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
61 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
61 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
62 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
62 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
63 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
63 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
64 end
64 end
65
65
66 def test_browse_branch
66 def test_browse_branch
67 get :show, :id => 3, :rev => 'test_branch'
67 get :show, :id => 3, :rev => 'test_branch'
68 assert_response :success
68 assert_response :success
69 assert_template 'show'
69 assert_template 'show'
70 assert_not_nil assigns(:entries)
70 assert_not_nil assigns(:entries)
71 assert_equal 4, assigns(:entries).size
71 assert_equal 4, assigns(:entries).size
72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
75 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
75 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
76 end
76 end
77
77
78 def test_browse_directory
78 def test_browse_directory
79 get :show, :id => 3, :path => ['images']
79 get :show, :id => 3, :path => ['images']
80 assert_response :success
80 assert_response :success
81 assert_template 'show'
81 assert_template 'show'
82 assert_not_nil assigns(:entries)
82 assert_not_nil assigns(:entries)
83 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
83 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
84 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
84 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
85 assert_not_nil entry
85 assert_not_nil entry
86 assert_equal 'file', entry.kind
86 assert_equal 'file', entry.kind
87 assert_equal 'images/edit.png', entry.path
87 assert_equal 'images/edit.png', entry.path
88 end
88 end
89
89
90 def test_browse_at_given_revision
90 def test_browse_at_given_revision
91 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
91 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
92 assert_response :success
92 assert_response :success
93 assert_template 'show'
93 assert_template 'show'
94 assert_not_nil assigns(:entries)
94 assert_not_nil assigns(:entries)
95 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
95 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
96 end
96 end
97
97
98 def test_changes
98 def test_changes
99 get :changes, :id => 3, :path => ['images', 'edit.png']
99 get :changes, :id => 3, :path => ['images', 'edit.png']
100 assert_response :success
100 assert_response :success
101 assert_template 'changes'
101 assert_template 'changes'
102 assert_tag :tag => 'h2', :content => 'edit.png'
102 assert_tag :tag => 'h2', :content => 'edit.png'
103 end
103 end
104
104
105 def test_entry_show
105 def test_entry_show
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
107 assert_response :success
107 assert_response :success
108 assert_template 'entry'
108 assert_template 'entry'
109 # Line 19
109 # Line 19
110 assert_tag :tag => 'th',
110 assert_tag :tag => 'th',
111 :content => /11/,
111 :content => /11/,
112 :attributes => { :class => /line-num/ },
112 :attributes => { :class => /line-num/ },
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
114 end
114 end
115
115
116 def test_entry_download
116 def test_entry_download
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
118 assert_response :success
118 assert_response :success
119 # File content
119 # File content
120 assert @response.body.include?('WITHOUT ANY WARRANTY')
120 assert @response.body.include?('WITHOUT ANY WARRANTY')
121 end
121 end
122
122
123 def test_directory_entry
123 def test_directory_entry
124 get :entry, :id => 3, :path => ['sources']
124 get :entry, :id => 3, :path => ['sources']
125 assert_response :success
125 assert_response :success
126 assert_template 'show'
126 assert_template 'show'
127 assert_not_nil assigns(:entry)
127 assert_not_nil assigns(:entry)
128 assert_equal 'sources', assigns(:entry).name
128 assert_equal 'sources', assigns(:entry).name
129 end
129 end
130
130
131 def test_diff
131 def test_diff
132 @repository.fetch_changesets
132 @repository.fetch_changesets
133 @repository.reload
133 @repository.reload
134
134
135 # Full diff of changeset 2f9c0091
135 # Full diff of changeset 2f9c0091
136 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
136 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
137 assert_response :success
137 assert_response :success
138 assert_template 'diff'
138 assert_template 'diff'
139 # Line 22 removed
139 # Line 22 removed
140 assert_tag :tag => 'th',
140 assert_tag :tag => 'th',
141 :content => /22/,
141 :content => /22/,
142 :sibling => { :tag => 'td',
142 :sibling => { :tag => 'td',
143 :attributes => { :class => /diff_out/ },
143 :attributes => { :class => /diff_out/ },
144 :content => /def remove/ }
144 :content => /def remove/ }
145 assert_tag :tag => 'h2', :content => /2f9c0091/
145 assert_tag :tag => 'h2', :content => /2f9c0091/
146 end
146 end
147
147
148 def test_diff_two_revs
148 def test_diff_two_revs
149 @repository.fetch_changesets
149 @repository.fetch_changesets
150 @repository.reload
150 @repository.reload
151
151
152 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
152 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
153 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
153 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
154 assert_response :success
154 assert_response :success
155 assert_template 'diff'
155 assert_template 'diff'
156
156
157 diff = assigns(:diff)
157 diff = assigns(:diff)
158 assert_not_nil diff
158 assert_not_nil diff
159 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
159 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
160 end
160 end
161
161
162 def test_annotate
162 def test_annotate
163 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
163 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
164 assert_response :success
164 assert_response :success
165 assert_template 'annotate'
165 assert_template 'annotate'
166 # Line 23, changeset 2f9c0091
166 # Line 23, changeset 2f9c0091
167 assert_tag :tag => 'th', :content => /24/,
167 assert_tag :tag => 'th', :content => /24/,
168 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
168 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
169 :sibling => { :tag => 'td', :content => /jsmith/ },
169 :sibling => { :tag => 'td', :content => /jsmith/ },
170 :sibling => { :tag => 'td', :content => /watcher =/ }
170 :sibling => { :tag => 'td', :content => /watcher =/ }
171 end
171 end
172
172
173 def test_annotate_binary_file
173 def test_annotate_binary_file
174 get :annotate, :id => 3, :path => ['images', 'edit.png']
174 get :annotate, :id => 3, :path => ['images', 'edit.png']
175 assert_response 500
175 assert_response 500
176 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
176 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
177 :content => /can not be annotated/
177 :content => /can not be annotated/
178 end
178 end
179
179
180 def test_revision
180 def test_revision
181 @repository.fetch_changesets
181 @repository.fetch_changesets
182 @repository.reload
182 @repository.reload
183 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
183 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
184 get :revision, :id => 3, :rev => r
184 get :revision, :id => 3, :rev => r
185 assert_response :success
185 assert_response :success
186 assert_template 'revision'
186 assert_template 'revision'
187 end
187 end
188 end
188 end
189
189
190 def test_empty_revision
190 def test_empty_revision
191 @repository.fetch_changesets
191 @repository.fetch_changesets
192 @repository.reload
192 @repository.reload
193 ['', ' ', nil].each do |r|
193 ['', ' ', nil].each do |r|
194 get :revision, :id => 1, :rev => r
194 get :revision, :id => 3, :rev => r
195 assert_response 404
195 assert_response 404
196 assert_error_tag :content => /was not found/
196 assert_error_tag :content => /was not found/
197 end
197 end
198 end
198 end
199 else
199 else
200 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
200 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
201 def test_fake; assert true end
201 def test_fake; assert true end
202 end
202 end
203 end
203 end
General Comments 0
You need to be logged in to leave comments. Login now