Chris@909
|
1 # Redmine - project management software
|
Chris@1295
|
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class RepositoriesControllerTest < ActionController::TestCase
|
Chris@1115
|
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
|
Chris@441
|
22 :repositories, :issues, :issue_statuses, :changesets, :changes,
|
Chris@441
|
23 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
|
Chris@441
|
24
|
Chris@0
|
25 def setup
|
Chris@0
|
26 User.current = nil
|
Chris@0
|
27 end
|
Chris@441
|
28
|
Chris@1115
|
29 def test_new
|
Chris@1115
|
30 @request.session[:user_id] = 1
|
Chris@1115
|
31 get :new, :project_id => 'subproject1'
|
Chris@1115
|
32 assert_response :success
|
Chris@1115
|
33 assert_template 'new'
|
Chris@1115
|
34 assert_kind_of Repository::Subversion, assigns(:repository)
|
Chris@1115
|
35 assert assigns(:repository).new_record?
|
Chris@1115
|
36 assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil}
|
Chris@1115
|
37 end
|
Chris@1115
|
38
|
Chris@1115
|
39 def test_new_should_propose_enabled_scm_only
|
Chris@1115
|
40 @request.session[:user_id] = 1
|
Chris@1115
|
41 with_settings :enabled_scm => ['Mercurial', 'Git'] do
|
Chris@1115
|
42 get :new, :project_id => 'subproject1'
|
Chris@1115
|
43 end
|
Chris@1115
|
44 assert_response :success
|
Chris@1115
|
45 assert_template 'new'
|
Chris@1115
|
46 assert_kind_of Repository::Mercurial, assigns(:repository)
|
Chris@1115
|
47 assert_tag 'select', :attributes => {:name => 'repository_scm'},
|
Chris@1115
|
48 :children => {:count => 3}
|
Chris@1115
|
49 assert_tag 'select', :attributes => {:name => 'repository_scm'},
|
Chris@1115
|
50 :child => {:tag => 'option', :attributes => {:value => 'Mercurial', :selected => 'selected'}}
|
Chris@1115
|
51 assert_tag 'select', :attributes => {:name => 'repository_scm'},
|
Chris@1115
|
52 :child => {:tag => 'option', :attributes => {:value => 'Git', :selected => nil}}
|
Chris@1115
|
53 end
|
Chris@1115
|
54
|
Chris@1115
|
55 def test_create
|
Chris@1115
|
56 @request.session[:user_id] = 1
|
Chris@1115
|
57 assert_difference 'Repository.count' do
|
Chris@1115
|
58 post :create, :project_id => 'subproject1',
|
Chris@1115
|
59 :repository_scm => 'Subversion',
|
Chris@1115
|
60 :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
|
Chris@1115
|
61 end
|
Chris@1115
|
62 assert_response 302
|
Chris@1115
|
63 repository = Repository.first(:order => 'id DESC')
|
Chris@1115
|
64 assert_kind_of Repository::Subversion, repository
|
Chris@1115
|
65 assert_equal 'file:///test', repository.url
|
Chris@1115
|
66 end
|
Chris@1115
|
67
|
Chris@1115
|
68 def test_create_with_failure
|
Chris@1115
|
69 @request.session[:user_id] = 1
|
Chris@1115
|
70 assert_no_difference 'Repository.count' do
|
Chris@1115
|
71 post :create, :project_id => 'subproject1',
|
Chris@1115
|
72 :repository_scm => 'Subversion',
|
Chris@1115
|
73 :repository => {:url => 'invalid'}
|
Chris@1115
|
74 end
|
Chris@1115
|
75 assert_response :success
|
Chris@1115
|
76 assert_template 'new'
|
Chris@1115
|
77 assert_kind_of Repository::Subversion, assigns(:repository)
|
Chris@1115
|
78 assert assigns(:repository).new_record?
|
Chris@1115
|
79 end
|
Chris@1115
|
80
|
Chris@1115
|
81 def test_edit
|
Chris@1115
|
82 @request.session[:user_id] = 1
|
Chris@1115
|
83 get :edit, :id => 11
|
Chris@1115
|
84 assert_response :success
|
Chris@1115
|
85 assert_template 'edit'
|
Chris@1115
|
86 assert_equal Repository.find(11), assigns(:repository)
|
Chris@1115
|
87 assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'}
|
Chris@1115
|
88 end
|
Chris@1115
|
89
|
Chris@1115
|
90 def test_update
|
Chris@1115
|
91 @request.session[:user_id] = 1
|
Chris@1115
|
92 put :update, :id => 11, :repository => {:password => 'test_update'}
|
Chris@1115
|
93 assert_response 302
|
Chris@1115
|
94 assert_equal 'test_update', Repository.find(11).password
|
Chris@1115
|
95 end
|
Chris@1115
|
96
|
Chris@1115
|
97 def test_update_with_failure
|
Chris@1115
|
98 @request.session[:user_id] = 1
|
Chris@1115
|
99 put :update, :id => 11, :repository => {:password => 'x'*260}
|
Chris@1115
|
100 assert_response :success
|
Chris@1115
|
101 assert_template 'edit'
|
Chris@1115
|
102 assert_equal Repository.find(11), assigns(:repository)
|
Chris@1115
|
103 end
|
Chris@1115
|
104
|
Chris@1115
|
105 def test_destroy
|
Chris@1115
|
106 @request.session[:user_id] = 1
|
Chris@1115
|
107 assert_difference 'Repository.count', -1 do
|
Chris@1115
|
108 delete :destroy, :id => 11
|
Chris@1115
|
109 end
|
Chris@1115
|
110 assert_response 302
|
Chris@1115
|
111 assert_nil Repository.find_by_id(11)
|
Chris@1115
|
112 end
|
Chris@1115
|
113
|
Chris@0
|
114 def test_revisions
|
Chris@0
|
115 get :revisions, :id => 1
|
Chris@0
|
116 assert_response :success
|
Chris@0
|
117 assert_template 'revisions'
|
Chris@1115
|
118 assert_equal Repository.find(10), assigns(:repository)
|
Chris@0
|
119 assert_not_nil assigns(:changesets)
|
Chris@0
|
120 end
|
Chris@0
|
121
|
Chris@1115
|
122 def test_revisions_for_other_repository
|
Chris@1115
|
123 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
|
Chris@1115
|
124
|
Chris@1115
|
125 get :revisions, :id => 1, :repository_id => 'foo'
|
Chris@1115
|
126 assert_response :success
|
Chris@1115
|
127 assert_template 'revisions'
|
Chris@1115
|
128 assert_equal repository, assigns(:repository)
|
Chris@1115
|
129 assert_not_nil assigns(:changesets)
|
Chris@1115
|
130 end
|
Chris@1115
|
131
|
Chris@1115
|
132 def test_revisions_for_invalid_repository
|
Chris@1115
|
133 get :revisions, :id => 1, :repository_id => 'foo'
|
Chris@1115
|
134 assert_response 404
|
Chris@1115
|
135 end
|
Chris@1115
|
136
|
Chris@0
|
137 def test_revision
|
Chris@0
|
138 get :revision, :id => 1, :rev => 1
|
Chris@0
|
139 assert_response :success
|
Chris@0
|
140 assert_not_nil assigns(:changeset)
|
Chris@0
|
141 assert_equal "1", assigns(:changeset).revision
|
Chris@0
|
142 end
|
Chris@441
|
143
|
Chris@1115
|
144 def test_revision_should_not_change_the_project_menu_link
|
Chris@1115
|
145 get :revision, :id => 1, :rev => 1
|
Chris@1115
|
146 assert_response :success
|
Chris@1115
|
147
|
Chris@1115
|
148 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/},
|
Chris@1115
|
149 :ancestor => {:attributes => {:id => 'main-menu'}}
|
Chris@1115
|
150 end
|
Chris@1115
|
151
|
Chris@0
|
152 def test_revision_with_before_nil_and_afer_normal
|
Chris@0
|
153 get :revision, {:id => 1, :rev => 1}
|
Chris@0
|
154 assert_response :success
|
Chris@0
|
155 assert_template 'revision'
|
Chris@0
|
156 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
|
Chris@0
|
157 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
|
Chris@0
|
158 }
|
Chris@0
|
159 assert_tag :tag => "div", :attributes => { :class => "contextual" },
|
Chris@0
|
160 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
|
Chris@0
|
161 }
|
Chris@0
|
162 end
|
Chris@441
|
163
|
Chris@1115
|
164 def test_add_related_issue
|
Chris@1115
|
165 @request.session[:user_id] = 2
|
Chris@1115
|
166 assert_difference 'Changeset.find(103).issues.size' do
|
Chris@1115
|
167 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
|
Chris@1115
|
168 assert_response :success
|
Chris@1115
|
169 assert_template 'add_related_issue'
|
Chris@1115
|
170 assert_equal 'text/javascript', response.content_type
|
Chris@1115
|
171 end
|
Chris@1115
|
172 assert_equal [2], Changeset.find(103).issue_ids
|
Chris@1115
|
173 assert_include 'related-issues', response.body
|
Chris@1115
|
174 assert_include 'Feature request #2', response.body
|
Chris@1115
|
175 end
|
Chris@1115
|
176
|
Chris@1115
|
177 def test_add_related_issue_with_invalid_issue_id
|
Chris@1115
|
178 @request.session[:user_id] = 2
|
Chris@1115
|
179 assert_no_difference 'Changeset.find(103).issues.size' do
|
Chris@1115
|
180 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
|
Chris@1115
|
181 assert_response :success
|
Chris@1115
|
182 assert_template 'add_related_issue'
|
Chris@1115
|
183 assert_equal 'text/javascript', response.content_type
|
Chris@1115
|
184 end
|
Chris@1115
|
185 assert_include 'alert("Issue is invalid")', response.body
|
Chris@1115
|
186 end
|
Chris@1115
|
187
|
Chris@1115
|
188 def test_remove_related_issue
|
Chris@1115
|
189 Changeset.find(103).issues << Issue.find(1)
|
Chris@1115
|
190 Changeset.find(103).issues << Issue.find(2)
|
Chris@1115
|
191
|
Chris@1115
|
192 @request.session[:user_id] = 2
|
Chris@1115
|
193 assert_difference 'Changeset.find(103).issues.size', -1 do
|
Chris@1115
|
194 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
|
Chris@1115
|
195 assert_response :success
|
Chris@1115
|
196 assert_template 'remove_related_issue'
|
Chris@1115
|
197 assert_equal 'text/javascript', response.content_type
|
Chris@1115
|
198 end
|
Chris@1115
|
199 assert_equal [1], Changeset.find(103).issue_ids
|
Chris@1115
|
200 assert_include 'related-issue-2', response.body
|
Chris@1115
|
201 end
|
Chris@1115
|
202
|
Chris@0
|
203 def test_graph_commits_per_month
|
Chris@1115
|
204 # Make sure there's some data to display
|
Chris@1115
|
205 latest = Project.find(1).repository.changesets.maximum(:commit_date)
|
Chris@1115
|
206 assert_not_nil latest
|
Chris@1115
|
207 Date.stubs(:today).returns(latest.to_date + 10)
|
Chris@1115
|
208
|
Chris@0
|
209 get :graph, :id => 1, :graph => 'commits_per_month'
|
Chris@0
|
210 assert_response :success
|
Chris@0
|
211 assert_equal 'image/svg+xml', @response.content_type
|
Chris@0
|
212 end
|
Chris@441
|
213
|
Chris@0
|
214 def test_graph_commits_per_author
|
Chris@0
|
215 get :graph, :id => 1, :graph => 'commits_per_author'
|
Chris@0
|
216 assert_response :success
|
Chris@0
|
217 assert_equal 'image/svg+xml', @response.content_type
|
Chris@0
|
218 end
|
Chris@441
|
219
|
Chris@1115
|
220 def test_get_committers
|
Chris@0
|
221 @request.session[:user_id] = 2
|
Chris@0
|
222 # add a commit with an unknown user
|
Chris@441
|
223 Changeset.create!(
|
Chris@441
|
224 :repository => Project.find(1).repository,
|
Chris@441
|
225 :committer => 'foo',
|
Chris@441
|
226 :committed_on => Time.now,
|
Chris@441
|
227 :revision => 100,
|
Chris@441
|
228 :comments => 'Committed by foo.'
|
Chris@441
|
229 )
|
Chris@441
|
230
|
Chris@1115
|
231 get :committers, :id => 10
|
Chris@0
|
232 assert_response :success
|
Chris@0
|
233 assert_template 'committers'
|
Chris@909
|
234
|
Chris@0
|
235 assert_tag :td, :content => 'dlopper',
|
Chris@0
|
236 :sibling => { :tag => 'td',
|
Chris@0
|
237 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
|
Chris@0
|
238 :child => { :tag => 'option', :content => 'Dave Lopper',
|
Chris@0
|
239 :attributes => { :value => '3', :selected => 'selected' }}}}
|
Chris@0
|
240 assert_tag :td, :content => 'foo',
|
Chris@0
|
241 :sibling => { :tag => 'td',
|
Chris@0
|
242 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
|
Chris@0
|
243 assert_no_tag :td, :content => 'foo',
|
Chris@0
|
244 :sibling => { :tag => 'td',
|
Chris@0
|
245 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
|
Chris@0
|
246 end
|
Chris@0
|
247
|
Chris@1115
|
248 def test_post_committers
|
Chris@0
|
249 @request.session[:user_id] = 2
|
Chris@0
|
250 # add a commit with an unknown user
|
Chris@441
|
251 c = Changeset.create!(
|
Chris@441
|
252 :repository => Project.find(1).repository,
|
Chris@441
|
253 :committer => 'foo',
|
Chris@441
|
254 :committed_on => Time.now,
|
Chris@441
|
255 :revision => 100,
|
Chris@441
|
256 :comments => 'Committed by foo.'
|
Chris@441
|
257 )
|
Chris@0
|
258 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
|
Chris@1115
|
259 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
|
Chris@1115
|
260 assert_response 302
|
Chris@0
|
261 assert_equal User.find(2), c.reload.user
|
Chris@0
|
262 end
|
Chris@0
|
263 end
|
Chris@0
|
264 end
|