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