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