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