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