@@ -1,273 +1,274 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'projects_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, |
|
26 | 26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages |
|
27 | 27 | |
|
28 | 28 | def setup |
|
29 | 29 | @controller = ProjectsController.new |
|
30 | 30 | @request = ActionController::TestRequest.new |
|
31 | 31 | @response = ActionController::TestResponse.new |
|
32 | 32 | @request.session[:user_id] = nil |
|
33 | Setting.default_language = 'en' | |
|
33 | 34 | end |
|
34 | 35 | |
|
35 | 36 | def test_index |
|
36 | 37 | get :index |
|
37 | 38 | assert_response :success |
|
38 | 39 | assert_template 'index' |
|
39 | 40 | assert_not_nil assigns(:project_tree) |
|
40 | 41 | # Root project as hash key |
|
41 | 42 | assert assigns(:project_tree).keys.include?(Project.find(1)) |
|
42 | 43 | # Subproject in corresponding value |
|
43 | 44 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) |
|
44 | 45 | end |
|
45 | 46 | |
|
46 | 47 | def test_index_atom |
|
47 | 48 | get :index, :format => 'atom' |
|
48 | 49 | assert_response :success |
|
49 | 50 | assert_template 'common/feed.atom.rxml' |
|
50 | 51 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
51 | 52 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) |
|
52 | 53 | end |
|
53 | 54 | |
|
54 | 55 | def test_show_by_id |
|
55 | 56 | get :show, :id => 1 |
|
56 | 57 | assert_response :success |
|
57 | 58 | assert_template 'show' |
|
58 | 59 | assert_not_nil assigns(:project) |
|
59 | 60 | end |
|
60 | 61 | |
|
61 | 62 | def test_show_by_identifier |
|
62 | 63 | get :show, :id => 'ecookbook' |
|
63 | 64 | assert_response :success |
|
64 | 65 | assert_template 'show' |
|
65 | 66 | assert_not_nil assigns(:project) |
|
66 | 67 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | def test_private_subprojects_hidden |
|
70 | 71 | get :show, :id => 'ecookbook' |
|
71 | 72 | assert_response :success |
|
72 | 73 | assert_template 'show' |
|
73 | 74 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
74 | 75 | end |
|
75 | 76 | |
|
76 | 77 | def test_private_subprojects_visible |
|
77 | 78 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
78 | 79 | get :show, :id => 'ecookbook' |
|
79 | 80 | assert_response :success |
|
80 | 81 | assert_template 'show' |
|
81 | 82 | assert_tag :tag => 'a', :content => /Private child/ |
|
82 | 83 | end |
|
83 | 84 | |
|
84 | 85 | def test_settings |
|
85 | 86 | @request.session[:user_id] = 2 # manager |
|
86 | 87 | get :settings, :id => 1 |
|
87 | 88 | assert_response :success |
|
88 | 89 | assert_template 'settings' |
|
89 | 90 | end |
|
90 | 91 | |
|
91 | 92 | def test_edit |
|
92 | 93 | @request.session[:user_id] = 2 # manager |
|
93 | 94 | post :edit, :id => 1, :project => {:name => 'Test changed name', |
|
94 | 95 | :issue_custom_field_ids => ['']} |
|
95 | 96 | assert_redirected_to 'projects/settings/ecookbook' |
|
96 | 97 | project = Project.find(1) |
|
97 | 98 | assert_equal 'Test changed name', project.name |
|
98 | 99 | end |
|
99 | 100 | |
|
100 | 101 | def test_get_destroy |
|
101 | 102 | @request.session[:user_id] = 1 # admin |
|
102 | 103 | get :destroy, :id => 1 |
|
103 | 104 | assert_response :success |
|
104 | 105 | assert_template 'destroy' |
|
105 | 106 | assert_not_nil Project.find_by_id(1) |
|
106 | 107 | end |
|
107 | 108 | |
|
108 | 109 | def test_post_destroy |
|
109 | 110 | @request.session[:user_id] = 1 # admin |
|
110 | 111 | post :destroy, :id => 1, :confirm => 1 |
|
111 | 112 | assert_redirected_to 'admin/projects' |
|
112 | 113 | assert_nil Project.find_by_id(1) |
|
113 | 114 | end |
|
114 | 115 | |
|
115 | 116 | def test_list_files |
|
116 | 117 | get :list_files, :id => 1 |
|
117 | 118 | assert_response :success |
|
118 | 119 | assert_template 'list_files' |
|
119 | 120 | assert_not_nil assigns(:versions) |
|
120 | 121 | end |
|
121 | 122 | |
|
122 | 123 | def test_changelog |
|
123 | 124 | get :changelog, :id => 1 |
|
124 | 125 | assert_response :success |
|
125 | 126 | assert_template 'changelog' |
|
126 | 127 | assert_not_nil assigns(:versions) |
|
127 | 128 | end |
|
128 | 129 | |
|
129 | 130 | def test_roadmap |
|
130 | 131 | get :roadmap, :id => 1 |
|
131 | 132 | assert_response :success |
|
132 | 133 | assert_template 'roadmap' |
|
133 | 134 | assert_not_nil assigns(:versions) |
|
134 | 135 | # Version with no date set appears |
|
135 | 136 | assert assigns(:versions).include?(Version.find(3)) |
|
136 | 137 | # Completed version doesn't appear |
|
137 | 138 | assert !assigns(:versions).include?(Version.find(1)) |
|
138 | 139 | end |
|
139 | 140 | |
|
140 | 141 | def test_roadmap_with_completed_versions |
|
141 | 142 | get :roadmap, :id => 1, :completed => 1 |
|
142 | 143 | assert_response :success |
|
143 | 144 | assert_template 'roadmap' |
|
144 | 145 | assert_not_nil assigns(:versions) |
|
145 | 146 | # Version with no date set appears |
|
146 | 147 | assert assigns(:versions).include?(Version.find(3)) |
|
147 | 148 | # Completed version appears |
|
148 | 149 | assert assigns(:versions).include?(Version.find(1)) |
|
149 | 150 | end |
|
150 | 151 | |
|
151 | 152 | def test_project_activity |
|
152 | 153 | get :activity, :id => 1, :with_subprojects => 0 |
|
153 | 154 | assert_response :success |
|
154 | 155 | assert_template 'activity' |
|
155 | 156 | assert_not_nil assigns(:events_by_day) |
|
156 | 157 | |
|
157 | 158 | assert_tag :tag => "h3", |
|
158 | 159 | :content => /#{2.days.ago.to_date.day}/, |
|
159 | 160 | :sibling => { :tag => "dl", |
|
160 | 161 | :child => { :tag => "dt", |
|
161 | 162 | :attributes => { :class => /issue-edit/ }, |
|
162 | 163 | :child => { :tag => "a", |
|
163 | 164 | :content => /(#{IssueStatus.find(2).name})/, |
|
164 | 165 | } |
|
165 | 166 | } |
|
166 | 167 | } |
|
167 | 168 | end |
|
168 | 169 | |
|
169 | 170 | def test_previous_project_activity |
|
170 | 171 | get :activity, :id => 1, :from => 3.days.ago.to_date |
|
171 | 172 | assert_response :success |
|
172 | 173 | assert_template 'activity' |
|
173 | 174 | assert_not_nil assigns(:events_by_day) |
|
174 | 175 | |
|
175 | 176 | assert_tag :tag => "h3", |
|
176 | 177 | :content => /#{3.day.ago.to_date.day}/, |
|
177 | 178 | :sibling => { :tag => "dl", |
|
178 | 179 | :child => { :tag => "dt", |
|
179 | 180 | :attributes => { :class => /issue/ }, |
|
180 | 181 | :child => { :tag => "a", |
|
181 | 182 | :content => /#{Issue.find(1).subject}/, |
|
182 | 183 | } |
|
183 | 184 | } |
|
184 | 185 | } |
|
185 | 186 | end |
|
186 | 187 | |
|
187 | 188 | def test_global_activity |
|
188 | 189 | get :activity |
|
189 | 190 | assert_response :success |
|
190 | 191 | assert_template 'activity' |
|
191 | 192 | assert_not_nil assigns(:events_by_day) |
|
192 | 193 | |
|
193 | 194 | assert_tag :tag => "h3", |
|
194 | 195 | :content => /#{5.day.ago.to_date.day}/, |
|
195 | 196 | :sibling => { :tag => "dl", |
|
196 | 197 | :child => { :tag => "dt", |
|
197 | 198 | :attributes => { :class => /issue/ }, |
|
198 | 199 | :child => { :tag => "a", |
|
199 | 200 | :content => /#{Issue.find(5).subject}/, |
|
200 | 201 | } |
|
201 | 202 | } |
|
202 | 203 | } |
|
203 | 204 | end |
|
204 | 205 | |
|
205 | 206 | def test_activity_atom_feed |
|
206 | 207 | get :activity, :format => 'atom' |
|
207 | 208 | assert_response :success |
|
208 | 209 | assert_template 'common/feed.atom.rxml' |
|
209 | 210 | end |
|
210 | 211 | |
|
211 | 212 | def test_archive |
|
212 | 213 | @request.session[:user_id] = 1 # admin |
|
213 | 214 | post :archive, :id => 1 |
|
214 | 215 | assert_redirected_to 'admin/projects' |
|
215 | 216 | assert !Project.find(1).active? |
|
216 | 217 | end |
|
217 | 218 | |
|
218 | 219 | def test_unarchive |
|
219 | 220 | @request.session[:user_id] = 1 # admin |
|
220 | 221 | Project.find(1).archive |
|
221 | 222 | post :unarchive, :id => 1 |
|
222 | 223 | assert_redirected_to 'admin/projects' |
|
223 | 224 | assert Project.find(1).active? |
|
224 | 225 | end |
|
225 | 226 | |
|
226 | 227 | def test_project_menu |
|
227 | 228 | assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do |
|
228 | 229 | Redmine::MenuManager.map :project_menu do |menu| |
|
229 | 230 | menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo' |
|
230 | 231 | menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity |
|
231 | 232 | menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar |
|
232 | 233 | end |
|
233 | 234 | |
|
234 | 235 | get :show, :id => 1 |
|
235 | 236 | assert_tag :div, :attributes => { :id => 'main-menu' }, |
|
236 | 237 | :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } } |
|
237 | 238 | |
|
238 | 239 | assert_tag :div, :attributes => { :id => 'main-menu' }, |
|
239 | 240 | :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' }, |
|
240 | 241 | :before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } } |
|
241 | 242 | |
|
242 | 243 | assert_tag :div, :attributes => { :id => 'main-menu' }, |
|
243 | 244 | :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' }, |
|
244 | 245 | :before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } } |
|
245 | 246 | |
|
246 | 247 | # Remove the menu items |
|
247 | 248 | Redmine::MenuManager.map :project_menu do |menu| |
|
248 | 249 | menu.delete :foo |
|
249 | 250 | menu.delete :bar |
|
250 | 251 | menu.delete :hello |
|
251 | 252 | end |
|
252 | 253 | end |
|
253 | 254 | end |
|
254 | 255 | |
|
255 | 256 | # A hook that is manually registered later |
|
256 | 257 | class ProjectBasedTemplate < Redmine::Hook::ViewListener |
|
257 | 258 | def view_layouts_base_html_head(context) |
|
258 | 259 | # Adds a project stylesheet |
|
259 | 260 | stylesheet_link_tag(context[:project].identifier) if context[:project] |
|
260 | 261 | end |
|
261 | 262 | end |
|
262 | 263 | # Don't use this hook now |
|
263 | 264 | Redmine::Hook.clear_listeners |
|
264 | 265 | |
|
265 | 266 | def test_hook_response |
|
266 | 267 | Redmine::Hook.add_listener(ProjectBasedTemplate) |
|
267 | 268 | get :show, :id => 1 |
|
268 | 269 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, |
|
269 | 270 | :parent => {:tag => 'head'} |
|
270 | 271 | |
|
271 | 272 | Redmine::Hook.clear_listeners |
|
272 | 273 | end |
|
273 | 274 | end |
@@ -1,152 +1,154 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class RepositoryTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :trackers, |
|
23 | 23 | :projects_trackers, |
|
24 | 24 | :repositories, |
|
25 | 25 | :issues, |
|
26 | 26 | :issue_statuses, |
|
27 | 27 | :changesets, |
|
28 | 28 | :changes, |
|
29 | 29 | :users, |
|
30 | 30 | :enumerations |
|
31 | 31 | |
|
32 | 32 | def setup |
|
33 | 33 | @repository = Project.find(1).repository |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def test_create |
|
37 | 37 | repository = Repository::Subversion.new(:project => Project.find(3)) |
|
38 | 38 | assert !repository.save |
|
39 | 39 | |
|
40 | 40 | repository.url = "svn://localhost" |
|
41 | 41 | assert repository.save |
|
42 | 42 | repository.reload |
|
43 | 43 | |
|
44 | 44 | project = Project.find(3) |
|
45 | 45 | assert_equal repository, project.repository |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_destroy |
|
49 | 49 | changesets = Changeset.count(:all, :conditions => "repository_id = 10") |
|
50 | 50 | changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset) |
|
51 | 51 | assert_difference 'Changeset.count', -changesets do |
|
52 | 52 | assert_difference 'Change.count', -changes do |
|
53 | 53 | Repository.find(10).destroy |
|
54 | 54 | end |
|
55 | 55 | end |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_should_not_create_with_disabled_scm |
|
59 | 59 | # disable Subversion |
|
60 | 60 | Setting.enabled_scm = ['Darcs', 'Git'] |
|
61 | 61 | repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") |
|
62 | 62 | assert !repository.save |
|
63 | 63 | assert_equal :activerecord_error_invalid, repository.errors.on(:type) |
|
64 | 64 | # re-enable Subversion for following tests |
|
65 | 65 | Setting.delete_all |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_scan_changesets_for_issue_ids |
|
69 | Setting.default_language = 'en' | |
|
70 | ||
|
69 | 71 | # choosing a status to apply to fix issues |
|
70 | 72 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
71 | 73 | Setting.commit_fix_done_ratio = "90" |
|
72 | 74 | Setting.commit_ref_keywords = 'refs , references, IssueID' |
|
73 | 75 | Setting.commit_fix_keywords = 'fixes , closes' |
|
74 | 76 | Setting.default_language = 'en' |
|
75 | 77 | ActionMailer::Base.deliveries.clear |
|
76 | 78 | |
|
77 | 79 | # make sure issue 1 is not already closed |
|
78 | 80 | fixed_issue = Issue.find(1) |
|
79 | 81 | assert !fixed_issue.status.is_closed? |
|
80 | 82 | old_status = fixed_issue.status |
|
81 | 83 | |
|
82 | 84 | Repository.scan_changesets_for_issue_ids |
|
83 | 85 | assert_equal [101, 102], Issue.find(3).changeset_ids |
|
84 | 86 | |
|
85 | 87 | # fixed issues |
|
86 | 88 | fixed_issue.reload |
|
87 | 89 | assert fixed_issue.status.is_closed? |
|
88 | 90 | assert_equal 90, fixed_issue.done_ratio |
|
89 | 91 | assert_equal [101], fixed_issue.changeset_ids |
|
90 | 92 | |
|
91 | 93 | # issue change |
|
92 | 94 | journal = fixed_issue.journals.find(:first, :order => 'created_on desc') |
|
93 | 95 | assert_equal User.find_by_login('dlopper'), journal.user |
|
94 | 96 | assert_equal 'Applied in changeset r2.', journal.notes |
|
95 | 97 | |
|
96 | 98 | # 2 email notifications |
|
97 | 99 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
98 | 100 | mail = ActionMailer::Base.deliveries.first |
|
99 | 101 | assert_kind_of TMail::Mail, mail |
|
100 | 102 | assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") |
|
101 | 103 | assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}") |
|
102 | 104 | |
|
103 | 105 | # ignoring commits referencing an issue of another project |
|
104 | 106 | assert_equal [], Issue.find(4).changesets |
|
105 | 107 | end |
|
106 | 108 | |
|
107 | 109 | def test_for_changeset_comments_strip |
|
108 | 110 | repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' ) |
|
109 | 111 | comment = <<-COMMENT |
|
110 | 112 | This is a loooooooooooooooooooooooooooong comment |
|
111 | 113 | |
|
112 | 114 | |
|
113 | 115 | COMMENT |
|
114 | 116 | changeset = Changeset.new( |
|
115 | 117 | :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c', |
|
116 | 118 | :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository ) |
|
117 | 119 | assert( changeset.save ) |
|
118 | 120 | assert_not_equal( comment, changeset.comments ) |
|
119 | 121 | assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments ) |
|
120 | 122 | end |
|
121 | 123 | |
|
122 | 124 | def test_for_urls_strip |
|
123 | 125 | repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', |
|
124 | 126 | :root_url => 'foo ') |
|
125 | 127 | assert repository.save |
|
126 | 128 | repository.reload |
|
127 | 129 | assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url |
|
128 | 130 | assert_equal 'foo', repository.root_url |
|
129 | 131 | end |
|
130 | 132 | |
|
131 | 133 | def test_manual_user_mapping |
|
132 | 134 | assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do |
|
133 | 135 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') |
|
134 | 136 | assert_nil c.user |
|
135 | 137 | @repository.committer_ids = {'foo' => '2'} |
|
136 | 138 | assert_equal User.find(2), c.reload.user |
|
137 | 139 | # committer is now mapped |
|
138 | 140 | c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.') |
|
139 | 141 | assert_equal User.find(2), c.user |
|
140 | 142 | end |
|
141 | 143 | end |
|
142 | 144 | |
|
143 | 145 | def test_auto_user_mapping_by_username |
|
144 | 146 | c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') |
|
145 | 147 | assert_equal User.find(2), c.user |
|
146 | 148 | end |
|
147 | 149 | |
|
148 | 150 | def test_auto_user_mapping_by_email |
|
149 | 151 | c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.') |
|
150 | 152 | assert_equal User.find(2), c.user |
|
151 | 153 | end |
|
152 | 154 | end |
General Comments 0
You need to be logged in to leave comments.
Login now