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