##// END OF EJS Templates
scm: mercurial: functional test for accept both of revision number and changeset id (#3724)....
Toshi MARUYAMA -
r4544:a223a0dffdca
parent child
Show More
@@ -1,170 +1,176
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::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 end
36 end
37
37
38 if File.directory?(REPOSITORY_PATH)
38 if File.directory?(REPOSITORY_PATH)
39 def test_show
39 def test_show
40 get :show, :id => 3
40 get :show, :id => 3
41 assert_response :success
41 assert_response :success
42 assert_template 'show'
42 assert_template 'show'
43 assert_not_nil assigns(:entries)
43 assert_not_nil assigns(:entries)
44 assert_not_nil assigns(:changesets)
44 assert_not_nil assigns(:changesets)
45 end
45 end
46
46
47 def test_show_root
47 def test_show_root
48 get :show, :id => 3
48 get :show, :id => 3
49 assert_response :success
49 assert_response :success
50 assert_template 'show'
50 assert_template 'show'
51 assert_not_nil assigns(:entries)
51 assert_not_nil assigns(:entries)
52 assert_equal 4, assigns(:entries).size
52 assert_equal 4, assigns(:entries).size
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
56 end
56 end
57
57
58 def test_show_directory
58 def test_show_directory
59 get :show, :id => 3, :path => ['images']
59 get :show, :id => 3, :path => ['images']
60 assert_response :success
60 assert_response :success
61 assert_template 'show'
61 assert_template 'show'
62 assert_not_nil assigns(:entries)
62 assert_not_nil assigns(:entries)
63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
65 assert_not_nil entry
65 assert_not_nil entry
66 assert_equal 'file', entry.kind
66 assert_equal 'file', entry.kind
67 assert_equal 'images/edit.png', entry.path
67 assert_equal 'images/edit.png', entry.path
68 end
68 end
69
69
70 def test_show_at_given_revision
70 def test_show_at_given_revision
71 get :show, :id => 3, :path => ['images'], :rev => 0
71 [0, '0', '0885933ad4f6'].each do |r1|
72 assert_response :success
72 get :show, :id => 3, :path => ['images'], :rev => r1
73 assert_template 'show'
73 assert_response :success
74 assert_not_nil assigns(:entries)
74 assert_template 'show'
75 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
75 assert_not_nil assigns(:entries)
76 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
77 end
76 end
78 end
77
79
78 def test_show_directory_sql_escape_percent
80 def test_show_directory_sql_escape_percent
79 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => 13
81 [13, '13', '3a330eb32958'].each do |r1|
80 assert_response :success
82 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
81 assert_template 'show'
83 assert_response :success
84 assert_template 'show'
82
85
83 assert_not_nil assigns(:entries)
86 assert_not_nil assigns(:entries)
84 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
87 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
85 changesets = assigns(:changesets)
88 changesets = assigns(:changesets)
86
89
87 ## This is not yet implemented.
90 ## This is not yet implemented.
88 # assert_not_nil changesets
91 # assert_not_nil changesets
89 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
92 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
93 end
90 end
94 end
91
95
92 def test_changes
96 def test_changes
93 get :changes, :id => 3, :path => ['images', 'edit.png']
97 get :changes, :id => 3, :path => ['images', 'edit.png']
94 assert_response :success
98 assert_response :success
95 assert_template 'changes'
99 assert_template 'changes'
96 assert_tag :tag => 'h2', :content => 'edit.png'
100 assert_tag :tag => 'h2', :content => 'edit.png'
97 end
101 end
98
102
99 def test_entry_show
103 def test_entry_show
100 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
104 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
101 assert_response :success
105 assert_response :success
102 assert_template 'entry'
106 assert_template 'entry'
103 # Line 10
107 # Line 10
104 assert_tag :tag => 'th',
108 assert_tag :tag => 'th',
105 :content => '10',
109 :content => '10',
106 :attributes => { :class => 'line-num' },
110 :attributes => { :class => 'line-num' },
107 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
111 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
108 end
112 end
109
113
110 def test_entry_download
114 def test_entry_download
111 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
115 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
112 assert_response :success
116 assert_response :success
113 # File content
117 # File content
114 assert @response.body.include?('WITHOUT ANY WARRANTY')
118 assert @response.body.include?('WITHOUT ANY WARRANTY')
115 end
119 end
116
120
117 def test_directory_entry
121 def test_directory_entry
118 get :entry, :id => 3, :path => ['sources']
122 get :entry, :id => 3, :path => ['sources']
119 assert_response :success
123 assert_response :success
120 assert_template 'show'
124 assert_template 'show'
121 assert_not_nil assigns(:entry)
125 assert_not_nil assigns(:entry)
122 assert_equal 'sources', assigns(:entry).name
126 assert_equal 'sources', assigns(:entry).name
123 end
127 end
124
128
125 def test_diff
129 def test_diff
126 # Full diff of changeset 4
130 [4, '4', 'def6d2f1254a'].each do |r1|
127 get :diff, :id => 3, :rev => 4
131 # Full diff of changeset 4
128 assert_response :success
132 get :diff, :id => 3, :rev => 4
129 assert_template 'diff'
133 assert_response :success
130 # Line 22 removed
134 assert_template 'diff'
131 assert_tag :tag => 'th',
135 # Line 22 removed
132 :content => '22',
136 assert_tag :tag => 'th',
133 :sibling => { :tag => 'td',
137 :content => '22',
134 :attributes => { :class => /diff_out/ },
138 :sibling => { :tag => 'td',
135 :content => /def remove/ }
139 :attributes => { :class => /diff_out/ },
140 :content => /def remove/ }
141 end
136 end
142 end
137
143
138 def test_annotate
144 def test_annotate
139 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
145 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
140 assert_response :success
146 assert_response :success
141 assert_template 'annotate'
147 assert_template 'annotate'
142 # Line 23, revision 4:def6d2f1254a
148 # Line 23, revision 4:def6d2f1254a
143 assert_tag :tag => 'th',
149 assert_tag :tag => 'th',
144 :content => '23',
150 :content => '23',
145 :attributes => { :class => 'line-num' },
151 :attributes => { :class => 'line-num' },
146 :sibling =>
152 :sibling =>
147 {
153 {
148 :tag => 'td',
154 :tag => 'td',
149 :attributes => { :class => 'revision' },
155 :attributes => { :class => 'revision' },
150 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
156 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
151 }
157 }
152 assert_tag :tag => 'th',
158 assert_tag :tag => 'th',
153 :content => '23',
159 :content => '23',
154 :attributes => { :class => 'line-num' },
160 :attributes => { :class => 'line-num' },
155 :sibling =>
161 :sibling =>
156 {
162 {
157 :tag => 'td' ,
163 :tag => 'td' ,
158 :content => 'jsmith' ,
164 :content => 'jsmith' ,
159 :attributes => { :class => 'author' },
165 :attributes => { :class => 'author' },
160 }
166 }
161 assert_tag :tag => 'th',
167 assert_tag :tag => 'th',
162 :content => '23',
168 :content => '23',
163 :attributes => { :class => 'line-num' },
169 :attributes => { :class => 'line-num' },
164 :sibling => { :tag => 'td', :content => /watcher =/ }
170 :sibling => { :tag => 'td', :content => /watcher =/ }
165 end
171 end
166 else
172 else
167 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
173 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
168 def test_fake; assert true end
174 def test_fake; assert true end
169 end
175 end
170 end
176 end
General Comments 0
You need to be logged in to leave comments. Login now