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