##// END OF EJS Templates
scm: cvs: code clean up functional test....
Toshi MARUYAMA -
r4961:f41848fda457
parent child
Show More
@@ -1,206 +1,206
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 RepositoriesCvsControllerTest < 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/cvs_repository'
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30 # CVS module
31 31 MODULE_NAME = 'test'
32 32 PRJ_ID = 3
33 33
34 34 def setup
35 35 @controller = RepositoriesController.new
36 36 @request = ActionController::TestRequest.new
37 37 @response = ActionController::TestResponse.new
38 38 Setting.default_language = 'en'
39 39 User.current = nil
40 40
41 41 @project = Project.find(PRJ_ID)
42 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
43 :root_url => REPOSITORY_PATH,
44 :url => MODULE_NAME,
42 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
43 :root_url => REPOSITORY_PATH,
44 :url => MODULE_NAME,
45 45 :log_encoding => 'UTF-8')
46 46 assert @repository
47 47 end
48
48
49 49 if File.directory?(REPOSITORY_PATH)
50 50 def test_show
51 51 @repository.fetch_changesets
52 52 @repository.reload
53 53 get :show, :id => PRJ_ID
54 54 assert_response :success
55 55 assert_template 'show'
56 56 assert_not_nil assigns(:entries)
57 57 assert_not_nil assigns(:changesets)
58 58 end
59
59
60 60 def test_browse_root
61 61 @repository.fetch_changesets
62 62 @repository.reload
63 63 get :show, :id => PRJ_ID
64 64 assert_response :success
65 65 assert_template 'show'
66 66 assert_not_nil assigns(:entries)
67 67 assert_equal 3, assigns(:entries).size
68
68
69 69 entry = assigns(:entries).detect {|e| e.name == 'images'}
70 70 assert_equal 'dir', entry.kind
71 71
72 72 entry = assigns(:entries).detect {|e| e.name == 'README'}
73 73 assert_equal 'file', entry.kind
74 74 end
75
75
76 76 def test_browse_directory
77 77 @repository.fetch_changesets
78 78 @repository.reload
79 79 get :show, :id => PRJ_ID, :path => ['images']
80 80 assert_response :success
81 81 assert_template 'show'
82 82 assert_not_nil assigns(:entries)
83 83 assert_equal ['add.png', 'delete.png', '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 @repository.fetch_changesets
92 92 @repository.reload
93 93 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
94 94 assert_response :success
95 95 assert_template 'show'
96 96 assert_not_nil assigns(:entries)
97 97 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
98 98 end
99
99
100 100 def test_entry
101 101 @repository.fetch_changesets
102 102 @repository.reload
103 103 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
104 104 assert_response :success
105 105 assert_template 'entry'
106 106 assert_no_tag :tag => 'td', :attributes => { :class => /line-code/},
107 107 :content => /before_filter/
108 108 end
109
109
110 110 def test_entry_at_given_revision
111 111 # changesets must be loaded
112 112 @repository.fetch_changesets
113 113 @repository.reload
114 114 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
115 115 assert_response :success
116 116 assert_template 'entry'
117 117 # this line was removed in r3
118 118 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
119 119 :content => /before_filter/
120 120 end
121
121
122 122 def test_entry_not_found
123 123 @repository.fetch_changesets
124 124 @repository.reload
125 125 get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
126 126 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
127 127 :content => /The entry or revision was not found in the repository/
128 128 end
129
129
130 130 def test_entry_download
131 131 @repository.fetch_changesets
132 132 @repository.reload
133 133 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
134 134 assert_response :success
135 135 end
136 136
137 137 def test_directory_entry
138 138 @repository.fetch_changesets
139 139 @repository.reload
140 140 get :entry, :id => PRJ_ID, :path => ['sources']
141 141 assert_response :success
142 142 assert_template 'show'
143 143 assert_not_nil assigns(:entry)
144 144 assert_equal 'sources', assigns(:entry).name
145 145 end
146
146
147 147 def test_diff
148 148 @repository.fetch_changesets
149 149 @repository.reload
150 150 get :diff, :id => PRJ_ID, :rev => 3, :type => 'inline'
151 151 assert_response :success
152 152 assert_template 'diff'
153 153 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
154 154 :content => /watched.remove_watcher/
155 155 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
156 156 :content => /watched.remove_all_watcher/
157 157 end
158
158
159 159 def test_diff_new_files
160 160 @repository.fetch_changesets
161 161 @repository.reload
162 162 get :diff, :id => PRJ_ID, :rev => 1, :type => 'inline'
163 163 assert_response :success
164 164 assert_template 'diff'
165 165 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
166 166 :content => /watched.remove_watcher/
167 167 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
168 168 :content => /test\/README/
169 169 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
170 170 :content => /test\/images\/delete.png /
171 171 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
172 172 :content => /test\/images\/edit.png/
173 173 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
174 :content => /test\/sources\/watchers_controller.rb/
174 :content => /test\/sources\/watchers_controller.rb/
175 175 end
176 176
177 177 def test_annotate
178 178 @repository.fetch_changesets
179 179 @repository.reload
180 180 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
181 181 assert_response :success
182 182 assert_template 'annotate'
183 183 # 1.1 line
184 184 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
185 185 :content => '18',
186 186 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
187 187 :content => /1.1/,
188 188 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
189 189 :content => /LANG/
190 190 }
191 191 }
192 192 # 1.2 line
193 193 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
194 194 :content => '32',
195 195 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
196 196 :content => /1.2/,
197 197 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
198 198 :content => /LANG/
199 199 }
200 200 }
201 201 end
202 202 else
203 203 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
204 204 def test_fake; assert true end
205 205 end
206 206 end
General Comments 0
You need to be logged in to leave comments. Login now