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