##// END OF EJS Templates
scm: mercurial: fix revision at functional diff test....
Toshi MARUYAMA -
r4598:2b24b6c9bb40
parent child
Show More
@@ -1,212 +1,212
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 RepositoriesMercurialControllerTest < 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/mercurial_repository'
29 29
30 30 def setup
31 31 @controller = RepositoriesController.new
32 32 @request = ActionController::TestRequest.new
33 33 @response = ActionController::TestResponse.new
34 34 User.current = nil
35 35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 36 assert @repository
37 37 end
38 38
39 39 if File.directory?(REPOSITORY_PATH)
40 40 def test_show
41 41 get :show, :id => 3
42 42 assert_response :success
43 43 assert_template 'show'
44 44 assert_not_nil assigns(:entries)
45 45 assert_not_nil assigns(:changesets)
46 46 end
47
47
48 48 def test_show_root
49 49 get :show, :id => 3
50 50 assert_response :success
51 51 assert_template 'show'
52 52 assert_not_nil assigns(:entries)
53 53 assert_equal 4, assigns(:entries).size
54 54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 57 end
58
58
59 59 def test_show_directory
60 60 get :show, :id => 3, :path => ['images']
61 61 assert_response :success
62 62 assert_template 'show'
63 63 assert_not_nil assigns(:entries)
64 64 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
65 65 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
66 66 assert_not_nil entry
67 67 assert_equal 'file', entry.kind
68 68 assert_equal 'images/edit.png', entry.path
69 69 end
70 70
71 71 def test_show_at_given_revision
72 72 [0, '0', '0885933ad4f6'].each do |r1|
73 73 get :show, :id => 3, :path => ['images'], :rev => r1
74 74 assert_response :success
75 75 assert_template 'show'
76 76 assert_not_nil assigns(:entries)
77 77 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
78 78 end
79 79 end
80 80
81 81 def test_show_directory_sql_escape_percent
82 82 [13, '13', '3a330eb32958'].each do |r1|
83 83 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
84 84 assert_response :success
85 85 assert_template 'show'
86 86
87 87 assert_not_nil assigns(:entries)
88 88 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
89 89 changesets = assigns(:changesets)
90 90
91 91 ## This is not yet implemented.
92 92 # assert_not_nil changesets
93 93 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
94 94 end
95 95 end
96 96
97 97 def test_changes
98 98 get :changes, :id => 3, :path => ['images', 'edit.png']
99 99 assert_response :success
100 100 assert_template 'changes'
101 101 assert_tag :tag => 'h2', :content => 'edit.png'
102 102 end
103 103
104 104 def test_entry_show
105 105 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
106 106 assert_response :success
107 107 assert_template 'entry'
108 108 # Line 10
109 109 assert_tag :tag => 'th',
110 110 :content => '10',
111 111 :attributes => { :class => 'line-num' },
112 112 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
113 113 end
114 114
115 115 def test_entry_download
116 116 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
117 117 assert_response :success
118 118 # File content
119 119 assert @response.body.include?('WITHOUT ANY WARRANTY')
120 120 end
121 121
122 122 def test_directory_entry
123 123 get :entry, :id => 3, :path => ['sources']
124 124 assert_response :success
125 125 assert_template 'show'
126 126 assert_not_nil assigns(:entry)
127 127 assert_equal 'sources', assigns(:entry).name
128 128 end
129 129
130 130 def test_diff
131 131 @repository.fetch_changesets
132 132 @repository.reload
133 133
134 134 [4, '4', 'def6d2f1254a'].each do |r1|
135 135 # Full diff of changeset 4
136 get :diff, :id => 3, :rev => 4
136 get :diff, :id => 3, :rev => r1
137 137 assert_response :success
138 138 assert_template 'diff'
139 139
140 140 if @repository.scm.class.client_version_above?([1, 2])
141 141 # Line 22 removed
142 142 assert_tag :tag => 'th',
143 143 :content => '22',
144 144 :sibling => { :tag => 'td',
145 145 :attributes => { :class => /diff_out/ },
146 146 :content => /def remove/ }
147 147 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
148 148 end
149 149 end
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 [2, '400bb8672109', '400', 400].each do |r1|
157 157 [4, 'def6d2f1254a'].each do |r2|
158 158 get :diff, :id => 3, :rev => r1,
159 159 :rev_to => r2
160 160 assert_response :success
161 161 assert_template 'diff'
162 162
163 163 diff = assigns(:diff)
164 164 assert_not_nil diff
165 165 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
166 166 end
167 167 end
168 168 end
169 169
170 170 def test_annotate
171 171 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
172 172 assert_response :success
173 173 assert_template 'annotate'
174 174 # Line 23, revision 4:def6d2f1254a
175 175 assert_tag :tag => 'th',
176 176 :content => '23',
177 177 :attributes => { :class => 'line-num' },
178 178 :sibling =>
179 179 {
180 180 :tag => 'td',
181 181 :attributes => { :class => 'revision' },
182 182 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
183 183 }
184 184 assert_tag :tag => 'th',
185 185 :content => '23',
186 186 :attributes => { :class => 'line-num' },
187 187 :sibling =>
188 188 {
189 189 :tag => 'td' ,
190 190 :content => 'jsmith' ,
191 191 :attributes => { :class => 'author' },
192 192 }
193 193 assert_tag :tag => 'th',
194 194 :content => '23',
195 195 :attributes => { :class => 'line-num' },
196 196 :sibling => { :tag => 'td', :content => /watcher =/ }
197 197 end
198 198
199 199 def test_empty_revision
200 200 @repository.fetch_changesets
201 201 @repository.reload
202 202 ['', ' ', nil].each do |r|
203 203 get :revision, :id => 3, :rev => r
204 204 assert_response 404
205 205 assert_error_tag :content => /was not found/
206 206 end
207 207 end
208 208 else
209 209 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
210 210 def test_fake; assert true end
211 211 end
212 212 end
General Comments 0
You need to be logged in to leave comments. Login now