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