##// END OF EJS Templates
scm: git: use constant value for project id in functional test....
Toshi MARUYAMA -
r5576:02b43944e3b0
parent child
Show More
@@ -1,255 +1,257
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesGitControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 PRJ_ID = 3
30 31
31 32 def setup
32 33 @controller = RepositoriesController.new
33 34 @request = ActionController::TestRequest.new
34 35 @response = ActionController::TestResponse.new
35 36 User.current = nil
36 37 @repository = Repository::Git.create(
37 38 :project => Project.find(3),
38 39 :url => REPOSITORY_PATH,
39 40 :path_encoding => 'ISO-8859-1'
40 41 )
41 42 assert @repository
42 43 end
43 44
44 45 if File.directory?(REPOSITORY_PATH)
45 46 def test_browse_root
46 47 @repository.fetch_changesets
47 48 @repository.reload
48 get :show, :id => 3
49 get :show, :id => PRJ_ID
49 50 assert_response :success
50 51 assert_template 'show'
51 52 assert_not_nil assigns(:entries)
52 53 assert_equal 9, assigns(:entries).size
53 54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
54 55 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
55 56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 58 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
58 59 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
59 60 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
60 61 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
61 62 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
62 63 assert_not_nil assigns(:changesets)
63 64 assigns(:changesets).size > 0
64 65 end
65 66
66 67 def test_browse_branch
67 68 @repository.fetch_changesets
68 69 @repository.reload
69 get :show, :id => 3, :rev => 'test_branch'
70 get :show, :id => PRJ_ID, :rev => 'test_branch'
70 71 assert_response :success
71 72 assert_template 'show'
72 73 assert_not_nil assigns(:entries)
73 74 assert_equal 4, assigns(:entries).size
74 75 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
75 76 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 77 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 78 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
78 79 assert_not_nil assigns(:changesets)
79 80 assigns(:changesets).size > 0
80 81 end
81 82
82 83 def test_browse_tag
83 84 @repository.fetch_changesets
84 85 @repository.reload
85 86 [
86 87 "tag00.lightweight",
87 88 "tag01.annotated",
88 89 ].each do |t1|
89 get :show, :id => 3, :rev => t1
90 get :show, :id => PRJ_ID, :rev => t1
90 91 assert_response :success
91 92 assert_template 'show'
92 93 assert_not_nil assigns(:entries)
93 94 assigns(:entries).size > 0
94 95 assert_not_nil assigns(:changesets)
95 96 assigns(:changesets).size > 0
96 97 end
97 98 end
98 99
99 100 def test_browse_directory
100 101 @repository.fetch_changesets
101 102 @repository.reload
102 get :show, :id => 3, :path => ['images']
103 get :show, :id => PRJ_ID, :path => ['images']
103 104 assert_response :success
104 105 assert_template 'show'
105 106 assert_not_nil assigns(:entries)
106 107 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
107 108 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
108 109 assert_not_nil entry
109 110 assert_equal 'file', entry.kind
110 111 assert_equal 'images/edit.png', entry.path
111 112 assert_not_nil assigns(:changesets)
112 113 assigns(:changesets).size > 0
113 114 end
114 115
115 116 def test_browse_at_given_revision
116 117 @repository.fetch_changesets
117 118 @repository.reload
118 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
119 get :show, :id => PRJ_ID, :path => ['images'],
120 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
119 121 assert_response :success
120 122 assert_template 'show'
121 123 assert_not_nil assigns(:entries)
122 124 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
123 125 assert_not_nil assigns(:changesets)
124 126 assigns(:changesets).size > 0
125 127 end
126 128
127 129 def test_changes
128 get :changes, :id => 3, :path => ['images', 'edit.png']
130 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
129 131 assert_response :success
130 132 assert_template 'changes'
131 133 assert_tag :tag => 'h2', :content => 'edit.png'
132 134 end
133 135
134 136 def test_entry_show
135 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
137 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
136 138 assert_response :success
137 139 assert_template 'entry'
138 140 # Line 19
139 141 assert_tag :tag => 'th',
140 142 :content => '11',
141 143 :attributes => { :class => 'line-num' },
142 144 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
143 145 end
144 146
145 147 def test_entry_download
146 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
148 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
149 :format => 'raw'
147 150 assert_response :success
148 151 # File content
149 152 assert @response.body.include?('WITHOUT ANY WARRANTY')
150 153 end
151 154
152 155 def test_directory_entry
153 get :entry, :id => 3, :path => ['sources']
156 get :entry, :id => PRJ_ID, :path => ['sources']
154 157 assert_response :success
155 158 assert_template 'show'
156 159 assert_not_nil assigns(:entry)
157 160 assert_equal 'sources', assigns(:entry).name
158 161 end
159 162
160 163 def test_diff
161 164 @repository.fetch_changesets
162 165 @repository.reload
163
164 166 # Full diff of changeset 2f9c0091
165 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
167 get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
166 168 assert_response :success
167 169 assert_template 'diff'
168 170 # Line 22 removed
169 171 assert_tag :tag => 'th',
170 172 :content => /22/,
171 173 :sibling => { :tag => 'td',
172 174 :attributes => { :class => /diff_out/ },
173 175 :content => /def remove/ }
174 176 assert_tag :tag => 'h2', :content => /2f9c0091/
175 177 end
176 178
177 179 def test_diff_two_revs
178 180 @repository.fetch_changesets
179 181 @repository.reload
180
181 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
182 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
182 get :diff, :id => PRJ_ID,
183 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
184 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
183 185 assert_response :success
184 186 assert_template 'diff'
185
186 187 diff = assigns(:diff)
187 188 assert_not_nil diff
188 189 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
189 190 end
190 191
191 192 def test_annotate
192 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
193 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
193 194 assert_response :success
194 195 assert_template 'annotate'
195 196 # Line 23, changeset 2f9c0091
196 197 assert_tag :tag => 'th', :content => '24',
197 198 :sibling => {
198 199 :tag => 'td',
199 200 :child => {
200 201 :tag => 'a',
201 202 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
202 203 }
203 204 },
204 205 :sibling => { :tag => 'td', :content => /jsmith/ }
205 206 assert_tag :tag => 'th', :content => '24',
206 207 :sibling => {
207 208 :tag => 'td',
208 209 :child => {
209 210 :tag => 'a',
210 211 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
211 212 }
212 213 },
213 214 :sibling => { :tag => 'td', :content => /watcher =/ }
214 215 end
215 216
216 217 def test_annotate_at_given_revision
217 218 @repository.fetch_changesets
218 219 @repository.reload
219 get :annotate, :id => 3, :rev => 'deff7', :path => ['sources', 'watchers_controller.rb']
220 get :annotate, :id => PRJ_ID, :rev => 'deff7',
221 :path => ['sources', 'watchers_controller.rb']
220 222 assert_response :success
221 223 assert_template 'annotate'
222 224 assert_tag :tag => 'h2', :content => /@ deff712f/
223 225 end
224 226
225 227 def test_annotate_binary_file
226 get :annotate, :id => 3, :path => ['images', 'edit.png']
228 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
227 229 assert_response 500
228 230 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
229 231 :content => /cannot be annotated/
230 232 end
231 233
232 234 def test_revision
233 235 @repository.fetch_changesets
234 236 @repository.reload
235 237 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
236 get :revision, :id => 3, :rev => r
238 get :revision, :id => PRJ_ID, :rev => r
237 239 assert_response :success
238 240 assert_template 'revision'
239 241 end
240 242 end
241 243
242 244 def test_empty_revision
243 245 @repository.fetch_changesets
244 246 @repository.reload
245 247 ['', ' ', nil].each do |r|
246 get :revision, :id => 3, :rev => r
248 get :revision, :id => PRJ_ID, :rev => r
247 249 assert_response 404
248 250 assert_error_tag :content => /was not found/
249 251 end
250 252 end
251 253 else
252 254 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
253 255 def test_fake; assert true end
254 256 end
255 257 end
General Comments 0
You need to be logged in to leave comments. Login now