comparison test/functional/.svn/text-base/repositories_subversion_controller_test.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children 94944d00e43c
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
24 class RepositoriesSubversionControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28
29 def setup
30 @controller = RepositoriesController.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
33 Setting.default_language = 'en'
34 User.current = nil
35 end
36
37 if repository_configured?('subversion')
38 def test_show
39 get :show, :id => 1
40 assert_response :success
41 assert_template 'show'
42 assert_not_nil assigns(:entries)
43 assert_not_nil assigns(:changesets)
44 end
45
46 def test_browse_root
47 get :show, :id => 1
48 assert_response :success
49 assert_template 'show'
50 assert_not_nil assigns(:entries)
51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
52 assert_equal 'dir', entry.kind
53 end
54
55 def test_browse_directory
56 get :show, :id => 1, :path => ['subversion_test']
57 assert_response :success
58 assert_template 'show'
59 assert_not_nil assigns(:entries)
60 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
61 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
62 assert_equal 'file', entry.kind
63 assert_equal 'subversion_test/helloworld.c', entry.path
64 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
65 end
66
67 def test_browse_at_given_revision
68 get :show, :id => 1, :path => ['subversion_test'], :rev => 4
69 assert_response :success
70 assert_template 'show'
71 assert_not_nil assigns(:entries)
72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
73 end
74
75 def test_file_changes
76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
77 assert_response :success
78 assert_template 'changes'
79
80 changesets = assigns(:changesets)
81 assert_not_nil changesets
82 assert_equal %w(6 3 2), changesets.collect(&:revision)
83
84 # svn properties displayed with svn >= 1.5 only
85 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
86 assert_not_nil assigns(:properties)
87 assert_equal 'native', assigns(:properties)['svn:eol-style']
88 assert_tag :ul,
89 :child => { :tag => 'li',
90 :child => { :tag => 'b', :content => 'svn:eol-style' },
91 :child => { :tag => 'span', :content => 'native' } }
92 end
93 end
94
95 def test_directory_changes
96 get :changes, :id => 1, :path => ['subversion_test', 'folder' ]
97 assert_response :success
98 assert_template 'changes'
99
100 changesets = assigns(:changesets)
101 assert_not_nil changesets
102 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
103 end
104
105 def test_entry
106 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
107 assert_response :success
108 assert_template 'entry'
109 end
110
111 def test_entry_should_send_if_too_big
112 # no files in the test repo is larger than 1KB...
113 with_settings :file_max_size_displayed => 0 do
114 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
115 assert_response :success
116 assert_template ''
117 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
118 end
119 end
120
121 def test_entry_at_given_revision
122 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
123 assert_response :success
124 assert_template 'entry'
125 # this line was removed in r3 and file was moved in r6
126 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
127 :content => /Here's the code/
128 end
129
130 def test_entry_not_found
131 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
132 assert_tag :tag => 'div', :attributes => { :class => /error/ },
133 :content => /The entry or revision was not found in the repository/
134 end
135
136 def test_entry_download
137 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
138 assert_response :success
139 assert_template ''
140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
141 end
142
143 def test_directory_entry
144 get :entry, :id => 1, :path => ['subversion_test', 'folder']
145 assert_response :success
146 assert_template 'show'
147 assert_not_nil assigns(:entry)
148 assert_equal 'folder', assigns(:entry).name
149 end
150
151 def test_revision
152 get :revision, :id => 1, :rev => 2
153 assert_response :success
154 assert_template 'revision'
155 assert_tag :tag => 'ul',
156 :child => { :tag => 'li',
157 # link to the entry at rev 2
158 :child => { :tag => 'a',
159 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
160 :content => 'repo',
161 # link to partial diff
162 :sibling => { :tag => 'a',
163 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
164 }
165 }
166 }
167 end
168
169 def test_revision_with_repository_pointing_to_a_subdirectory
170 r = Project.find(1).repository
171 # Changes repository url to a subdirectory
172 r.update_attribute :url, (r.url + '/test/some')
173
174 get :revision, :id => 1, :rev => 2
175 assert_response :success
176 assert_template 'revision'
177 assert_tag :tag => 'ul',
178 :child => { :tag => 'li',
179 # link to the entry at rev 2
180 :child => { :tag => 'a',
181 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
182 :content => 'repo',
183 # link to partial diff
184 :sibling => { :tag => 'a',
185 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
186 }
187 }
188 }
189 end
190
191 def test_revision_diff
192 get :diff, :id => 1, :rev => 3
193 assert_response :success
194 assert_template 'diff'
195 end
196
197 def test_directory_diff
198 get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
199 assert_response :success
200 assert_template 'diff'
201
202 diff = assigns(:diff)
203 assert_not_nil diff
204 # 2 files modified
205 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
206 end
207
208 def test_annotate
209 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
210 assert_response :success
211 assert_template 'annotate'
212 end
213 else
214 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
215 def test_fake; assert true end
216 end
217 end