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