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