@@ -1,124 +1,124 | |||||
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 | require 'admin_controller' |
|
19 | require 'admin_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class AdminController; def rescue_action(e) raise e end; end |
|
22 | class AdminController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class AdminControllerTest < Test::Unit::TestCase |
|
24 | class AdminControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles |
|
25 | fixtures :projects, :users, :roles | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = AdminController.new |
|
28 | @controller = AdminController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_index |
|
35 | def test_index | |
36 | get :index |
|
36 | get :index | |
37 | assert_no_tag :tag => 'div', |
|
37 | assert_no_tag :tag => 'div', | |
38 | :attributes => { :class => /nodata/ } |
|
38 | :attributes => { :class => /nodata/ } | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_index_with_no_configuration_data |
|
41 | def test_index_with_no_configuration_data | |
42 | delete_configuration_data |
|
42 | delete_configuration_data | |
43 | get :index |
|
43 | get :index | |
44 | assert_tag :tag => 'div', |
|
44 | assert_tag :tag => 'div', | |
45 | :attributes => { :class => /nodata/ } |
|
45 | :attributes => { :class => /nodata/ } | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_projects |
|
48 | def test_projects | |
49 | get :projects |
|
49 | get :projects | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'projects' |
|
51 | assert_template 'projects' | |
52 | assert_not_nil assigns(:projects) |
|
52 | assert_not_nil assigns(:projects) | |
53 | # active projects only |
|
53 | # active projects only | |
54 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
54 | assert_nil assigns(:projects).detect {|u| !u.active?} | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_projects_with_name_filter |
|
57 | def test_projects_with_name_filter | |
58 | get :projects, :name => 'store', :status => '' |
|
58 | get :projects, :name => 'store', :status => '' | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'projects' |
|
60 | assert_template 'projects' | |
61 | projects = assigns(:projects) |
|
61 | projects = assigns(:projects) | |
62 | assert_not_nil projects |
|
62 | assert_not_nil projects | |
63 | assert_equal 1, projects.size |
|
63 | assert_equal 1, projects.size | |
64 | assert_equal 'OnlineStore', projects.first.name |
|
64 | assert_equal 'OnlineStore', projects.first.name | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_load_default_configuration_data |
|
67 | def test_load_default_configuration_data | |
68 | delete_configuration_data |
|
68 | delete_configuration_data | |
69 | post :default_configuration, :lang => 'fr' |
|
69 | post :default_configuration, :lang => 'fr' | |
70 | assert IssueStatus.find_by_name('Nouveau') |
|
70 | assert IssueStatus.find_by_name('Nouveau') | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_test_email |
|
73 | def test_test_email | |
74 | get :test_email |
|
74 | get :test_email | |
75 | assert_redirected_to 'settings/edit' |
|
75 | assert_redirected_to '/settings/edit?tab=notifications' | |
76 | mail = ActionMailer::Base.deliveries.last |
|
76 | mail = ActionMailer::Base.deliveries.last | |
77 | assert_kind_of TMail::Mail, mail |
|
77 | assert_kind_of TMail::Mail, mail | |
78 | user = User.find(1) |
|
78 | user = User.find(1) | |
79 | assert_equal [user.mail], mail.bcc |
|
79 | assert_equal [user.mail], mail.bcc | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_no_plugins |
|
82 | def test_no_plugins | |
83 | Redmine::Plugin.clear |
|
83 | Redmine::Plugin.clear | |
84 |
|
84 | |||
85 | get :plugins |
|
85 | get :plugins | |
86 | assert_response :success |
|
86 | assert_response :success | |
87 | assert_template 'plugins' |
|
87 | assert_template 'plugins' | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_plugins |
|
90 | def test_plugins | |
91 | # Register a few plugins |
|
91 | # Register a few plugins | |
92 | Redmine::Plugin.register :foo do |
|
92 | Redmine::Plugin.register :foo do | |
93 | name 'Foo plugin' |
|
93 | name 'Foo plugin' | |
94 | author 'John Smith' |
|
94 | author 'John Smith' | |
95 | description 'This is a test plugin' |
|
95 | description 'This is a test plugin' | |
96 | version '0.0.1' |
|
96 | version '0.0.1' | |
97 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
97 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' | |
98 | end |
|
98 | end | |
99 | Redmine::Plugin.register :bar do |
|
99 | Redmine::Plugin.register :bar do | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | get :plugins |
|
102 | get :plugins | |
103 | assert_response :success |
|
103 | assert_response :success | |
104 | assert_template 'plugins' |
|
104 | assert_template 'plugins' | |
105 |
|
105 | |||
106 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
106 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } | |
107 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
107 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_info |
|
110 | def test_info | |
111 | get :info |
|
111 | get :info | |
112 | assert_response :success |
|
112 | assert_response :success | |
113 | assert_template 'info' |
|
113 | assert_template 'info' | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | private |
|
116 | private | |
117 |
|
117 | |||
118 | def delete_configuration_data |
|
118 | def delete_configuration_data | |
119 | Role.delete_all('builtin = 0') |
|
119 | Role.delete_all('builtin = 0') | |
120 | Tracker.delete_all |
|
120 | Tracker.delete_all | |
121 | IssueStatus.delete_all |
|
121 | IssueStatus.delete_all | |
122 | Enumeration.delete_all |
|
122 | Enumeration.delete_all | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end |
@@ -1,126 +1,126 | |||||
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 'attachments_controller' |
|
19 | require 'attachments_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class AttachmentsController; def rescue_action(e) raise e end; end |
|
22 | class AttachmentsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | class AttachmentsControllerTest < Test::Unit::TestCase |
|
25 | class AttachmentsControllerTest < Test::Unit::TestCase | |
26 | fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments, |
|
26 | fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments, | |
27 | :versions, :wiki_pages, :wikis |
|
27 | :versions, :wiki_pages, :wikis | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = AttachmentsController.new |
|
30 | @controller = AttachmentsController.new | |
31 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
32 | @response = ActionController::TestResponse.new |
|
32 | @response = ActionController::TestResponse.new | |
33 | Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files" |
|
33 | Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files" | |
34 | User.current = nil |
|
34 | User.current = nil | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_routing |
|
37 | def test_routing | |
38 | assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1') |
|
38 | assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1') | |
39 | assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext') |
|
39 | assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext') | |
40 | assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1') |
|
40 | assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1') | |
41 | assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext') |
|
41 | assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext') | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_recognizes |
|
44 | def test_recognizes | |
45 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1') |
|
45 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1') | |
46 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1') |
|
46 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1') | |
47 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext') |
|
47 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext') | |
48 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1') |
|
48 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1') | |
49 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext') |
|
49 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext') | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_show_diff |
|
52 | def test_show_diff | |
53 | get :show, :id => 5 |
|
53 | get :show, :id => 5 | |
54 | assert_response :success |
|
54 | assert_response :success | |
55 | assert_template 'diff' |
|
55 | assert_template 'diff' | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_show_text_file |
|
58 | def test_show_text_file | |
59 | get :show, :id => 4 |
|
59 | get :show, :id => 4 | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'file' |
|
61 | assert_template 'file' | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_show_other |
|
64 | def test_show_other | |
65 | get :show, :id => 6 |
|
65 | get :show, :id => 6 | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_equal 'application/octet-stream', @response.content_type |
|
67 | assert_equal 'application/octet-stream', @response.content_type | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_download_text_file |
|
70 | def test_download_text_file | |
71 | get :download, :id => 4 |
|
71 | get :download, :id => 4 | |
72 | assert_response :success |
|
72 | assert_response :success | |
73 | assert_equal 'application/x-ruby', @response.content_type |
|
73 | assert_equal 'application/x-ruby', @response.content_type | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_anonymous_on_private_private |
|
76 | def test_anonymous_on_private_private | |
77 | get :download, :id => 7 |
|
77 | get :download, :id => 7 | |
78 | assert_redirected_to 'account/login' |
|
78 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7' | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_destroy_issue_attachment |
|
81 | def test_destroy_issue_attachment | |
82 | issue = Issue.find(3) |
|
82 | issue = Issue.find(3) | |
83 | @request.session[:user_id] = 2 |
|
83 | @request.session[:user_id] = 2 | |
84 |
|
84 | |||
85 | assert_difference 'issue.attachments.count', -1 do |
|
85 | assert_difference 'issue.attachments.count', -1 do | |
86 | post :destroy, :id => 1 |
|
86 | post :destroy, :id => 1 | |
87 | end |
|
87 | end | |
88 | # no referrer |
|
88 | # no referrer | |
89 | assert_redirected_to 'projects/show/ecookbook' |
|
89 | assert_redirected_to 'projects/show/ecookbook' | |
90 | assert_nil Attachment.find_by_id(1) |
|
90 | assert_nil Attachment.find_by_id(1) | |
91 | j = issue.journals.find(:first, :order => 'created_on DESC') |
|
91 | j = issue.journals.find(:first, :order => 'created_on DESC') | |
92 | assert_equal 'attachment', j.details.first.property |
|
92 | assert_equal 'attachment', j.details.first.property | |
93 | assert_equal '1', j.details.first.prop_key |
|
93 | assert_equal '1', j.details.first.prop_key | |
94 | assert_equal 'error281.txt', j.details.first.old_value |
|
94 | assert_equal 'error281.txt', j.details.first.old_value | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_destroy_wiki_page_attachment |
|
97 | def test_destroy_wiki_page_attachment | |
98 | @request.session[:user_id] = 2 |
|
98 | @request.session[:user_id] = 2 | |
99 | assert_difference 'Attachment.count', -1 do |
|
99 | assert_difference 'Attachment.count', -1 do | |
100 | post :destroy, :id => 3 |
|
100 | post :destroy, :id => 3 | |
101 | assert_response 302 |
|
101 | assert_response 302 | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def test_destroy_project_attachment |
|
105 | def test_destroy_project_attachment | |
106 | @request.session[:user_id] = 2 |
|
106 | @request.session[:user_id] = 2 | |
107 | assert_difference 'Attachment.count', -1 do |
|
107 | assert_difference 'Attachment.count', -1 do | |
108 | post :destroy, :id => 8 |
|
108 | post :destroy, :id => 8 | |
109 | assert_response 302 |
|
109 | assert_response 302 | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_destroy_version_attachment |
|
113 | def test_destroy_version_attachment | |
114 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
115 | assert_difference 'Attachment.count', -1 do |
|
115 | assert_difference 'Attachment.count', -1 do | |
116 | post :destroy, :id => 9 |
|
116 | post :destroy, :id => 9 | |
117 | assert_response 302 |
|
117 | assert_response 302 | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_destroy_without_permission |
|
121 | def test_destroy_without_permission | |
122 | post :destroy, :id => 3 |
|
122 | post :destroy, :id => 3 | |
123 | assert_redirected_to '/login' |
|
123 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3' | |
124 | assert Attachment.find_by_id(3) |
|
124 | assert Attachment.find_by_id(3) | |
125 | end |
|
125 | end | |
126 | end |
|
126 | end |
@@ -1,758 +1,759 | |||||
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 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class IssuesController; def rescue_action(e) raise e end; end |
|
22 | class IssuesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class IssuesControllerTest < Test::Unit::TestCase |
|
24 | class IssuesControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, |
|
25 | fixtures :projects, | |
26 | :users, |
|
26 | :users, | |
27 | :roles, |
|
27 | :roles, | |
28 | :members, |
|
28 | :members, | |
29 | :issues, |
|
29 | :issues, | |
30 | :issue_statuses, |
|
30 | :issue_statuses, | |
31 | :versions, |
|
31 | :versions, | |
32 | :trackers, |
|
32 | :trackers, | |
33 | :projects_trackers, |
|
33 | :projects_trackers, | |
34 | :issue_categories, |
|
34 | :issue_categories, | |
35 | :enabled_modules, |
|
35 | :enabled_modules, | |
36 | :enumerations, |
|
36 | :enumerations, | |
37 | :attachments, |
|
37 | :attachments, | |
38 | :workflows, |
|
38 | :workflows, | |
39 | :custom_fields, |
|
39 | :custom_fields, | |
40 | :custom_values, |
|
40 | :custom_values, | |
41 | :custom_fields_trackers, |
|
41 | :custom_fields_trackers, | |
42 | :time_entries, |
|
42 | :time_entries, | |
43 | :journals, |
|
43 | :journals, | |
44 | :journal_details |
|
44 | :journal_details | |
45 |
|
45 | |||
46 | def setup |
|
46 | def setup | |
47 | @controller = IssuesController.new |
|
47 | @controller = IssuesController.new | |
48 | @request = ActionController::TestRequest.new |
|
48 | @request = ActionController::TestRequest.new | |
49 | @response = ActionController::TestResponse.new |
|
49 | @response = ActionController::TestResponse.new | |
50 | User.current = nil |
|
50 | User.current = nil | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_index |
|
53 | def test_index | |
54 | get :index |
|
54 | get :index | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template 'index.rhtml' |
|
56 | assert_template 'index.rhtml' | |
57 | assert_not_nil assigns(:issues) |
|
57 | assert_not_nil assigns(:issues) | |
58 | assert_nil assigns(:project) |
|
58 | assert_nil assigns(:project) | |
59 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
59 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
60 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
60 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
61 | # private projects hidden |
|
61 | # private projects hidden | |
62 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
62 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
63 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
63 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_index_should_not_list_issues_when_module_disabled |
|
66 | def test_index_should_not_list_issues_when_module_disabled | |
67 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
67 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
68 | get :index |
|
68 | get :index | |
69 | assert_response :success |
|
69 | assert_response :success | |
70 | assert_template 'index.rhtml' |
|
70 | assert_template 'index.rhtml' | |
71 | assert_not_nil assigns(:issues) |
|
71 | assert_not_nil assigns(:issues) | |
72 | assert_nil assigns(:project) |
|
72 | assert_nil assigns(:project) | |
73 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
73 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
74 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
74 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_index_with_project |
|
77 | def test_index_with_project | |
78 | Setting.display_subprojects_issues = 0 |
|
78 | Setting.display_subprojects_issues = 0 | |
79 | get :index, :project_id => 1 |
|
79 | get :index, :project_id => 1 | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_template 'index.rhtml' |
|
81 | assert_template 'index.rhtml' | |
82 | assert_not_nil assigns(:issues) |
|
82 | assert_not_nil assigns(:issues) | |
83 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
83 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
84 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
84 | assert_no_tag :tag => 'a', :content => /Subproject issue/ | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_index_with_project_and_subprojects |
|
87 | def test_index_with_project_and_subprojects | |
88 | Setting.display_subprojects_issues = 1 |
|
88 | Setting.display_subprojects_issues = 1 | |
89 | get :index, :project_id => 1 |
|
89 | get :index, :project_id => 1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'index.rhtml' |
|
91 | assert_template 'index.rhtml' | |
92 | assert_not_nil assigns(:issues) |
|
92 | assert_not_nil assigns(:issues) | |
93 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
93 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
94 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
94 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
95 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
95 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
98 | def test_index_with_project_and_subprojects_should_show_private_subprojects | |
99 | @request.session[:user_id] = 2 |
|
99 | @request.session[:user_id] = 2 | |
100 | Setting.display_subprojects_issues = 1 |
|
100 | Setting.display_subprojects_issues = 1 | |
101 | get :index, :project_id => 1 |
|
101 | get :index, :project_id => 1 | |
102 | assert_response :success |
|
102 | assert_response :success | |
103 | assert_template 'index.rhtml' |
|
103 | assert_template 'index.rhtml' | |
104 | assert_not_nil assigns(:issues) |
|
104 | assert_not_nil assigns(:issues) | |
105 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
105 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
106 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
106 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
107 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
107 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_index_with_project_and_filter |
|
110 | def test_index_with_project_and_filter | |
111 | get :index, :project_id => 1, :set_filter => 1 |
|
111 | get :index, :project_id => 1, :set_filter => 1 | |
112 | assert_response :success |
|
112 | assert_response :success | |
113 | assert_template 'index.rhtml' |
|
113 | assert_template 'index.rhtml' | |
114 | assert_not_nil assigns(:issues) |
|
114 | assert_not_nil assigns(:issues) | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_index_csv_with_project |
|
117 | def test_index_csv_with_project | |
118 | get :index, :format => 'csv' |
|
118 | get :index, :format => 'csv' | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 | assert_not_nil assigns(:issues) |
|
120 | assert_not_nil assigns(:issues) | |
121 | assert_equal 'text/csv', @response.content_type |
|
121 | assert_equal 'text/csv', @response.content_type | |
122 |
|
122 | |||
123 | get :index, :project_id => 1, :format => 'csv' |
|
123 | get :index, :project_id => 1, :format => 'csv' | |
124 | assert_response :success |
|
124 | assert_response :success | |
125 | assert_not_nil assigns(:issues) |
|
125 | assert_not_nil assigns(:issues) | |
126 | assert_equal 'text/csv', @response.content_type |
|
126 | assert_equal 'text/csv', @response.content_type | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_index_pdf |
|
129 | def test_index_pdf | |
130 | get :index, :format => 'pdf' |
|
130 | get :index, :format => 'pdf' | |
131 | assert_response :success |
|
131 | assert_response :success | |
132 | assert_not_nil assigns(:issues) |
|
132 | assert_not_nil assigns(:issues) | |
133 | assert_equal 'application/pdf', @response.content_type |
|
133 | assert_equal 'application/pdf', @response.content_type | |
134 |
|
134 | |||
135 | get :index, :project_id => 1, :format => 'pdf' |
|
135 | get :index, :project_id => 1, :format => 'pdf' | |
136 | assert_response :success |
|
136 | assert_response :success | |
137 | assert_not_nil assigns(:issues) |
|
137 | assert_not_nil assigns(:issues) | |
138 | assert_equal 'application/pdf', @response.content_type |
|
138 | assert_equal 'application/pdf', @response.content_type | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_index_sort |
|
141 | def test_index_sort | |
142 | get :index, :sort_key => 'tracker' |
|
142 | get :index, :sort_key => 'tracker' | |
143 | assert_response :success |
|
143 | assert_response :success | |
144 |
|
144 | |||
145 | sort_params = @request.session['issuesindex_sort'] |
|
145 | sort_params = @request.session['issuesindex_sort'] | |
146 | assert sort_params.is_a?(Hash) |
|
146 | assert sort_params.is_a?(Hash) | |
147 | assert_equal 'tracker', sort_params[:key] |
|
147 | assert_equal 'tracker', sort_params[:key] | |
148 | assert_equal 'ASC', sort_params[:order] |
|
148 | assert_equal 'ASC', sort_params[:order] | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_gantt |
|
151 | def test_gantt | |
152 | get :gantt, :project_id => 1 |
|
152 | get :gantt, :project_id => 1 | |
153 | assert_response :success |
|
153 | assert_response :success | |
154 | assert_template 'gantt.rhtml' |
|
154 | assert_template 'gantt.rhtml' | |
155 | assert_not_nil assigns(:gantt) |
|
155 | assert_not_nil assigns(:gantt) | |
156 | events = assigns(:gantt).events |
|
156 | events = assigns(:gantt).events | |
157 | assert_not_nil events |
|
157 | assert_not_nil events | |
158 | # Issue with start and due dates |
|
158 | # Issue with start and due dates | |
159 | i = Issue.find(1) |
|
159 | i = Issue.find(1) | |
160 | assert_not_nil i.due_date |
|
160 | assert_not_nil i.due_date | |
161 | assert events.include?(Issue.find(1)) |
|
161 | assert events.include?(Issue.find(1)) | |
162 | # Issue with without due date but targeted to a version with date |
|
162 | # Issue with without due date but targeted to a version with date | |
163 | i = Issue.find(2) |
|
163 | i = Issue.find(2) | |
164 | assert_nil i.due_date |
|
164 | assert_nil i.due_date | |
165 | assert events.include?(i) |
|
165 | assert events.include?(i) | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | def test_cross_project_gantt |
|
168 | def test_cross_project_gantt | |
169 | get :gantt |
|
169 | get :gantt | |
170 | assert_response :success |
|
170 | assert_response :success | |
171 | assert_template 'gantt.rhtml' |
|
171 | assert_template 'gantt.rhtml' | |
172 | assert_not_nil assigns(:gantt) |
|
172 | assert_not_nil assigns(:gantt) | |
173 | events = assigns(:gantt).events |
|
173 | events = assigns(:gantt).events | |
174 | assert_not_nil events |
|
174 | assert_not_nil events | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def test_gantt_export_to_pdf |
|
177 | def test_gantt_export_to_pdf | |
178 | get :gantt, :project_id => 1, :format => 'pdf' |
|
178 | get :gantt, :project_id => 1, :format => 'pdf' | |
179 | assert_response :success |
|
179 | assert_response :success | |
180 | assert_equal 'application/pdf', @response.content_type |
|
180 | assert_equal 'application/pdf', @response.content_type | |
181 | assert @response.body.starts_with?('%PDF') |
|
181 | assert @response.body.starts_with?('%PDF') | |
182 | assert_not_nil assigns(:gantt) |
|
182 | assert_not_nil assigns(:gantt) | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def test_cross_project_gantt_export_to_pdf |
|
185 | def test_cross_project_gantt_export_to_pdf | |
186 | get :gantt, :format => 'pdf' |
|
186 | get :gantt, :format => 'pdf' | |
187 | assert_response :success |
|
187 | assert_response :success | |
188 | assert_equal 'application/pdf', @response.content_type |
|
188 | assert_equal 'application/pdf', @response.content_type | |
189 | assert @response.body.starts_with?('%PDF') |
|
189 | assert @response.body.starts_with?('%PDF') | |
190 | assert_not_nil assigns(:gantt) |
|
190 | assert_not_nil assigns(:gantt) | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | if Object.const_defined?(:Magick) |
|
193 | if Object.const_defined?(:Magick) | |
194 | def test_gantt_image |
|
194 | def test_gantt_image | |
195 | get :gantt, :project_id => 1, :format => 'png' |
|
195 | get :gantt, :project_id => 1, :format => 'png' | |
196 | assert_response :success |
|
196 | assert_response :success | |
197 | assert_equal 'image/png', @response.content_type |
|
197 | assert_equal 'image/png', @response.content_type | |
198 | end |
|
198 | end | |
199 | else |
|
199 | else | |
200 | puts "RMagick not installed. Skipping tests !!!" |
|
200 | puts "RMagick not installed. Skipping tests !!!" | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_calendar |
|
203 | def test_calendar | |
204 | get :calendar, :project_id => 1 |
|
204 | get :calendar, :project_id => 1 | |
205 | assert_response :success |
|
205 | assert_response :success | |
206 | assert_template 'calendar' |
|
206 | assert_template 'calendar' | |
207 | assert_not_nil assigns(:calendar) |
|
207 | assert_not_nil assigns(:calendar) | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def test_cross_project_calendar |
|
210 | def test_cross_project_calendar | |
211 | get :calendar |
|
211 | get :calendar | |
212 | assert_response :success |
|
212 | assert_response :success | |
213 | assert_template 'calendar' |
|
213 | assert_template 'calendar' | |
214 | assert_not_nil assigns(:calendar) |
|
214 | assert_not_nil assigns(:calendar) | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_changes |
|
217 | def test_changes | |
218 | get :changes, :project_id => 1 |
|
218 | get :changes, :project_id => 1 | |
219 | assert_response :success |
|
219 | assert_response :success | |
220 | assert_not_nil assigns(:journals) |
|
220 | assert_not_nil assigns(:journals) | |
221 | assert_equal 'application/atom+xml', @response.content_type |
|
221 | assert_equal 'application/atom+xml', @response.content_type | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def test_show_by_anonymous |
|
224 | def test_show_by_anonymous | |
225 | get :show, :id => 1 |
|
225 | get :show, :id => 1 | |
226 | assert_response :success |
|
226 | assert_response :success | |
227 | assert_template 'show.rhtml' |
|
227 | assert_template 'show.rhtml' | |
228 | assert_not_nil assigns(:issue) |
|
228 | assert_not_nil assigns(:issue) | |
229 | assert_equal Issue.find(1), assigns(:issue) |
|
229 | assert_equal Issue.find(1), assigns(:issue) | |
230 |
|
230 | |||
231 | # anonymous role is allowed to add a note |
|
231 | # anonymous role is allowed to add a note | |
232 | assert_tag :tag => 'form', |
|
232 | assert_tag :tag => 'form', | |
233 | :descendant => { :tag => 'fieldset', |
|
233 | :descendant => { :tag => 'fieldset', | |
234 | :child => { :tag => 'legend', |
|
234 | :child => { :tag => 'legend', | |
235 | :content => /Notes/ } } |
|
235 | :content => /Notes/ } } | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
238 | def test_show_by_manager |
|
238 | def test_show_by_manager | |
239 | @request.session[:user_id] = 2 |
|
239 | @request.session[:user_id] = 2 | |
240 | get :show, :id => 1 |
|
240 | get :show, :id => 1 | |
241 | assert_response :success |
|
241 | assert_response :success | |
242 |
|
242 | |||
243 | assert_tag :tag => 'form', |
|
243 | assert_tag :tag => 'form', | |
244 | :descendant => { :tag => 'fieldset', |
|
244 | :descendant => { :tag => 'fieldset', | |
245 | :child => { :tag => 'legend', |
|
245 | :child => { :tag => 'legend', | |
246 | :content => /Change properties/ } }, |
|
246 | :content => /Change properties/ } }, | |
247 | :descendant => { :tag => 'fieldset', |
|
247 | :descendant => { :tag => 'fieldset', | |
248 | :child => { :tag => 'legend', |
|
248 | :child => { :tag => 'legend', | |
249 | :content => /Log time/ } }, |
|
249 | :content => /Log time/ } }, | |
250 | :descendant => { :tag => 'fieldset', |
|
250 | :descendant => { :tag => 'fieldset', | |
251 | :child => { :tag => 'legend', |
|
251 | :child => { :tag => 'legend', | |
252 | :content => /Notes/ } } |
|
252 | :content => /Notes/ } } | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_show_export_to_pdf |
|
255 | def test_show_export_to_pdf | |
256 | get :show, :id => 1, :format => 'pdf' |
|
256 | get :show, :id => 1, :format => 'pdf' | |
257 | assert_response :success |
|
257 | assert_response :success | |
258 | assert_equal 'application/pdf', @response.content_type |
|
258 | assert_equal 'application/pdf', @response.content_type | |
259 | assert @response.body.starts_with?('%PDF') |
|
259 | assert @response.body.starts_with?('%PDF') | |
260 | assert_not_nil assigns(:issue) |
|
260 | assert_not_nil assigns(:issue) | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | def test_get_new |
|
263 | def test_get_new | |
264 | @request.session[:user_id] = 2 |
|
264 | @request.session[:user_id] = 2 | |
265 | get :new, :project_id => 1, :tracker_id => 1 |
|
265 | get :new, :project_id => 1, :tracker_id => 1 | |
266 | assert_response :success |
|
266 | assert_response :success | |
267 | assert_template 'new' |
|
267 | assert_template 'new' | |
268 |
|
268 | |||
269 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
269 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', | |
270 | :value => 'Default string' } |
|
270 | :value => 'Default string' } | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_get_new_without_tracker_id |
|
273 | def test_get_new_without_tracker_id | |
274 | @request.session[:user_id] = 2 |
|
274 | @request.session[:user_id] = 2 | |
275 | get :new, :project_id => 1 |
|
275 | get :new, :project_id => 1 | |
276 | assert_response :success |
|
276 | assert_response :success | |
277 | assert_template 'new' |
|
277 | assert_template 'new' | |
278 |
|
278 | |||
279 | issue = assigns(:issue) |
|
279 | issue = assigns(:issue) | |
280 | assert_not_nil issue |
|
280 | assert_not_nil issue | |
281 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
281 | assert_equal Project.find(1).trackers.first, issue.tracker | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_update_new_form |
|
284 | def test_update_new_form | |
285 | @request.session[:user_id] = 2 |
|
285 | @request.session[:user_id] = 2 | |
286 | xhr :post, :new, :project_id => 1, |
|
286 | xhr :post, :new, :project_id => 1, | |
287 | :issue => {:tracker_id => 2, |
|
287 | :issue => {:tracker_id => 2, | |
288 | :subject => 'This is the test_new issue', |
|
288 | :subject => 'This is the test_new issue', | |
289 | :description => 'This is the description', |
|
289 | :description => 'This is the description', | |
290 | :priority_id => 5} |
|
290 | :priority_id => 5} | |
291 | assert_response :success |
|
291 | assert_response :success | |
292 | assert_template 'new' |
|
292 | assert_template 'new' | |
293 | end |
|
293 | end | |
294 |
|
294 | |||
295 | def test_post_new |
|
295 | def test_post_new | |
296 | @request.session[:user_id] = 2 |
|
296 | @request.session[:user_id] = 2 | |
297 | post :new, :project_id => 1, |
|
297 | post :new, :project_id => 1, | |
298 | :issue => {:tracker_id => 3, |
|
298 | :issue => {:tracker_id => 3, | |
299 | :subject => 'This is the test_new issue', |
|
299 | :subject => 'This is the test_new issue', | |
300 | :description => 'This is the description', |
|
300 | :description => 'This is the description', | |
301 | :priority_id => 5, |
|
301 | :priority_id => 5, | |
302 | :estimated_hours => '', |
|
302 | :estimated_hours => '', | |
303 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
303 | :custom_field_values => {'2' => 'Value for field 2'}} | |
304 |
assert_redirected_to 'issues |
|
304 | assert_redirected_to :controller => 'issues', :action => 'show' | |
305 |
|
305 | |||
306 | issue = Issue.find_by_subject('This is the test_new issue') |
|
306 | issue = Issue.find_by_subject('This is the test_new issue') | |
307 | assert_not_nil issue |
|
307 | assert_not_nil issue | |
308 | assert_equal 2, issue.author_id |
|
308 | assert_equal 2, issue.author_id | |
309 | assert_equal 3, issue.tracker_id |
|
309 | assert_equal 3, issue.tracker_id | |
310 | assert_nil issue.estimated_hours |
|
310 | assert_nil issue.estimated_hours | |
311 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
311 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | |
312 | assert_not_nil v |
|
312 | assert_not_nil v | |
313 | assert_equal 'Value for field 2', v.value |
|
313 | assert_equal 'Value for field 2', v.value | |
314 | end |
|
314 | end | |
315 |
|
315 | |||
316 | def test_post_new_without_custom_fields_param |
|
316 | def test_post_new_without_custom_fields_param | |
317 | @request.session[:user_id] = 2 |
|
317 | @request.session[:user_id] = 2 | |
318 | post :new, :project_id => 1, |
|
318 | post :new, :project_id => 1, | |
319 | :issue => {:tracker_id => 1, |
|
319 | :issue => {:tracker_id => 1, | |
320 | :subject => 'This is the test_new issue', |
|
320 | :subject => 'This is the test_new issue', | |
321 | :description => 'This is the description', |
|
321 | :description => 'This is the description', | |
322 | :priority_id => 5} |
|
322 | :priority_id => 5} | |
323 |
assert_redirected_to 'issues |
|
323 | assert_redirected_to :controller => 'issues', :action => 'show' | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def test_post_new_with_required_custom_field_and_without_custom_fields_param |
|
326 | def test_post_new_with_required_custom_field_and_without_custom_fields_param | |
327 | field = IssueCustomField.find_by_name('Database') |
|
327 | field = IssueCustomField.find_by_name('Database') | |
328 | field.update_attribute(:is_required, true) |
|
328 | field.update_attribute(:is_required, true) | |
329 |
|
329 | |||
330 | @request.session[:user_id] = 2 |
|
330 | @request.session[:user_id] = 2 | |
331 | post :new, :project_id => 1, |
|
331 | post :new, :project_id => 1, | |
332 | :issue => {:tracker_id => 1, |
|
332 | :issue => {:tracker_id => 1, | |
333 | :subject => 'This is the test_new issue', |
|
333 | :subject => 'This is the test_new issue', | |
334 | :description => 'This is the description', |
|
334 | :description => 'This is the description', | |
335 | :priority_id => 5} |
|
335 | :priority_id => 5} | |
336 | assert_response :success |
|
336 | assert_response :success | |
337 | assert_template 'new' |
|
337 | assert_template 'new' | |
338 | issue = assigns(:issue) |
|
338 | issue = assigns(:issue) | |
339 | assert_not_nil issue |
|
339 | assert_not_nil issue | |
340 | assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) |
|
340 | assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) | |
341 | end |
|
341 | end | |
342 |
|
342 | |||
343 | def test_post_new_with_watchers |
|
343 | def test_post_new_with_watchers | |
344 | @request.session[:user_id] = 2 |
|
344 | @request.session[:user_id] = 2 | |
345 | ActionMailer::Base.deliveries.clear |
|
345 | ActionMailer::Base.deliveries.clear | |
346 |
|
346 | |||
347 | assert_difference 'Watcher.count', 2 do |
|
347 | assert_difference 'Watcher.count', 2 do | |
348 | post :new, :project_id => 1, |
|
348 | post :new, :project_id => 1, | |
349 | :issue => {:tracker_id => 1, |
|
349 | :issue => {:tracker_id => 1, | |
350 | :subject => 'This is a new issue with watchers', |
|
350 | :subject => 'This is a new issue with watchers', | |
351 | :description => 'This is the description', |
|
351 | :description => 'This is the description', | |
352 | :priority_id => 5, |
|
352 | :priority_id => 5, | |
353 | :watcher_user_ids => ['2', '3']} |
|
353 | :watcher_user_ids => ['2', '3']} | |
354 | end |
|
354 | end | |
355 | assert_redirected_to 'issues/show' |
|
|||
356 |
|
||||
357 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
355 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
|
356 | assert_not_nil issue | |||
|
357 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |||
|
358 | ||||
358 | # Watchers added |
|
359 | # Watchers added | |
359 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
360 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
360 | assert issue.watched_by?(User.find(3)) |
|
361 | assert issue.watched_by?(User.find(3)) | |
361 | # Watchers notified |
|
362 | # Watchers notified | |
362 | mail = ActionMailer::Base.deliveries.last |
|
363 | mail = ActionMailer::Base.deliveries.last | |
363 | assert_kind_of TMail::Mail, mail |
|
364 | assert_kind_of TMail::Mail, mail | |
364 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
365 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
365 | end |
|
366 | end | |
366 |
|
367 | |||
367 | def test_post_should_preserve_fields_values_on_validation_failure |
|
368 | def test_post_should_preserve_fields_values_on_validation_failure | |
368 | @request.session[:user_id] = 2 |
|
369 | @request.session[:user_id] = 2 | |
369 | post :new, :project_id => 1, |
|
370 | post :new, :project_id => 1, | |
370 | :issue => {:tracker_id => 1, |
|
371 | :issue => {:tracker_id => 1, | |
371 | :subject => 'This is the test_new issue', |
|
372 | :subject => 'This is the test_new issue', | |
372 | # empty description |
|
373 | # empty description | |
373 | :description => '', |
|
374 | :description => '', | |
374 | :priority_id => 6, |
|
375 | :priority_id => 6, | |
375 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
376 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
376 | assert_response :success |
|
377 | assert_response :success | |
377 | assert_template 'new' |
|
378 | assert_template 'new' | |
378 |
|
379 | |||
379 | assert_tag :input, :attributes => { :name => 'issue[subject]', |
|
380 | assert_tag :input, :attributes => { :name => 'issue[subject]', | |
380 | :value => 'This is the test_new issue' } |
|
381 | :value => 'This is the test_new issue' } | |
381 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
382 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
382 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
383 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
383 | :value => '6' }, |
|
384 | :value => '6' }, | |
384 | :content => 'High' } |
|
385 | :content => 'High' } | |
385 | # Custom fields |
|
386 | # Custom fields | |
386 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
387 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | |
387 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
388 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
388 | :value => 'Oracle' }, |
|
389 | :value => 'Oracle' }, | |
389 | :content => 'Oracle' } |
|
390 | :content => 'Oracle' } | |
390 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
391 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
391 | :value => 'Value for field 2'} |
|
392 | :value => 'Value for field 2'} | |
392 | end |
|
393 | end | |
393 |
|
394 | |||
394 | def test_copy_issue |
|
395 | def test_copy_issue | |
395 | @request.session[:user_id] = 2 |
|
396 | @request.session[:user_id] = 2 | |
396 | get :new, :project_id => 1, :copy_from => 1 |
|
397 | get :new, :project_id => 1, :copy_from => 1 | |
397 | assert_template 'new' |
|
398 | assert_template 'new' | |
398 | assert_not_nil assigns(:issue) |
|
399 | assert_not_nil assigns(:issue) | |
399 | orig = Issue.find(1) |
|
400 | orig = Issue.find(1) | |
400 | assert_equal orig.subject, assigns(:issue).subject |
|
401 | assert_equal orig.subject, assigns(:issue).subject | |
401 | end |
|
402 | end | |
402 |
|
403 | |||
403 | def test_get_edit |
|
404 | def test_get_edit | |
404 | @request.session[:user_id] = 2 |
|
405 | @request.session[:user_id] = 2 | |
405 | get :edit, :id => 1 |
|
406 | get :edit, :id => 1 | |
406 | assert_response :success |
|
407 | assert_response :success | |
407 | assert_template 'edit' |
|
408 | assert_template 'edit' | |
408 | assert_not_nil assigns(:issue) |
|
409 | assert_not_nil assigns(:issue) | |
409 | assert_equal Issue.find(1), assigns(:issue) |
|
410 | assert_equal Issue.find(1), assigns(:issue) | |
410 | end |
|
411 | end | |
411 |
|
412 | |||
412 | def test_get_edit_with_params |
|
413 | def test_get_edit_with_params | |
413 | @request.session[:user_id] = 2 |
|
414 | @request.session[:user_id] = 2 | |
414 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } |
|
415 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } | |
415 | assert_response :success |
|
416 | assert_response :success | |
416 | assert_template 'edit' |
|
417 | assert_template 'edit' | |
417 |
|
418 | |||
418 | issue = assigns(:issue) |
|
419 | issue = assigns(:issue) | |
419 | assert_not_nil issue |
|
420 | assert_not_nil issue | |
420 |
|
421 | |||
421 | assert_equal 5, issue.status_id |
|
422 | assert_equal 5, issue.status_id | |
422 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
423 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | |
423 | :child => { :tag => 'option', |
|
424 | :child => { :tag => 'option', | |
424 | :content => 'Closed', |
|
425 | :content => 'Closed', | |
425 | :attributes => { :selected => 'selected' } } |
|
426 | :attributes => { :selected => 'selected' } } | |
426 |
|
427 | |||
427 | assert_equal 7, issue.priority_id |
|
428 | assert_equal 7, issue.priority_id | |
428 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
429 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
429 | :child => { :tag => 'option', |
|
430 | :child => { :tag => 'option', | |
430 | :content => 'Urgent', |
|
431 | :content => 'Urgent', | |
431 | :attributes => { :selected => 'selected' } } |
|
432 | :attributes => { :selected => 'selected' } } | |
432 | end |
|
433 | end | |
433 |
|
434 | |||
434 | def test_reply_to_issue |
|
435 | def test_reply_to_issue | |
435 | @request.session[:user_id] = 2 |
|
436 | @request.session[:user_id] = 2 | |
436 | get :reply, :id => 1 |
|
437 | get :reply, :id => 1 | |
437 | assert_response :success |
|
438 | assert_response :success | |
438 | assert_select_rjs :show, "update" |
|
439 | assert_select_rjs :show, "update" | |
439 | end |
|
440 | end | |
440 |
|
441 | |||
441 | def test_reply_to_note |
|
442 | def test_reply_to_note | |
442 | @request.session[:user_id] = 2 |
|
443 | @request.session[:user_id] = 2 | |
443 | get :reply, :id => 1, :journal_id => 2 |
|
444 | get :reply, :id => 1, :journal_id => 2 | |
444 | assert_response :success |
|
445 | assert_response :success | |
445 | assert_select_rjs :show, "update" |
|
446 | assert_select_rjs :show, "update" | |
446 | end |
|
447 | end | |
447 |
|
448 | |||
448 | def test_post_edit_without_custom_fields_param |
|
449 | def test_post_edit_without_custom_fields_param | |
449 | @request.session[:user_id] = 2 |
|
450 | @request.session[:user_id] = 2 | |
450 | ActionMailer::Base.deliveries.clear |
|
451 | ActionMailer::Base.deliveries.clear | |
451 |
|
452 | |||
452 | issue = Issue.find(1) |
|
453 | issue = Issue.find(1) | |
453 | assert_equal '125', issue.custom_value_for(2).value |
|
454 | assert_equal '125', issue.custom_value_for(2).value | |
454 | old_subject = issue.subject |
|
455 | old_subject = issue.subject | |
455 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
456 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
456 |
|
457 | |||
457 | assert_difference('Journal.count') do |
|
458 | assert_difference('Journal.count') do | |
458 | assert_difference('JournalDetail.count', 2) do |
|
459 | assert_difference('JournalDetail.count', 2) do | |
459 | post :edit, :id => 1, :issue => {:subject => new_subject, |
|
460 | post :edit, :id => 1, :issue => {:subject => new_subject, | |
460 | :priority_id => '6', |
|
461 | :priority_id => '6', | |
461 | :category_id => '1' # no change |
|
462 | :category_id => '1' # no change | |
462 | } |
|
463 | } | |
463 | end |
|
464 | end | |
464 | end |
|
465 | end | |
465 | assert_redirected_to 'issues/show/1' |
|
466 | assert_redirected_to 'issues/show/1' | |
466 | issue.reload |
|
467 | issue.reload | |
467 | assert_equal new_subject, issue.subject |
|
468 | assert_equal new_subject, issue.subject | |
468 | # Make sure custom fields were not cleared |
|
469 | # Make sure custom fields were not cleared | |
469 | assert_equal '125', issue.custom_value_for(2).value |
|
470 | assert_equal '125', issue.custom_value_for(2).value | |
470 |
|
471 | |||
471 | mail = ActionMailer::Base.deliveries.last |
|
472 | mail = ActionMailer::Base.deliveries.last | |
472 | assert_kind_of TMail::Mail, mail |
|
473 | assert_kind_of TMail::Mail, mail | |
473 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
474 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
474 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
475 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") | |
475 | end |
|
476 | end | |
476 |
|
477 | |||
477 | def test_post_edit_with_custom_field_change |
|
478 | def test_post_edit_with_custom_field_change | |
478 | @request.session[:user_id] = 2 |
|
479 | @request.session[:user_id] = 2 | |
479 | issue = Issue.find(1) |
|
480 | issue = Issue.find(1) | |
480 | assert_equal '125', issue.custom_value_for(2).value |
|
481 | assert_equal '125', issue.custom_value_for(2).value | |
481 |
|
482 | |||
482 | assert_difference('Journal.count') do |
|
483 | assert_difference('Journal.count') do | |
483 | assert_difference('JournalDetail.count', 3) do |
|
484 | assert_difference('JournalDetail.count', 3) do | |
484 | post :edit, :id => 1, :issue => {:subject => 'Custom field change', |
|
485 | post :edit, :id => 1, :issue => {:subject => 'Custom field change', | |
485 | :priority_id => '6', |
|
486 | :priority_id => '6', | |
486 | :category_id => '1', # no change |
|
487 | :category_id => '1', # no change | |
487 | :custom_field_values => { '2' => 'New custom value' } |
|
488 | :custom_field_values => { '2' => 'New custom value' } | |
488 | } |
|
489 | } | |
489 | end |
|
490 | end | |
490 | end |
|
491 | end | |
491 | assert_redirected_to 'issues/show/1' |
|
492 | assert_redirected_to 'issues/show/1' | |
492 | issue.reload |
|
493 | issue.reload | |
493 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
494 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
494 |
|
495 | |||
495 | mail = ActionMailer::Base.deliveries.last |
|
496 | mail = ActionMailer::Base.deliveries.last | |
496 | assert_kind_of TMail::Mail, mail |
|
497 | assert_kind_of TMail::Mail, mail | |
497 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
498 | assert mail.body.include?("Searchable field changed from 125 to New custom value") | |
498 | end |
|
499 | end | |
499 |
|
500 | |||
500 | def test_post_edit_with_status_and_assignee_change |
|
501 | def test_post_edit_with_status_and_assignee_change | |
501 | issue = Issue.find(1) |
|
502 | issue = Issue.find(1) | |
502 | assert_equal 1, issue.status_id |
|
503 | assert_equal 1, issue.status_id | |
503 | @request.session[:user_id] = 2 |
|
504 | @request.session[:user_id] = 2 | |
504 | assert_difference('TimeEntry.count', 0) do |
|
505 | assert_difference('TimeEntry.count', 0) do | |
505 | post :edit, |
|
506 | post :edit, | |
506 | :id => 1, |
|
507 | :id => 1, | |
507 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
508 | :issue => { :status_id => 2, :assigned_to_id => 3 }, | |
508 | :notes => 'Assigned to dlopper', |
|
509 | :notes => 'Assigned to dlopper', | |
509 | :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } |
|
510 | :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } | |
510 | end |
|
511 | end | |
511 | assert_redirected_to 'issues/show/1' |
|
512 | assert_redirected_to 'issues/show/1' | |
512 | issue.reload |
|
513 | issue.reload | |
513 | assert_equal 2, issue.status_id |
|
514 | assert_equal 2, issue.status_id | |
514 | j = issue.journals.find(:first, :order => 'id DESC') |
|
515 | j = issue.journals.find(:first, :order => 'id DESC') | |
515 | assert_equal 'Assigned to dlopper', j.notes |
|
516 | assert_equal 'Assigned to dlopper', j.notes | |
516 | assert_equal 2, j.details.size |
|
517 | assert_equal 2, j.details.size | |
517 |
|
518 | |||
518 | mail = ActionMailer::Base.deliveries.last |
|
519 | mail = ActionMailer::Base.deliveries.last | |
519 | assert mail.body.include?("Status changed from New to Assigned") |
|
520 | assert mail.body.include?("Status changed from New to Assigned") | |
520 | end |
|
521 | end | |
521 |
|
522 | |||
522 | def test_post_edit_with_note_only |
|
523 | def test_post_edit_with_note_only | |
523 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
524 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
524 | # anonymous user |
|
525 | # anonymous user | |
525 | post :edit, |
|
526 | post :edit, | |
526 | :id => 1, |
|
527 | :id => 1, | |
527 | :notes => notes |
|
528 | :notes => notes | |
528 | assert_redirected_to 'issues/show/1' |
|
529 | assert_redirected_to 'issues/show/1' | |
529 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
530 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
530 | assert_equal notes, j.notes |
|
531 | assert_equal notes, j.notes | |
531 | assert_equal 0, j.details.size |
|
532 | assert_equal 0, j.details.size | |
532 | assert_equal User.anonymous, j.user |
|
533 | assert_equal User.anonymous, j.user | |
533 |
|
534 | |||
534 | mail = ActionMailer::Base.deliveries.last |
|
535 | mail = ActionMailer::Base.deliveries.last | |
535 | assert mail.body.include?(notes) |
|
536 | assert mail.body.include?(notes) | |
536 | end |
|
537 | end | |
537 |
|
538 | |||
538 | def test_post_edit_with_note_and_spent_time |
|
539 | def test_post_edit_with_note_and_spent_time | |
539 | @request.session[:user_id] = 2 |
|
540 | @request.session[:user_id] = 2 | |
540 | spent_hours_before = Issue.find(1).spent_hours |
|
541 | spent_hours_before = Issue.find(1).spent_hours | |
541 | assert_difference('TimeEntry.count') do |
|
542 | assert_difference('TimeEntry.count') do | |
542 | post :edit, |
|
543 | post :edit, | |
543 | :id => 1, |
|
544 | :id => 1, | |
544 | :notes => '2.5 hours added', |
|
545 | :notes => '2.5 hours added', | |
545 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } |
|
546 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first } | |
546 | end |
|
547 | end | |
547 | assert_redirected_to 'issues/show/1' |
|
548 | assert_redirected_to 'issues/show/1' | |
548 |
|
549 | |||
549 | issue = Issue.find(1) |
|
550 | issue = Issue.find(1) | |
550 |
|
551 | |||
551 | j = issue.journals.find(:first, :order => 'id DESC') |
|
552 | j = issue.journals.find(:first, :order => 'id DESC') | |
552 | assert_equal '2.5 hours added', j.notes |
|
553 | assert_equal '2.5 hours added', j.notes | |
553 | assert_equal 0, j.details.size |
|
554 | assert_equal 0, j.details.size | |
554 |
|
555 | |||
555 | t = issue.time_entries.find(:first, :order => 'id DESC') |
|
556 | t = issue.time_entries.find(:first, :order => 'id DESC') | |
556 | assert_not_nil t |
|
557 | assert_not_nil t | |
557 | assert_equal 2.5, t.hours |
|
558 | assert_equal 2.5, t.hours | |
558 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
559 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
559 | end |
|
560 | end | |
560 |
|
561 | |||
561 | def test_post_edit_with_attachment_only |
|
562 | def test_post_edit_with_attachment_only | |
562 | set_tmp_attachments_directory |
|
563 | set_tmp_attachments_directory | |
563 |
|
564 | |||
564 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
565 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
565 | # journal to get fetched in the next find. |
|
566 | # journal to get fetched in the next find. | |
566 | Journal.delete_all |
|
567 | Journal.delete_all | |
567 |
|
568 | |||
568 | # anonymous user |
|
569 | # anonymous user | |
569 | post :edit, |
|
570 | post :edit, | |
570 | :id => 1, |
|
571 | :id => 1, | |
571 | :notes => '', |
|
572 | :notes => '', | |
572 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} |
|
573 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} | |
573 | assert_redirected_to 'issues/show/1' |
|
574 | assert_redirected_to 'issues/show/1' | |
574 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
575 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
575 | assert j.notes.blank? |
|
576 | assert j.notes.blank? | |
576 | assert_equal 1, j.details.size |
|
577 | assert_equal 1, j.details.size | |
577 | assert_equal 'testfile.txt', j.details.first.value |
|
578 | assert_equal 'testfile.txt', j.details.first.value | |
578 | assert_equal User.anonymous, j.user |
|
579 | assert_equal User.anonymous, j.user | |
579 |
|
580 | |||
580 | mail = ActionMailer::Base.deliveries.last |
|
581 | mail = ActionMailer::Base.deliveries.last | |
581 | assert mail.body.include?('testfile.txt') |
|
582 | assert mail.body.include?('testfile.txt') | |
582 | end |
|
583 | end | |
583 |
|
584 | |||
584 | def test_post_edit_with_no_change |
|
585 | def test_post_edit_with_no_change | |
585 | issue = Issue.find(1) |
|
586 | issue = Issue.find(1) | |
586 | issue.journals.clear |
|
587 | issue.journals.clear | |
587 | ActionMailer::Base.deliveries.clear |
|
588 | ActionMailer::Base.deliveries.clear | |
588 |
|
589 | |||
589 | post :edit, |
|
590 | post :edit, | |
590 | :id => 1, |
|
591 | :id => 1, | |
591 | :notes => '' |
|
592 | :notes => '' | |
592 | assert_redirected_to 'issues/show/1' |
|
593 | assert_redirected_to 'issues/show/1' | |
593 |
|
594 | |||
594 | issue.reload |
|
595 | issue.reload | |
595 | assert issue.journals.empty? |
|
596 | assert issue.journals.empty? | |
596 | # No email should be sent |
|
597 | # No email should be sent | |
597 | assert ActionMailer::Base.deliveries.empty? |
|
598 | assert ActionMailer::Base.deliveries.empty? | |
598 | end |
|
599 | end | |
599 |
|
600 | |||
600 | def test_bulk_edit |
|
601 | def test_bulk_edit | |
601 | @request.session[:user_id] = 2 |
|
602 | @request.session[:user_id] = 2 | |
602 | # update issues priority |
|
603 | # update issues priority | |
603 | post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' |
|
604 | post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' | |
604 | assert_response 302 |
|
605 | assert_response 302 | |
605 | # check that the issues were updated |
|
606 | # check that the issues were updated | |
606 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
607 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
607 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
608 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes | |
608 | end |
|
609 | end | |
609 |
|
610 | |||
610 | def test_bulk_unassign |
|
611 | def test_bulk_unassign | |
611 | assert_not_nil Issue.find(2).assigned_to |
|
612 | assert_not_nil Issue.find(2).assigned_to | |
612 | @request.session[:user_id] = 2 |
|
613 | @request.session[:user_id] = 2 | |
613 | # unassign issues |
|
614 | # unassign issues | |
614 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none' |
|
615 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none' | |
615 | assert_response 302 |
|
616 | assert_response 302 | |
616 | # check that the issues were updated |
|
617 | # check that the issues were updated | |
617 | assert_nil Issue.find(2).assigned_to |
|
618 | assert_nil Issue.find(2).assigned_to | |
618 | end |
|
619 | end | |
619 |
|
620 | |||
620 | def test_move_one_issue_to_another_project |
|
621 | def test_move_one_issue_to_another_project | |
621 | @request.session[:user_id] = 1 |
|
622 | @request.session[:user_id] = 1 | |
622 | post :move, :id => 1, :new_project_id => 2 |
|
623 | post :move, :id => 1, :new_project_id => 2 | |
623 | assert_redirected_to 'projects/ecookbook/issues' |
|
624 | assert_redirected_to 'projects/ecookbook/issues' | |
624 | assert_equal 2, Issue.find(1).project_id |
|
625 | assert_equal 2, Issue.find(1).project_id | |
625 | end |
|
626 | end | |
626 |
|
627 | |||
627 | def test_bulk_move_to_another_project |
|
628 | def test_bulk_move_to_another_project | |
628 | @request.session[:user_id] = 1 |
|
629 | @request.session[:user_id] = 1 | |
629 | post :move, :ids => [1, 2], :new_project_id => 2 |
|
630 | post :move, :ids => [1, 2], :new_project_id => 2 | |
630 | assert_redirected_to 'projects/ecookbook/issues' |
|
631 | assert_redirected_to 'projects/ecookbook/issues' | |
631 | # Issues moved to project 2 |
|
632 | # Issues moved to project 2 | |
632 | assert_equal 2, Issue.find(1).project_id |
|
633 | assert_equal 2, Issue.find(1).project_id | |
633 | assert_equal 2, Issue.find(2).project_id |
|
634 | assert_equal 2, Issue.find(2).project_id | |
634 | # No tracker change |
|
635 | # No tracker change | |
635 | assert_equal 1, Issue.find(1).tracker_id |
|
636 | assert_equal 1, Issue.find(1).tracker_id | |
636 | assert_equal 2, Issue.find(2).tracker_id |
|
637 | assert_equal 2, Issue.find(2).tracker_id | |
637 | end |
|
638 | end | |
638 |
|
639 | |||
639 | def test_bulk_move_to_another_tracker |
|
640 | def test_bulk_move_to_another_tracker | |
640 | @request.session[:user_id] = 1 |
|
641 | @request.session[:user_id] = 1 | |
641 | post :move, :ids => [1, 2], :new_tracker_id => 2 |
|
642 | post :move, :ids => [1, 2], :new_tracker_id => 2 | |
642 | assert_redirected_to 'projects/ecookbook/issues' |
|
643 | assert_redirected_to 'projects/ecookbook/issues' | |
643 | assert_equal 2, Issue.find(1).tracker_id |
|
644 | assert_equal 2, Issue.find(1).tracker_id | |
644 | assert_equal 2, Issue.find(2).tracker_id |
|
645 | assert_equal 2, Issue.find(2).tracker_id | |
645 | end |
|
646 | end | |
646 |
|
647 | |||
647 | def test_context_menu_one_issue |
|
648 | def test_context_menu_one_issue | |
648 | @request.session[:user_id] = 2 |
|
649 | @request.session[:user_id] = 2 | |
649 | get :context_menu, :ids => [1] |
|
650 | get :context_menu, :ids => [1] | |
650 | assert_response :success |
|
651 | assert_response :success | |
651 | assert_template 'context_menu' |
|
652 | assert_template 'context_menu' | |
652 | assert_tag :tag => 'a', :content => 'Edit', |
|
653 | assert_tag :tag => 'a', :content => 'Edit', | |
653 | :attributes => { :href => '/issues/edit/1', |
|
654 | :attributes => { :href => '/issues/edit/1', | |
654 | :class => 'icon-edit' } |
|
655 | :class => 'icon-edit' } | |
655 | assert_tag :tag => 'a', :content => 'Closed', |
|
656 | assert_tag :tag => 'a', :content => 'Closed', | |
656 | :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5', |
|
657 | :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5', | |
657 | :class => '' } |
|
658 | :class => '' } | |
658 | assert_tag :tag => 'a', :content => 'Immediate', |
|
659 | assert_tag :tag => 'a', :content => 'Immediate', | |
659 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', |
|
660 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', | |
660 | :class => '' } |
|
661 | :class => '' } | |
661 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
662 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
662 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', |
|
663 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', | |
663 | :class => '' } |
|
664 | :class => '' } | |
664 | assert_tag :tag => 'a', :content => 'Copy', |
|
665 | assert_tag :tag => 'a', :content => 'Copy', | |
665 | :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1', |
|
666 | :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1', | |
666 | :class => 'icon-copy' } |
|
667 | :class => 'icon-copy' } | |
667 | assert_tag :tag => 'a', :content => 'Move', |
|
668 | assert_tag :tag => 'a', :content => 'Move', | |
668 | :attributes => { :href => '/issues/move?ids%5B%5D=1', |
|
669 | :attributes => { :href => '/issues/move?ids%5B%5D=1', | |
669 | :class => 'icon-move' } |
|
670 | :class => 'icon-move' } | |
670 | assert_tag :tag => 'a', :content => 'Delete', |
|
671 | assert_tag :tag => 'a', :content => 'Delete', | |
671 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', |
|
672 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', | |
672 | :class => 'icon-del' } |
|
673 | :class => 'icon-del' } | |
673 | end |
|
674 | end | |
674 |
|
675 | |||
675 | def test_context_menu_one_issue_by_anonymous |
|
676 | def test_context_menu_one_issue_by_anonymous | |
676 | get :context_menu, :ids => [1] |
|
677 | get :context_menu, :ids => [1] | |
677 | assert_response :success |
|
678 | assert_response :success | |
678 | assert_template 'context_menu' |
|
679 | assert_template 'context_menu' | |
679 | assert_tag :tag => 'a', :content => 'Delete', |
|
680 | assert_tag :tag => 'a', :content => 'Delete', | |
680 | :attributes => { :href => '#', |
|
681 | :attributes => { :href => '#', | |
681 | :class => 'icon-del disabled' } |
|
682 | :class => 'icon-del disabled' } | |
682 | end |
|
683 | end | |
683 |
|
684 | |||
684 | def test_context_menu_multiple_issues_of_same_project |
|
685 | def test_context_menu_multiple_issues_of_same_project | |
685 | @request.session[:user_id] = 2 |
|
686 | @request.session[:user_id] = 2 | |
686 | get :context_menu, :ids => [1, 2] |
|
687 | get :context_menu, :ids => [1, 2] | |
687 | assert_response :success |
|
688 | assert_response :success | |
688 | assert_template 'context_menu' |
|
689 | assert_template 'context_menu' | |
689 | assert_tag :tag => 'a', :content => 'Edit', |
|
690 | assert_tag :tag => 'a', :content => 'Edit', | |
690 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', |
|
691 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', | |
691 | :class => 'icon-edit' } |
|
692 | :class => 'icon-edit' } | |
692 | assert_tag :tag => 'a', :content => 'Immediate', |
|
693 | assert_tag :tag => 'a', :content => 'Immediate', | |
693 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', |
|
694 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', | |
694 | :class => '' } |
|
695 | :class => '' } | |
695 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
696 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
696 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', |
|
697 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', | |
697 | :class => '' } |
|
698 | :class => '' } | |
698 | assert_tag :tag => 'a', :content => 'Move', |
|
699 | assert_tag :tag => 'a', :content => 'Move', | |
699 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', |
|
700 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', | |
700 | :class => 'icon-move' } |
|
701 | :class => 'icon-move' } | |
701 | assert_tag :tag => 'a', :content => 'Delete', |
|
702 | assert_tag :tag => 'a', :content => 'Delete', | |
702 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', |
|
703 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', | |
703 | :class => 'icon-del' } |
|
704 | :class => 'icon-del' } | |
704 | end |
|
705 | end | |
705 |
|
706 | |||
706 | def test_context_menu_multiple_issues_of_different_project |
|
707 | def test_context_menu_multiple_issues_of_different_project | |
707 | @request.session[:user_id] = 2 |
|
708 | @request.session[:user_id] = 2 | |
708 | get :context_menu, :ids => [1, 2, 4] |
|
709 | get :context_menu, :ids => [1, 2, 4] | |
709 | assert_response :success |
|
710 | assert_response :success | |
710 | assert_template 'context_menu' |
|
711 | assert_template 'context_menu' | |
711 | assert_tag :tag => 'a', :content => 'Delete', |
|
712 | assert_tag :tag => 'a', :content => 'Delete', | |
712 | :attributes => { :href => '#', |
|
713 | :attributes => { :href => '#', | |
713 | :class => 'icon-del disabled' } |
|
714 | :class => 'icon-del disabled' } | |
714 | end |
|
715 | end | |
715 |
|
716 | |||
716 | def test_destroy_issue_with_no_time_entries |
|
717 | def test_destroy_issue_with_no_time_entries | |
717 | assert_nil TimeEntry.find_by_issue_id(2) |
|
718 | assert_nil TimeEntry.find_by_issue_id(2) | |
718 | @request.session[:user_id] = 2 |
|
719 | @request.session[:user_id] = 2 | |
719 | post :destroy, :id => 2 |
|
720 | post :destroy, :id => 2 | |
720 | assert_redirected_to 'projects/ecookbook/issues' |
|
721 | assert_redirected_to 'projects/ecookbook/issues' | |
721 | assert_nil Issue.find_by_id(2) |
|
722 | assert_nil Issue.find_by_id(2) | |
722 | end |
|
723 | end | |
723 |
|
724 | |||
724 | def test_destroy_issues_with_time_entries |
|
725 | def test_destroy_issues_with_time_entries | |
725 | @request.session[:user_id] = 2 |
|
726 | @request.session[:user_id] = 2 | |
726 | post :destroy, :ids => [1, 3] |
|
727 | post :destroy, :ids => [1, 3] | |
727 | assert_response :success |
|
728 | assert_response :success | |
728 | assert_template 'destroy' |
|
729 | assert_template 'destroy' | |
729 | assert_not_nil assigns(:hours) |
|
730 | assert_not_nil assigns(:hours) | |
730 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
731 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
731 | end |
|
732 | end | |
732 |
|
733 | |||
733 | def test_destroy_issues_and_destroy_time_entries |
|
734 | def test_destroy_issues_and_destroy_time_entries | |
734 | @request.session[:user_id] = 2 |
|
735 | @request.session[:user_id] = 2 | |
735 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
736 | post :destroy, :ids => [1, 3], :todo => 'destroy' | |
736 | assert_redirected_to 'projects/ecookbook/issues' |
|
737 | assert_redirected_to 'projects/ecookbook/issues' | |
737 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
738 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
738 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
739 | assert_nil TimeEntry.find_by_id([1, 2]) | |
739 | end |
|
740 | end | |
740 |
|
741 | |||
741 | def test_destroy_issues_and_assign_time_entries_to_project |
|
742 | def test_destroy_issues_and_assign_time_entries_to_project | |
742 | @request.session[:user_id] = 2 |
|
743 | @request.session[:user_id] = 2 | |
743 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
744 | post :destroy, :ids => [1, 3], :todo => 'nullify' | |
744 | assert_redirected_to 'projects/ecookbook/issues' |
|
745 | assert_redirected_to 'projects/ecookbook/issues' | |
745 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
746 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
746 | assert_nil TimeEntry.find(1).issue_id |
|
747 | assert_nil TimeEntry.find(1).issue_id | |
747 | assert_nil TimeEntry.find(2).issue_id |
|
748 | assert_nil TimeEntry.find(2).issue_id | |
748 | end |
|
749 | end | |
749 |
|
750 | |||
750 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
751 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
751 | @request.session[:user_id] = 2 |
|
752 | @request.session[:user_id] = 2 | |
752 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
753 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
753 | assert_redirected_to 'projects/ecookbook/issues' |
|
754 | assert_redirected_to 'projects/ecookbook/issues' | |
754 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
755 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
755 | assert_equal 2, TimeEntry.find(1).issue_id |
|
756 | assert_equal 2, TimeEntry.find(1).issue_id | |
756 | assert_equal 2, TimeEntry.find(2).issue_id |
|
757 | assert_equal 2, TimeEntry.find(2).issue_id | |
757 | end |
|
758 | end | |
758 | end |
|
759 | end |
@@ -1,278 +1,278 | |||||
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 | require 'timelog_controller' |
|
19 | require 'timelog_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class TimelogController; def rescue_action(e) raise e end; end |
|
22 | class TimelogController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class TimelogControllerTest < Test::Unit::TestCase |
|
24 | class TimelogControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values |
|
25 | fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = TimelogController.new |
|
28 | @controller = TimelogController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_get_edit |
|
33 | def test_get_edit | |
34 | @request.session[:user_id] = 3 |
|
34 | @request.session[:user_id] = 3 | |
35 | get :edit, :project_id => 1 |
|
35 | get :edit, :project_id => 1 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'edit' |
|
37 | assert_template 'edit' | |
38 | # Default activity selected |
|
38 | # Default activity selected | |
39 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
39 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, | |
40 | :content => 'Development' |
|
40 | :content => 'Development' | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_post_edit |
|
43 | def test_post_edit | |
44 | @request.session[:user_id] = 3 |
|
44 | @request.session[:user_id] = 3 | |
45 | post :edit, :project_id => 1, |
|
45 | post :edit, :project_id => 1, | |
46 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
46 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
47 | # Not the default activity |
|
47 | # Not the default activity | |
48 | :activity_id => '11', |
|
48 | :activity_id => '11', | |
49 | :spent_on => '2008-03-14', |
|
49 | :spent_on => '2008-03-14', | |
50 | :issue_id => '1', |
|
50 | :issue_id => '1', | |
51 | :hours => '7.3'} |
|
51 | :hours => '7.3'} | |
52 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
52 | assert_redirected_to 'projects/ecookbook/timelog/details' | |
53 |
|
53 | |||
54 | i = Issue.find(1) |
|
54 | i = Issue.find(1) | |
55 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
55 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
56 | assert_not_nil t |
|
56 | assert_not_nil t | |
57 | assert_equal 11, t.activity_id |
|
57 | assert_equal 11, t.activity_id | |
58 | assert_equal 7.3, t.hours |
|
58 | assert_equal 7.3, t.hours | |
59 | assert_equal 3, t.user_id |
|
59 | assert_equal 3, t.user_id | |
60 | assert_equal i, t.issue |
|
60 | assert_equal i, t.issue | |
61 | assert_equal i.project, t.project |
|
61 | assert_equal i.project, t.project | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_update |
|
64 | def test_update | |
65 | entry = TimeEntry.find(1) |
|
65 | entry = TimeEntry.find(1) | |
66 | assert_equal 1, entry.issue_id |
|
66 | assert_equal 1, entry.issue_id | |
67 | assert_equal 2, entry.user_id |
|
67 | assert_equal 2, entry.user_id | |
68 |
|
68 | |||
69 | @request.session[:user_id] = 1 |
|
69 | @request.session[:user_id] = 1 | |
70 | post :edit, :id => 1, |
|
70 | post :edit, :id => 1, | |
71 | :time_entry => {:issue_id => '2', |
|
71 | :time_entry => {:issue_id => '2', | |
72 | :hours => '8'} |
|
72 | :hours => '8'} | |
73 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
73 | assert_redirected_to 'projects/ecookbook/timelog/details' | |
74 | entry.reload |
|
74 | entry.reload | |
75 |
|
75 | |||
76 | assert_equal 8, entry.hours |
|
76 | assert_equal 8, entry.hours | |
77 | assert_equal 2, entry.issue_id |
|
77 | assert_equal 2, entry.issue_id | |
78 | assert_equal 2, entry.user_id |
|
78 | assert_equal 2, entry.user_id | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_destroy |
|
81 | def test_destroy | |
82 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
83 | post :destroy, :id => 1 |
|
83 | post :destroy, :id => 1 | |
84 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
84 | assert_redirected_to 'projects/ecookbook/timelog/details' | |
85 | assert_nil TimeEntry.find_by_id(1) |
|
85 | assert_nil TimeEntry.find_by_id(1) | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_report_no_criteria |
|
88 | def test_report_no_criteria | |
89 | get :report, :project_id => 1 |
|
89 | get :report, :project_id => 1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'report' |
|
91 | assert_template 'report' | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_report_all_projects |
|
94 | def test_report_all_projects | |
95 | get :report |
|
95 | get :report | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'report' |
|
97 | assert_template 'report' | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_report_all_projects_denied |
|
100 | def test_report_all_projects_denied | |
101 | r = Role.anonymous |
|
101 | r = Role.anonymous | |
102 | r.permissions.delete(:view_time_entries) |
|
102 | r.permissions.delete(:view_time_entries) | |
103 | r.permissions_will_change! |
|
103 | r.permissions_will_change! | |
104 | r.save |
|
104 | r.save | |
105 | get :report |
|
105 | get :report | |
106 | assert_redirected_to '/account/login' |
|
106 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftimelog%2Freport' | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def test_report_all_projects_one_criteria |
|
109 | def test_report_all_projects_one_criteria | |
110 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
110 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
111 | assert_response :success |
|
111 | assert_response :success | |
112 | assert_template 'report' |
|
112 | assert_template 'report' | |
113 | assert_not_nil assigns(:total_hours) |
|
113 | assert_not_nil assigns(:total_hours) | |
114 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
114 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_report_all_time |
|
117 | def test_report_all_time | |
118 | get :report, :project_id => 1, :criterias => ['project', 'issue'] |
|
118 | get :report, :project_id => 1, :criterias => ['project', 'issue'] | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 | assert_template 'report' |
|
120 | assert_template 'report' | |
121 | assert_not_nil assigns(:total_hours) |
|
121 | assert_not_nil assigns(:total_hours) | |
122 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
122 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def test_report_all_time_by_day |
|
125 | def test_report_all_time_by_day | |
126 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' |
|
126 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' | |
127 | assert_response :success |
|
127 | assert_response :success | |
128 | assert_template 'report' |
|
128 | assert_template 'report' | |
129 | assert_not_nil assigns(:total_hours) |
|
129 | assert_not_nil assigns(:total_hours) | |
130 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
130 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
131 | assert_tag :tag => 'th', :content => '2007-03-12' |
|
131 | assert_tag :tag => 'th', :content => '2007-03-12' | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_report_one_criteria |
|
134 | def test_report_one_criteria | |
135 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
135 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
136 | assert_response :success |
|
136 | assert_response :success | |
137 | assert_template 'report' |
|
137 | assert_template 'report' | |
138 | assert_not_nil assigns(:total_hours) |
|
138 | assert_not_nil assigns(:total_hours) | |
139 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
139 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | def test_report_two_criterias |
|
142 | def test_report_two_criterias | |
143 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] |
|
143 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
144 | assert_response :success |
|
144 | assert_response :success | |
145 | assert_template 'report' |
|
145 | assert_template 'report' | |
146 | assert_not_nil assigns(:total_hours) |
|
146 | assert_not_nil assigns(:total_hours) | |
147 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
147 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def test_report_custom_field_criteria |
|
150 | def test_report_custom_field_criteria | |
151 | get :report, :project_id => 1, :criterias => ['project', 'cf_1'] |
|
151 | get :report, :project_id => 1, :criterias => ['project', 'cf_1'] | |
152 | assert_response :success |
|
152 | assert_response :success | |
153 | assert_template 'report' |
|
153 | assert_template 'report' | |
154 | assert_not_nil assigns(:total_hours) |
|
154 | assert_not_nil assigns(:total_hours) | |
155 | assert_not_nil assigns(:criterias) |
|
155 | assert_not_nil assigns(:criterias) | |
156 | assert_equal 2, assigns(:criterias).size |
|
156 | assert_equal 2, assigns(:criterias).size | |
157 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
157 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
158 | # Custom field column |
|
158 | # Custom field column | |
159 | assert_tag :tag => 'th', :content => 'Database' |
|
159 | assert_tag :tag => 'th', :content => 'Database' | |
160 | # Custom field row |
|
160 | # Custom field row | |
161 | assert_tag :tag => 'td', :content => 'MySQL', |
|
161 | assert_tag :tag => 'td', :content => 'MySQL', | |
162 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, |
|
162 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | |
163 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, |
|
163 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | |
164 | :content => '1' }} |
|
164 | :content => '1' }} | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def test_report_one_criteria_no_result |
|
167 | def test_report_one_criteria_no_result | |
168 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] |
|
168 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
169 | assert_response :success |
|
169 | assert_response :success | |
170 | assert_template 'report' |
|
170 | assert_template 'report' | |
171 | assert_not_nil assigns(:total_hours) |
|
171 | assert_not_nil assigns(:total_hours) | |
172 | assert_equal "0.00", "%.2f" % assigns(:total_hours) |
|
172 | assert_equal "0.00", "%.2f" % assigns(:total_hours) | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def test_report_all_projects_csv_export |
|
175 | def test_report_all_projects_csv_export | |
176 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
176 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
177 | assert_response :success |
|
177 | assert_response :success | |
178 | assert_equal 'text/csv', @response.content_type |
|
178 | assert_equal 'text/csv', @response.content_type | |
179 | lines = @response.body.chomp.split("\n") |
|
179 | lines = @response.body.chomp.split("\n") | |
180 | # Headers |
|
180 | # Headers | |
181 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
181 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
182 | # Total row |
|
182 | # Total row | |
183 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
183 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | def test_report_csv_export |
|
186 | def test_report_csv_export | |
187 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
187 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
188 | assert_response :success |
|
188 | assert_response :success | |
189 | assert_equal 'text/csv', @response.content_type |
|
189 | assert_equal 'text/csv', @response.content_type | |
190 | lines = @response.body.chomp.split("\n") |
|
190 | lines = @response.body.chomp.split("\n") | |
191 | # Headers |
|
191 | # Headers | |
192 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
192 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
193 | # Total row |
|
193 | # Total row | |
194 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
194 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | def test_details_all_projects |
|
197 | def test_details_all_projects | |
198 | get :details |
|
198 | get :details | |
199 | assert_response :success |
|
199 | assert_response :success | |
200 | assert_template 'details' |
|
200 | assert_template 'details' | |
201 | assert_not_nil assigns(:total_hours) |
|
201 | assert_not_nil assigns(:total_hours) | |
202 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
202 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | def test_details_at_project_level |
|
205 | def test_details_at_project_level | |
206 | get :details, :project_id => 1 |
|
206 | get :details, :project_id => 1 | |
207 | assert_response :success |
|
207 | assert_response :success | |
208 | assert_template 'details' |
|
208 | assert_template 'details' | |
209 | assert_not_nil assigns(:entries) |
|
209 | assert_not_nil assigns(:entries) | |
210 | assert_equal 4, assigns(:entries).size |
|
210 | assert_equal 4, assigns(:entries).size | |
211 | # project and subproject |
|
211 | # project and subproject | |
212 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
212 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | |
213 | assert_not_nil assigns(:total_hours) |
|
213 | assert_not_nil assigns(:total_hours) | |
214 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
214 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
215 | # display all time by default |
|
215 | # display all time by default | |
216 | assert_equal '2007-03-11'.to_date, assigns(:from) |
|
216 | assert_equal '2007-03-11'.to_date, assigns(:from) | |
217 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
217 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | def test_details_at_project_level_with_date_range |
|
220 | def test_details_at_project_level_with_date_range | |
221 | get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' |
|
221 | get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' | |
222 | assert_response :success |
|
222 | assert_response :success | |
223 | assert_template 'details' |
|
223 | assert_template 'details' | |
224 | assert_not_nil assigns(:entries) |
|
224 | assert_not_nil assigns(:entries) | |
225 | assert_equal 3, assigns(:entries).size |
|
225 | assert_equal 3, assigns(:entries).size | |
226 | assert_not_nil assigns(:total_hours) |
|
226 | assert_not_nil assigns(:total_hours) | |
227 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
227 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
228 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
228 | assert_equal '2007-03-20'.to_date, assigns(:from) | |
229 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
229 | assert_equal '2007-04-30'.to_date, assigns(:to) | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | def test_details_at_project_level_with_period |
|
232 | def test_details_at_project_level_with_period | |
233 | get :details, :project_id => 1, :period => '7_days' |
|
233 | get :details, :project_id => 1, :period => '7_days' | |
234 | assert_response :success |
|
234 | assert_response :success | |
235 | assert_template 'details' |
|
235 | assert_template 'details' | |
236 | assert_not_nil assigns(:entries) |
|
236 | assert_not_nil assigns(:entries) | |
237 | assert_not_nil assigns(:total_hours) |
|
237 | assert_not_nil assigns(:total_hours) | |
238 | assert_equal Date.today - 7, assigns(:from) |
|
238 | assert_equal Date.today - 7, assigns(:from) | |
239 | assert_equal Date.today, assigns(:to) |
|
239 | assert_equal Date.today, assigns(:to) | |
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | def test_details_at_issue_level |
|
242 | def test_details_at_issue_level | |
243 | get :details, :issue_id => 1 |
|
243 | get :details, :issue_id => 1 | |
244 | assert_response :success |
|
244 | assert_response :success | |
245 | assert_template 'details' |
|
245 | assert_template 'details' | |
246 | assert_not_nil assigns(:entries) |
|
246 | assert_not_nil assigns(:entries) | |
247 | assert_equal 2, assigns(:entries).size |
|
247 | assert_equal 2, assigns(:entries).size | |
248 | assert_not_nil assigns(:total_hours) |
|
248 | assert_not_nil assigns(:total_hours) | |
249 | assert_equal 154.25, assigns(:total_hours) |
|
249 | assert_equal 154.25, assigns(:total_hours) | |
250 | # display all time by default |
|
250 | # display all time by default | |
251 | assert_equal '2007-03-11'.to_date, assigns(:from) |
|
251 | assert_equal '2007-03-11'.to_date, assigns(:from) | |
252 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
252 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_details_atom_feed |
|
255 | def test_details_atom_feed | |
256 | get :details, :project_id => 1, :format => 'atom' |
|
256 | get :details, :project_id => 1, :format => 'atom' | |
257 | assert_response :success |
|
257 | assert_response :success | |
258 | assert_equal 'application/atom+xml', @response.content_type |
|
258 | assert_equal 'application/atom+xml', @response.content_type | |
259 | assert_not_nil assigns(:items) |
|
259 | assert_not_nil assigns(:items) | |
260 | assert assigns(:items).first.is_a?(TimeEntry) |
|
260 | assert assigns(:items).first.is_a?(TimeEntry) | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | def test_details_all_projects_csv_export |
|
263 | def test_details_all_projects_csv_export | |
264 | get :details, :format => 'csv' |
|
264 | get :details, :format => 'csv' | |
265 | assert_response :success |
|
265 | assert_response :success | |
266 | assert_equal 'text/csv', @response.content_type |
|
266 | assert_equal 'text/csv', @response.content_type | |
267 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") |
|
267 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
268 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") |
|
268 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
269 | end |
|
269 | end | |
270 |
|
270 | |||
271 | def test_details_csv_export |
|
271 | def test_details_csv_export | |
272 | get :details, :project_id => 1, :format => 'csv' |
|
272 | get :details, :project_id => 1, :format => 'csv' | |
273 | assert_response :success |
|
273 | assert_response :success | |
274 | assert_equal 'text/csv', @response.content_type |
|
274 | assert_equal 'text/csv', @response.content_type | |
275 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") |
|
275 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
276 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") |
|
276 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
277 | end |
|
277 | end | |
278 | end |
|
278 | end |
@@ -1,72 +1,72 | |||||
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 | require 'users_controller' |
|
19 | require 'users_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class UsersController; def rescue_action(e) raise e end; end |
|
22 | class UsersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class UsersControllerTest < Test::Unit::TestCase |
|
24 | class UsersControllerTest < Test::Unit::TestCase | |
25 | fixtures :users, :projects, :members |
|
25 | fixtures :users, :projects, :members | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = UsersController.new |
|
28 | @controller = UsersController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_index |
|
35 | def test_index | |
36 | get :index |
|
36 | get :index | |
37 | assert_response :success |
|
37 | assert_response :success | |
38 | assert_template 'list' |
|
38 | assert_template 'list' | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_list |
|
41 | def test_list | |
42 | get :list |
|
42 | get :list | |
43 | assert_response :success |
|
43 | assert_response :success | |
44 | assert_template 'list' |
|
44 | assert_template 'list' | |
45 | assert_not_nil assigns(:users) |
|
45 | assert_not_nil assigns(:users) | |
46 | # active users only |
|
46 | # active users only | |
47 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
47 | assert_nil assigns(:users).detect {|u| !u.active?} | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_list_with_name_filter |
|
50 | def test_list_with_name_filter | |
51 | get :list, :name => 'john' |
|
51 | get :list, :name => 'john' | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'list' |
|
53 | assert_template 'list' | |
54 | users = assigns(:users) |
|
54 | users = assigns(:users) | |
55 | assert_not_nil users |
|
55 | assert_not_nil users | |
56 | assert_equal 1, users.size |
|
56 | assert_equal 1, users.size | |
57 | assert_equal 'John', users.first.firstname |
|
57 | assert_equal 'John', users.first.firstname | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_edit_membership |
|
60 | def test_edit_membership | |
61 | post :edit_membership, :id => 2, :membership_id => 1, |
|
61 | post :edit_membership, :id => 2, :membership_id => 1, | |
62 | :membership => { :role_id => 2} |
|
62 | :membership => { :role_id => 2} | |
63 | assert_redirected_to 'users/edit/2' |
|
63 | assert_redirected_to '/users/edit/2?tab=memberships' | |
64 | assert_equal 2, Member.find(1).role_id |
|
64 | assert_equal 2, Member.find(1).role_id | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_destroy_membership |
|
67 | def test_destroy_membership | |
68 | post :destroy_membership, :id => 2, :membership_id => 1 |
|
68 | post :destroy_membership, :id => 2, :membership_id => 1 | |
69 | assert_redirected_to 'users/edit/2' |
|
69 | assert_redirected_to '/users/edit/2?tab=memberships' | |
70 | assert_nil Member.find_by_id(1) |
|
70 | assert_nil Member.find_by_id(1) | |
71 | end |
|
71 | end | |
72 | end |
|
72 | end |
@@ -1,73 +1,73 | |||||
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 | require 'versions_controller' |
|
19 | require 'versions_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class VersionsController; def rescue_action(e) raise e end; end |
|
22 | class VersionsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class VersionsControllerTest < Test::Unit::TestCase |
|
24 | class VersionsControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :enabled_modules |
|
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :enabled_modules | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = VersionsController.new |
|
28 | @controller = VersionsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_show |
|
34 | def test_show | |
35 | get :show, :id => 2 |
|
35 | get :show, :id => 2 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'show' |
|
37 | assert_template 'show' | |
38 | assert_not_nil assigns(:version) |
|
38 | assert_not_nil assigns(:version) | |
39 |
|
39 | |||
40 | assert_tag :tag => 'h2', :content => /1.0/ |
|
40 | assert_tag :tag => 'h2', :content => /1.0/ | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_get_edit |
|
43 | def test_get_edit | |
44 | @request.session[:user_id] = 2 |
|
44 | @request.session[:user_id] = 2 | |
45 | get :edit, :id => 2 |
|
45 | get :edit, :id => 2 | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'edit' |
|
47 | assert_template 'edit' | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_post_edit |
|
50 | def test_post_edit | |
51 | @request.session[:user_id] = 2 |
|
51 | @request.session[:user_id] = 2 | |
52 | post :edit, :id => 2, |
|
52 | post :edit, :id => 2, | |
53 | :version => { :name => 'New version name', |
|
53 | :version => { :name => 'New version name', | |
54 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
54 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
55 | assert_redirected_to 'projects/settings/ecookbook' |
|
55 | assert_redirected_to '/projects/settings/ecookbook?tab=versions' | |
56 | version = Version.find(2) |
|
56 | version = Version.find(2) | |
57 | assert_equal 'New version name', version.name |
|
57 | assert_equal 'New version name', version.name | |
58 | assert_equal Date.today, version.effective_date |
|
58 | assert_equal Date.today, version.effective_date | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_destroy |
|
61 | def test_destroy | |
62 | @request.session[:user_id] = 2 |
|
62 | @request.session[:user_id] = 2 | |
63 | post :destroy, :id => 3 |
|
63 | post :destroy, :id => 3 | |
64 | assert_redirected_to 'projects/settings/ecookbook' |
|
64 | assert_redirected_to '/projects/settings/ecookbook?tab=versions' | |
65 | assert_nil Version.find_by_id(3) |
|
65 | assert_nil Version.find_by_id(3) | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_issue_status_by |
|
68 | def test_issue_status_by | |
69 | xhr :get, :status_by, :id => 2 |
|
69 | xhr :get, :status_by, :id => 2 | |
70 | assert_response :success |
|
70 | assert_response :success | |
71 | assert_template '_issue_counts' |
|
71 | assert_template '_issue_counts' | |
72 | end |
|
72 | end | |
73 | end |
|
73 | end |
@@ -1,259 +1,259 | |||||
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 | require 'wiki_controller' |
|
19 | require 'wiki_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WikiController; def rescue_action(e) raise e end; end |
|
22 | class WikiController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WikiControllerTest < Test::Unit::TestCase |
|
24 | class WikiControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments |
|
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WikiController.new |
|
28 | @controller = WikiController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_show_start_page |
|
34 | def test_show_start_page | |
35 | get :index, :id => 'ecookbook' |
|
35 | get :index, :id => 'ecookbook' | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'show' |
|
37 | assert_template 'show' | |
38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
|
38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ | |
39 |
|
39 | |||
40 | # child_pages macro |
|
40 | # child_pages macro | |
41 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
41 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
42 | :child => { :tag => 'li', |
|
42 | :child => { :tag => 'li', | |
43 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, |
|
43 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, | |
44 | :content => 'Page with an inline image' } } |
|
44 | :content => 'Page with an inline image' } } | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_show_page_with_name |
|
47 | def test_show_page_with_name | |
48 | get :index, :id => 1, :page => 'Another_page' |
|
48 | get :index, :id => 1, :page => 'Another_page' | |
49 | assert_response :success |
|
49 | assert_response :success | |
50 | assert_template 'show' |
|
50 | assert_template 'show' | |
51 | assert_tag :tag => 'h1', :content => /Another page/ |
|
51 | assert_tag :tag => 'h1', :content => /Another page/ | |
52 | # Included page with an inline image |
|
52 | # Included page with an inline image | |
53 | assert_tag :tag => 'p', :content => /This is an inline image/ |
|
53 | assert_tag :tag => 'p', :content => /This is an inline image/ | |
54 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', |
|
54 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', | |
55 | :alt => 'This is a logo' } |
|
55 | :alt => 'This is a logo' } | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_show_unexistent_page_without_edit_right |
|
58 | def test_show_unexistent_page_without_edit_right | |
59 | get :index, :id => 1, :page => 'Unexistent page' |
|
59 | get :index, :id => 1, :page => 'Unexistent page' | |
60 | assert_response 404 |
|
60 | assert_response 404 | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_show_unexistent_page_with_edit_right |
|
63 | def test_show_unexistent_page_with_edit_right | |
64 | @request.session[:user_id] = 2 |
|
64 | @request.session[:user_id] = 2 | |
65 | get :index, :id => 1, :page => 'Unexistent page' |
|
65 | get :index, :id => 1, :page => 'Unexistent page' | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'edit' |
|
67 | assert_template 'edit' | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_create_page |
|
70 | def test_create_page | |
71 | @request.session[:user_id] = 2 |
|
71 | @request.session[:user_id] = 2 | |
72 | post :edit, :id => 1, |
|
72 | post :edit, :id => 1, | |
73 | :page => 'New page', |
|
73 | :page => 'New page', | |
74 | :content => {:comments => 'Created the page', |
|
74 | :content => {:comments => 'Created the page', | |
75 | :text => "h1. New page\n\nThis is a new page", |
|
75 | :text => "h1. New page\n\nThis is a new page", | |
76 | :version => 0} |
|
76 | :version => 0} | |
77 | assert_redirected_to 'wiki/ecookbook/New_page' |
|
77 | assert_redirected_to 'wiki/ecookbook/New_page' | |
78 | page = Project.find(1).wiki.find_page('New page') |
|
78 | page = Project.find(1).wiki.find_page('New page') | |
79 | assert !page.new_record? |
|
79 | assert !page.new_record? | |
80 | assert_not_nil page.content |
|
80 | assert_not_nil page.content | |
81 | assert_equal 'Created the page', page.content.comments |
|
81 | assert_equal 'Created the page', page.content.comments | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_preview |
|
84 | def test_preview | |
85 | @request.session[:user_id] = 2 |
|
85 | @request.session[:user_id] = 2 | |
86 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', |
|
86 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', | |
87 | :content => { :comments => '', |
|
87 | :content => { :comments => '', | |
88 | :text => 'this is a *previewed text*', |
|
88 | :text => 'this is a *previewed text*', | |
89 | :version => 3 } |
|
89 | :version => 3 } | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_template 'common/_preview' |
|
91 | assert_template 'common/_preview' | |
92 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
92 | assert_tag :tag => 'strong', :content => /previewed text/ | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_preview_new_page |
|
95 | def test_preview_new_page | |
96 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
97 | xhr :post, :preview, :id => 1, :page => 'New page', |
|
97 | xhr :post, :preview, :id => 1, :page => 'New page', | |
98 | :content => { :text => 'h1. New page', |
|
98 | :content => { :text => 'h1. New page', | |
99 | :comments => '', |
|
99 | :comments => '', | |
100 | :version => 0 } |
|
100 | :version => 0 } | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_template 'common/_preview' |
|
102 | assert_template 'common/_preview' | |
103 | assert_tag :tag => 'h1', :content => /New page/ |
|
103 | assert_tag :tag => 'h1', :content => /New page/ | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_history |
|
106 | def test_history | |
107 | get :history, :id => 1, :page => 'CookBook_documentation' |
|
107 | get :history, :id => 1, :page => 'CookBook_documentation' | |
108 | assert_response :success |
|
108 | assert_response :success | |
109 | assert_template 'history' |
|
109 | assert_template 'history' | |
110 | assert_not_nil assigns(:versions) |
|
110 | assert_not_nil assigns(:versions) | |
111 | assert_equal 3, assigns(:versions).size |
|
111 | assert_equal 3, assigns(:versions).size | |
112 | assert_select "input[type=submit][name=commit]" |
|
112 | assert_select "input[type=submit][name=commit]" | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_history_with_one_version |
|
115 | def test_history_with_one_version | |
116 | get :history, :id => 1, :page => 'Another_page' |
|
116 | get :history, :id => 1, :page => 'Another_page' | |
117 | assert_response :success |
|
117 | assert_response :success | |
118 | assert_template 'history' |
|
118 | assert_template 'history' | |
119 | assert_not_nil assigns(:versions) |
|
119 | assert_not_nil assigns(:versions) | |
120 | assert_equal 1, assigns(:versions).size |
|
120 | assert_equal 1, assigns(:versions).size | |
121 | assert_select "input[type=submit][name=commit]", false |
|
121 | assert_select "input[type=submit][name=commit]", false | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | def test_diff |
|
124 | def test_diff | |
125 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
125 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 | |
126 | assert_response :success |
|
126 | assert_response :success | |
127 | assert_template 'diff' |
|
127 | assert_template 'diff' | |
128 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
128 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
129 | :content => /updated/ |
|
129 | :content => /updated/ | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_annotate |
|
132 | def test_annotate | |
133 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 |
|
133 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 | |
134 | assert_response :success |
|
134 | assert_response :success | |
135 | assert_template 'annotate' |
|
135 | assert_template 'annotate' | |
136 | # Line 1 |
|
136 | # Line 1 | |
137 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, |
|
137 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, | |
138 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, |
|
138 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, | |
139 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } |
|
139 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } | |
140 | # Line 2 |
|
140 | # Line 2 | |
141 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, |
|
141 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, | |
142 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, |
|
142 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, | |
143 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } |
|
143 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } | |
144 | end |
|
144 | end | |
145 |
|
145 | |||
146 | def test_rename_with_redirect |
|
146 | def test_rename_with_redirect | |
147 | @request.session[:user_id] = 2 |
|
147 | @request.session[:user_id] = 2 | |
148 | post :rename, :id => 1, :page => 'Another_page', |
|
148 | post :rename, :id => 1, :page => 'Another_page', | |
149 | :wiki_page => { :title => 'Another renamed page', |
|
149 | :wiki_page => { :title => 'Another renamed page', | |
150 | :redirect_existing_links => 1 } |
|
150 | :redirect_existing_links => 1 } | |
151 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' |
|
151 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
152 | wiki = Project.find(1).wiki |
|
152 | wiki = Project.find(1).wiki | |
153 | # Check redirects |
|
153 | # Check redirects | |
154 | assert_not_nil wiki.find_page('Another page') |
|
154 | assert_not_nil wiki.find_page('Another page') | |
155 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
155 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_rename_without_redirect |
|
158 | def test_rename_without_redirect | |
159 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 | |
160 | post :rename, :id => 1, :page => 'Another_page', |
|
160 | post :rename, :id => 1, :page => 'Another_page', | |
161 | :wiki_page => { :title => 'Another renamed page', |
|
161 | :wiki_page => { :title => 'Another renamed page', | |
162 | :redirect_existing_links => "0" } |
|
162 | :redirect_existing_links => "0" } | |
163 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' |
|
163 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
164 | wiki = Project.find(1).wiki |
|
164 | wiki = Project.find(1).wiki | |
165 | # Check that there's no redirects |
|
165 | # Check that there's no redirects | |
166 | assert_nil wiki.find_page('Another page') |
|
166 | assert_nil wiki.find_page('Another page') | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_destroy |
|
169 | def test_destroy | |
170 | @request.session[:user_id] = 2 |
|
170 | @request.session[:user_id] = 2 | |
171 | post :destroy, :id => 1, :page => 'CookBook_documentation' |
|
171 | post :destroy, :id => 1, :page => 'CookBook_documentation' | |
172 | assert_redirected_to 'wiki/ecookbook/Page_index/special' |
|
172 | assert_redirected_to 'wiki/ecookbook/Page_index/special' | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def test_page_index |
|
175 | def test_page_index | |
176 | get :special, :id => 'ecookbook', :page => 'Page_index' |
|
176 | get :special, :id => 'ecookbook', :page => 'Page_index' | |
177 | assert_response :success |
|
177 | assert_response :success | |
178 | assert_template 'special_page_index' |
|
178 | assert_template 'special_page_index' | |
179 | pages = assigns(:pages) |
|
179 | pages = assigns(:pages) | |
180 | assert_not_nil pages |
|
180 | assert_not_nil pages | |
181 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
181 | assert_equal Project.find(1).wiki.pages.size, pages.size | |
182 |
|
182 | |||
183 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
183 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
184 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, |
|
184 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | |
185 | :content => 'CookBook documentation' }, |
|
185 | :content => 'CookBook documentation' }, | |
186 | :child => { :tag => 'ul', |
|
186 | :child => { :tag => 'ul', | |
187 | :child => { :tag => 'li', |
|
187 | :child => { :tag => 'li', | |
188 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, |
|
188 | :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' }, | |
189 | :content => 'Page with an inline image' } } } }, |
|
189 | :content => 'Page with an inline image' } } } }, | |
190 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' }, |
|
190 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' }, | |
191 | :content => 'Another page' } } |
|
191 | :content => 'Another page' } } | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def test_not_found |
|
194 | def test_not_found | |
195 | get :index, :id => 999 |
|
195 | get :index, :id => 999 | |
196 | assert_response 404 |
|
196 | assert_response 404 | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | def test_protect_page |
|
199 | def test_protect_page | |
200 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
200 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
201 | assert !page.protected? |
|
201 | assert !page.protected? | |
202 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
203 | post :protect, :id => 1, :page => page.title, :protected => '1' |
|
203 | post :protect, :id => 1, :page => page.title, :protected => '1' | |
204 | assert_redirected_to 'wiki/ecookbook/Another_page' |
|
204 | assert_redirected_to 'wiki/ecookbook/Another_page' | |
205 | assert page.reload.protected? |
|
205 | assert page.reload.protected? | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def test_unprotect_page |
|
208 | def test_unprotect_page | |
209 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
209 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
210 | assert page.protected? |
|
210 | assert page.protected? | |
211 | @request.session[:user_id] = 2 |
|
211 | @request.session[:user_id] = 2 | |
212 | post :protect, :id => 1, :page => page.title, :protected => '0' |
|
212 | post :protect, :id => 1, :page => page.title, :protected => '0' | |
213 | assert_redirected_to 'wiki/ecookbook' |
|
213 | assert_redirected_to '/wiki/ecookbook/CookBook_documentation' | |
214 | assert !page.reload.protected? |
|
214 | assert !page.reload.protected? | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_show_page_with_edit_link |
|
217 | def test_show_page_with_edit_link | |
218 | @request.session[:user_id] = 2 |
|
218 | @request.session[:user_id] = 2 | |
219 | get :index, :id => 1 |
|
219 | get :index, :id => 1 | |
220 | assert_response :success |
|
220 | assert_response :success | |
221 | assert_template 'show' |
|
221 | assert_template 'show' | |
222 | assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } |
|
222 | assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } | |
223 | end |
|
223 | end | |
224 |
|
224 | |||
225 | def test_show_page_without_edit_link |
|
225 | def test_show_page_without_edit_link | |
226 | @request.session[:user_id] = 4 |
|
226 | @request.session[:user_id] = 4 | |
227 | get :index, :id => 1 |
|
227 | get :index, :id => 1 | |
228 | assert_response :success |
|
228 | assert_response :success | |
229 | assert_template 'show' |
|
229 | assert_template 'show' | |
230 | assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } |
|
230 | assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' } | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def test_edit_unprotected_page |
|
233 | def test_edit_unprotected_page | |
234 | # Non members can edit unprotected wiki pages |
|
234 | # Non members can edit unprotected wiki pages | |
235 | @request.session[:user_id] = 4 |
|
235 | @request.session[:user_id] = 4 | |
236 | get :edit, :id => 1, :page => 'Another_page' |
|
236 | get :edit, :id => 1, :page => 'Another_page' | |
237 | assert_response :success |
|
237 | assert_response :success | |
238 | assert_template 'edit' |
|
238 | assert_template 'edit' | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | def test_edit_protected_page_by_nonmember |
|
241 | def test_edit_protected_page_by_nonmember | |
242 | # Non members can't edit protected wiki pages |
|
242 | # Non members can't edit protected wiki pages | |
243 | @request.session[:user_id] = 4 |
|
243 | @request.session[:user_id] = 4 | |
244 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
244 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
245 | assert_response 403 |
|
245 | assert_response 403 | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def test_edit_protected_page_by_member |
|
248 | def test_edit_protected_page_by_member | |
249 | @request.session[:user_id] = 2 |
|
249 | @request.session[:user_id] = 2 | |
250 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
250 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
251 | assert_response :success |
|
251 | assert_response :success | |
252 | assert_template 'edit' |
|
252 | assert_template 'edit' | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_history_of_non_existing_page_should_return_404 |
|
255 | def test_history_of_non_existing_page_should_return_404 | |
256 | get :history, :id => 1, :page => 'Unknown_page' |
|
256 | get :history, :id => 1, :page => 'Unknown_page' | |
257 | assert_response 404 |
|
257 | assert_response 404 | |
258 | end |
|
258 | end | |
259 | end |
|
259 | end |
@@ -1,56 +1,56 | |||||
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 | require 'wikis_controller' |
|
19 | require 'wikis_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WikisController; def rescue_action(e) raise e end; end |
|
22 | class WikisController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WikisControllerTest < Test::Unit::TestCase |
|
24 | class WikisControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis |
|
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WikisController.new |
|
28 | @controller = WikisController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_create |
|
34 | def test_create | |
35 | @request.session[:user_id] = 1 |
|
35 | @request.session[:user_id] = 1 | |
36 | assert_nil Project.find(3).wiki |
|
36 | assert_nil Project.find(3).wiki | |
37 | post :edit, :id => 3, :wiki => { :start_page => 'Start page' } |
|
37 | post :edit, :id => 3, :wiki => { :start_page => 'Start page' } | |
38 | assert_response :success |
|
38 | assert_response :success | |
39 | wiki = Project.find(3).wiki |
|
39 | wiki = Project.find(3).wiki | |
40 | assert_not_nil wiki |
|
40 | assert_not_nil wiki | |
41 | assert_equal 'Start page', wiki.start_page |
|
41 | assert_equal 'Start page', wiki.start_page | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_destroy |
|
44 | def test_destroy | |
45 | @request.session[:user_id] = 1 |
|
45 | @request.session[:user_id] = 1 | |
46 | post :destroy, :id => 1, :confirm => 1 |
|
46 | post :destroy, :id => 1, :confirm => 1 | |
47 | assert_redirected_to 'projects/settings/ecookbook' |
|
47 | assert_redirected_to '/projects/settings/ecookbook?tab=wiki' | |
48 | assert_nil Project.find(1).wiki |
|
48 | assert_nil Project.find(1).wiki | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def test_not_found |
|
51 | def test_not_found | |
52 | @request.session[:user_id] = 1 |
|
52 | @request.session[:user_id] = 1 | |
53 | post :destroy, :id => 999, :confirm => 1 |
|
53 | post :destroy, :id => 999, :confirm => 1 | |
54 | assert_response 404 |
|
54 | assert_response 404 | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end |
@@ -1,84 +1,84 | |||||
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 'workflows_controller' |
|
19 | require 'workflows_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WorkflowsController; def rescue_action(e) raise e end; end |
|
22 | class WorkflowsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WorkflowsControllerTest < Test::Unit::TestCase |
|
24 | class WorkflowsControllerTest < Test::Unit::TestCase | |
25 | fixtures :roles, :trackers, :workflows |
|
25 | fixtures :roles, :trackers, :workflows | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WorkflowsController.new |
|
28 | @controller = WorkflowsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_index |
|
35 | def test_index | |
36 | get :index |
|
36 | get :index | |
37 | assert_response :success |
|
37 | assert_response :success | |
38 | assert_template 'index' |
|
38 | assert_template 'index' | |
39 |
|
39 | |||
40 | count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') |
|
40 | count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | |
41 | assert_tag :tag => 'a', :content => count.to_s, |
|
41 | assert_tag :tag => 'a', :content => count.to_s, | |
42 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } |
|
42 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_get_edit |
|
45 | def test_get_edit | |
46 | get :edit |
|
46 | get :edit | |
47 | assert_response :success |
|
47 | assert_response :success | |
48 | assert_template 'edit' |
|
48 | assert_template 'edit' | |
49 | assert_not_nil assigns(:roles) |
|
49 | assert_not_nil assigns(:roles) | |
50 | assert_not_nil assigns(:trackers) |
|
50 | assert_not_nil assigns(:trackers) | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_get_edit_with_role_and_tracker |
|
53 | def test_get_edit_with_role_and_tracker | |
54 | get :edit, :role_id => 2, :tracker_id => 1 |
|
54 | get :edit, :role_id => 2, :tracker_id => 1 | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template 'edit' |
|
56 | assert_template 'edit' | |
57 | # allowed transitions |
|
57 | # allowed transitions | |
58 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
58 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
59 | :name => 'issue_status[2][]', |
|
59 | :name => 'issue_status[2][]', | |
60 | :value => '1', |
|
60 | :value => '1', | |
61 | :checked => 'checked' } |
|
61 | :checked => 'checked' } | |
62 | # not allowed |
|
62 | # not allowed | |
63 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
63 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
64 | :name => 'issue_status[2][]', |
|
64 | :name => 'issue_status[2][]', | |
65 | :value => '3', |
|
65 | :value => '3', | |
66 | :checked => nil } |
|
66 | :checked => nil } | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_post_edit |
|
69 | def test_post_edit | |
70 | post :edit, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']} |
|
70 | post :edit, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']} | |
71 | assert_redirected_to 'workflows/edit' |
|
71 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
72 |
|
72 | |||
73 | assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
73 | assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
74 | assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) |
|
74 | assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | |
75 | assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) |
|
75 | assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_clear_workflow |
|
78 | def test_clear_workflow | |
79 | assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 |
|
79 | assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | |
80 |
|
80 | |||
81 | post :edit, :role_id => 2, :tracker_id => 1 |
|
81 | post :edit, :role_id => 2, :tracker_id => 1 | |
82 | assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
82 | assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end |
General Comments 0
You need to be logged in to leave comments.
Login now