Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'repositories_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class RepositoriesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
|
Chris@0
|
26
|
Chris@0
|
27 # No '..' in the repository path
|
Chris@0
|
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
Chris@0
|
29
|
Chris@0
|
30 def setup
|
Chris@0
|
31 @controller = RepositoriesController.new
|
Chris@0
|
32 @request = ActionController::TestRequest.new
|
Chris@0
|
33 @response = ActionController::TestResponse.new
|
Chris@0
|
34 User.current = nil
|
Chris@119
|
35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
Chris@119
|
36 assert @repository
|
Chris@245
|
37 @diff_c_support = true
|
Chris@0
|
38 end
|
Chris@119
|
39
|
Chris@0
|
40 if File.directory?(REPOSITORY_PATH)
|
Chris@0
|
41 def test_show
|
Chris@0
|
42 get :show, :id => 3
|
Chris@0
|
43 assert_response :success
|
Chris@0
|
44 assert_template 'show'
|
Chris@0
|
45 assert_not_nil assigns(:entries)
|
Chris@0
|
46 assert_not_nil assigns(:changesets)
|
Chris@0
|
47 end
|
Chris@128
|
48
|
Chris@0
|
49 def test_show_root
|
Chris@0
|
50 get :show, :id => 3
|
Chris@0
|
51 assert_response :success
|
Chris@0
|
52 assert_template 'show'
|
Chris@0
|
53 assert_not_nil assigns(:entries)
|
Chris@119
|
54 assert_equal 4, assigns(:entries).size
|
Chris@119
|
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
Chris@0
|
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
Chris@119
|
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
Chris@0
|
58 end
|
Chris@128
|
59
|
Chris@0
|
60 def test_show_directory
|
Chris@0
|
61 get :show, :id => 3, :path => ['images']
|
Chris@0
|
62 assert_response :success
|
Chris@0
|
63 assert_template 'show'
|
Chris@0
|
64 assert_not_nil assigns(:entries)
|
Chris@0
|
65 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
Chris@0
|
67 assert_not_nil entry
|
Chris@0
|
68 assert_equal 'file', entry.kind
|
Chris@0
|
69 assert_equal 'images/edit.png', entry.path
|
Chris@0
|
70 end
|
Chris@119
|
71
|
Chris@0
|
72 def test_show_at_given_revision
|
Chris@119
|
73 [0, '0', '0885933ad4f6'].each do |r1|
|
Chris@119
|
74 get :show, :id => 3, :path => ['images'], :rev => r1
|
Chris@119
|
75 assert_response :success
|
Chris@119
|
76 assert_template 'show'
|
Chris@119
|
77 assert_not_nil assigns(:entries)
|
Chris@119
|
78 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
Chris@119
|
79 end
|
Chris@0
|
80 end
|
Chris@119
|
81
|
Chris@119
|
82 def test_show_directory_sql_escape_percent
|
Chris@119
|
83 [13, '13', '3a330eb32958'].each do |r1|
|
Chris@119
|
84 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
|
Chris@119
|
85 assert_response :success
|
Chris@119
|
86 assert_template 'show'
|
Chris@119
|
87
|
Chris@119
|
88 assert_not_nil assigns(:entries)
|
Chris@119
|
89 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
|
Chris@119
|
90 changesets = assigns(:changesets)
|
Chris@119
|
91
|
Chris@119
|
92 ## This is not yet implemented.
|
Chris@119
|
93 # assert_not_nil changesets
|
Chris@119
|
94 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
|
Chris@119
|
95 end
|
Chris@119
|
96 end
|
Chris@119
|
97
|
Chris@0
|
98 def test_changes
|
Chris@0
|
99 get :changes, :id => 3, :path => ['images', 'edit.png']
|
Chris@0
|
100 assert_response :success
|
Chris@0
|
101 assert_template 'changes'
|
Chris@0
|
102 assert_tag :tag => 'h2', :content => 'edit.png'
|
Chris@0
|
103 end
|
Chris@0
|
104
|
Chris@0
|
105 def test_entry_show
|
Chris@0
|
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
Chris@0
|
107 assert_response :success
|
Chris@0
|
108 assert_template 'entry'
|
Chris@119
|
109 # Line 10
|
Chris@0
|
110 assert_tag :tag => 'th',
|
Chris@119
|
111 :content => '10',
|
Chris@119
|
112 :attributes => { :class => 'line-num' },
|
Chris@0
|
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
|
Chris@0
|
114 end
|
Chris@0
|
115
|
Chris@0
|
116 def test_entry_download
|
Chris@0
|
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
|
Chris@0
|
118 assert_response :success
|
Chris@0
|
119 # File content
|
Chris@0
|
120 assert @response.body.include?('WITHOUT ANY WARRANTY')
|
Chris@0
|
121 end
|
Chris@0
|
122
|
Chris@0
|
123 def test_directory_entry
|
Chris@0
|
124 get :entry, :id => 3, :path => ['sources']
|
Chris@0
|
125 assert_response :success
|
Chris@0
|
126 assert_template 'show'
|
Chris@0
|
127 assert_not_nil assigns(:entry)
|
Chris@0
|
128 assert_equal 'sources', assigns(:entry).name
|
Chris@0
|
129 end
|
Chris@0
|
130
|
Chris@0
|
131 def test_diff
|
Chris@119
|
132 @repository.fetch_changesets
|
Chris@119
|
133 @repository.reload
|
Chris@119
|
134
|
Chris@119
|
135 [4, '4', 'def6d2f1254a'].each do |r1|
|
Chris@119
|
136 # Full diff of changeset 4
|
Chris@128
|
137 get :diff, :id => 3, :rev => r1
|
Chris@119
|
138 assert_response :success
|
Chris@119
|
139 assert_template 'diff'
|
Chris@119
|
140
|
Chris@245
|
141 if @diff_c_support
|
Chris@119
|
142 # Line 22 removed
|
Chris@119
|
143 assert_tag :tag => 'th',
|
Chris@119
|
144 :content => '22',
|
Chris@119
|
145 :sibling => { :tag => 'td',
|
Chris@119
|
146 :attributes => { :class => /diff_out/ },
|
Chris@119
|
147 :content => /def remove/ }
|
Chris@119
|
148 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
|
Chris@119
|
149 end
|
Chris@119
|
150 end
|
Chris@0
|
151 end
|
Chris@119
|
152
|
Chris@119
|
153 def test_diff_two_revs
|
Chris@119
|
154 @repository.fetch_changesets
|
Chris@119
|
155 @repository.reload
|
Chris@119
|
156
|
Chris@119
|
157 [2, '400bb8672109', '400', 400].each do |r1|
|
Chris@119
|
158 [4, 'def6d2f1254a'].each do |r2|
|
Chris@119
|
159 get :diff, :id => 3, :rev => r1,
|
Chris@119
|
160 :rev_to => r2
|
Chris@119
|
161 assert_response :success
|
Chris@119
|
162 assert_template 'diff'
|
Chris@119
|
163
|
Chris@119
|
164 diff = assigns(:diff)
|
Chris@119
|
165 assert_not_nil diff
|
Chris@119
|
166 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
|
Chris@119
|
167 end
|
Chris@119
|
168 end
|
Chris@119
|
169 end
|
Chris@119
|
170
|
Chris@0
|
171 def test_annotate
|
Chris@0
|
172 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
Chris@0
|
173 assert_response :success
|
Chris@0
|
174 assert_template 'annotate'
|
Chris@119
|
175 # Line 23, revision 4:def6d2f1254a
|
Chris@119
|
176 assert_tag :tag => 'th',
|
Chris@119
|
177 :content => '23',
|
Chris@119
|
178 :attributes => { :class => 'line-num' },
|
Chris@119
|
179 :sibling =>
|
Chris@119
|
180 {
|
Chris@119
|
181 :tag => 'td',
|
Chris@119
|
182 :attributes => { :class => 'revision' },
|
Chris@119
|
183 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
|
Chris@119
|
184 }
|
Chris@119
|
185 assert_tag :tag => 'th',
|
Chris@119
|
186 :content => '23',
|
Chris@119
|
187 :attributes => { :class => 'line-num' },
|
Chris@119
|
188 :sibling =>
|
Chris@119
|
189 {
|
Chris@119
|
190 :tag => 'td' ,
|
Chris@119
|
191 :content => 'jsmith' ,
|
Chris@119
|
192 :attributes => { :class => 'author' },
|
Chris@119
|
193 }
|
Chris@119
|
194 assert_tag :tag => 'th',
|
Chris@119
|
195 :content => '23',
|
Chris@119
|
196 :attributes => { :class => 'line-num' },
|
Chris@0
|
197 :sibling => { :tag => 'td', :content => /watcher =/ }
|
Chris@0
|
198 end
|
Chris@119
|
199
|
Chris@210
|
200 def test_annotate_at_given_revision
|
Chris@210
|
201 @repository.fetch_changesets
|
Chris@210
|
202 @repository.reload
|
Chris@210
|
203 [2, '400bb8672109', '400', 400].each do |r1|
|
Chris@210
|
204 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
|
Chris@210
|
205 assert_response :success
|
Chris@210
|
206 assert_template 'annotate'
|
Chris@210
|
207 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
|
Chris@210
|
208 end
|
Chris@210
|
209 end
|
Chris@210
|
210
|
Chris@119
|
211 def test_empty_revision
|
Chris@119
|
212 @repository.fetch_changesets
|
Chris@119
|
213 @repository.reload
|
Chris@119
|
214 ['', ' ', nil].each do |r|
|
Chris@128
|
215 get :revision, :id => 3, :rev => r
|
Chris@128
|
216 assert_response 404
|
Chris@119
|
217 assert_error_tag :content => /was not found/
|
Chris@119
|
218 end
|
Chris@119
|
219 end
|
Chris@0
|
220 else
|
Chris@0
|
221 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
|
Chris@0
|
222 def test_fake; assert true end
|
Chris@0
|
223 end
|
Chris@0
|
224 end
|