comparison .svn/pristine/7d/7d3ac76c84dee77bab1ef37f05ae263ad699e2b8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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.first(:order => 'id DESC')
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_revisions
115 get :revisions, :id => 1
116 assert_response :success
117 assert_template 'revisions'
118 assert_equal Repository.find(10), assigns(:repository)
119 assert_not_nil assigns(:changesets)
120 end
121
122 def test_revisions_for_other_repository
123 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
124
125 get :revisions, :id => 1, :repository_id => 'foo'
126 assert_response :success
127 assert_template 'revisions'
128 assert_equal repository, assigns(:repository)
129 assert_not_nil assigns(:changesets)
130 end
131
132 def test_revisions_for_invalid_repository
133 get :revisions, :id => 1, :repository_id => 'foo'
134 assert_response 404
135 end
136
137 def test_revision
138 get :revision, :id => 1, :rev => 1
139 assert_response :success
140 assert_not_nil assigns(:changeset)
141 assert_equal "1", assigns(:changeset).revision
142 end
143
144 def test_revision_should_not_change_the_project_menu_link
145 get :revision, :id => 1, :rev => 1
146 assert_response :success
147
148 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/},
149 :ancestor => {:attributes => {:id => 'main-menu'}}
150 end
151
152 def test_revision_with_before_nil_and_afer_normal
153 get :revision, {:id => 1, :rev => 1}
154 assert_response :success
155 assert_template 'revision'
156 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
157 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
158 }
159 assert_tag :tag => "div", :attributes => { :class => "contextual" },
160 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
161 }
162 end
163
164 def test_add_related_issue
165 @request.session[:user_id] = 2
166 assert_difference 'Changeset.find(103).issues.size' do
167 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
168 assert_response :success
169 assert_template 'add_related_issue'
170 assert_equal 'text/javascript', response.content_type
171 end
172 assert_equal [2], Changeset.find(103).issue_ids
173 assert_include 'related-issues', response.body
174 assert_include 'Feature request #2', response.body
175 end
176
177 def test_add_related_issue_with_invalid_issue_id
178 @request.session[:user_id] = 2
179 assert_no_difference 'Changeset.find(103).issues.size' do
180 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
181 assert_response :success
182 assert_template 'add_related_issue'
183 assert_equal 'text/javascript', response.content_type
184 end
185 assert_include 'alert("Issue is invalid")', response.body
186 end
187
188 def test_remove_related_issue
189 Changeset.find(103).issues << Issue.find(1)
190 Changeset.find(103).issues << Issue.find(2)
191
192 @request.session[:user_id] = 2
193 assert_difference 'Changeset.find(103).issues.size', -1 do
194 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
195 assert_response :success
196 assert_template 'remove_related_issue'
197 assert_equal 'text/javascript', response.content_type
198 end
199 assert_equal [1], Changeset.find(103).issue_ids
200 assert_include 'related-issue-2', response.body
201 end
202
203 def test_graph_commits_per_month
204 # Make sure there's some data to display
205 latest = Project.find(1).repository.changesets.maximum(:commit_date)
206 assert_not_nil latest
207 Date.stubs(:today).returns(latest.to_date + 10)
208
209 get :graph, :id => 1, :graph => 'commits_per_month'
210 assert_response :success
211 assert_equal 'image/svg+xml', @response.content_type
212 end
213
214 def test_graph_commits_per_author
215 get :graph, :id => 1, :graph => 'commits_per_author'
216 assert_response :success
217 assert_equal 'image/svg+xml', @response.content_type
218 end
219
220 def test_get_committers
221 @request.session[:user_id] = 2
222 # add a commit with an unknown user
223 Changeset.create!(
224 :repository => Project.find(1).repository,
225 :committer => 'foo',
226 :committed_on => Time.now,
227 :revision => 100,
228 :comments => 'Committed by foo.'
229 )
230
231 get :committers, :id => 10
232 assert_response :success
233 assert_template 'committers'
234
235 assert_tag :td, :content => 'dlopper',
236 :sibling => { :tag => 'td',
237 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
238 :child => { :tag => 'option', :content => 'Dave Lopper',
239 :attributes => { :value => '3', :selected => 'selected' }}}}
240 assert_tag :td, :content => 'foo',
241 :sibling => { :tag => 'td',
242 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
243 assert_no_tag :td, :content => 'foo',
244 :sibling => { :tag => 'td',
245 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
246 end
247
248 def test_post_committers
249 @request.session[:user_id] = 2
250 # add a commit with an unknown user
251 c = Changeset.create!(
252 :repository => Project.find(1).repository,
253 :committer => 'foo',
254 :committed_on => Time.now,
255 :revision => 100,
256 :comments => 'Committed by foo.'
257 )
258 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
259 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
260 assert_response 302
261 assert_equal User.find(2), c.reload.user
262 end
263 end
264 end