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