@@ -1,212 +1,214 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 | 42 | @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), |
|
43 | 43 | :root_url => REPOSITORY_PATH, |
|
44 | 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_browse_root |
|
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_equal 3, assigns(:entries).size |
|
58 | 58 | |
|
59 | 59 | entry = assigns(:entries).detect {|e| e.name == 'images'} |
|
60 | 60 | assert_equal 'dir', entry.kind |
|
61 | 61 | |
|
62 | 62 | entry = assigns(:entries).detect {|e| e.name == 'README'} |
|
63 | 63 | assert_equal 'file', entry.kind |
|
64 | 64 | |
|
65 | 65 | assert_not_nil assigns(:changesets) |
|
66 | 66 | assigns(:changesets).size > 0 |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_browse_directory |
|
70 | 70 | @repository.fetch_changesets |
|
71 | 71 | @repository.reload |
|
72 | 72 | get :show, :id => PRJ_ID, :path => ['images'] |
|
73 | 73 | assert_response :success |
|
74 | 74 | assert_template 'show' |
|
75 | 75 | assert_not_nil assigns(:entries) |
|
76 | 76 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
77 | 77 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
78 | 78 | assert_not_nil entry |
|
79 | 79 | assert_equal 'file', entry.kind |
|
80 | 80 | assert_equal 'images/edit.png', entry.path |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def test_browse_at_given_revision |
|
84 | 84 | @repository.fetch_changesets |
|
85 | 85 | @repository.reload |
|
86 | 86 | get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 |
|
87 | 87 | assert_response :success |
|
88 | 88 | assert_template 'show' |
|
89 | 89 | assert_not_nil assigns(:entries) |
|
90 | 90 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_entry |
|
94 | 94 | @repository.fetch_changesets |
|
95 | 95 | @repository.reload |
|
96 | 96 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
97 | 97 | assert_response :success |
|
98 | 98 | assert_template 'entry' |
|
99 | 99 | assert_no_tag :tag => 'td', |
|
100 | 100 | :attributes => { :class => /line-code/}, |
|
101 | 101 | :content => /before_filter/ |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def test_entry_at_given_revision |
|
105 | 105 | # changesets must be loaded |
|
106 | 106 | @repository.fetch_changesets |
|
107 | 107 | @repository.reload |
|
108 | 108 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2 |
|
109 | 109 | assert_response :success |
|
110 | 110 | assert_template 'entry' |
|
111 | 111 | # this line was removed in r3 |
|
112 | 112 | assert_tag :tag => 'td', |
|
113 | 113 | :attributes => { :class => /line-code/}, |
|
114 | 114 | :content => /before_filter/ |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_entry_not_found |
|
118 | 118 | @repository.fetch_changesets |
|
119 | 119 | @repository.reload |
|
120 | 120 | get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c'] |
|
121 | 121 | assert_tag :tag => 'p', |
|
122 | 122 | :attributes => { :id => /errorExplanation/ }, |
|
123 | 123 | :content => /The entry or revision was not found in the repository/ |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_entry_download |
|
127 | 127 | @repository.fetch_changesets |
|
128 | 128 | @repository.reload |
|
129 | 129 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
130 | 130 | assert_response :success |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def test_directory_entry |
|
134 | 134 | @repository.fetch_changesets |
|
135 | 135 | @repository.reload |
|
136 | 136 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
137 | 137 | assert_response :success |
|
138 | 138 | assert_template 'show' |
|
139 | 139 | assert_not_nil assigns(:entry) |
|
140 | 140 | assert_equal 'sources', assigns(:entry).name |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | def test_diff |
|
144 | 144 | @repository.fetch_changesets |
|
145 | 145 | @repository.reload |
|
146 | get :diff, :id => PRJ_ID, :rev => 3, :type => 'inline' | |
|
147 | assert_response :success | |
|
148 | assert_template 'diff' | |
|
149 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, | |
|
150 | :content => /before_filter :require_login/ | |
|
151 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
|
152 | :content => /with one change/ | |
|
146 | ['inline', 'sbs'].each do |dt| | |
|
147 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt | |
|
148 | assert_response :success | |
|
149 | assert_template 'diff' | |
|
150 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, | |
|
151 | :content => /before_filter :require_login/ | |
|
152 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, | |
|
153 | :content => /with one change/ | |
|
154 | end | |
|
153 | 155 | end |
|
154 | 156 | |
|
155 | 157 | def test_diff_new_files |
|
156 | 158 | @repository.fetch_changesets |
|
157 | 159 | @repository.reload |
|
158 | 160 | get :diff, :id => PRJ_ID, :rev => 1, :type => 'inline' |
|
159 | 161 | assert_response :success |
|
160 | 162 | assert_template 'diff' |
|
161 | 163 | assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, |
|
162 | 164 | :content => /watched.remove_watcher/ |
|
163 | 165 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
164 | 166 | :content => /test\/README/ |
|
165 | 167 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
166 | 168 | :content => /test\/images\/delete.png / |
|
167 | 169 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
168 | 170 | :content => /test\/images\/edit.png/ |
|
169 | 171 | assert_tag :tag => 'th', :attributes => { :class => 'filename' }, |
|
170 | 172 | :content => /test\/sources\/watchers_controller.rb/ |
|
171 | 173 | end |
|
172 | 174 | |
|
173 | 175 | def test_annotate |
|
174 | 176 | @repository.fetch_changesets |
|
175 | 177 | @repository.reload |
|
176 | 178 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
177 | 179 | assert_response :success |
|
178 | 180 | assert_template 'annotate' |
|
179 | 181 | # 1.1 line |
|
180 | 182 | assert_tag :tag => 'th', |
|
181 | 183 | :attributes => { :class => 'line-num' }, |
|
182 | 184 | :content => '18', |
|
183 | 185 | :sibling => { |
|
184 | 186 | :tag => 'td', |
|
185 | 187 | :attributes => { :class => 'revision' }, |
|
186 | 188 | :content => /1.1/, |
|
187 | 189 | :sibling => { |
|
188 | 190 | :tag => 'td', |
|
189 | 191 | :attributes => { :class => 'author' }, |
|
190 | 192 | :content => /LANG/ |
|
191 | 193 | } |
|
192 | 194 | } |
|
193 | 195 | # 1.2 line |
|
194 | 196 | assert_tag :tag => 'th', |
|
195 | 197 | :attributes => { :class => 'line-num' }, |
|
196 | 198 | :content => '32', |
|
197 | 199 | :sibling => { |
|
198 | 200 | :tag => 'td', |
|
199 | 201 | :attributes => { :class => 'revision' }, |
|
200 | 202 | :content => /1.2/, |
|
201 | 203 | :sibling => { |
|
202 | 204 | :tag => 'td', |
|
203 | 205 | :attributes => { :class => 'author' }, |
|
204 | 206 | :content => /LANG/ |
|
205 | 207 | } |
|
206 | 208 | } |
|
207 | 209 | end |
|
208 | 210 | else |
|
209 | 211 | puts "CVS test repository NOT FOUND. Skipping functional tests !!!" |
|
210 | 212 | def test_fake; assert true end |
|
211 | 213 | end |
|
212 | 214 | end |
General Comments 0
You need to be logged in to leave comments.
Login now