@@ -1,247 +1,247 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
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 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( |
|
36 | @repository = Repository::Git.create( | |
37 | :project => Project.find(3), |
|
37 | :project => Project.find(3), | |
38 | :url => REPOSITORY_PATH, |
|
38 | :url => REPOSITORY_PATH, | |
39 | :path_encoding => 'ISO-8859-1' |
|
39 | :path_encoding => 'ISO-8859-1' | |
40 | ) |
|
40 | ) | |
41 | assert @repository |
|
41 | assert @repository | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | if File.directory?(REPOSITORY_PATH) |
|
44 | if File.directory?(REPOSITORY_PATH) | |
45 | def test_browse_root |
|
45 | def test_browse_root | |
46 | @repository.fetch_changesets |
|
46 | @repository.fetch_changesets | |
47 | @repository.reload |
|
47 | @repository.reload | |
48 | get :show, :id => 3 |
|
48 | get :show, :id => 3 | |
49 | assert_response :success |
|
49 | assert_response :success | |
50 | assert_template 'show' |
|
50 | assert_template 'show' | |
51 | assert_not_nil assigns(:entries) |
|
51 | assert_not_nil assigns(:entries) | |
52 | assert_equal 9, assigns(:entries).size |
|
52 | assert_equal 9, assigns(:entries).size | |
53 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
53 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
54 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} |
|
54 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} | |
55 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
55 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
56 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
56 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
57 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} |
|
57 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} | |
58 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} |
|
58 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} | |
59 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} |
|
59 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} | |
60 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} |
|
60 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} | |
61 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} |
|
61 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} | |
62 | assert_not_nil assigns(:changesets) |
|
62 | assert_not_nil assigns(:changesets) | |
63 | assigns(:changesets).size > 0 |
|
63 | assigns(:changesets).size > 0 | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_browse_branch |
|
66 | def test_browse_branch | |
67 | @repository.fetch_changesets |
|
67 | @repository.fetch_changesets | |
68 | @repository.reload |
|
68 | @repository.reload | |
69 | get :show, :id => 3, :rev => 'test_branch' |
|
69 | get :show, :id => 3, :rev => 'test_branch' | |
70 | assert_response :success |
|
70 | assert_response :success | |
71 | assert_template 'show' |
|
71 | assert_template 'show' | |
72 | assert_not_nil assigns(:entries) |
|
72 | assert_not_nil assigns(:entries) | |
73 | assert_equal 4, assigns(:entries).size |
|
73 | assert_equal 4, assigns(:entries).size | |
74 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
74 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
75 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
75 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
76 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
76 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
77 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} |
|
77 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} | |
78 | assert_not_nil assigns(:changesets) |
|
78 | assert_not_nil assigns(:changesets) | |
79 | assigns(:changesets).size > 0 |
|
79 | assigns(:changesets).size > 0 | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_browse_tag |
|
82 | def test_browse_tag | |
83 | @repository.fetch_changesets |
|
83 | @repository.fetch_changesets | |
84 | @repository.reload |
|
84 | @repository.reload | |
85 | [ |
|
85 | [ | |
86 | "tag00.lightweight", |
|
86 | "tag00.lightweight", | |
87 | "tag01.annotated", |
|
87 | "tag01.annotated", | |
88 | ].each do |t1| |
|
88 | ].each do |t1| | |
89 | get :show, :id => 3, :rev => t1 |
|
89 | get :show, :id => 3, :rev => t1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'show' |
|
91 | assert_template 'show' | |
92 | assert_not_nil assigns(:entries) |
|
92 | assert_not_nil assigns(:entries) | |
93 | assigns(:entries).size > 0 |
|
93 | assigns(:entries).size > 0 | |
94 | assert_not_nil assigns(:changesets) |
|
94 | assert_not_nil assigns(:changesets) | |
95 | assigns(:changesets).size > 0 |
|
95 | assigns(:changesets).size > 0 | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_browse_directory |
|
99 | def test_browse_directory | |
100 | @repository.fetch_changesets |
|
100 | @repository.fetch_changesets | |
101 | @repository.reload |
|
101 | @repository.reload | |
102 | get :show, :id => 3, :path => ['images'] |
|
102 | get :show, :id => 3, :path => ['images'] | |
103 | assert_response :success |
|
103 | assert_response :success | |
104 | assert_template 'show' |
|
104 | assert_template 'show' | |
105 | assert_not_nil assigns(:entries) |
|
105 | assert_not_nil assigns(:entries) | |
106 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) |
|
106 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) | |
107 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
107 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
108 | assert_not_nil entry |
|
108 | assert_not_nil entry | |
109 | assert_equal 'file', entry.kind |
|
109 | assert_equal 'file', entry.kind | |
110 | assert_equal 'images/edit.png', entry.path |
|
110 | assert_equal 'images/edit.png', entry.path | |
111 | assert_not_nil assigns(:changesets) |
|
111 | assert_not_nil assigns(:changesets) | |
112 | assigns(:changesets).size > 0 |
|
112 | assigns(:changesets).size > 0 | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_browse_at_given_revision |
|
115 | def test_browse_at_given_revision | |
116 | @repository.fetch_changesets |
|
116 | @repository.fetch_changesets | |
117 | @repository.reload |
|
117 | @repository.reload | |
118 | get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' |
|
118 | get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 | assert_template 'show' |
|
120 | assert_template 'show' | |
121 | assert_not_nil assigns(:entries) |
|
121 | assert_not_nil assigns(:entries) | |
122 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
122 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
123 | assert_not_nil assigns(:changesets) |
|
123 | assert_not_nil assigns(:changesets) | |
124 | assigns(:changesets).size > 0 |
|
124 | assigns(:changesets).size > 0 | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_changes |
|
127 | def test_changes | |
128 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
128 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
129 | assert_response :success |
|
129 | assert_response :success | |
130 | assert_template 'changes' |
|
130 | assert_template 'changes' | |
131 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
131 | assert_tag :tag => 'h2', :content => 'edit.png' | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_entry_show |
|
134 | def test_entry_show | |
135 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
135 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
136 | assert_response :success |
|
136 | assert_response :success | |
137 | assert_template 'entry' |
|
137 | assert_template 'entry' | |
138 | # Line 19 |
|
138 | # Line 19 | |
139 | assert_tag :tag => 'th', |
|
139 | assert_tag :tag => 'th', | |
140 | :content => '11', |
|
140 | :content => '11', | |
141 | :attributes => { :class => 'line-num' }, |
|
141 | :attributes => { :class => 'line-num' }, | |
142 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
142 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_entry_download |
|
145 | def test_entry_download | |
146 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
146 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
147 | assert_response :success |
|
147 | assert_response :success | |
148 | # File content |
|
148 | # File content | |
149 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
149 | assert @response.body.include?('WITHOUT ANY WARRANTY') | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | def test_directory_entry |
|
152 | def test_directory_entry | |
153 | get :entry, :id => 3, :path => ['sources'] |
|
153 | get :entry, :id => 3, :path => ['sources'] | |
154 | assert_response :success |
|
154 | assert_response :success | |
155 | assert_template 'show' |
|
155 | assert_template 'show' | |
156 | assert_not_nil assigns(:entry) |
|
156 | assert_not_nil assigns(:entry) | |
157 | assert_equal 'sources', assigns(:entry).name |
|
157 | assert_equal 'sources', assigns(:entry).name | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 | def test_diff |
|
160 | def test_diff | |
161 | @repository.fetch_changesets |
|
161 | @repository.fetch_changesets | |
162 | @repository.reload |
|
162 | @repository.reload | |
163 |
|
163 | |||
164 | # Full diff of changeset 2f9c0091 |
|
164 | # Full diff of changeset 2f9c0091 | |
165 | get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
165 | get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
166 | assert_response :success |
|
166 | assert_response :success | |
167 | assert_template 'diff' |
|
167 | assert_template 'diff' | |
168 | # Line 22 removed |
|
168 | # Line 22 removed | |
169 | assert_tag :tag => 'th', |
|
169 | assert_tag :tag => 'th', | |
170 | :content => /22/, |
|
170 | :content => /22/, | |
171 |
:sibling => { :tag => 'td', |
|
171 | :sibling => { :tag => 'td', | |
172 | :attributes => { :class => /diff_out/ }, |
|
172 | :attributes => { :class => /diff_out/ }, | |
173 | :content => /def remove/ } |
|
173 | :content => /def remove/ } | |
174 | assert_tag :tag => 'h2', :content => /2f9c0091/ |
|
174 | assert_tag :tag => 'h2', :content => /2f9c0091/ | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def test_diff_two_revs |
|
177 | def test_diff_two_revs | |
178 | @repository.fetch_changesets |
|
178 | @repository.fetch_changesets | |
179 | @repository.reload |
|
179 | @repository.reload | |
180 |
|
180 | |||
181 | get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
181 | get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', | |
182 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
182 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
183 | assert_response :success |
|
183 | assert_response :success | |
184 | assert_template 'diff' |
|
184 | assert_template 'diff' | |
185 |
|
185 | |||
186 | diff = assigns(:diff) |
|
186 | diff = assigns(:diff) | |
187 | assert_not_nil diff |
|
187 | assert_not_nil diff | |
188 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ |
|
188 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | def test_annotate |
|
191 | def test_annotate | |
192 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
192 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
193 | assert_response :success |
|
193 | assert_response :success | |
194 | assert_template 'annotate' |
|
194 | assert_template 'annotate' | |
195 | # Line 23, changeset 2f9c0091 |
|
195 | # Line 23, changeset 2f9c0091 | |
196 | assert_tag :tag => 'th', :content => '24', |
|
196 | assert_tag :tag => 'th', :content => '24', | |
197 | :sibling => { |
|
197 | :sibling => { | |
198 | :tag => 'td', |
|
198 | :tag => 'td', | |
199 | :child => { |
|
199 | :child => { | |
200 | :tag => 'a', |
|
200 | :tag => 'a', | |
201 | :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/ |
|
201 | :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/ | |
202 | } |
|
202 | } | |
203 | }, |
|
203 | }, | |
204 | :sibling => { :tag => 'td', :content => /jsmith/ }, |
|
204 | :sibling => { :tag => 'td', :content => /jsmith/ }, | |
205 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
205 | :sibling => { :tag => 'td', :content => /watcher =/ } | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def test_annotate_at_given_revision |
|
208 | def test_annotate_at_given_revision | |
209 | @repository.fetch_changesets |
|
209 | @repository.fetch_changesets | |
210 | @repository.reload |
|
210 | @repository.reload | |
211 | get :annotate, :id => 3, :rev => 'deff7', :path => ['sources', 'watchers_controller.rb'] |
|
211 | get :annotate, :id => 3, :rev => 'deff7', :path => ['sources', 'watchers_controller.rb'] | |
212 | assert_response :success |
|
212 | assert_response :success | |
213 | assert_template 'annotate' |
|
213 | assert_template 'annotate' | |
214 | assert_tag :tag => 'h2', :content => /@ deff712f/ |
|
214 | assert_tag :tag => 'h2', :content => /@ deff712f/ | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_annotate_binary_file |
|
217 | def test_annotate_binary_file | |
218 | get :annotate, :id => 3, :path => ['images', 'edit.png'] |
|
218 | get :annotate, :id => 3, :path => ['images', 'edit.png'] | |
219 | assert_response 500 |
|
219 | assert_response 500 | |
220 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
220 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, | |
221 | :content => /cannot be annotated/ |
|
221 | :content => /cannot be annotated/ | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def test_revision |
|
224 | def test_revision | |
225 | @repository.fetch_changesets |
|
225 | @repository.fetch_changesets | |
226 | @repository.reload |
|
226 | @repository.reload | |
227 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| |
|
227 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| | |
228 | get :revision, :id => 3, :rev => r |
|
228 | get :revision, :id => 3, :rev => r | |
229 | assert_response :success |
|
229 | assert_response :success | |
230 | assert_template 'revision' |
|
230 | assert_template 'revision' | |
231 | end |
|
231 | end | |
232 | end |
|
232 | end | |
233 |
|
233 | |||
234 | def test_empty_revision |
|
234 | def test_empty_revision | |
235 | @repository.fetch_changesets |
|
235 | @repository.fetch_changesets | |
236 | @repository.reload |
|
236 | @repository.reload | |
237 | ['', ' ', nil].each do |r| |
|
237 | ['', ' ', nil].each do |r| | |
238 | get :revision, :id => 3, :rev => r |
|
238 | get :revision, :id => 3, :rev => r | |
239 | assert_response 404 |
|
239 | assert_response 404 | |
240 | assert_error_tag :content => /was not found/ |
|
240 | assert_error_tag :content => /was not found/ | |
241 | end |
|
241 | end | |
242 | end |
|
242 | end | |
243 | else |
|
243 | else | |
244 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" |
|
244 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" | |
245 | def test_fake; assert true end |
|
245 | def test_fake; assert true end | |
246 | end |
|
246 | end | |
247 | end |
|
247 | end |
General Comments 0
You need to be logged in to leave comments.
Login now