comparison .svn/pristine/af/af9af6c7e5a0647f8676df5d9cd78d394797b260.svn-base @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 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.expand_path('../../test_helper', __FILE__)
19
20 class RepositoriesControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
22 :repositories, :issues, :issue_statuses, :changesets, :changes,
23 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
24
25 def setup
26 User.current = nil
27 end
28
29 def test_new
30 @request.session[:user_id] = 1
31 get :new, :project_id => 'subproject1'
32 assert_response :success
33 assert_template 'new'
34 assert_kind_of Repository::Subversion, assigns(:repository)
35 assert assigns(:repository).new_record?
36 assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil}
37 end
38
39 def test_new_should_propose_enabled_scm_only
40 @request.session[:user_id] = 1
41 with_settings :enabled_scm => ['Mercurial', 'Git'] do
42 get :new, :project_id => 'subproject1'
43 end
44 assert_response :success
45 assert_template 'new'
46 assert_kind_of Repository::Mercurial, assigns(:repository)
47 assert_tag 'select', :attributes => {:name => 'repository_scm'},
48 :children => {:count => 3}
49 assert_tag 'select', :attributes => {:name => 'repository_scm'},
50 :child => {:tag => 'option', :attributes => {:value => 'Mercurial', :selected => 'selected'}}
51 assert_tag 'select', :attributes => {:name => 'repository_scm'},
52 :child => {:tag => 'option', :attributes => {:value => 'Git', :selected => nil}}
53 end
54
55 def test_create
56 @request.session[:user_id] = 1
57 assert_difference 'Repository.count' do
58 post :create, :project_id => 'subproject1',
59 :repository_scm => 'Subversion',
60 :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
61 end
62 assert_response 302
63 repository = Repository.order('id DESC').first
64 assert_kind_of Repository::Subversion, repository
65 assert_equal 'file:///test', repository.url
66 end
67
68 def test_create_with_failure
69 @request.session[:user_id] = 1
70 assert_no_difference 'Repository.count' do
71 post :create, :project_id => 'subproject1',
72 :repository_scm => 'Subversion',
73 :repository => {:url => 'invalid'}
74 end
75 assert_response :success
76 assert_template 'new'
77 assert_kind_of Repository::Subversion, assigns(:repository)
78 assert assigns(:repository).new_record?
79 end
80
81 def test_edit
82 @request.session[:user_id] = 1
83 get :edit, :id => 11
84 assert_response :success
85 assert_template 'edit'
86 assert_equal Repository.find(11), assigns(:repository)
87 assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'}
88 end
89
90 def test_update
91 @request.session[:user_id] = 1
92 put :update, :id => 11, :repository => {:password => 'test_update'}
93 assert_response 302
94 assert_equal 'test_update', Repository.find(11).password
95 end
96
97 def test_update_with_failure
98 @request.session[:user_id] = 1
99 put :update, :id => 11, :repository => {:password => 'x'*260}
100 assert_response :success
101 assert_template 'edit'
102 assert_equal Repository.find(11), assigns(:repository)
103 end
104
105 def test_destroy
106 @request.session[:user_id] = 1
107 assert_difference 'Repository.count', -1 do
108 delete :destroy, :id => 11
109 end
110 assert_response 302
111 assert_nil Repository.find_by_id(11)
112 end
113
114 def test_show_with_autofetch_changesets_enabled_should_fetch_changesets
115 Repository::Subversion.any_instance.expects(:fetch_changesets).once
116
117 with_settings :autofetch_changesets => '1' do
118 get :show, :id => 1
119 end
120 end
121
122 def test_show_with_autofetch_changesets_disabled_should_not_fetch_changesets
123 Repository::Subversion.any_instance.expects(:fetch_changesets).never
124
125 with_settings :autofetch_changesets => '0' do
126 get :show, :id => 1
127 end
128 end
129
130 def test_show_with_closed_project_should_not_fetch_changesets
131 Repository::Subversion.any_instance.expects(:fetch_changesets).never
132 Project.find(1).close
133
134 with_settings :autofetch_changesets => '1' do
135 get :show, :id => 1
136 end
137 end
138
139 def test_revisions
140 get :revisions, :id => 1
141 assert_response :success
142 assert_template 'revisions'
143 assert_equal Repository.find(10), assigns(:repository)
144 assert_not_nil assigns(:changesets)
145 end
146
147 def test_revisions_for_other_repository
148 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
149
150 get :revisions, :id => 1, :repository_id => 'foo'
151 assert_response :success
152 assert_template 'revisions'
153 assert_equal repository, assigns(:repository)
154 assert_not_nil assigns(:changesets)
155 end
156
157 def test_revisions_for_invalid_repository
158 get :revisions, :id => 1, :repository_id => 'foo'
159 assert_response 404
160 end
161
162 def test_revision
163 get :revision, :id => 1, :rev => 1
164 assert_response :success
165 assert_not_nil assigns(:changeset)
166 assert_equal "1", assigns(:changeset).revision
167 end
168
169 def test_revision_should_not_change_the_project_menu_link
170 get :revision, :id => 1, :rev => 1
171 assert_response :success
172
173 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/},
174 :ancestor => {:attributes => {:id => 'main-menu'}}
175 end
176
177 def test_revision_with_before_nil_and_afer_normal
178 get :revision, {:id => 1, :rev => 1}
179 assert_response :success
180 assert_template 'revision'
181 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
182 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
183 }
184 assert_tag :tag => "div", :attributes => { :class => "contextual" },
185 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
186 }
187 end
188
189 def test_add_related_issue
190 @request.session[:user_id] = 2
191 assert_difference 'Changeset.find(103).issues.size' do
192 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
193 assert_response :success
194 assert_template 'add_related_issue'
195 assert_equal 'text/javascript', response.content_type
196 end
197 assert_equal [2], Changeset.find(103).issue_ids
198 assert_include 'related-issues', response.body
199 assert_include 'Feature request #2', response.body
200 end
201
202 def test_add_related_issue_should_accept_issue_id_with_sharp
203 @request.session[:user_id] = 2
204 assert_difference 'Changeset.find(103).issues.size' do
205 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => "#2", :format => 'js'
206 end
207 assert_equal [2], Changeset.find(103).issue_ids
208 end
209
210 def test_add_related_issue_with_invalid_issue_id
211 @request.session[:user_id] = 2
212 assert_no_difference 'Changeset.find(103).issues.size' do
213 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
214 assert_response :success
215 assert_template 'add_related_issue'
216 assert_equal 'text/javascript', response.content_type
217 end
218 assert_include 'alert("Issue is invalid")', response.body
219 end
220
221 def test_remove_related_issue
222 Changeset.find(103).issues << Issue.find(1)
223 Changeset.find(103).issues << Issue.find(2)
224
225 @request.session[:user_id] = 2
226 assert_difference 'Changeset.find(103).issues.size', -1 do
227 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
228 assert_response :success
229 assert_template 'remove_related_issue'
230 assert_equal 'text/javascript', response.content_type
231 end
232 assert_equal [1], Changeset.find(103).issue_ids
233 assert_include 'related-issue-2', response.body
234 end
235
236 def test_graph_commits_per_month
237 # Make sure there's some data to display
238 latest = Project.find(1).repository.changesets.maximum(:commit_date)
239 assert_not_nil latest
240 Date.stubs(:today).returns(latest.to_date + 10)
241
242 get :graph, :id => 1, :graph => 'commits_per_month'
243 assert_response :success
244 assert_equal 'image/svg+xml', @response.content_type
245 end
246
247 def test_graph_commits_per_author
248 get :graph, :id => 1, :graph => 'commits_per_author'
249 assert_response :success
250 assert_equal 'image/svg+xml', @response.content_type
251 end
252
253 def test_get_committers
254 @request.session[:user_id] = 2
255 # add a commit with an unknown user
256 Changeset.create!(
257 :repository => Project.find(1).repository,
258 :committer => 'foo',
259 :committed_on => Time.now,
260 :revision => 100,
261 :comments => 'Committed by foo.'
262 )
263
264 get :committers, :id => 10
265 assert_response :success
266 assert_template 'committers'
267
268 assert_tag :td, :content => 'dlopper',
269 :sibling => { :tag => 'td',
270 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
271 :child => { :tag => 'option', :content => 'Dave Lopper',
272 :attributes => { :value => '3', :selected => 'selected' }}}}
273 assert_tag :td, :content => 'foo',
274 :sibling => { :tag => 'td',
275 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
276 assert_no_tag :td, :content => 'foo',
277 :sibling => { :tag => 'td',
278 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
279 end
280
281 def test_post_committers
282 @request.session[:user_id] = 2
283 # add a commit with an unknown user
284 c = Changeset.create!(
285 :repository => Project.find(1).repository,
286 :committer => 'foo',
287 :committed_on => Time.now,
288 :revision => 100,
289 :comments => 'Committed by foo.'
290 )
291 assert_no_difference "Changeset.where(:user_id => 3).count" do
292 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
293 assert_response 302
294 assert_equal User.find(2), c.reload.user
295 end
296 end
297 end