@@ -1,146 +1,139 | |||||
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 < ActionController::TestCase |
|
24 | class AdminControllerTest < ActionController::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_projects_routing |
|
|||
42 | assert_routing( |
|
|||
43 | {:method => :get, :path => '/admin/projects'}, |
|
|||
44 | :controller => 'admin', :action => 'projects' |
|
|||
45 | ) |
|
|||
46 | end |
|
|||
47 |
|
||||
48 | def test_index_with_no_configuration_data |
|
41 | def test_index_with_no_configuration_data | |
49 | delete_configuration_data |
|
42 | delete_configuration_data | |
50 | get :index |
|
43 | get :index | |
51 | assert_tag :tag => 'div', |
|
44 | assert_tag :tag => 'div', | |
52 | :attributes => { :class => /nodata/ } |
|
45 | :attributes => { :class => /nodata/ } | |
53 | end |
|
46 | end | |
54 |
|
47 | |||
55 | def test_projects |
|
48 | def test_projects | |
56 | get :projects |
|
49 | get :projects | |
57 | assert_response :success |
|
50 | assert_response :success | |
58 | assert_template 'projects' |
|
51 | assert_template 'projects' | |
59 | assert_not_nil assigns(:projects) |
|
52 | assert_not_nil assigns(:projects) | |
60 | # active projects only |
|
53 | # active projects only | |
61 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
54 | assert_nil assigns(:projects).detect {|u| !u.active?} | |
62 | end |
|
55 | end | |
63 |
|
56 | |||
64 | def test_projects_with_name_filter |
|
57 | def test_projects_with_name_filter | |
65 | get :projects, :name => 'store', :status => '' |
|
58 | get :projects, :name => 'store', :status => '' | |
66 | assert_response :success |
|
59 | assert_response :success | |
67 | assert_template 'projects' |
|
60 | assert_template 'projects' | |
68 | projects = assigns(:projects) |
|
61 | projects = assigns(:projects) | |
69 | assert_not_nil projects |
|
62 | assert_not_nil projects | |
70 | assert_equal 1, projects.size |
|
63 | assert_equal 1, projects.size | |
71 | assert_equal 'OnlineStore', projects.first.name |
|
64 | assert_equal 'OnlineStore', projects.first.name | |
72 | end |
|
65 | end | |
73 |
|
66 | |||
74 | def test_load_default_configuration_data |
|
67 | def test_load_default_configuration_data | |
75 | delete_configuration_data |
|
68 | delete_configuration_data | |
76 | post :default_configuration, :lang => 'fr' |
|
69 | post :default_configuration, :lang => 'fr' | |
77 | assert IssueStatus.find_by_name('Nouveau') |
|
70 | assert IssueStatus.find_by_name('Nouveau') | |
78 | end |
|
71 | end | |
79 |
|
72 | |||
80 | def test_test_email |
|
73 | def test_test_email | |
81 | get :test_email |
|
74 | get :test_email | |
82 | assert_redirected_to '/settings/edit?tab=notifications' |
|
75 | assert_redirected_to '/settings/edit?tab=notifications' | |
83 | mail = ActionMailer::Base.deliveries.last |
|
76 | mail = ActionMailer::Base.deliveries.last | |
84 | assert_kind_of TMail::Mail, mail |
|
77 | assert_kind_of TMail::Mail, mail | |
85 | user = User.find(1) |
|
78 | user = User.find(1) | |
86 | assert_equal [user.mail], mail.bcc |
|
79 | assert_equal [user.mail], mail.bcc | |
87 | end |
|
80 | end | |
88 |
|
81 | |||
89 | def test_no_plugins |
|
82 | def test_no_plugins | |
90 | Redmine::Plugin.clear |
|
83 | Redmine::Plugin.clear | |
91 |
|
84 | |||
92 | get :plugins |
|
85 | get :plugins | |
93 | assert_response :success |
|
86 | assert_response :success | |
94 | assert_template 'plugins' |
|
87 | assert_template 'plugins' | |
95 | end |
|
88 | end | |
96 |
|
89 | |||
97 | def test_plugins |
|
90 | def test_plugins | |
98 | # Register a few plugins |
|
91 | # Register a few plugins | |
99 | Redmine::Plugin.register :foo do |
|
92 | Redmine::Plugin.register :foo do | |
100 | name 'Foo plugin' |
|
93 | name 'Foo plugin' | |
101 | author 'John Smith' |
|
94 | author 'John Smith' | |
102 | description 'This is a test plugin' |
|
95 | description 'This is a test plugin' | |
103 | version '0.0.1' |
|
96 | version '0.0.1' | |
104 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
97 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' | |
105 | end |
|
98 | end | |
106 | Redmine::Plugin.register :bar do |
|
99 | Redmine::Plugin.register :bar do | |
107 | end |
|
100 | end | |
108 |
|
101 | |||
109 | get :plugins |
|
102 | get :plugins | |
110 | assert_response :success |
|
103 | assert_response :success | |
111 | assert_template 'plugins' |
|
104 | assert_template 'plugins' | |
112 |
|
105 | |||
113 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
106 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } | |
114 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
107 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } | |
115 | end |
|
108 | end | |
116 |
|
109 | |||
117 | def test_info |
|
110 | def test_info | |
118 | get :info |
|
111 | get :info | |
119 | assert_response :success |
|
112 | assert_response :success | |
120 | assert_template 'info' |
|
113 | assert_template 'info' | |
121 | end |
|
114 | end | |
122 |
|
115 | |||
123 | def test_admin_menu_plugin_extension |
|
116 | def test_admin_menu_plugin_extension | |
124 | Redmine::MenuManager.map :admin_menu do |menu| |
|
117 | Redmine::MenuManager.map :admin_menu do |menu| | |
125 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' |
|
118 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' | |
126 | end |
|
119 | end | |
127 |
|
120 | |||
128 | get :index |
|
121 | get :index | |
129 | assert_response :success |
|
122 | assert_response :success | |
130 | assert_tag :a, :attributes => { :href => '/foo/bar' }, |
|
123 | assert_tag :a, :attributes => { :href => '/foo/bar' }, | |
131 | :content => 'Test' |
|
124 | :content => 'Test' | |
132 |
|
125 | |||
133 | Redmine::MenuManager.map :admin_menu do |menu| |
|
126 | Redmine::MenuManager.map :admin_menu do |menu| | |
134 | menu.delete :test_admin_menu_plugin_extension |
|
127 | menu.delete :test_admin_menu_plugin_extension | |
135 | end |
|
128 | end | |
136 | end |
|
129 | end | |
137 |
|
130 | |||
138 | private |
|
131 | private | |
139 |
|
132 | |||
140 | def delete_configuration_data |
|
133 | def delete_configuration_data | |
141 | Role.delete_all('builtin = 0') |
|
134 | Role.delete_all('builtin = 0') | |
142 | Tracker.delete_all |
|
135 | Tracker.delete_all | |
143 | IssueStatus.delete_all |
|
136 | IssueStatus.delete_all | |
144 | Enumeration.delete_all |
|
137 | Enumeration.delete_all | |
145 | end |
|
138 | end | |
146 | end |
|
139 | end |
@@ -1,1368 +1,1354 | |||||
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 < ActionController::TestCase |
|
24 | class IssuesControllerTest < ActionController::TestCase | |
25 | fixtures :projects, |
|
25 | fixtures :projects, | |
26 | :users, |
|
26 | :users, | |
27 | :roles, |
|
27 | :roles, | |
28 | :members, |
|
28 | :members, | |
29 | :member_roles, |
|
29 | :member_roles, | |
30 | :issues, |
|
30 | :issues, | |
31 | :issue_statuses, |
|
31 | :issue_statuses, | |
32 | :versions, |
|
32 | :versions, | |
33 | :trackers, |
|
33 | :trackers, | |
34 | :projects_trackers, |
|
34 | :projects_trackers, | |
35 | :issue_categories, |
|
35 | :issue_categories, | |
36 | :enabled_modules, |
|
36 | :enabled_modules, | |
37 | :enumerations, |
|
37 | :enumerations, | |
38 | :attachments, |
|
38 | :attachments, | |
39 | :workflows, |
|
39 | :workflows, | |
40 | :custom_fields, |
|
40 | :custom_fields, | |
41 | :custom_values, |
|
41 | :custom_values, | |
42 | :custom_fields_projects, |
|
42 | :custom_fields_projects, | |
43 | :custom_fields_trackers, |
|
43 | :custom_fields_trackers, | |
44 | :time_entries, |
|
44 | :time_entries, | |
45 | :journals, |
|
45 | :journals, | |
46 | :journal_details, |
|
46 | :journal_details, | |
47 | :queries |
|
47 | :queries | |
48 |
|
48 | |||
49 | def setup |
|
49 | def setup | |
50 | @controller = IssuesController.new |
|
50 | @controller = IssuesController.new | |
51 | @request = ActionController::TestRequest.new |
|
51 | @request = ActionController::TestRequest.new | |
52 | @response = ActionController::TestResponse.new |
|
52 | @response = ActionController::TestResponse.new | |
53 | User.current = nil |
|
53 | User.current = nil | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_index |
|
56 | def test_index | |
57 | Setting.default_language = 'en' |
|
57 | Setting.default_language = 'en' | |
58 |
|
58 | |||
59 | get :index |
|
59 | get :index | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'index.rhtml' |
|
61 | assert_template 'index.rhtml' | |
62 | assert_not_nil assigns(:issues) |
|
62 | assert_not_nil assigns(:issues) | |
63 | assert_nil assigns(:project) |
|
63 | assert_nil assigns(:project) | |
64 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
64 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
65 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
65 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
66 | # private projects hidden |
|
66 | # private projects hidden | |
67 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
67 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
68 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
68 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ | |
69 | # project column |
|
69 | # project column | |
70 | assert_tag :tag => 'th', :content => /Project/ |
|
70 | assert_tag :tag => 'th', :content => /Project/ | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_index_should_not_list_issues_when_module_disabled |
|
73 | def test_index_should_not_list_issues_when_module_disabled | |
74 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
74 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
75 | get :index |
|
75 | get :index | |
76 | assert_response :success |
|
76 | assert_response :success | |
77 | assert_template 'index.rhtml' |
|
77 | assert_template 'index.rhtml' | |
78 | assert_not_nil assigns(:issues) |
|
78 | assert_not_nil assigns(:issues) | |
79 | assert_nil assigns(:project) |
|
79 | assert_nil assigns(:project) | |
80 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
80 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
81 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
81 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_index_should_not_list_issues_when_module_disabled |
|
84 | def test_index_should_not_list_issues_when_module_disabled | |
85 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
85 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
86 | get :index |
|
86 | get :index | |
87 | assert_response :success |
|
87 | assert_response :success | |
88 | assert_template 'index.rhtml' |
|
88 | assert_template 'index.rhtml' | |
89 | assert_not_nil assigns(:issues) |
|
89 | assert_not_nil assigns(:issues) | |
90 | assert_nil assigns(:project) |
|
90 | assert_nil assigns(:project) | |
91 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
91 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
92 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
92 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_index_with_project |
|
95 | def test_index_with_project | |
96 | Setting.display_subprojects_issues = 0 |
|
96 | Setting.display_subprojects_issues = 0 | |
97 | get :index, :project_id => 1 |
|
97 | get :index, :project_id => 1 | |
98 | assert_response :success |
|
98 | assert_response :success | |
99 | assert_template 'index.rhtml' |
|
99 | assert_template 'index.rhtml' | |
100 | assert_not_nil assigns(:issues) |
|
100 | assert_not_nil assigns(:issues) | |
101 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
101 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
102 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
102 | assert_no_tag :tag => 'a', :content => /Subproject issue/ | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def test_index_with_project_and_subprojects |
|
105 | def test_index_with_project_and_subprojects | |
106 | Setting.display_subprojects_issues = 1 |
|
106 | Setting.display_subprojects_issues = 1 | |
107 | get :index, :project_id => 1 |
|
107 | get :index, :project_id => 1 | |
108 | assert_response :success |
|
108 | assert_response :success | |
109 | assert_template 'index.rhtml' |
|
109 | assert_template 'index.rhtml' | |
110 | assert_not_nil assigns(:issues) |
|
110 | assert_not_nil assigns(:issues) | |
111 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
111 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
112 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
112 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
113 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
113 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
116 | def test_index_with_project_and_subprojects_should_show_private_subprojects | |
117 | @request.session[:user_id] = 2 |
|
117 | @request.session[:user_id] = 2 | |
118 | Setting.display_subprojects_issues = 1 |
|
118 | Setting.display_subprojects_issues = 1 | |
119 | get :index, :project_id => 1 |
|
119 | get :index, :project_id => 1 | |
120 | assert_response :success |
|
120 | assert_response :success | |
121 | assert_template 'index.rhtml' |
|
121 | assert_template 'index.rhtml' | |
122 | assert_not_nil assigns(:issues) |
|
122 | assert_not_nil assigns(:issues) | |
123 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
123 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
124 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
124 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
125 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
125 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_index_with_project_and_filter |
|
128 | def test_index_with_project_and_filter | |
129 | get :index, :project_id => 1, :set_filter => 1 |
|
129 | get :index, :project_id => 1, :set_filter => 1 | |
130 | assert_response :success |
|
130 | assert_response :success | |
131 | assert_template 'index.rhtml' |
|
131 | assert_template 'index.rhtml' | |
132 | assert_not_nil assigns(:issues) |
|
132 | assert_not_nil assigns(:issues) | |
133 | end |
|
133 | end | |
134 |
|
134 | |||
135 | def test_index_with_query |
|
135 | def test_index_with_query | |
136 | get :index, :project_id => 1, :query_id => 5 |
|
136 | get :index, :project_id => 1, :query_id => 5 | |
137 | assert_response :success |
|
137 | assert_response :success | |
138 | assert_template 'index.rhtml' |
|
138 | assert_template 'index.rhtml' | |
139 | assert_not_nil assigns(:issues) |
|
139 | assert_not_nil assigns(:issues) | |
140 | assert_nil assigns(:issue_count_by_group) |
|
140 | assert_nil assigns(:issue_count_by_group) | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_index_with_query_grouped_by_tracker |
|
143 | def test_index_with_query_grouped_by_tracker | |
144 | get :index, :project_id => 1, :query_id => 6 |
|
144 | get :index, :project_id => 1, :query_id => 6 | |
145 | assert_response :success |
|
145 | assert_response :success | |
146 | assert_template 'index.rhtml' |
|
146 | assert_template 'index.rhtml' | |
147 | assert_not_nil assigns(:issues) |
|
147 | assert_not_nil assigns(:issues) | |
148 | assert_not_nil assigns(:issue_count_by_group) |
|
148 | assert_not_nil assigns(:issue_count_by_group) | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_index_with_query_grouped_by_list_custom_field |
|
151 | def test_index_with_query_grouped_by_list_custom_field | |
152 | get :index, :project_id => 1, :query_id => 9 |
|
152 | get :index, :project_id => 1, :query_id => 9 | |
153 | assert_response :success |
|
153 | assert_response :success | |
154 | assert_template 'index.rhtml' |
|
154 | assert_template 'index.rhtml' | |
155 | assert_not_nil assigns(:issues) |
|
155 | assert_not_nil assigns(:issues) | |
156 | assert_not_nil assigns(:issue_count_by_group) |
|
156 | assert_not_nil assigns(:issue_count_by_group) | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def test_index_sort_by_field_not_included_in_columns |
|
159 | def test_index_sort_by_field_not_included_in_columns | |
160 | Setting.issue_list_default_columns = %w(subject author) |
|
160 | Setting.issue_list_default_columns = %w(subject author) | |
161 | get :index, :sort => 'tracker' |
|
161 | get :index, :sort => 'tracker' | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def test_index_csv_with_project |
|
164 | def test_index_csv_with_project | |
165 | Setting.default_language = 'en' |
|
165 | Setting.default_language = 'en' | |
166 |
|
166 | |||
167 | get :index, :format => 'csv' |
|
167 | get :index, :format => 'csv' | |
168 | assert_response :success |
|
168 | assert_response :success | |
169 | assert_not_nil assigns(:issues) |
|
169 | assert_not_nil assigns(:issues) | |
170 | assert_equal 'text/csv', @response.content_type |
|
170 | assert_equal 'text/csv', @response.content_type | |
171 | assert @response.body.starts_with?("#,") |
|
171 | assert @response.body.starts_with?("#,") | |
172 |
|
172 | |||
173 | get :index, :project_id => 1, :format => 'csv' |
|
173 | get :index, :project_id => 1, :format => 'csv' | |
174 | assert_response :success |
|
174 | assert_response :success | |
175 | assert_not_nil assigns(:issues) |
|
175 | assert_not_nil assigns(:issues) | |
176 | assert_equal 'text/csv', @response.content_type |
|
176 | assert_equal 'text/csv', @response.content_type | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | def test_index_pdf |
|
179 | def test_index_pdf | |
180 | get :index, :format => 'pdf' |
|
180 | get :index, :format => 'pdf' | |
181 | assert_response :success |
|
181 | assert_response :success | |
182 | assert_not_nil assigns(:issues) |
|
182 | assert_not_nil assigns(:issues) | |
183 | assert_equal 'application/pdf', @response.content_type |
|
183 | assert_equal 'application/pdf', @response.content_type | |
184 |
|
184 | |||
185 | get :index, :project_id => 1, :format => 'pdf' |
|
185 | get :index, :project_id => 1, :format => 'pdf' | |
186 | assert_response :success |
|
186 | assert_response :success | |
187 | assert_not_nil assigns(:issues) |
|
187 | assert_not_nil assigns(:issues) | |
188 | assert_equal 'application/pdf', @response.content_type |
|
188 | assert_equal 'application/pdf', @response.content_type | |
189 |
|
189 | |||
190 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
190 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | |
191 | assert_response :success |
|
191 | assert_response :success | |
192 | assert_not_nil assigns(:issues) |
|
192 | assert_not_nil assigns(:issues) | |
193 | assert_equal 'application/pdf', @response.content_type |
|
193 | assert_equal 'application/pdf', @response.content_type | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_index_pdf_with_query_grouped_by_list_custom_field |
|
196 | def test_index_pdf_with_query_grouped_by_list_custom_field | |
197 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
|
197 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' | |
198 | assert_response :success |
|
198 | assert_response :success | |
199 | assert_not_nil assigns(:issues) |
|
199 | assert_not_nil assigns(:issues) | |
200 | assert_not_nil assigns(:issue_count_by_group) |
|
200 | assert_not_nil assigns(:issue_count_by_group) | |
201 | assert_equal 'application/pdf', @response.content_type |
|
201 | assert_equal 'application/pdf', @response.content_type | |
202 | end |
|
202 | end | |
203 |
|
203 | |||
204 | def test_index_sort |
|
204 | def test_index_sort | |
205 | get :index, :sort => 'tracker,id:desc' |
|
205 | get :index, :sort => 'tracker,id:desc' | |
206 | assert_response :success |
|
206 | assert_response :success | |
207 |
|
207 | |||
208 | sort_params = @request.session['issues_index_sort'] |
|
208 | sort_params = @request.session['issues_index_sort'] | |
209 | assert sort_params.is_a?(String) |
|
209 | assert sort_params.is_a?(String) | |
210 | assert_equal 'tracker,id:desc', sort_params |
|
210 | assert_equal 'tracker,id:desc', sort_params | |
211 |
|
211 | |||
212 | issues = assigns(:issues) |
|
212 | issues = assigns(:issues) | |
213 | assert_not_nil issues |
|
213 | assert_not_nil issues | |
214 | assert !issues.empty? |
|
214 | assert !issues.empty? | |
215 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
215 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | def test_index_with_columns |
|
218 | def test_index_with_columns | |
219 | columns = ['tracker', 'subject', 'assigned_to'] |
|
219 | columns = ['tracker', 'subject', 'assigned_to'] | |
220 | get :index, :set_filter => 1, :query => { 'column_names' => columns} |
|
220 | get :index, :set_filter => 1, :query => { 'column_names' => columns} | |
221 | assert_response :success |
|
221 | assert_response :success | |
222 |
|
222 | |||
223 | # query should use specified columns |
|
223 | # query should use specified columns | |
224 | query = assigns(:query) |
|
224 | query = assigns(:query) | |
225 | assert_kind_of Query, query |
|
225 | assert_kind_of Query, query | |
226 | assert_equal columns, query.column_names.map(&:to_s) |
|
226 | assert_equal columns, query.column_names.map(&:to_s) | |
227 |
|
227 | |||
228 | # columns should be stored in session |
|
228 | # columns should be stored in session | |
229 | assert_kind_of Hash, session[:query] |
|
229 | assert_kind_of Hash, session[:query] | |
230 | assert_kind_of Array, session[:query][:column_names] |
|
230 | assert_kind_of Array, session[:query][:column_names] | |
231 | assert_equal columns, session[:query][:column_names].map(&:to_s) |
|
231 | assert_equal columns, session[:query][:column_names].map(&:to_s) | |
232 | end |
|
232 | end | |
233 |
|
233 | |||
234 | def test_gantt |
|
234 | def test_gantt | |
235 | get :gantt, :project_id => 1 |
|
235 | get :gantt, :project_id => 1 | |
236 | assert_response :success |
|
236 | assert_response :success | |
237 | assert_template 'gantt.rhtml' |
|
237 | assert_template 'gantt.rhtml' | |
238 | assert_not_nil assigns(:gantt) |
|
238 | assert_not_nil assigns(:gantt) | |
239 | events = assigns(:gantt).events |
|
239 | events = assigns(:gantt).events | |
240 | assert_not_nil events |
|
240 | assert_not_nil events | |
241 | # Issue with start and due dates |
|
241 | # Issue with start and due dates | |
242 | i = Issue.find(1) |
|
242 | i = Issue.find(1) | |
243 | assert_not_nil i.due_date |
|
243 | assert_not_nil i.due_date | |
244 | assert events.include?(Issue.find(1)) |
|
244 | assert events.include?(Issue.find(1)) | |
245 | # Issue with without due date but targeted to a version with date |
|
245 | # Issue with without due date but targeted to a version with date | |
246 | i = Issue.find(2) |
|
246 | i = Issue.find(2) | |
247 | assert_nil i.due_date |
|
247 | assert_nil i.due_date | |
248 | assert events.include?(i) |
|
248 | assert events.include?(i) | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | def test_cross_project_gantt |
|
251 | def test_cross_project_gantt | |
252 | get :gantt |
|
252 | get :gantt | |
253 | assert_response :success |
|
253 | assert_response :success | |
254 | assert_template 'gantt.rhtml' |
|
254 | assert_template 'gantt.rhtml' | |
255 | assert_not_nil assigns(:gantt) |
|
255 | assert_not_nil assigns(:gantt) | |
256 | events = assigns(:gantt).events |
|
256 | events = assigns(:gantt).events | |
257 | assert_not_nil events |
|
257 | assert_not_nil events | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | def test_gantt_export_to_pdf |
|
260 | def test_gantt_export_to_pdf | |
261 | get :gantt, :project_id => 1, :format => 'pdf' |
|
261 | get :gantt, :project_id => 1, :format => 'pdf' | |
262 | assert_response :success |
|
262 | assert_response :success | |
263 | assert_equal 'application/pdf', @response.content_type |
|
263 | assert_equal 'application/pdf', @response.content_type | |
264 | assert @response.body.starts_with?('%PDF') |
|
264 | assert @response.body.starts_with?('%PDF') | |
265 | assert_not_nil assigns(:gantt) |
|
265 | assert_not_nil assigns(:gantt) | |
266 | end |
|
266 | end | |
267 |
|
267 | |||
268 | def test_cross_project_gantt_export_to_pdf |
|
268 | def test_cross_project_gantt_export_to_pdf | |
269 | get :gantt, :format => 'pdf' |
|
269 | get :gantt, :format => 'pdf' | |
270 | assert_response :success |
|
270 | assert_response :success | |
271 | assert_equal 'application/pdf', @response.content_type |
|
271 | assert_equal 'application/pdf', @response.content_type | |
272 | assert @response.body.starts_with?('%PDF') |
|
272 | assert @response.body.starts_with?('%PDF') | |
273 | assert_not_nil assigns(:gantt) |
|
273 | assert_not_nil assigns(:gantt) | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
276 | if Object.const_defined?(:Magick) |
|
276 | if Object.const_defined?(:Magick) | |
277 | def test_gantt_image |
|
277 | def test_gantt_image | |
278 | get :gantt, :project_id => 1, :format => 'png' |
|
278 | get :gantt, :project_id => 1, :format => 'png' | |
279 | assert_response :success |
|
279 | assert_response :success | |
280 | assert_equal 'image/png', @response.content_type |
|
280 | assert_equal 'image/png', @response.content_type | |
281 | end |
|
281 | end | |
282 | else |
|
282 | else | |
283 | puts "RMagick not installed. Skipping tests !!!" |
|
283 | puts "RMagick not installed. Skipping tests !!!" | |
284 | end |
|
284 | end | |
285 |
|
285 | |||
286 | def test_calendar |
|
286 | def test_calendar | |
287 | get :calendar, :project_id => 1 |
|
287 | get :calendar, :project_id => 1 | |
288 | assert_response :success |
|
288 | assert_response :success | |
289 | assert_template 'calendar' |
|
289 | assert_template 'calendar' | |
290 | assert_not_nil assigns(:calendar) |
|
290 | assert_not_nil assigns(:calendar) | |
291 | end |
|
291 | end | |
292 |
|
292 | |||
293 | def test_cross_project_calendar |
|
293 | def test_cross_project_calendar | |
294 | get :calendar |
|
294 | get :calendar | |
295 | assert_response :success |
|
295 | assert_response :success | |
296 | assert_template 'calendar' |
|
296 | assert_template 'calendar' | |
297 | assert_not_nil assigns(:calendar) |
|
297 | assert_not_nil assigns(:calendar) | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_changes |
|
300 | def test_changes | |
301 | get :changes, :project_id => 1 |
|
301 | get :changes, :project_id => 1 | |
302 | assert_response :success |
|
302 | assert_response :success | |
303 | assert_not_nil assigns(:journals) |
|
303 | assert_not_nil assigns(:journals) | |
304 | assert_equal 'application/atom+xml', @response.content_type |
|
304 | assert_equal 'application/atom+xml', @response.content_type | |
305 | end |
|
305 | end | |
306 |
|
306 | |||
307 | def test_show_by_anonymous |
|
307 | def test_show_by_anonymous | |
308 | get :show, :id => 1 |
|
308 | get :show, :id => 1 | |
309 | assert_response :success |
|
309 | assert_response :success | |
310 | assert_template 'show.rhtml' |
|
310 | assert_template 'show.rhtml' | |
311 | assert_not_nil assigns(:issue) |
|
311 | assert_not_nil assigns(:issue) | |
312 | assert_equal Issue.find(1), assigns(:issue) |
|
312 | assert_equal Issue.find(1), assigns(:issue) | |
313 |
|
313 | |||
314 | # anonymous role is allowed to add a note |
|
314 | # anonymous role is allowed to add a note | |
315 | assert_tag :tag => 'form', |
|
315 | assert_tag :tag => 'form', | |
316 | :descendant => { :tag => 'fieldset', |
|
316 | :descendant => { :tag => 'fieldset', | |
317 | :child => { :tag => 'legend', |
|
317 | :child => { :tag => 'legend', | |
318 | :content => /Notes/ } } |
|
318 | :content => /Notes/ } } | |
319 | end |
|
319 | end | |
320 |
|
320 | |||
321 | def test_show_by_manager |
|
321 | def test_show_by_manager | |
322 | @request.session[:user_id] = 2 |
|
322 | @request.session[:user_id] = 2 | |
323 | get :show, :id => 1 |
|
323 | get :show, :id => 1 | |
324 | assert_response :success |
|
324 | assert_response :success | |
325 |
|
325 | |||
326 | assert_tag :tag => 'form', |
|
326 | assert_tag :tag => 'form', | |
327 | :descendant => { :tag => 'fieldset', |
|
327 | :descendant => { :tag => 'fieldset', | |
328 | :child => { :tag => 'legend', |
|
328 | :child => { :tag => 'legend', | |
329 | :content => /Change properties/ } }, |
|
329 | :content => /Change properties/ } }, | |
330 | :descendant => { :tag => 'fieldset', |
|
330 | :descendant => { :tag => 'fieldset', | |
331 | :child => { :tag => 'legend', |
|
331 | :child => { :tag => 'legend', | |
332 | :content => /Log time/ } }, |
|
332 | :content => /Log time/ } }, | |
333 | :descendant => { :tag => 'fieldset', |
|
333 | :descendant => { :tag => 'fieldset', | |
334 | :child => { :tag => 'legend', |
|
334 | :child => { :tag => 'legend', | |
335 | :content => /Notes/ } } |
|
335 | :content => /Notes/ } } | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | def test_show_should_deny_anonymous_access_without_permission |
|
338 | def test_show_should_deny_anonymous_access_without_permission | |
339 | Role.anonymous.remove_permission!(:view_issues) |
|
339 | Role.anonymous.remove_permission!(:view_issues) | |
340 | get :show, :id => 1 |
|
340 | get :show, :id => 1 | |
341 | assert_response :redirect |
|
341 | assert_response :redirect | |
342 | end |
|
342 | end | |
343 |
|
343 | |||
344 | def test_show_should_deny_non_member_access_without_permission |
|
344 | def test_show_should_deny_non_member_access_without_permission | |
345 | Role.non_member.remove_permission!(:view_issues) |
|
345 | Role.non_member.remove_permission!(:view_issues) | |
346 | @request.session[:user_id] = 9 |
|
346 | @request.session[:user_id] = 9 | |
347 | get :show, :id => 1 |
|
347 | get :show, :id => 1 | |
348 | assert_response 403 |
|
348 | assert_response 403 | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | def test_show_should_deny_member_access_without_permission |
|
351 | def test_show_should_deny_member_access_without_permission | |
352 | Role.find(1).remove_permission!(:view_issues) |
|
352 | Role.find(1).remove_permission!(:view_issues) | |
353 | @request.session[:user_id] = 2 |
|
353 | @request.session[:user_id] = 2 | |
354 | get :show, :id => 1 |
|
354 | get :show, :id => 1 | |
355 | assert_response 403 |
|
355 | assert_response 403 | |
356 | end |
|
356 | end | |
357 |
|
357 | |||
358 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
358 | def test_show_should_not_disclose_relations_to_invisible_issues | |
359 | Setting.cross_project_issue_relations = '1' |
|
359 | Setting.cross_project_issue_relations = '1' | |
360 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
360 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | |
361 | # Relation to a private project issue |
|
361 | # Relation to a private project issue | |
362 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
362 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | |
363 |
|
363 | |||
364 | get :show, :id => 1 |
|
364 | get :show, :id => 1 | |
365 | assert_response :success |
|
365 | assert_response :success | |
366 |
|
366 | |||
367 | assert_tag :div, :attributes => { :id => 'relations' }, |
|
367 | assert_tag :div, :attributes => { :id => 'relations' }, | |
368 | :descendant => { :tag => 'a', :content => /#2$/ } |
|
368 | :descendant => { :tag => 'a', :content => /#2$/ } | |
369 | assert_no_tag :div, :attributes => { :id => 'relations' }, |
|
369 | assert_no_tag :div, :attributes => { :id => 'relations' }, | |
370 | :descendant => { :tag => 'a', :content => /#4$/ } |
|
370 | :descendant => { :tag => 'a', :content => /#4$/ } | |
371 | end |
|
371 | end | |
372 |
|
372 | |||
373 | def test_show_atom |
|
373 | def test_show_atom | |
374 | get :show, :id => 2, :format => 'atom' |
|
374 | get :show, :id => 2, :format => 'atom' | |
375 | assert_response :success |
|
375 | assert_response :success | |
376 | assert_template 'changes.rxml' |
|
376 | assert_template 'changes.rxml' | |
377 | # Inline image |
|
377 | # Inline image | |
378 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
|
378 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | def test_show_export_to_pdf |
|
381 | def test_show_export_to_pdf | |
382 | get :show, :id => 3, :format => 'pdf' |
|
382 | get :show, :id => 3, :format => 'pdf' | |
383 | assert_response :success |
|
383 | assert_response :success | |
384 | assert_equal 'application/pdf', @response.content_type |
|
384 | assert_equal 'application/pdf', @response.content_type | |
385 | assert @response.body.starts_with?('%PDF') |
|
385 | assert @response.body.starts_with?('%PDF') | |
386 | assert_not_nil assigns(:issue) |
|
386 | assert_not_nil assigns(:issue) | |
387 | end |
|
387 | end | |
388 |
|
388 | |||
389 | def test_get_new |
|
389 | def test_get_new | |
390 | @request.session[:user_id] = 2 |
|
390 | @request.session[:user_id] = 2 | |
391 | get :new, :project_id => 1, :tracker_id => 1 |
|
391 | get :new, :project_id => 1, :tracker_id => 1 | |
392 | assert_response :success |
|
392 | assert_response :success | |
393 | assert_template 'new' |
|
393 | assert_template 'new' | |
394 |
|
394 | |||
395 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
395 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', | |
396 | :value => 'Default string' } |
|
396 | :value => 'Default string' } | |
397 | end |
|
397 | end | |
398 |
|
398 | |||
399 | def test_get_new_without_tracker_id |
|
399 | def test_get_new_without_tracker_id | |
400 | @request.session[:user_id] = 2 |
|
400 | @request.session[:user_id] = 2 | |
401 | get :new, :project_id => 1 |
|
401 | get :new, :project_id => 1 | |
402 | assert_response :success |
|
402 | assert_response :success | |
403 | assert_template 'new' |
|
403 | assert_template 'new' | |
404 |
|
404 | |||
405 | issue = assigns(:issue) |
|
405 | issue = assigns(:issue) | |
406 | assert_not_nil issue |
|
406 | assert_not_nil issue | |
407 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
407 | assert_equal Project.find(1).trackers.first, issue.tracker | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | def test_get_new_with_no_default_status_should_display_an_error |
|
410 | def test_get_new_with_no_default_status_should_display_an_error | |
411 | @request.session[:user_id] = 2 |
|
411 | @request.session[:user_id] = 2 | |
412 | IssueStatus.delete_all |
|
412 | IssueStatus.delete_all | |
413 |
|
413 | |||
414 | get :new, :project_id => 1 |
|
414 | get :new, :project_id => 1 | |
415 | assert_response 500 |
|
415 | assert_response 500 | |
416 | assert_not_nil flash[:error] |
|
416 | assert_not_nil flash[:error] | |
417 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
417 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
418 | :content => /No default issue/ |
|
418 | :content => /No default issue/ | |
419 | end |
|
419 | end | |
420 |
|
420 | |||
421 | def test_get_new_with_no_tracker_should_display_an_error |
|
421 | def test_get_new_with_no_tracker_should_display_an_error | |
422 | @request.session[:user_id] = 2 |
|
422 | @request.session[:user_id] = 2 | |
423 | Tracker.delete_all |
|
423 | Tracker.delete_all | |
424 |
|
424 | |||
425 | get :new, :project_id => 1 |
|
425 | get :new, :project_id => 1 | |
426 | assert_response 500 |
|
426 | assert_response 500 | |
427 | assert_not_nil flash[:error] |
|
427 | assert_not_nil flash[:error] | |
428 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
428 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
429 | :content => /No tracker/ |
|
429 | :content => /No tracker/ | |
430 | end |
|
430 | end | |
431 |
|
431 | |||
432 | def test_update_new_form |
|
432 | def test_update_new_form | |
433 | @request.session[:user_id] = 2 |
|
433 | @request.session[:user_id] = 2 | |
434 | xhr :post, :update_form, :project_id => 1, |
|
434 | xhr :post, :update_form, :project_id => 1, | |
435 | :issue => {:tracker_id => 2, |
|
435 | :issue => {:tracker_id => 2, | |
436 | :subject => 'This is the test_new issue', |
|
436 | :subject => 'This is the test_new issue', | |
437 | :description => 'This is the description', |
|
437 | :description => 'This is the description', | |
438 | :priority_id => 5} |
|
438 | :priority_id => 5} | |
439 | assert_response :success |
|
439 | assert_response :success | |
440 | assert_template 'attributes' |
|
440 | assert_template 'attributes' | |
441 |
|
441 | |||
442 | issue = assigns(:issue) |
|
442 | issue = assigns(:issue) | |
443 | assert_kind_of Issue, issue |
|
443 | assert_kind_of Issue, issue | |
444 | assert_equal 1, issue.project_id |
|
444 | assert_equal 1, issue.project_id | |
445 | assert_equal 2, issue.tracker_id |
|
445 | assert_equal 2, issue.tracker_id | |
446 | assert_equal 'This is the test_new issue', issue.subject |
|
446 | assert_equal 'This is the test_new issue', issue.subject | |
447 | end |
|
447 | end | |
448 |
|
448 | |||
449 | def test_post_new |
|
449 | def test_post_new | |
450 | @request.session[:user_id] = 2 |
|
450 | @request.session[:user_id] = 2 | |
451 | assert_difference 'Issue.count' do |
|
451 | assert_difference 'Issue.count' do | |
452 | post :new, :project_id => 1, |
|
452 | post :new, :project_id => 1, | |
453 | :issue => {:tracker_id => 3, |
|
453 | :issue => {:tracker_id => 3, | |
454 | :status_id => 2, |
|
454 | :status_id => 2, | |
455 | :subject => 'This is the test_new issue', |
|
455 | :subject => 'This is the test_new issue', | |
456 | :description => 'This is the description', |
|
456 | :description => 'This is the description', | |
457 | :priority_id => 5, |
|
457 | :priority_id => 5, | |
458 | :estimated_hours => '', |
|
458 | :estimated_hours => '', | |
459 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
459 | :custom_field_values => {'2' => 'Value for field 2'}} | |
460 | end |
|
460 | end | |
461 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
461 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
462 |
|
462 | |||
463 | issue = Issue.find_by_subject('This is the test_new issue') |
|
463 | issue = Issue.find_by_subject('This is the test_new issue') | |
464 | assert_not_nil issue |
|
464 | assert_not_nil issue | |
465 | assert_equal 2, issue.author_id |
|
465 | assert_equal 2, issue.author_id | |
466 | assert_equal 3, issue.tracker_id |
|
466 | assert_equal 3, issue.tracker_id | |
467 | assert_equal 2, issue.status_id |
|
467 | assert_equal 2, issue.status_id | |
468 | assert_nil issue.estimated_hours |
|
468 | assert_nil issue.estimated_hours | |
469 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
469 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | |
470 | assert_not_nil v |
|
470 | assert_not_nil v | |
471 | assert_equal 'Value for field 2', v.value |
|
471 | assert_equal 'Value for field 2', v.value | |
472 | end |
|
472 | end | |
473 |
|
473 | |||
474 | def test_post_new_and_continue |
|
474 | def test_post_new_and_continue | |
475 | @request.session[:user_id] = 2 |
|
475 | @request.session[:user_id] = 2 | |
476 | post :new, :project_id => 1, |
|
476 | post :new, :project_id => 1, | |
477 | :issue => {:tracker_id => 3, |
|
477 | :issue => {:tracker_id => 3, | |
478 | :subject => 'This is first issue', |
|
478 | :subject => 'This is first issue', | |
479 | :priority_id => 5}, |
|
479 | :priority_id => 5}, | |
480 | :continue => '' |
|
480 | :continue => '' | |
481 | assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3} |
|
481 | assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3} | |
482 | end |
|
482 | end | |
483 |
|
483 | |||
484 | def test_post_new_without_custom_fields_param |
|
484 | def test_post_new_without_custom_fields_param | |
485 | @request.session[:user_id] = 2 |
|
485 | @request.session[:user_id] = 2 | |
486 | assert_difference 'Issue.count' do |
|
486 | assert_difference 'Issue.count' do | |
487 | post :new, :project_id => 1, |
|
487 | post :new, :project_id => 1, | |
488 | :issue => {:tracker_id => 1, |
|
488 | :issue => {:tracker_id => 1, | |
489 | :subject => 'This is the test_new issue', |
|
489 | :subject => 'This is the test_new issue', | |
490 | :description => 'This is the description', |
|
490 | :description => 'This is the description', | |
491 | :priority_id => 5} |
|
491 | :priority_id => 5} | |
492 | end |
|
492 | end | |
493 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
493 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
494 | end |
|
494 | end | |
495 |
|
495 | |||
496 | def test_post_new_with_required_custom_field_and_without_custom_fields_param |
|
496 | def test_post_new_with_required_custom_field_and_without_custom_fields_param | |
497 | field = IssueCustomField.find_by_name('Database') |
|
497 | field = IssueCustomField.find_by_name('Database') | |
498 | field.update_attribute(:is_required, true) |
|
498 | field.update_attribute(:is_required, true) | |
499 |
|
499 | |||
500 | @request.session[:user_id] = 2 |
|
500 | @request.session[:user_id] = 2 | |
501 | post :new, :project_id => 1, |
|
501 | post :new, :project_id => 1, | |
502 | :issue => {:tracker_id => 1, |
|
502 | :issue => {:tracker_id => 1, | |
503 | :subject => 'This is the test_new issue', |
|
503 | :subject => 'This is the test_new issue', | |
504 | :description => 'This is the description', |
|
504 | :description => 'This is the description', | |
505 | :priority_id => 5} |
|
505 | :priority_id => 5} | |
506 | assert_response :success |
|
506 | assert_response :success | |
507 | assert_template 'new' |
|
507 | assert_template 'new' | |
508 | issue = assigns(:issue) |
|
508 | issue = assigns(:issue) | |
509 | assert_not_nil issue |
|
509 | assert_not_nil issue | |
510 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
510 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
511 | end |
|
511 | end | |
512 |
|
512 | |||
513 | def test_post_new_with_watchers |
|
513 | def test_post_new_with_watchers | |
514 | @request.session[:user_id] = 2 |
|
514 | @request.session[:user_id] = 2 | |
515 | ActionMailer::Base.deliveries.clear |
|
515 | ActionMailer::Base.deliveries.clear | |
516 |
|
516 | |||
517 | assert_difference 'Watcher.count', 2 do |
|
517 | assert_difference 'Watcher.count', 2 do | |
518 | post :new, :project_id => 1, |
|
518 | post :new, :project_id => 1, | |
519 | :issue => {:tracker_id => 1, |
|
519 | :issue => {:tracker_id => 1, | |
520 | :subject => 'This is a new issue with watchers', |
|
520 | :subject => 'This is a new issue with watchers', | |
521 | :description => 'This is the description', |
|
521 | :description => 'This is the description', | |
522 | :priority_id => 5, |
|
522 | :priority_id => 5, | |
523 | :watcher_user_ids => ['2', '3']} |
|
523 | :watcher_user_ids => ['2', '3']} | |
524 | end |
|
524 | end | |
525 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
525 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
526 | assert_not_nil issue |
|
526 | assert_not_nil issue | |
527 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
527 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
528 |
|
528 | |||
529 | # Watchers added |
|
529 | # Watchers added | |
530 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
530 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
531 | assert issue.watched_by?(User.find(3)) |
|
531 | assert issue.watched_by?(User.find(3)) | |
532 | # Watchers notified |
|
532 | # Watchers notified | |
533 | mail = ActionMailer::Base.deliveries.last |
|
533 | mail = ActionMailer::Base.deliveries.last | |
534 | assert_kind_of TMail::Mail, mail |
|
534 | assert_kind_of TMail::Mail, mail | |
535 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
535 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
536 | end |
|
536 | end | |
537 |
|
537 | |||
538 | def test_post_new_subissue |
|
538 | def test_post_new_subissue | |
539 | @request.session[:user_id] = 2 |
|
539 | @request.session[:user_id] = 2 | |
540 |
|
540 | |||
541 | assert_difference 'Issue.count' do |
|
541 | assert_difference 'Issue.count' do | |
542 | post :new, :project_id => 1, |
|
542 | post :new, :project_id => 1, | |
543 | :issue => {:tracker_id => 1, |
|
543 | :issue => {:tracker_id => 1, | |
544 | :subject => 'This is a child issue', |
|
544 | :subject => 'This is a child issue', | |
545 | :parent_issue_id => 2} |
|
545 | :parent_issue_id => 2} | |
546 | end |
|
546 | end | |
547 | issue = Issue.find_by_subject('This is a child issue') |
|
547 | issue = Issue.find_by_subject('This is a child issue') | |
548 | assert_not_nil issue |
|
548 | assert_not_nil issue | |
549 | assert_equal Issue.find(2), issue.parent |
|
549 | assert_equal Issue.find(2), issue.parent | |
550 | end |
|
550 | end | |
551 |
|
551 | |||
552 | def test_post_new_should_send_a_notification |
|
552 | def test_post_new_should_send_a_notification | |
553 | ActionMailer::Base.deliveries.clear |
|
553 | ActionMailer::Base.deliveries.clear | |
554 | @request.session[:user_id] = 2 |
|
554 | @request.session[:user_id] = 2 | |
555 | assert_difference 'Issue.count' do |
|
555 | assert_difference 'Issue.count' do | |
556 | post :new, :project_id => 1, |
|
556 | post :new, :project_id => 1, | |
557 | :issue => {:tracker_id => 3, |
|
557 | :issue => {:tracker_id => 3, | |
558 | :subject => 'This is the test_new issue', |
|
558 | :subject => 'This is the test_new issue', | |
559 | :description => 'This is the description', |
|
559 | :description => 'This is the description', | |
560 | :priority_id => 5, |
|
560 | :priority_id => 5, | |
561 | :estimated_hours => '', |
|
561 | :estimated_hours => '', | |
562 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
562 | :custom_field_values => {'2' => 'Value for field 2'}} | |
563 | end |
|
563 | end | |
564 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
564 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
565 |
|
565 | |||
566 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
566 | assert_equal 1, ActionMailer::Base.deliveries.size | |
567 | end |
|
567 | end | |
568 |
|
568 | |||
569 | def test_post_should_preserve_fields_values_on_validation_failure |
|
569 | def test_post_should_preserve_fields_values_on_validation_failure | |
570 | @request.session[:user_id] = 2 |
|
570 | @request.session[:user_id] = 2 | |
571 | post :new, :project_id => 1, |
|
571 | post :new, :project_id => 1, | |
572 | :issue => {:tracker_id => 1, |
|
572 | :issue => {:tracker_id => 1, | |
573 | # empty subject |
|
573 | # empty subject | |
574 | :subject => '', |
|
574 | :subject => '', | |
575 | :description => 'This is a description', |
|
575 | :description => 'This is a description', | |
576 | :priority_id => 6, |
|
576 | :priority_id => 6, | |
577 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
577 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
578 | assert_response :success |
|
578 | assert_response :success | |
579 | assert_template 'new' |
|
579 | assert_template 'new' | |
580 |
|
580 | |||
581 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
581 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | |
582 | :content => 'This is a description' |
|
582 | :content => 'This is a description' | |
583 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
583 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
584 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
584 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
585 | :value => '6' }, |
|
585 | :value => '6' }, | |
586 | :content => 'High' } |
|
586 | :content => 'High' } | |
587 | # Custom fields |
|
587 | # Custom fields | |
588 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
588 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | |
589 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
589 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
590 | :value => 'Oracle' }, |
|
590 | :value => 'Oracle' }, | |
591 | :content => 'Oracle' } |
|
591 | :content => 'Oracle' } | |
592 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
592 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
593 | :value => 'Value for field 2'} |
|
593 | :value => 'Value for field 2'} | |
594 | end |
|
594 | end | |
595 |
|
595 | |||
596 | def test_post_new_should_ignore_non_safe_attributes |
|
596 | def test_post_new_should_ignore_non_safe_attributes | |
597 | @request.session[:user_id] = 2 |
|
597 | @request.session[:user_id] = 2 | |
598 | assert_nothing_raised do |
|
598 | assert_nothing_raised do | |
599 | post :new, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
599 | post :new, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | |
600 | end |
|
600 | end | |
601 | end |
|
601 | end | |
602 |
|
602 | |||
603 | context "without workflow privilege" do |
|
603 | context "without workflow privilege" do | |
604 | setup do |
|
604 | setup do | |
605 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
|
605 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
606 | Role.anonymous.add_permission! :add_issues |
|
606 | Role.anonymous.add_permission! :add_issues | |
607 | end |
|
607 | end | |
608 |
|
608 | |||
609 | context "#new" do |
|
609 | context "#new" do | |
610 | should "propose default status only" do |
|
610 | should "propose default status only" do | |
611 | get :new, :project_id => 1 |
|
611 | get :new, :project_id => 1 | |
612 | assert_response :success |
|
612 | assert_response :success | |
613 | assert_template 'new' |
|
613 | assert_template 'new' | |
614 | assert_tag :tag => 'select', |
|
614 | assert_tag :tag => 'select', | |
615 | :attributes => {:name => 'issue[status_id]'}, |
|
615 | :attributes => {:name => 'issue[status_id]'}, | |
616 | :children => {:count => 1}, |
|
616 | :children => {:count => 1}, | |
617 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} |
|
617 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} | |
618 | end |
|
618 | end | |
619 |
|
619 | |||
620 | should "accept default status" do |
|
620 | should "accept default status" do | |
621 | assert_difference 'Issue.count' do |
|
621 | assert_difference 'Issue.count' do | |
622 | post :new, :project_id => 1, |
|
622 | post :new, :project_id => 1, | |
623 | :issue => {:tracker_id => 1, |
|
623 | :issue => {:tracker_id => 1, | |
624 | :subject => 'This is an issue', |
|
624 | :subject => 'This is an issue', | |
625 | :status_id => 1} |
|
625 | :status_id => 1} | |
626 | end |
|
626 | end | |
627 | issue = Issue.last(:order => 'id') |
|
627 | issue = Issue.last(:order => 'id') | |
628 | assert_equal IssueStatus.default, issue.status |
|
628 | assert_equal IssueStatus.default, issue.status | |
629 | end |
|
629 | end | |
630 |
|
630 | |||
631 | should "ignore unauthorized status" do |
|
631 | should "ignore unauthorized status" do | |
632 | assert_difference 'Issue.count' do |
|
632 | assert_difference 'Issue.count' do | |
633 | post :new, :project_id => 1, |
|
633 | post :new, :project_id => 1, | |
634 | :issue => {:tracker_id => 1, |
|
634 | :issue => {:tracker_id => 1, | |
635 | :subject => 'This is an issue', |
|
635 | :subject => 'This is an issue', | |
636 | :status_id => 3} |
|
636 | :status_id => 3} | |
637 | end |
|
637 | end | |
638 | issue = Issue.last(:order => 'id') |
|
638 | issue = Issue.last(:order => 'id') | |
639 | assert_equal IssueStatus.default, issue.status |
|
639 | assert_equal IssueStatus.default, issue.status | |
640 | end |
|
640 | end | |
641 | end |
|
641 | end | |
642 | end |
|
642 | end | |
643 |
|
643 | |||
644 | def test_copy_issue |
|
644 | def test_copy_issue | |
645 | @request.session[:user_id] = 2 |
|
645 | @request.session[:user_id] = 2 | |
646 | get :new, :project_id => 1, :copy_from => 1 |
|
646 | get :new, :project_id => 1, :copy_from => 1 | |
647 | assert_template 'new' |
|
647 | assert_template 'new' | |
648 | assert_not_nil assigns(:issue) |
|
648 | assert_not_nil assigns(:issue) | |
649 | orig = Issue.find(1) |
|
649 | orig = Issue.find(1) | |
650 | assert_equal orig.subject, assigns(:issue).subject |
|
650 | assert_equal orig.subject, assigns(:issue).subject | |
651 | end |
|
651 | end | |
652 |
|
652 | |||
653 | def test_get_edit |
|
653 | def test_get_edit | |
654 | @request.session[:user_id] = 2 |
|
654 | @request.session[:user_id] = 2 | |
655 | get :edit, :id => 1 |
|
655 | get :edit, :id => 1 | |
656 | assert_response :success |
|
656 | assert_response :success | |
657 | assert_template 'edit' |
|
657 | assert_template 'edit' | |
658 | assert_not_nil assigns(:issue) |
|
658 | assert_not_nil assigns(:issue) | |
659 | assert_equal Issue.find(1), assigns(:issue) |
|
659 | assert_equal Issue.find(1), assigns(:issue) | |
660 | end |
|
660 | end | |
661 |
|
661 | |||
662 | def test_get_edit_with_params |
|
662 | def test_get_edit_with_params | |
663 | @request.session[:user_id] = 2 |
|
663 | @request.session[:user_id] = 2 | |
664 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } |
|
664 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } | |
665 | assert_response :success |
|
665 | assert_response :success | |
666 | assert_template 'edit' |
|
666 | assert_template 'edit' | |
667 |
|
667 | |||
668 | issue = assigns(:issue) |
|
668 | issue = assigns(:issue) | |
669 | assert_not_nil issue |
|
669 | assert_not_nil issue | |
670 |
|
670 | |||
671 | assert_equal 5, issue.status_id |
|
671 | assert_equal 5, issue.status_id | |
672 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
672 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | |
673 | :child => { :tag => 'option', |
|
673 | :child => { :tag => 'option', | |
674 | :content => 'Closed', |
|
674 | :content => 'Closed', | |
675 | :attributes => { :selected => 'selected' } } |
|
675 | :attributes => { :selected => 'selected' } } | |
676 |
|
676 | |||
677 | assert_equal 7, issue.priority_id |
|
677 | assert_equal 7, issue.priority_id | |
678 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
678 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
679 | :child => { :tag => 'option', |
|
679 | :child => { :tag => 'option', | |
680 | :content => 'Urgent', |
|
680 | :content => 'Urgent', | |
681 | :attributes => { :selected => 'selected' } } |
|
681 | :attributes => { :selected => 'selected' } } | |
682 | end |
|
682 | end | |
683 |
|
683 | |||
684 | def test_update_edit_form |
|
684 | def test_update_edit_form | |
685 | @request.session[:user_id] = 2 |
|
685 | @request.session[:user_id] = 2 | |
686 | xhr :post, :update_form, :project_id => 1, |
|
686 | xhr :post, :update_form, :project_id => 1, | |
687 | :id => 1, |
|
687 | :id => 1, | |
688 | :issue => {:tracker_id => 2, |
|
688 | :issue => {:tracker_id => 2, | |
689 | :subject => 'This is the test_new issue', |
|
689 | :subject => 'This is the test_new issue', | |
690 | :description => 'This is the description', |
|
690 | :description => 'This is the description', | |
691 | :priority_id => 5} |
|
691 | :priority_id => 5} | |
692 | assert_response :success |
|
692 | assert_response :success | |
693 | assert_template 'attributes' |
|
693 | assert_template 'attributes' | |
694 |
|
694 | |||
695 | issue = assigns(:issue) |
|
695 | issue = assigns(:issue) | |
696 | assert_kind_of Issue, issue |
|
696 | assert_kind_of Issue, issue | |
697 | assert_equal 1, issue.id |
|
697 | assert_equal 1, issue.id | |
698 | assert_equal 1, issue.project_id |
|
698 | assert_equal 1, issue.project_id | |
699 | assert_equal 2, issue.tracker_id |
|
699 | assert_equal 2, issue.tracker_id | |
700 | assert_equal 'This is the test_new issue', issue.subject |
|
700 | assert_equal 'This is the test_new issue', issue.subject | |
701 | end |
|
701 | end | |
702 |
|
702 | |||
703 | def test_reply_to_issue |
|
703 | def test_reply_to_issue | |
704 | @request.session[:user_id] = 2 |
|
704 | @request.session[:user_id] = 2 | |
705 | get :reply, :id => 1 |
|
705 | get :reply, :id => 1 | |
706 | assert_response :success |
|
706 | assert_response :success | |
707 | assert_select_rjs :show, "update" |
|
707 | assert_select_rjs :show, "update" | |
708 | end |
|
708 | end | |
709 |
|
709 | |||
710 | def test_reply_to_note |
|
710 | def test_reply_to_note | |
711 | @request.session[:user_id] = 2 |
|
711 | @request.session[:user_id] = 2 | |
712 | get :reply, :id => 1, :journal_id => 2 |
|
712 | get :reply, :id => 1, :journal_id => 2 | |
713 | assert_response :success |
|
713 | assert_response :success | |
714 | assert_select_rjs :show, "update" |
|
714 | assert_select_rjs :show, "update" | |
715 | end |
|
715 | end | |
716 |
|
716 | |||
717 | def test_update_using_invalid_http_verbs |
|
717 | def test_update_using_invalid_http_verbs | |
718 | @request.session[:user_id] = 2 |
|
718 | @request.session[:user_id] = 2 | |
719 | subject = 'Updated by an invalid http verb' |
|
719 | subject = 'Updated by an invalid http verb' | |
720 |
|
720 | |||
721 | get :update, :id => 1, :issue => {:subject => subject} |
|
721 | get :update, :id => 1, :issue => {:subject => subject} | |
722 | assert_not_equal subject, Issue.find(1).subject |
|
722 | assert_not_equal subject, Issue.find(1).subject | |
723 |
|
723 | |||
724 | post :update, :id => 1, :issue => {:subject => subject} |
|
724 | post :update, :id => 1, :issue => {:subject => subject} | |
725 | assert_not_equal subject, Issue.find(1).subject |
|
725 | assert_not_equal subject, Issue.find(1).subject | |
726 |
|
726 | |||
727 | delete :update, :id => 1, :issue => {:subject => subject} |
|
727 | delete :update, :id => 1, :issue => {:subject => subject} | |
728 | assert_not_equal subject, Issue.find(1).subject |
|
728 | assert_not_equal subject, Issue.find(1).subject | |
729 | end |
|
729 | end | |
730 |
|
730 | |||
731 | def test_put_update_without_custom_fields_param |
|
731 | def test_put_update_without_custom_fields_param | |
732 | @request.session[:user_id] = 2 |
|
732 | @request.session[:user_id] = 2 | |
733 | ActionMailer::Base.deliveries.clear |
|
733 | ActionMailer::Base.deliveries.clear | |
734 |
|
734 | |||
735 | issue = Issue.find(1) |
|
735 | issue = Issue.find(1) | |
736 | assert_equal '125', issue.custom_value_for(2).value |
|
736 | assert_equal '125', issue.custom_value_for(2).value | |
737 | old_subject = issue.subject |
|
737 | old_subject = issue.subject | |
738 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
738 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
739 |
|
739 | |||
740 | assert_difference('Journal.count') do |
|
740 | assert_difference('Journal.count') do | |
741 | assert_difference('JournalDetail.count', 2) do |
|
741 | assert_difference('JournalDetail.count', 2) do | |
742 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
742 | put :update, :id => 1, :issue => {:subject => new_subject, | |
743 | :priority_id => '6', |
|
743 | :priority_id => '6', | |
744 | :category_id => '1' # no change |
|
744 | :category_id => '1' # no change | |
745 | } |
|
745 | } | |
746 | end |
|
746 | end | |
747 | end |
|
747 | end | |
748 | assert_redirected_to :action => 'show', :id => '1' |
|
748 | assert_redirected_to :action => 'show', :id => '1' | |
749 | issue.reload |
|
749 | issue.reload | |
750 | assert_equal new_subject, issue.subject |
|
750 | assert_equal new_subject, issue.subject | |
751 | # Make sure custom fields were not cleared |
|
751 | # Make sure custom fields were not cleared | |
752 | assert_equal '125', issue.custom_value_for(2).value |
|
752 | assert_equal '125', issue.custom_value_for(2).value | |
753 |
|
753 | |||
754 | mail = ActionMailer::Base.deliveries.last |
|
754 | mail = ActionMailer::Base.deliveries.last | |
755 | assert_kind_of TMail::Mail, mail |
|
755 | assert_kind_of TMail::Mail, mail | |
756 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
756 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
757 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
757 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") | |
758 | end |
|
758 | end | |
759 |
|
759 | |||
760 | def test_put_update_with_custom_field_change |
|
760 | def test_put_update_with_custom_field_change | |
761 | @request.session[:user_id] = 2 |
|
761 | @request.session[:user_id] = 2 | |
762 | issue = Issue.find(1) |
|
762 | issue = Issue.find(1) | |
763 | assert_equal '125', issue.custom_value_for(2).value |
|
763 | assert_equal '125', issue.custom_value_for(2).value | |
764 |
|
764 | |||
765 | assert_difference('Journal.count') do |
|
765 | assert_difference('Journal.count') do | |
766 | assert_difference('JournalDetail.count', 3) do |
|
766 | assert_difference('JournalDetail.count', 3) do | |
767 | put :update, :id => 1, :issue => {:subject => 'Custom field change', |
|
767 | put :update, :id => 1, :issue => {:subject => 'Custom field change', | |
768 | :priority_id => '6', |
|
768 | :priority_id => '6', | |
769 | :category_id => '1', # no change |
|
769 | :category_id => '1', # no change | |
770 | :custom_field_values => { '2' => 'New custom value' } |
|
770 | :custom_field_values => { '2' => 'New custom value' } | |
771 | } |
|
771 | } | |
772 | end |
|
772 | end | |
773 | end |
|
773 | end | |
774 | assert_redirected_to :action => 'show', :id => '1' |
|
774 | assert_redirected_to :action => 'show', :id => '1' | |
775 | issue.reload |
|
775 | issue.reload | |
776 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
776 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
777 |
|
777 | |||
778 | mail = ActionMailer::Base.deliveries.last |
|
778 | mail = ActionMailer::Base.deliveries.last | |
779 | assert_kind_of TMail::Mail, mail |
|
779 | assert_kind_of TMail::Mail, mail | |
780 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
780 | assert mail.body.include?("Searchable field changed from 125 to New custom value") | |
781 | end |
|
781 | end | |
782 |
|
782 | |||
783 | def test_put_update_with_status_and_assignee_change |
|
783 | def test_put_update_with_status_and_assignee_change | |
784 | issue = Issue.find(1) |
|
784 | issue = Issue.find(1) | |
785 | assert_equal 1, issue.status_id |
|
785 | assert_equal 1, issue.status_id | |
786 | @request.session[:user_id] = 2 |
|
786 | @request.session[:user_id] = 2 | |
787 | assert_difference('TimeEntry.count', 0) do |
|
787 | assert_difference('TimeEntry.count', 0) do | |
788 | put :update, |
|
788 | put :update, | |
789 | :id => 1, |
|
789 | :id => 1, | |
790 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
790 | :issue => { :status_id => 2, :assigned_to_id => 3 }, | |
791 | :notes => 'Assigned to dlopper', |
|
791 | :notes => 'Assigned to dlopper', | |
792 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
792 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | |
793 | end |
|
793 | end | |
794 | assert_redirected_to :action => 'show', :id => '1' |
|
794 | assert_redirected_to :action => 'show', :id => '1' | |
795 | issue.reload |
|
795 | issue.reload | |
796 | assert_equal 2, issue.status_id |
|
796 | assert_equal 2, issue.status_id | |
797 | j = Journal.find(:first, :order => 'id DESC') |
|
797 | j = Journal.find(:first, :order => 'id DESC') | |
798 | assert_equal 'Assigned to dlopper', j.notes |
|
798 | assert_equal 'Assigned to dlopper', j.notes | |
799 | assert_equal 2, j.details.size |
|
799 | assert_equal 2, j.details.size | |
800 |
|
800 | |||
801 | mail = ActionMailer::Base.deliveries.last |
|
801 | mail = ActionMailer::Base.deliveries.last | |
802 | assert mail.body.include?("Status changed from New to Assigned") |
|
802 | assert mail.body.include?("Status changed from New to Assigned") | |
803 | # subject should contain the new status |
|
803 | # subject should contain the new status | |
804 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
804 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | |
805 | end |
|
805 | end | |
806 |
|
806 | |||
807 | def test_put_update_with_note_only |
|
807 | def test_put_update_with_note_only | |
808 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
808 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
809 | # anonymous user |
|
809 | # anonymous user | |
810 | put :update, |
|
810 | put :update, | |
811 | :id => 1, |
|
811 | :id => 1, | |
812 | :notes => notes |
|
812 | :notes => notes | |
813 | assert_redirected_to :action => 'show', :id => '1' |
|
813 | assert_redirected_to :action => 'show', :id => '1' | |
814 | j = Journal.find(:first, :order => 'id DESC') |
|
814 | j = Journal.find(:first, :order => 'id DESC') | |
815 | assert_equal notes, j.notes |
|
815 | assert_equal notes, j.notes | |
816 | assert_equal 0, j.details.size |
|
816 | assert_equal 0, j.details.size | |
817 | assert_equal User.anonymous, j.user |
|
817 | assert_equal User.anonymous, j.user | |
818 |
|
818 | |||
819 | mail = ActionMailer::Base.deliveries.last |
|
819 | mail = ActionMailer::Base.deliveries.last | |
820 | assert mail.body.include?(notes) |
|
820 | assert mail.body.include?(notes) | |
821 | end |
|
821 | end | |
822 |
|
822 | |||
823 | def test_put_update_with_note_and_spent_time |
|
823 | def test_put_update_with_note_and_spent_time | |
824 | @request.session[:user_id] = 2 |
|
824 | @request.session[:user_id] = 2 | |
825 | spent_hours_before = Issue.find(1).spent_hours |
|
825 | spent_hours_before = Issue.find(1).spent_hours | |
826 | assert_difference('TimeEntry.count') do |
|
826 | assert_difference('TimeEntry.count') do | |
827 | put :update, |
|
827 | put :update, | |
828 | :id => 1, |
|
828 | :id => 1, | |
829 | :notes => '2.5 hours added', |
|
829 | :notes => '2.5 hours added', | |
830 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first } |
|
830 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first } | |
831 | end |
|
831 | end | |
832 | assert_redirected_to :action => 'show', :id => '1' |
|
832 | assert_redirected_to :action => 'show', :id => '1' | |
833 |
|
833 | |||
834 | issue = Issue.find(1) |
|
834 | issue = Issue.find(1) | |
835 |
|
835 | |||
836 | j = Journal.find(:first, :order => 'id DESC') |
|
836 | j = Journal.find(:first, :order => 'id DESC') | |
837 | assert_equal '2.5 hours added', j.notes |
|
837 | assert_equal '2.5 hours added', j.notes | |
838 | assert_equal 0, j.details.size |
|
838 | assert_equal 0, j.details.size | |
839 |
|
839 | |||
840 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
|
840 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | |
841 | assert_not_nil t |
|
841 | assert_not_nil t | |
842 | assert_equal 2.5, t.hours |
|
842 | assert_equal 2.5, t.hours | |
843 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
843 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
844 | end |
|
844 | end | |
845 |
|
845 | |||
846 | def test_put_update_with_attachment_only |
|
846 | def test_put_update_with_attachment_only | |
847 | set_tmp_attachments_directory |
|
847 | set_tmp_attachments_directory | |
848 |
|
848 | |||
849 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
849 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
850 | # journal to get fetched in the next find. |
|
850 | # journal to get fetched in the next find. | |
851 | Journal.delete_all |
|
851 | Journal.delete_all | |
852 |
|
852 | |||
853 | # anonymous user |
|
853 | # anonymous user | |
854 | put :update, |
|
854 | put :update, | |
855 | :id => 1, |
|
855 | :id => 1, | |
856 | :notes => '', |
|
856 | :notes => '', | |
857 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
857 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
858 | assert_redirected_to :action => 'show', :id => '1' |
|
858 | assert_redirected_to :action => 'show', :id => '1' | |
859 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
859 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
860 | assert j.notes.blank? |
|
860 | assert j.notes.blank? | |
861 | assert_equal 1, j.details.size |
|
861 | assert_equal 1, j.details.size | |
862 | assert_equal 'testfile.txt', j.details.first.value |
|
862 | assert_equal 'testfile.txt', j.details.first.value | |
863 | assert_equal User.anonymous, j.user |
|
863 | assert_equal User.anonymous, j.user | |
864 |
|
864 | |||
865 | mail = ActionMailer::Base.deliveries.last |
|
865 | mail = ActionMailer::Base.deliveries.last | |
866 | assert mail.body.include?('testfile.txt') |
|
866 | assert mail.body.include?('testfile.txt') | |
867 | end |
|
867 | end | |
868 |
|
868 | |||
869 | def test_put_update_with_attachment_that_fails_to_save |
|
869 | def test_put_update_with_attachment_that_fails_to_save | |
870 | set_tmp_attachments_directory |
|
870 | set_tmp_attachments_directory | |
871 |
|
871 | |||
872 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
872 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
873 | # journal to get fetched in the next find. |
|
873 | # journal to get fetched in the next find. | |
874 | Journal.delete_all |
|
874 | Journal.delete_all | |
875 |
|
875 | |||
876 | # Mock out the unsaved attachment |
|
876 | # Mock out the unsaved attachment | |
877 | Attachment.any_instance.stubs(:create).returns(Attachment.new) |
|
877 | Attachment.any_instance.stubs(:create).returns(Attachment.new) | |
878 |
|
878 | |||
879 | # anonymous user |
|
879 | # anonymous user | |
880 | put :update, |
|
880 | put :update, | |
881 | :id => 1, |
|
881 | :id => 1, | |
882 | :notes => '', |
|
882 | :notes => '', | |
883 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
883 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
884 | assert_redirected_to :action => 'show', :id => '1' |
|
884 | assert_redirected_to :action => 'show', :id => '1' | |
885 | assert_equal '1 file(s) could not be saved.', flash[:warning] |
|
885 | assert_equal '1 file(s) could not be saved.', flash[:warning] | |
886 |
|
886 | |||
887 | end if Object.const_defined?(:Mocha) |
|
887 | end if Object.const_defined?(:Mocha) | |
888 |
|
888 | |||
889 | def test_put_update_with_no_change |
|
889 | def test_put_update_with_no_change | |
890 | issue = Issue.find(1) |
|
890 | issue = Issue.find(1) | |
891 | issue.journals.clear |
|
891 | issue.journals.clear | |
892 | ActionMailer::Base.deliveries.clear |
|
892 | ActionMailer::Base.deliveries.clear | |
893 |
|
893 | |||
894 | put :update, |
|
894 | put :update, | |
895 | :id => 1, |
|
895 | :id => 1, | |
896 | :notes => '' |
|
896 | :notes => '' | |
897 | assert_redirected_to :action => 'show', :id => '1' |
|
897 | assert_redirected_to :action => 'show', :id => '1' | |
898 |
|
898 | |||
899 | issue.reload |
|
899 | issue.reload | |
900 | assert issue.journals.empty? |
|
900 | assert issue.journals.empty? | |
901 | # No email should be sent |
|
901 | # No email should be sent | |
902 | assert ActionMailer::Base.deliveries.empty? |
|
902 | assert ActionMailer::Base.deliveries.empty? | |
903 | end |
|
903 | end | |
904 |
|
904 | |||
905 | def test_put_update_should_send_a_notification |
|
905 | def test_put_update_should_send_a_notification | |
906 | @request.session[:user_id] = 2 |
|
906 | @request.session[:user_id] = 2 | |
907 | ActionMailer::Base.deliveries.clear |
|
907 | ActionMailer::Base.deliveries.clear | |
908 | issue = Issue.find(1) |
|
908 | issue = Issue.find(1) | |
909 | old_subject = issue.subject |
|
909 | old_subject = issue.subject | |
910 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
910 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
911 |
|
911 | |||
912 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
912 | put :update, :id => 1, :issue => {:subject => new_subject, | |
913 | :priority_id => '6', |
|
913 | :priority_id => '6', | |
914 | :category_id => '1' # no change |
|
914 | :category_id => '1' # no change | |
915 | } |
|
915 | } | |
916 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
916 | assert_equal 1, ActionMailer::Base.deliveries.size | |
917 | end |
|
917 | end | |
918 |
|
918 | |||
919 | def test_put_update_with_invalid_spent_time |
|
919 | def test_put_update_with_invalid_spent_time | |
920 | @request.session[:user_id] = 2 |
|
920 | @request.session[:user_id] = 2 | |
921 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
921 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
922 |
|
922 | |||
923 | assert_no_difference('Journal.count') do |
|
923 | assert_no_difference('Journal.count') do | |
924 | put :update, |
|
924 | put :update, | |
925 | :id => 1, |
|
925 | :id => 1, | |
926 | :notes => notes, |
|
926 | :notes => notes, | |
927 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
927 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
928 | end |
|
928 | end | |
929 | assert_response :success |
|
929 | assert_response :success | |
930 | assert_template 'edit' |
|
930 | assert_template 'edit' | |
931 |
|
931 | |||
932 | assert_tag :textarea, :attributes => { :name => 'notes' }, |
|
932 | assert_tag :textarea, :attributes => { :name => 'notes' }, | |
933 | :content => notes |
|
933 | :content => notes | |
934 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
|
934 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | |
935 | end |
|
935 | end | |
936 |
|
936 | |||
937 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
937 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
938 | issue = Issue.find(2) |
|
938 | issue = Issue.find(2) | |
939 | @request.session[:user_id] = 2 |
|
939 | @request.session[:user_id] = 2 | |
940 |
|
940 | |||
941 | put :update, |
|
941 | put :update, | |
942 | :id => issue.id, |
|
942 | :id => issue.id, | |
943 | :issue => { |
|
943 | :issue => { | |
944 | :fixed_version_id => 4 |
|
944 | :fixed_version_id => 4 | |
945 | } |
|
945 | } | |
946 |
|
946 | |||
947 | assert_response :redirect |
|
947 | assert_response :redirect | |
948 | issue.reload |
|
948 | issue.reload | |
949 | assert_equal 4, issue.fixed_version_id |
|
949 | assert_equal 4, issue.fixed_version_id | |
950 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
950 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
951 | end |
|
951 | end | |
952 |
|
952 | |||
953 | def test_put_update_should_redirect_back_using_the_back_url_parameter |
|
953 | def test_put_update_should_redirect_back_using_the_back_url_parameter | |
954 | issue = Issue.find(2) |
|
954 | issue = Issue.find(2) | |
955 | @request.session[:user_id] = 2 |
|
955 | @request.session[:user_id] = 2 | |
956 |
|
956 | |||
957 | put :update, |
|
957 | put :update, | |
958 | :id => issue.id, |
|
958 | :id => issue.id, | |
959 | :issue => { |
|
959 | :issue => { | |
960 | :fixed_version_id => 4 |
|
960 | :fixed_version_id => 4 | |
961 | }, |
|
961 | }, | |
962 | :back_url => '/issues' |
|
962 | :back_url => '/issues' | |
963 |
|
963 | |||
964 | assert_response :redirect |
|
964 | assert_response :redirect | |
965 | assert_redirected_to '/issues' |
|
965 | assert_redirected_to '/issues' | |
966 | end |
|
966 | end | |
967 |
|
967 | |||
968 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
968 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
969 | issue = Issue.find(2) |
|
969 | issue = Issue.find(2) | |
970 | @request.session[:user_id] = 2 |
|
970 | @request.session[:user_id] = 2 | |
971 |
|
971 | |||
972 | put :update, |
|
972 | put :update, | |
973 | :id => issue.id, |
|
973 | :id => issue.id, | |
974 | :issue => { |
|
974 | :issue => { | |
975 | :fixed_version_id => 4 |
|
975 | :fixed_version_id => 4 | |
976 | }, |
|
976 | }, | |
977 | :back_url => 'http://google.com' |
|
977 | :back_url => 'http://google.com' | |
978 |
|
978 | |||
979 | assert_response :redirect |
|
979 | assert_response :redirect | |
980 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
980 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id | |
981 | end |
|
981 | end | |
982 |
|
982 | |||
983 | def test_get_bulk_edit |
|
983 | def test_get_bulk_edit | |
984 | @request.session[:user_id] = 2 |
|
984 | @request.session[:user_id] = 2 | |
985 | get :bulk_edit, :ids => [1, 2] |
|
985 | get :bulk_edit, :ids => [1, 2] | |
986 | assert_response :success |
|
986 | assert_response :success | |
987 | assert_template 'bulk_edit' |
|
987 | assert_template 'bulk_edit' | |
988 |
|
988 | |||
989 | # Project specific custom field, date type |
|
989 | # Project specific custom field, date type | |
990 | field = CustomField.find(9) |
|
990 | field = CustomField.find(9) | |
991 | assert !field.is_for_all? |
|
991 | assert !field.is_for_all? | |
992 | assert_equal 'date', field.field_format |
|
992 | assert_equal 'date', field.field_format | |
993 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
993 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
994 |
|
994 | |||
995 | # System wide custom field |
|
995 | # System wide custom field | |
996 | assert CustomField.find(1).is_for_all? |
|
996 | assert CustomField.find(1).is_for_all? | |
997 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
|
997 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | |
998 | end |
|
998 | end | |
999 |
|
999 | |||
1000 | def test_bulk_edit |
|
1000 | def test_bulk_edit | |
1001 | @request.session[:user_id] = 2 |
|
1001 | @request.session[:user_id] = 2 | |
1002 | # update issues priority |
|
1002 | # update issues priority | |
1003 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing', |
|
1003 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing', | |
1004 | :issue => {:priority_id => 7, |
|
1004 | :issue => {:priority_id => 7, | |
1005 | :assigned_to_id => '', |
|
1005 | :assigned_to_id => '', | |
1006 | :custom_field_values => {'2' => ''}} |
|
1006 | :custom_field_values => {'2' => ''}} | |
1007 |
|
1007 | |||
1008 | assert_response 302 |
|
1008 | assert_response 302 | |
1009 | # check that the issues were updated |
|
1009 | # check that the issues were updated | |
1010 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
1010 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
1011 |
|
1011 | |||
1012 | issue = Issue.find(1) |
|
1012 | issue = Issue.find(1) | |
1013 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
1013 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1014 | assert_equal '125', issue.custom_value_for(2).value |
|
1014 | assert_equal '125', issue.custom_value_for(2).value | |
1015 | assert_equal 'Bulk editing', journal.notes |
|
1015 | assert_equal 'Bulk editing', journal.notes | |
1016 | assert_equal 1, journal.details.size |
|
1016 | assert_equal 1, journal.details.size | |
1017 | end |
|
1017 | end | |
1018 |
|
1018 | |||
1019 | def test_bullk_edit_should_send_a_notification |
|
1019 | def test_bullk_edit_should_send_a_notification | |
1020 | @request.session[:user_id] = 2 |
|
1020 | @request.session[:user_id] = 2 | |
1021 | ActionMailer::Base.deliveries.clear |
|
1021 | ActionMailer::Base.deliveries.clear | |
1022 | post(:bulk_edit, |
|
1022 | post(:bulk_edit, | |
1023 | { |
|
1023 | { | |
1024 | :ids => [1, 2], |
|
1024 | :ids => [1, 2], | |
1025 | :notes => 'Bulk editing', |
|
1025 | :notes => 'Bulk editing', | |
1026 | :issue => { |
|
1026 | :issue => { | |
1027 | :priority_id => 7, |
|
1027 | :priority_id => 7, | |
1028 | :assigned_to_id => '', |
|
1028 | :assigned_to_id => '', | |
1029 | :custom_field_values => {'2' => ''} |
|
1029 | :custom_field_values => {'2' => ''} | |
1030 | } |
|
1030 | } | |
1031 | }) |
|
1031 | }) | |
1032 |
|
1032 | |||
1033 | assert_response 302 |
|
1033 | assert_response 302 | |
1034 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
1034 | assert_equal 2, ActionMailer::Base.deliveries.size | |
1035 | end |
|
1035 | end | |
1036 |
|
1036 | |||
1037 | def test_bulk_edit_status |
|
1037 | def test_bulk_edit_status | |
1038 | @request.session[:user_id] = 2 |
|
1038 | @request.session[:user_id] = 2 | |
1039 | # update issues priority |
|
1039 | # update issues priority | |
1040 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status', |
|
1040 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status', | |
1041 | :issue => {:priority_id => '', |
|
1041 | :issue => {:priority_id => '', | |
1042 | :assigned_to_id => '', |
|
1042 | :assigned_to_id => '', | |
1043 | :status_id => '5'} |
|
1043 | :status_id => '5'} | |
1044 |
|
1044 | |||
1045 | assert_response 302 |
|
1045 | assert_response 302 | |
1046 | issue = Issue.find(1) |
|
1046 | issue = Issue.find(1) | |
1047 | assert issue.closed? |
|
1047 | assert issue.closed? | |
1048 | end |
|
1048 | end | |
1049 |
|
1049 | |||
1050 | def test_bulk_edit_custom_field |
|
1050 | def test_bulk_edit_custom_field | |
1051 | @request.session[:user_id] = 2 |
|
1051 | @request.session[:user_id] = 2 | |
1052 | # update issues priority |
|
1052 | # update issues priority | |
1053 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
1053 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field', | |
1054 | :issue => {:priority_id => '', |
|
1054 | :issue => {:priority_id => '', | |
1055 | :assigned_to_id => '', |
|
1055 | :assigned_to_id => '', | |
1056 | :custom_field_values => {'2' => '777'}} |
|
1056 | :custom_field_values => {'2' => '777'}} | |
1057 |
|
1057 | |||
1058 | assert_response 302 |
|
1058 | assert_response 302 | |
1059 |
|
1059 | |||
1060 | issue = Issue.find(1) |
|
1060 | issue = Issue.find(1) | |
1061 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
1061 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1062 | assert_equal '777', issue.custom_value_for(2).value |
|
1062 | assert_equal '777', issue.custom_value_for(2).value | |
1063 | assert_equal 1, journal.details.size |
|
1063 | assert_equal 1, journal.details.size | |
1064 | assert_equal '125', journal.details.first.old_value |
|
1064 | assert_equal '125', journal.details.first.old_value | |
1065 | assert_equal '777', journal.details.first.value |
|
1065 | assert_equal '777', journal.details.first.value | |
1066 | end |
|
1066 | end | |
1067 |
|
1067 | |||
1068 | def test_bulk_unassign |
|
1068 | def test_bulk_unassign | |
1069 | assert_not_nil Issue.find(2).assigned_to |
|
1069 | assert_not_nil Issue.find(2).assigned_to | |
1070 | @request.session[:user_id] = 2 |
|
1070 | @request.session[:user_id] = 2 | |
1071 | # unassign issues |
|
1071 | # unassign issues | |
1072 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
1072 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} | |
1073 | assert_response 302 |
|
1073 | assert_response 302 | |
1074 | # check that the issues were updated |
|
1074 | # check that the issues were updated | |
1075 | assert_nil Issue.find(2).assigned_to |
|
1075 | assert_nil Issue.find(2).assigned_to | |
1076 | end |
|
1076 | end | |
1077 |
|
1077 | |||
1078 | def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject |
|
1078 | def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject | |
1079 | @request.session[:user_id] = 2 |
|
1079 | @request.session[:user_id] = 2 | |
1080 |
|
1080 | |||
1081 | post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
1081 | post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4} | |
1082 |
|
1082 | |||
1083 | assert_response :redirect |
|
1083 | assert_response :redirect | |
1084 | issues = Issue.find([1,2]) |
|
1084 | issues = Issue.find([1,2]) | |
1085 | issues.each do |issue| |
|
1085 | issues.each do |issue| | |
1086 | assert_equal 4, issue.fixed_version_id |
|
1086 | assert_equal 4, issue.fixed_version_id | |
1087 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
1087 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
1088 | end |
|
1088 | end | |
1089 | end |
|
1089 | end | |
1090 |
|
1090 | |||
1091 | def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter |
|
1091 | def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter | |
1092 | @request.session[:user_id] = 2 |
|
1092 | @request.session[:user_id] = 2 | |
1093 | post :bulk_edit, :ids => [1,2], :back_url => '/issues' |
|
1093 | post :bulk_edit, :ids => [1,2], :back_url => '/issues' | |
1094 |
|
1094 | |||
1095 | assert_response :redirect |
|
1095 | assert_response :redirect | |
1096 | assert_redirected_to '/issues' |
|
1096 | assert_redirected_to '/issues' | |
1097 | end |
|
1097 | end | |
1098 |
|
1098 | |||
1099 | def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
1099 | def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
1100 | @request.session[:user_id] = 2 |
|
1100 | @request.session[:user_id] = 2 | |
1101 | post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com' |
|
1101 | post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com' | |
1102 |
|
1102 | |||
1103 | assert_response :redirect |
|
1103 | assert_response :redirect | |
1104 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
1104 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier | |
1105 | end |
|
1105 | end | |
1106 |
|
1106 | |||
1107 | def test_move_one_issue_to_another_project |
|
1107 | def test_move_one_issue_to_another_project | |
1108 | @request.session[:user_id] = 2 |
|
1108 | @request.session[:user_id] = 2 | |
1109 | post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
1109 | post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' | |
1110 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1110 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1111 | assert_equal 2, Issue.find(1).project_id |
|
1111 | assert_equal 2, Issue.find(1).project_id | |
1112 | end |
|
1112 | end | |
1113 |
|
1113 | |||
1114 | def test_move_one_issue_to_another_project_should_follow_when_needed |
|
1114 | def test_move_one_issue_to_another_project_should_follow_when_needed | |
1115 | @request.session[:user_id] = 2 |
|
1115 | @request.session[:user_id] = 2 | |
1116 | post :move, :id => 1, :new_project_id => 2, :follow => '1' |
|
1116 | post :move, :id => 1, :new_project_id => 2, :follow => '1' | |
1117 | assert_redirected_to '/issues/1' |
|
1117 | assert_redirected_to '/issues/1' | |
1118 | end |
|
1118 | end | |
1119 |
|
1119 | |||
1120 | def test_bulk_move_to_another_project |
|
1120 | def test_bulk_move_to_another_project | |
1121 | @request.session[:user_id] = 2 |
|
1121 | @request.session[:user_id] = 2 | |
1122 | post :move, :ids => [1, 2], :new_project_id => 2 |
|
1122 | post :move, :ids => [1, 2], :new_project_id => 2 | |
1123 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1123 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1124 | # Issues moved to project 2 |
|
1124 | # Issues moved to project 2 | |
1125 | assert_equal 2, Issue.find(1).project_id |
|
1125 | assert_equal 2, Issue.find(1).project_id | |
1126 | assert_equal 2, Issue.find(2).project_id |
|
1126 | assert_equal 2, Issue.find(2).project_id | |
1127 | # No tracker change |
|
1127 | # No tracker change | |
1128 | assert_equal 1, Issue.find(1).tracker_id |
|
1128 | assert_equal 1, Issue.find(1).tracker_id | |
1129 | assert_equal 2, Issue.find(2).tracker_id |
|
1129 | assert_equal 2, Issue.find(2).tracker_id | |
1130 | end |
|
1130 | end | |
1131 |
|
1131 | |||
1132 | def test_bulk_move_to_another_tracker |
|
1132 | def test_bulk_move_to_another_tracker | |
1133 | @request.session[:user_id] = 2 |
|
1133 | @request.session[:user_id] = 2 | |
1134 | post :move, :ids => [1, 2], :new_tracker_id => 2 |
|
1134 | post :move, :ids => [1, 2], :new_tracker_id => 2 | |
1135 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1135 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1136 | assert_equal 2, Issue.find(1).tracker_id |
|
1136 | assert_equal 2, Issue.find(1).tracker_id | |
1137 | assert_equal 2, Issue.find(2).tracker_id |
|
1137 | assert_equal 2, Issue.find(2).tracker_id | |
1138 | end |
|
1138 | end | |
1139 |
|
1139 | |||
1140 | def test_bulk_copy_to_another_project |
|
1140 | def test_bulk_copy_to_another_project | |
1141 | @request.session[:user_id] = 2 |
|
1141 | @request.session[:user_id] = 2 | |
1142 | assert_difference 'Issue.count', 2 do |
|
1142 | assert_difference 'Issue.count', 2 do | |
1143 | assert_no_difference 'Project.find(1).issues.count' do |
|
1143 | assert_no_difference 'Project.find(1).issues.count' do | |
1144 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} |
|
1144 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} | |
1145 | end |
|
1145 | end | |
1146 | end |
|
1146 | end | |
1147 | assert_redirected_to 'projects/ecookbook/issues' |
|
1147 | assert_redirected_to 'projects/ecookbook/issues' | |
1148 | end |
|
1148 | end | |
1149 |
|
1149 | |||
1150 | context "#move via bulk copy" do |
|
1150 | context "#move via bulk copy" do | |
1151 | should "allow not changing the issue's attributes" do |
|
1151 | should "allow not changing the issue's attributes" do | |
1152 | @request.session[:user_id] = 2 |
|
1152 | @request.session[:user_id] = 2 | |
1153 | issue_before_move = Issue.find(1) |
|
1153 | issue_before_move = Issue.find(1) | |
1154 | assert_difference 'Issue.count', 1 do |
|
1154 | assert_difference 'Issue.count', 1 do | |
1155 | assert_no_difference 'Project.find(1).issues.count' do |
|
1155 | assert_no_difference 'Project.find(1).issues.count' do | |
1156 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
1156 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' | |
1157 | end |
|
1157 | end | |
1158 | end |
|
1158 | end | |
1159 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
1159 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) | |
1160 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
1160 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id | |
1161 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
1161 | assert_equal issue_before_move.status_id, issue_after_move.status_id | |
1162 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
1162 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id | |
1163 | end |
|
1163 | end | |
1164 |
|
1164 | |||
1165 | should "allow changing the issue's attributes" do |
|
1165 | should "allow changing the issue's attributes" do | |
1166 | @request.session[:user_id] = 2 |
|
1166 | @request.session[:user_id] = 2 | |
1167 | assert_difference 'Issue.count', 2 do |
|
1167 | assert_difference 'Issue.count', 2 do | |
1168 | assert_no_difference 'Project.find(1).issues.count' do |
|
1168 | assert_no_difference 'Project.find(1).issues.count' do | |
1169 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
1169 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31' | |
1170 | end |
|
1170 | end | |
1171 | end |
|
1171 | end | |
1172 |
|
1172 | |||
1173 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
1173 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) | |
1174 | assert_equal 2, copied_issues.size |
|
1174 | assert_equal 2, copied_issues.size | |
1175 | copied_issues.each do |issue| |
|
1175 | copied_issues.each do |issue| | |
1176 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
1176 | assert_equal 2, issue.project_id, "Project is incorrect" | |
1177 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
1177 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" | |
1178 | assert_equal 3, issue.status_id, "Status is incorrect" |
|
1178 | assert_equal 3, issue.status_id, "Status is incorrect" | |
1179 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
1179 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" | |
1180 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
1180 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
1181 | end |
|
1181 | end | |
1182 | end |
|
1182 | end | |
1183 | end |
|
1183 | end | |
1184 |
|
1184 | |||
1185 | def test_copy_to_another_project_should_follow_when_needed |
|
1185 | def test_copy_to_another_project_should_follow_when_needed | |
1186 | @request.session[:user_id] = 2 |
|
1186 | @request.session[:user_id] = 2 | |
1187 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' |
|
1187 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' | |
1188 | issue = Issue.first(:order => 'id DESC') |
|
1188 | issue = Issue.first(:order => 'id DESC') | |
1189 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
1189 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
1190 | end |
|
1190 | end | |
1191 |
|
1191 | |||
1192 | def test_context_menu_one_issue |
|
1192 | def test_context_menu_one_issue | |
1193 | @request.session[:user_id] = 2 |
|
1193 | @request.session[:user_id] = 2 | |
1194 | get :context_menu, :ids => [1] |
|
1194 | get :context_menu, :ids => [1] | |
1195 | assert_response :success |
|
1195 | assert_response :success | |
1196 | assert_template 'context_menu' |
|
1196 | assert_template 'context_menu' | |
1197 | assert_tag :tag => 'a', :content => 'Edit', |
|
1197 | assert_tag :tag => 'a', :content => 'Edit', | |
1198 | :attributes => { :href => '/issues/1/edit', |
|
1198 | :attributes => { :href => '/issues/1/edit', | |
1199 | :class => 'icon-edit' } |
|
1199 | :class => 'icon-edit' } | |
1200 | assert_tag :tag => 'a', :content => 'Closed', |
|
1200 | assert_tag :tag => 'a', :content => 'Closed', | |
1201 | :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5', |
|
1201 | :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5', | |
1202 | :class => '' } |
|
1202 | :class => '' } | |
1203 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1203 | assert_tag :tag => 'a', :content => 'Immediate', | |
1204 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bpriority_id%5D=8', |
|
1204 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bpriority_id%5D=8', | |
1205 | :class => '' } |
|
1205 | :class => '' } | |
1206 | # Versions |
|
1206 | # Versions | |
1207 | assert_tag :tag => 'a', :content => '2.0', |
|
1207 | assert_tag :tag => 'a', :content => '2.0', | |
1208 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3', |
|
1208 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3', | |
1209 | :class => '' } |
|
1209 | :class => '' } | |
1210 | assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0', |
|
1210 | assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0', | |
1211 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4', |
|
1211 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4', | |
1212 | :class => '' } |
|
1212 | :class => '' } | |
1213 |
|
1213 | |||
1214 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1214 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
1215 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3', |
|
1215 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3', | |
1216 | :class => '' } |
|
1216 | :class => '' } | |
1217 | assert_tag :tag => 'a', :content => 'Duplicate', |
|
1217 | assert_tag :tag => 'a', :content => 'Duplicate', | |
1218 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', |
|
1218 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', | |
1219 | :class => 'icon-duplicate' } |
|
1219 | :class => 'icon-duplicate' } | |
1220 | assert_tag :tag => 'a', :content => 'Copy', |
|
1220 | assert_tag :tag => 'a', :content => 'Copy', | |
1221 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1', |
|
1221 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1', | |
1222 | :class => 'icon-copy' } |
|
1222 | :class => 'icon-copy' } | |
1223 | assert_tag :tag => 'a', :content => 'Move', |
|
1223 | assert_tag :tag => 'a', :content => 'Move', | |
1224 | :attributes => { :href => '/issues/move?ids%5B%5D=1', |
|
1224 | :attributes => { :href => '/issues/move?ids%5B%5D=1', | |
1225 | :class => 'icon-move' } |
|
1225 | :class => 'icon-move' } | |
1226 | assert_tag :tag => 'a', :content => 'Delete', |
|
1226 | assert_tag :tag => 'a', :content => 'Delete', | |
1227 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', |
|
1227 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', | |
1228 | :class => 'icon-del' } |
|
1228 | :class => 'icon-del' } | |
1229 | end |
|
1229 | end | |
1230 |
|
1230 | |||
1231 | def test_context_menu_one_issue_by_anonymous |
|
1231 | def test_context_menu_one_issue_by_anonymous | |
1232 | get :context_menu, :ids => [1] |
|
1232 | get :context_menu, :ids => [1] | |
1233 | assert_response :success |
|
1233 | assert_response :success | |
1234 | assert_template 'context_menu' |
|
1234 | assert_template 'context_menu' | |
1235 | assert_tag :tag => 'a', :content => 'Delete', |
|
1235 | assert_tag :tag => 'a', :content => 'Delete', | |
1236 | :attributes => { :href => '#', |
|
1236 | :attributes => { :href => '#', | |
1237 | :class => 'icon-del disabled' } |
|
1237 | :class => 'icon-del disabled' } | |
1238 | end |
|
1238 | end | |
1239 |
|
1239 | |||
1240 | def test_context_menu_multiple_issues_of_same_project |
|
1240 | def test_context_menu_multiple_issues_of_same_project | |
1241 | @request.session[:user_id] = 2 |
|
1241 | @request.session[:user_id] = 2 | |
1242 | get :context_menu, :ids => [1, 2] |
|
1242 | get :context_menu, :ids => [1, 2] | |
1243 | assert_response :success |
|
1243 | assert_response :success | |
1244 | assert_template 'context_menu' |
|
1244 | assert_template 'context_menu' | |
1245 | assert_tag :tag => 'a', :content => 'Edit', |
|
1245 | assert_tag :tag => 'a', :content => 'Edit', | |
1246 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', |
|
1246 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', | |
1247 | :class => 'icon-edit' } |
|
1247 | :class => 'icon-edit' } | |
1248 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1248 | assert_tag :tag => 'a', :content => 'Immediate', | |
1249 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bpriority_id%5D=8', |
|
1249 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bpriority_id%5D=8', | |
1250 | :class => '' } |
|
1250 | :class => '' } | |
1251 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1251 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
1252 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bassigned_to_id%5D=3', |
|
1252 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bassigned_to_id%5D=3', | |
1253 | :class => '' } |
|
1253 | :class => '' } | |
1254 | assert_tag :tag => 'a', :content => 'Copy', |
|
1254 | assert_tag :tag => 'a', :content => 'Copy', | |
1255 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1&ids%5B%5D=2', |
|
1255 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1&ids%5B%5D=2', | |
1256 | :class => 'icon-copy' } |
|
1256 | :class => 'icon-copy' } | |
1257 | assert_tag :tag => 'a', :content => 'Move', |
|
1257 | assert_tag :tag => 'a', :content => 'Move', | |
1258 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', |
|
1258 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', | |
1259 | :class => 'icon-move' } |
|
1259 | :class => 'icon-move' } | |
1260 | assert_tag :tag => 'a', :content => 'Delete', |
|
1260 | assert_tag :tag => 'a', :content => 'Delete', | |
1261 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', |
|
1261 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', | |
1262 | :class => 'icon-del' } |
|
1262 | :class => 'icon-del' } | |
1263 | end |
|
1263 | end | |
1264 |
|
1264 | |||
1265 | def test_context_menu_multiple_issues_of_different_project |
|
1265 | def test_context_menu_multiple_issues_of_different_project | |
1266 | @request.session[:user_id] = 2 |
|
1266 | @request.session[:user_id] = 2 | |
1267 | get :context_menu, :ids => [1, 2, 4] |
|
1267 | get :context_menu, :ids => [1, 2, 4] | |
1268 | assert_response :success |
|
1268 | assert_response :success | |
1269 | assert_template 'context_menu' |
|
1269 | assert_template 'context_menu' | |
1270 | assert_tag :tag => 'a', :content => 'Delete', |
|
1270 | assert_tag :tag => 'a', :content => 'Delete', | |
1271 | :attributes => { :href => '#', |
|
1271 | :attributes => { :href => '#', | |
1272 | :class => 'icon-del disabled' } |
|
1272 | :class => 'icon-del disabled' } | |
1273 | end |
|
1273 | end | |
1274 |
|
1274 | |||
1275 | def test_preview_new_issue |
|
1275 | def test_preview_new_issue | |
1276 | @request.session[:user_id] = 2 |
|
1276 | @request.session[:user_id] = 2 | |
1277 | post :preview, :project_id => '1', :issue => {:description => 'Foo'} |
|
1277 | post :preview, :project_id => '1', :issue => {:description => 'Foo'} | |
1278 | assert_response :success |
|
1278 | assert_response :success | |
1279 | assert_template 'preview' |
|
1279 | assert_template 'preview' | |
1280 | assert_not_nil assigns(:description) |
|
1280 | assert_not_nil assigns(:description) | |
1281 | end |
|
1281 | end | |
1282 |
|
1282 | |||
1283 | def test_preview_notes |
|
1283 | def test_preview_notes | |
1284 | @request.session[:user_id] = 2 |
|
1284 | @request.session[:user_id] = 2 | |
1285 | post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' |
|
1285 | post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' | |
1286 | assert_response :success |
|
1286 | assert_response :success | |
1287 | assert_template 'preview' |
|
1287 | assert_template 'preview' | |
1288 | assert_not_nil assigns(:notes) |
|
1288 | assert_not_nil assigns(:notes) | |
1289 | end |
|
1289 | end | |
1290 |
|
1290 | |||
1291 | def test_auto_complete_routing |
|
|||
1292 | assert_routing( |
|
|||
1293 | {:method => :get, :path => '/issues/auto_complete'}, |
|
|||
1294 | :controller => 'issues', :action => 'auto_complete' |
|
|||
1295 | ) |
|
|||
1296 | end |
|
|||
1297 |
|
||||
1298 | def test_auto_complete_should_not_be_case_sensitive |
|
1291 | def test_auto_complete_should_not_be_case_sensitive | |
1299 | get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe' |
|
1292 | get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe' | |
1300 | assert_response :success |
|
1293 | assert_response :success | |
1301 | assert_not_nil assigns(:issues) |
|
1294 | assert_not_nil assigns(:issues) | |
1302 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
|
1295 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} | |
1303 | end |
|
1296 | end | |
1304 |
|
1297 | |||
1305 | def test_auto_complete_should_return_issue_with_given_id |
|
1298 | def test_auto_complete_should_return_issue_with_given_id | |
1306 | get :auto_complete, :project_id => 'subproject1', :q => '13' |
|
1299 | get :auto_complete, :project_id => 'subproject1', :q => '13' | |
1307 | assert_response :success |
|
1300 | assert_response :success | |
1308 | assert_not_nil assigns(:issues) |
|
1301 | assert_not_nil assigns(:issues) | |
1309 | assert assigns(:issues).include?(Issue.find(13)) |
|
1302 | assert assigns(:issues).include?(Issue.find(13)) | |
1310 | end |
|
1303 | end | |
1311 |
|
1304 | |||
1312 | def test_destroy_routing |
|
|||
1313 | assert_recognizes( #TODO: use DELETE on issue URI (need to change forms) |
|
|||
1314 | {:controller => 'issues', :action => 'destroy', :id => '1'}, |
|
|||
1315 | {:method => :post, :path => '/issues/1/destroy'} |
|
|||
1316 | ) |
|
|||
1317 | end |
|
|||
1318 |
|
||||
1319 | def test_destroy_issue_with_no_time_entries |
|
1305 | def test_destroy_issue_with_no_time_entries | |
1320 | assert_nil TimeEntry.find_by_issue_id(2) |
|
1306 | assert_nil TimeEntry.find_by_issue_id(2) | |
1321 | @request.session[:user_id] = 2 |
|
1307 | @request.session[:user_id] = 2 | |
1322 | post :destroy, :id => 2 |
|
1308 | post :destroy, :id => 2 | |
1323 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1309 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1324 | assert_nil Issue.find_by_id(2) |
|
1310 | assert_nil Issue.find_by_id(2) | |
1325 | end |
|
1311 | end | |
1326 |
|
1312 | |||
1327 | def test_destroy_issues_with_time_entries |
|
1313 | def test_destroy_issues_with_time_entries | |
1328 | @request.session[:user_id] = 2 |
|
1314 | @request.session[:user_id] = 2 | |
1329 | post :destroy, :ids => [1, 3] |
|
1315 | post :destroy, :ids => [1, 3] | |
1330 | assert_response :success |
|
1316 | assert_response :success | |
1331 | assert_template 'destroy' |
|
1317 | assert_template 'destroy' | |
1332 | assert_not_nil assigns(:hours) |
|
1318 | assert_not_nil assigns(:hours) | |
1333 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
1319 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
1334 | end |
|
1320 | end | |
1335 |
|
1321 | |||
1336 | def test_destroy_issues_and_destroy_time_entries |
|
1322 | def test_destroy_issues_and_destroy_time_entries | |
1337 | @request.session[:user_id] = 2 |
|
1323 | @request.session[:user_id] = 2 | |
1338 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
1324 | post :destroy, :ids => [1, 3], :todo => 'destroy' | |
1339 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1325 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1340 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1326 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1341 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
1327 | assert_nil TimeEntry.find_by_id([1, 2]) | |
1342 | end |
|
1328 | end | |
1343 |
|
1329 | |||
1344 | def test_destroy_issues_and_assign_time_entries_to_project |
|
1330 | def test_destroy_issues_and_assign_time_entries_to_project | |
1345 | @request.session[:user_id] = 2 |
|
1331 | @request.session[:user_id] = 2 | |
1346 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
1332 | post :destroy, :ids => [1, 3], :todo => 'nullify' | |
1347 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1333 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1348 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1334 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1349 | assert_nil TimeEntry.find(1).issue_id |
|
1335 | assert_nil TimeEntry.find(1).issue_id | |
1350 | assert_nil TimeEntry.find(2).issue_id |
|
1336 | assert_nil TimeEntry.find(2).issue_id | |
1351 | end |
|
1337 | end | |
1352 |
|
1338 | |||
1353 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
1339 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
1354 | @request.session[:user_id] = 2 |
|
1340 | @request.session[:user_id] = 2 | |
1355 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
1341 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
1356 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1342 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1357 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1343 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1358 | assert_equal 2, TimeEntry.find(1).issue_id |
|
1344 | assert_equal 2, TimeEntry.find(1).issue_id | |
1359 | assert_equal 2, TimeEntry.find(2).issue_id |
|
1345 | assert_equal 2, TimeEntry.find(2).issue_id | |
1360 | end |
|
1346 | end | |
1361 |
|
1347 | |||
1362 | def test_default_search_scope |
|
1348 | def test_default_search_scope | |
1363 | get :index |
|
1349 | get :index | |
1364 | assert_tag :div, :attributes => {:id => 'quick-search'}, |
|
1350 | assert_tag :div, :attributes => {:id => 'quick-search'}, | |
1365 | :child => {:tag => 'form', |
|
1351 | :child => {:tag => 'form', | |
1366 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |
|
1352 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | |
1367 | end |
|
1353 | end | |
1368 | end |
|
1354 | end |
@@ -1,229 +1,149 | |||||
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 < ActionController::TestCase |
|
24 | class UsersControllerTest < ActionController::TestCase | |
25 | include Redmine::I18n |
|
25 | include Redmine::I18n | |
26 |
|
26 | |||
27 | fixtures :users, :projects, :members, :member_roles, :roles |
|
27 | fixtures :users, :projects, :members, :member_roles, :roles | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = UsersController.new |
|
30 | @controller = UsersController.new | |
31 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
32 | @response = ActionController::TestResponse.new |
|
32 | @response = ActionController::TestResponse.new | |
33 | User.current = nil |
|
33 | User.current = nil | |
34 | @request.session[:user_id] = 1 # admin |
|
34 | @request.session[:user_id] = 1 # admin | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_index_routing |
|
|||
38 | assert_generates( |
|
|||
39 | '/users', |
|
|||
40 | :controller => 'users', :action => 'index' |
|
|||
41 | ) |
|
|||
42 | assert_routing( |
|
|||
43 | {:method => :get, :path => '/users'}, |
|
|||
44 | :controller => 'users', :action => 'index' |
|
|||
45 | ) |
|
|||
46 | assert_recognizes( |
|
|||
47 | {:controller => 'users', :action => 'index'}, |
|
|||
48 | {:method => :get, :path => '/users'} |
|
|||
49 | ) |
|
|||
50 | end |
|
|||
51 |
|
||||
52 | def test_index |
|
37 | def test_index | |
53 | get :index |
|
38 | get :index | |
54 | assert_response :success |
|
39 | assert_response :success | |
55 | assert_template 'index' |
|
40 | assert_template 'index' | |
56 | end |
|
41 | end | |
57 |
|
42 | |||
58 | def test_index |
|
43 | def test_index | |
59 | get :index |
|
44 | get :index | |
60 | assert_response :success |
|
45 | assert_response :success | |
61 | assert_template 'index' |
|
46 | assert_template 'index' | |
62 | assert_not_nil assigns(:users) |
|
47 | assert_not_nil assigns(:users) | |
63 | # active users only |
|
48 | # active users only | |
64 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
49 | assert_nil assigns(:users).detect {|u| !u.active?} | |
65 | end |
|
50 | end | |
66 |
|
51 | |||
67 | def test_index_with_name_filter |
|
52 | def test_index_with_name_filter | |
68 | get :index, :name => 'john' |
|
53 | get :index, :name => 'john' | |
69 | assert_response :success |
|
54 | assert_response :success | |
70 | assert_template 'index' |
|
55 | assert_template 'index' | |
71 | users = assigns(:users) |
|
56 | users = assigns(:users) | |
72 | assert_not_nil users |
|
57 | assert_not_nil users | |
73 | assert_equal 1, users.size |
|
58 | assert_equal 1, users.size | |
74 | assert_equal 'John', users.first.firstname |
|
59 | assert_equal 'John', users.first.firstname | |
75 | end |
|
60 | end | |
76 |
|
61 | |||
77 | def test_show_routing |
|
|||
78 | assert_routing( |
|
|||
79 | {:method => :get, :path => '/users/44'}, |
|
|||
80 | :controller => 'users', :action => 'show', :id => '44' |
|
|||
81 | ) |
|
|||
82 | assert_recognizes( |
|
|||
83 | {:controller => 'users', :action => 'show', :id => '44'}, |
|
|||
84 | {:method => :get, :path => '/users/44'} |
|
|||
85 | ) |
|
|||
86 | end |
|
|||
87 |
|
||||
88 | def test_show |
|
62 | def test_show | |
89 | @request.session[:user_id] = nil |
|
63 | @request.session[:user_id] = nil | |
90 | get :show, :id => 2 |
|
64 | get :show, :id => 2 | |
91 | assert_response :success |
|
65 | assert_response :success | |
92 | assert_template 'show' |
|
66 | assert_template 'show' | |
93 | assert_not_nil assigns(:user) |
|
67 | assert_not_nil assigns(:user) | |
94 | end |
|
68 | end | |
95 |
|
69 | |||
96 | def test_show_should_not_fail_when_custom_values_are_nil |
|
70 | def test_show_should_not_fail_when_custom_values_are_nil | |
97 | user = User.find(2) |
|
71 | user = User.find(2) | |
98 |
|
72 | |||
99 | # Create a custom field to illustrate the issue |
|
73 | # Create a custom field to illustrate the issue | |
100 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') |
|
74 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') | |
101 | custom_value = user.custom_values.build(:custom_field => custom_field).save! |
|
75 | custom_value = user.custom_values.build(:custom_field => custom_field).save! | |
102 |
|
76 | |||
103 | get :show, :id => 2 |
|
77 | get :show, :id => 2 | |
104 | assert_response :success |
|
78 | assert_response :success | |
105 | end |
|
79 | end | |
106 |
|
80 | |||
107 | def test_show_inactive |
|
81 | def test_show_inactive | |
108 | @request.session[:user_id] = nil |
|
82 | @request.session[:user_id] = nil | |
109 | get :show, :id => 5 |
|
83 | get :show, :id => 5 | |
110 | assert_response 404 |
|
84 | assert_response 404 | |
111 | end |
|
85 | end | |
112 |
|
86 | |||
113 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project |
|
87 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project | |
114 | @request.session[:user_id] = nil |
|
88 | @request.session[:user_id] = nil | |
115 | get :show, :id => 9 |
|
89 | get :show, :id => 9 | |
116 | assert_response 404 |
|
90 | assert_response 404 | |
117 | end |
|
91 | end | |
118 |
|
92 | |||
119 | def test_show_inactive_by_admin |
|
93 | def test_show_inactive_by_admin | |
120 | @request.session[:user_id] = 1 |
|
94 | @request.session[:user_id] = 1 | |
121 | get :show, :id => 5 |
|
95 | get :show, :id => 5 | |
122 | assert_response 200 |
|
96 | assert_response 200 | |
123 | assert_not_nil assigns(:user) |
|
97 | assert_not_nil assigns(:user) | |
124 | end |
|
98 | end | |
125 |
|
99 | |||
126 | def test_add_routing |
|
|||
127 | assert_routing( |
|
|||
128 | {:method => :get, :path => '/users/new'}, |
|
|||
129 | :controller => 'users', :action => 'add' |
|
|||
130 | ) |
|
|||
131 | assert_recognizes( |
|
|||
132 | #TODO: remove this and replace with POST to collection, need to modify form |
|
|||
133 | {:controller => 'users', :action => 'add'}, |
|
|||
134 | {:method => :post, :path => '/users/new'} |
|
|||
135 | ) |
|
|||
136 | assert_recognizes( |
|
|||
137 | {:controller => 'users', :action => 'add'}, |
|
|||
138 | {:method => :post, :path => '/users'} |
|
|||
139 | ) |
|
|||
140 | end |
|
|||
141 |
|
||||
142 | def test_edit_routing |
|
|||
143 | assert_routing( |
|
|||
144 | {:method => :get, :path => '/users/444/edit'}, |
|
|||
145 | :controller => 'users', :action => 'edit', :id => '444' |
|
|||
146 | ) |
|
|||
147 | assert_routing( |
|
|||
148 | {:method => :get, :path => '/users/222/edit/membership'}, |
|
|||
149 | :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' |
|
|||
150 | ) |
|
|||
151 | assert_recognizes( |
|
|||
152 | #TODO: use PUT on user_path, modify form |
|
|||
153 | {:controller => 'users', :action => 'edit', :id => '444'}, |
|
|||
154 | {:method => :post, :path => '/users/444/edit'} |
|
|||
155 | ) |
|
|||
156 | end |
|
|||
157 |
|
||||
158 | def test_edit |
|
100 | def test_edit | |
159 | ActionMailer::Base.deliveries.clear |
|
101 | ActionMailer::Base.deliveries.clear | |
160 | post :edit, :id => 2, :user => {:firstname => 'Changed'} |
|
102 | post :edit, :id => 2, :user => {:firstname => 'Changed'} | |
161 | assert_equal 'Changed', User.find(2).firstname |
|
103 | assert_equal 'Changed', User.find(2).firstname | |
162 | assert ActionMailer::Base.deliveries.empty? |
|
104 | assert ActionMailer::Base.deliveries.empty? | |
163 | end |
|
105 | end | |
164 |
|
106 | |||
165 | def test_edit_with_activation_should_send_a_notification |
|
107 | def test_edit_with_activation_should_send_a_notification | |
166 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
|
108 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | |
167 | u.login = 'foo' |
|
109 | u.login = 'foo' | |
168 | u.status = User::STATUS_REGISTERED |
|
110 | u.status = User::STATUS_REGISTERED | |
169 | u.save! |
|
111 | u.save! | |
170 | ActionMailer::Base.deliveries.clear |
|
112 | ActionMailer::Base.deliveries.clear | |
171 | Setting.bcc_recipients = '1' |
|
113 | Setting.bcc_recipients = '1' | |
172 |
|
114 | |||
173 | post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} |
|
115 | post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} | |
174 | assert u.reload.active? |
|
116 | assert u.reload.active? | |
175 | mail = ActionMailer::Base.deliveries.last |
|
117 | mail = ActionMailer::Base.deliveries.last | |
176 | assert_not_nil mail |
|
118 | assert_not_nil mail | |
177 | assert_equal ['foo.bar@somenet.foo'], mail.bcc |
|
119 | assert_equal ['foo.bar@somenet.foo'], mail.bcc | |
178 | assert mail.body.include?(ll('fr', :notice_account_activated)) |
|
120 | assert mail.body.include?(ll('fr', :notice_account_activated)) | |
179 | end |
|
121 | end | |
180 |
|
122 | |||
181 | def test_edit_with_password_change_should_send_a_notification |
|
123 | def test_edit_with_password_change_should_send_a_notification | |
182 | ActionMailer::Base.deliveries.clear |
|
124 | ActionMailer::Base.deliveries.clear | |
183 | Setting.bcc_recipients = '1' |
|
125 | Setting.bcc_recipients = '1' | |
184 |
|
126 | |||
185 | u = User.find(2) |
|
127 | u = User.find(2) | |
186 | post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' |
|
128 | post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' | |
187 | assert_equal User.hash_password('newpass'), u.reload.hashed_password |
|
129 | assert_equal User.hash_password('newpass'), u.reload.hashed_password | |
188 |
|
130 | |||
189 | mail = ActionMailer::Base.deliveries.last |
|
131 | mail = ActionMailer::Base.deliveries.last | |
190 | assert_not_nil mail |
|
132 | assert_not_nil mail | |
191 | assert_equal [u.mail], mail.bcc |
|
133 | assert_equal [u.mail], mail.bcc | |
192 | assert mail.body.include?('newpass') |
|
134 | assert mail.body.include?('newpass') | |
193 | end |
|
135 | end | |
194 |
|
136 | |||
195 | def test_add_membership_routing |
|
|||
196 | assert_routing( |
|
|||
197 | {:method => :post, :path => '/users/123/memberships'}, |
|
|||
198 | :controller => 'users', :action => 'edit_membership', :id => '123' |
|
|||
199 | ) |
|
|||
200 | end |
|
|||
201 |
|
||||
202 | def test_edit_membership_routing |
|
|||
203 | assert_routing( |
|
|||
204 | {:method => :post, :path => '/users/123/memberships/55'}, |
|
|||
205 | :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' |
|
|||
206 | ) |
|
|||
207 | end |
|
|||
208 |
|
||||
209 | def test_edit_membership |
|
137 | def test_edit_membership | |
210 | post :edit_membership, :id => 2, :membership_id => 1, |
|
138 | post :edit_membership, :id => 2, :membership_id => 1, | |
211 | :membership => { :role_ids => [2]} |
|
139 | :membership => { :role_ids => [2]} | |
212 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
140 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
213 | assert_equal [2], Member.find(1).role_ids |
|
141 | assert_equal [2], Member.find(1).role_ids | |
214 | end |
|
142 | end | |
215 |
|
143 | |||
216 | def test_destroy_membership |
|
144 | def test_destroy_membership | |
217 | assert_routing( |
|
|||
218 | #TODO: use DELETE method on user_membership_path, modify form |
|
|||
219 | {:method => :post, :path => '/users/567/memberships/12/destroy'}, |
|
|||
220 | :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' |
|
|||
221 | ) |
|
|||
222 | end |
|
|||
223 |
|
||||
224 | def test_destroy_membership |
|
|||
225 | post :destroy_membership, :id => 2, :membership_id => 1 |
|
145 | post :destroy_membership, :id => 2, :membership_id => 1 | |
226 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
146 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
227 | assert_nil Member.find_by_id(1) |
|
147 | assert_nil Member.find_by_id(1) | |
228 | end |
|
148 | end | |
229 | end |
|
149 | end |
@@ -1,115 +1,104 | |||||
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 < ActionController::TestCase |
|
24 | class VersionsControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules |
|
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :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_new_routing |
|
|||
44 | assert_routing( |
|
|||
45 | {:method => :get, :path => 'projects/foo/versions/new'}, |
|
|||
46 | :controller => 'versions', :action => 'new', :project_id => 'foo' |
|
|||
47 | ) |
|
|||
48 | assert_routing( |
|
|||
49 | {:method => :post, :path => 'projects/foo/versions/new'}, |
|
|||
50 | :controller => 'versions', :action => 'new', :project_id => 'foo' |
|
|||
51 | ) |
|
|||
52 | end |
|
|||
53 |
|
||||
54 | def test_new |
|
43 | def test_new | |
55 | @request.session[:user_id] = 2 # manager |
|
44 | @request.session[:user_id] = 2 # manager | |
56 | assert_difference 'Version.count' do |
|
45 | assert_difference 'Version.count' do | |
57 | post :new, :project_id => '1', :version => {:name => 'test_add_version'} |
|
46 | post :new, :project_id => '1', :version => {:name => 'test_add_version'} | |
58 | end |
|
47 | end | |
59 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
48 | assert_redirected_to '/projects/ecookbook/settings/versions' | |
60 | version = Version.find_by_name('test_add_version') |
|
49 | version = Version.find_by_name('test_add_version') | |
61 | assert_not_nil version |
|
50 | assert_not_nil version | |
62 | assert_equal 1, version.project_id |
|
51 | assert_equal 1, version.project_id | |
63 | end |
|
52 | end | |
64 |
|
53 | |||
65 | def test_new_from_issue_form |
|
54 | def test_new_from_issue_form | |
66 | @request.session[:user_id] = 2 # manager |
|
55 | @request.session[:user_id] = 2 # manager | |
67 | assert_difference 'Version.count' do |
|
56 | assert_difference 'Version.count' do | |
68 | xhr :post, :new, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
57 | xhr :post, :new, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} | |
69 | end |
|
58 | end | |
70 | assert_response :success |
|
59 | assert_response :success | |
71 | assert_select_rjs :replace, 'issue_fixed_version_id' |
|
60 | assert_select_rjs :replace, 'issue_fixed_version_id' | |
72 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
61 | version = Version.find_by_name('test_add_version_from_issue_form') | |
73 | assert_not_nil version |
|
62 | assert_not_nil version | |
74 | assert_equal 1, version.project_id |
|
63 | assert_equal 1, version.project_id | |
75 | end |
|
64 | end | |
76 |
|
65 | |||
77 | def test_get_edit |
|
66 | def test_get_edit | |
78 | @request.session[:user_id] = 2 |
|
67 | @request.session[:user_id] = 2 | |
79 | get :edit, :id => 2 |
|
68 | get :edit, :id => 2 | |
80 | assert_response :success |
|
69 | assert_response :success | |
81 | assert_template 'edit' |
|
70 | assert_template 'edit' | |
82 | end |
|
71 | end | |
83 |
|
72 | |||
84 | def test_close_completed |
|
73 | def test_close_completed | |
85 | Version.update_all("status = 'open'") |
|
74 | Version.update_all("status = 'open'") | |
86 | @request.session[:user_id] = 2 |
|
75 | @request.session[:user_id] = 2 | |
87 | post :close_completed, :project_id => 'ecookbook' |
|
76 | post :close_completed, :project_id => 'ecookbook' | |
88 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
77 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
89 | assert_not_nil Version.find_by_status('closed') |
|
78 | assert_not_nil Version.find_by_status('closed') | |
90 | end |
|
79 | end | |
91 |
|
80 | |||
92 | def test_post_edit |
|
81 | def test_post_edit | |
93 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
94 | post :edit, :id => 2, |
|
83 | post :edit, :id => 2, | |
95 | :version => { :name => 'New version name', |
|
84 | :version => { :name => 'New version name', | |
96 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
85 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
97 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
86 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
98 | version = Version.find(2) |
|
87 | version = Version.find(2) | |
99 | assert_equal 'New version name', version.name |
|
88 | assert_equal 'New version name', version.name | |
100 | assert_equal Date.today, version.effective_date |
|
89 | assert_equal Date.today, version.effective_date | |
101 | end |
|
90 | end | |
102 |
|
91 | |||
103 | def test_destroy |
|
92 | def test_destroy | |
104 | @request.session[:user_id] = 2 |
|
93 | @request.session[:user_id] = 2 | |
105 | post :destroy, :id => 3 |
|
94 | post :destroy, :id => 3 | |
106 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
95 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
107 | assert_nil Version.find_by_id(3) |
|
96 | assert_nil Version.find_by_id(3) | |
108 | end |
|
97 | end | |
109 |
|
98 | |||
110 | def test_issue_status_by |
|
99 | def test_issue_status_by | |
111 | xhr :get, :status_by, :id => 2 |
|
100 | xhr :get, :status_by, :id => 2 | |
112 | assert_response :success |
|
101 | assert_response :success | |
113 | assert_template '_issue_counts' |
|
102 | assert_template '_issue_counts' | |
114 | end |
|
103 | end | |
115 | end |
|
104 | end |
@@ -1,425 +1,325 | |||||
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 < ActionController::TestCase |
|
24 | class WikiControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, :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_index_routing |
|
|||
35 | assert_routing( |
|
|||
36 | {:method => :get, :path => '/projects/567/wiki'}, |
|
|||
37 | :controller => 'wiki', :action => 'index', :id => '567' |
|
|||
38 | ) |
|
|||
39 | assert_routing( |
|
|||
40 | {:method => :get, :path => '/projects/567/wiki/lalala'}, |
|
|||
41 | :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala' |
|
|||
42 | ) |
|
|||
43 | assert_generates( |
|
|||
44 | '/projects/567/wiki', |
|
|||
45 | :controller => 'wiki', :action => 'index', :id => '567', :page => nil |
|
|||
46 | ) |
|
|||
47 | end |
|
|||
48 |
|
||||
49 | def test_show_start_page |
|
34 | def test_show_start_page | |
50 | get :index, :id => 'ecookbook' |
|
35 | get :index, :id => 'ecookbook' | |
51 | assert_response :success |
|
36 | assert_response :success | |
52 | assert_template 'show' |
|
37 | assert_template 'show' | |
53 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
|
38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ | |
54 |
|
39 | |||
55 | # child_pages macro |
|
40 | # child_pages macro | |
56 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
41 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
57 | :child => { :tag => 'li', |
|
42 | :child => { :tag => 'li', | |
58 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
43 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
59 | :content => 'Page with an inline image' } } |
|
44 | :content => 'Page with an inline image' } } | |
60 | end |
|
45 | end | |
61 |
|
46 | |||
62 | def test_show_page_with_name |
|
47 | def test_show_page_with_name | |
63 | get :index, :id => 1, :page => 'Another_page' |
|
48 | get :index, :id => 1, :page => 'Another_page' | |
64 | assert_response :success |
|
49 | assert_response :success | |
65 | assert_template 'show' |
|
50 | assert_template 'show' | |
66 | assert_tag :tag => 'h1', :content => /Another page/ |
|
51 | assert_tag :tag => 'h1', :content => /Another page/ | |
67 | # Included page with an inline image |
|
52 | # Included page with an inline image | |
68 | assert_tag :tag => 'p', :content => /This is an inline image/ |
|
53 | assert_tag :tag => 'p', :content => /This is an inline image/ | |
69 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', |
|
54 | assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', | |
70 | :alt => 'This is a logo' } |
|
55 | :alt => 'This is a logo' } | |
71 | end |
|
56 | end | |
72 |
|
57 | |||
73 | def test_show_with_sidebar |
|
58 | def test_show_with_sidebar | |
74 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
59 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |
75 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
60 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |
76 | page.save! |
|
61 | page.save! | |
77 |
|
62 | |||
78 | get :index, :id => 1, :page => 'Another_page' |
|
63 | get :index, :id => 1, :page => 'Another_page' | |
79 | assert_response :success |
|
64 | assert_response :success | |
80 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
|
65 | assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | |
81 | :content => /Side bar content for test_show_with_sidebar/ |
|
66 | :content => /Side bar content for test_show_with_sidebar/ | |
82 | end |
|
67 | end | |
83 |
|
68 | |||
84 | def test_show_unexistent_page_without_edit_right |
|
69 | def test_show_unexistent_page_without_edit_right | |
85 | get :index, :id => 1, :page => 'Unexistent page' |
|
70 | get :index, :id => 1, :page => 'Unexistent page' | |
86 | assert_response 404 |
|
71 | assert_response 404 | |
87 | end |
|
72 | end | |
88 |
|
73 | |||
89 | def test_show_unexistent_page_with_edit_right |
|
74 | def test_show_unexistent_page_with_edit_right | |
90 | @request.session[:user_id] = 2 |
|
75 | @request.session[:user_id] = 2 | |
91 | get :index, :id => 1, :page => 'Unexistent page' |
|
76 | get :index, :id => 1, :page => 'Unexistent page' | |
92 | assert_response :success |
|
77 | assert_response :success | |
93 | assert_template 'edit' |
|
78 | assert_template 'edit' | |
94 | end |
|
79 | end | |
95 |
|
80 | |||
96 | def test_edit_routing |
|
|||
97 | assert_routing( |
|
|||
98 | {:method => :get, :path => '/projects/567/wiki/my_page/edit'}, |
|
|||
99 | :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page' |
|
|||
100 | ) |
|
|||
101 | assert_recognizes(#TODO: use PUT to page path, adjust forms accordingly |
|
|||
102 | {:controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'}, |
|
|||
103 | {:method => :post, :path => '/projects/567/wiki/my_page/edit'} |
|
|||
104 | ) |
|
|||
105 | end |
|
|||
106 |
|
||||
107 | def test_create_page |
|
81 | def test_create_page | |
108 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
109 | post :edit, :id => 1, |
|
83 | post :edit, :id => 1, | |
110 | :page => 'New page', |
|
84 | :page => 'New page', | |
111 | :content => {:comments => 'Created the page', |
|
85 | :content => {:comments => 'Created the page', | |
112 | :text => "h1. New page\n\nThis is a new page", |
|
86 | :text => "h1. New page\n\nThis is a new page", | |
113 | :version => 0} |
|
87 | :version => 0} | |
114 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page' |
|
88 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'New_page' | |
115 | page = Project.find(1).wiki.find_page('New page') |
|
89 | page = Project.find(1).wiki.find_page('New page') | |
116 | assert !page.new_record? |
|
90 | assert !page.new_record? | |
117 | assert_not_nil page.content |
|
91 | assert_not_nil page.content | |
118 | assert_equal 'Created the page', page.content.comments |
|
92 | assert_equal 'Created the page', page.content.comments | |
119 | end |
|
93 | end | |
120 |
|
94 | |||
121 | def test_create_page_with_attachments |
|
95 | def test_create_page_with_attachments | |
122 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
123 | assert_difference 'WikiPage.count' do |
|
97 | assert_difference 'WikiPage.count' do | |
124 | assert_difference 'Attachment.count' do |
|
98 | assert_difference 'Attachment.count' do | |
125 | post :edit, :id => 1, |
|
99 | post :edit, :id => 1, | |
126 | :page => 'New page', |
|
100 | :page => 'New page', | |
127 | :content => {:comments => 'Created the page', |
|
101 | :content => {:comments => 'Created the page', | |
128 | :text => "h1. New page\n\nThis is a new page", |
|
102 | :text => "h1. New page\n\nThis is a new page", | |
129 | :version => 0}, |
|
103 | :version => 0}, | |
130 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
104 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
131 | end |
|
105 | end | |
132 | end |
|
106 | end | |
133 | page = Project.find(1).wiki.find_page('New page') |
|
107 | page = Project.find(1).wiki.find_page('New page') | |
134 | assert_equal 1, page.attachments.count |
|
108 | assert_equal 1, page.attachments.count | |
135 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
109 | assert_equal 'testfile.txt', page.attachments.first.filename | |
136 | end |
|
110 | end | |
137 |
|
111 | |||
138 | def test_preview_routing |
|
|||
139 | assert_routing( |
|
|||
140 | {:method => :post, :path => '/projects/567/wiki/CookBook_documentation/preview'}, |
|
|||
141 | :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation' |
|
|||
142 | ) |
|
|||
143 | end |
|
|||
144 |
|
||||
145 | def test_preview |
|
112 | def test_preview | |
146 | @request.session[:user_id] = 2 |
|
113 | @request.session[:user_id] = 2 | |
147 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', |
|
114 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', | |
148 | :content => { :comments => '', |
|
115 | :content => { :comments => '', | |
149 | :text => 'this is a *previewed text*', |
|
116 | :text => 'this is a *previewed text*', | |
150 | :version => 3 } |
|
117 | :version => 3 } | |
151 | assert_response :success |
|
118 | assert_response :success | |
152 | assert_template 'common/_preview' |
|
119 | assert_template 'common/_preview' | |
153 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
120 | assert_tag :tag => 'strong', :content => /previewed text/ | |
154 | end |
|
121 | end | |
155 |
|
122 | |||
156 | def test_preview_new_page |
|
123 | def test_preview_new_page | |
157 | @request.session[:user_id] = 2 |
|
124 | @request.session[:user_id] = 2 | |
158 | xhr :post, :preview, :id => 1, :page => 'New page', |
|
125 | xhr :post, :preview, :id => 1, :page => 'New page', | |
159 | :content => { :text => 'h1. New page', |
|
126 | :content => { :text => 'h1. New page', | |
160 | :comments => '', |
|
127 | :comments => '', | |
161 | :version => 0 } |
|
128 | :version => 0 } | |
162 | assert_response :success |
|
129 | assert_response :success | |
163 | assert_template 'common/_preview' |
|
130 | assert_template 'common/_preview' | |
164 | assert_tag :tag => 'h1', :content => /New page/ |
|
131 | assert_tag :tag => 'h1', :content => /New page/ | |
165 | end |
|
132 | end | |
166 |
|
133 | |||
167 | def test_history_routing |
|
|||
168 | assert_routing( |
|
|||
169 | {:method => :get, :path => '/projects/1/wiki/CookBook_documentation/history'}, |
|
|||
170 | :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation' |
|
|||
171 | ) |
|
|||
172 | end |
|
|||
173 |
|
||||
174 | def test_history |
|
134 | def test_history | |
175 | get :history, :id => 1, :page => 'CookBook_documentation' |
|
135 | get :history, :id => 1, :page => 'CookBook_documentation' | |
176 | assert_response :success |
|
136 | assert_response :success | |
177 | assert_template 'history' |
|
137 | assert_template 'history' | |
178 | assert_not_nil assigns(:versions) |
|
138 | assert_not_nil assigns(:versions) | |
179 | assert_equal 3, assigns(:versions).size |
|
139 | assert_equal 3, assigns(:versions).size | |
180 | assert_select "input[type=submit][name=commit]" |
|
140 | assert_select "input[type=submit][name=commit]" | |
181 | end |
|
141 | end | |
182 |
|
142 | |||
183 | def test_history_with_one_version |
|
143 | def test_history_with_one_version | |
184 | get :history, :id => 1, :page => 'Another_page' |
|
144 | get :history, :id => 1, :page => 'Another_page' | |
185 | assert_response :success |
|
145 | assert_response :success | |
186 | assert_template 'history' |
|
146 | assert_template 'history' | |
187 | assert_not_nil assigns(:versions) |
|
147 | assert_not_nil assigns(:versions) | |
188 | assert_equal 1, assigns(:versions).size |
|
148 | assert_equal 1, assigns(:versions).size | |
189 | assert_select "input[type=submit][name=commit]", false |
|
149 | assert_select "input[type=submit][name=commit]", false | |
190 | end |
|
150 | end | |
191 |
|
151 | |||
192 | def test_diff_routing |
|
|||
193 | assert_routing( |
|
|||
194 | {:method => :get, :path => '/projects/1/wiki/CookBook_documentation/diff/2/vs/1'}, |
|
|||
195 | :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1' |
|
|||
196 | ) |
|
|||
197 | end |
|
|||
198 |
|
||||
199 | def test_diff |
|
152 | def test_diff | |
200 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
153 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 | |
201 | assert_response :success |
|
154 | assert_response :success | |
202 | assert_template 'diff' |
|
155 | assert_template 'diff' | |
203 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
156 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
204 | :content => /updated/ |
|
157 | :content => /updated/ | |
205 | end |
|
158 | end | |
206 |
|
159 | |||
207 | def test_annotate_routing |
|
|||
208 | assert_routing( |
|
|||
209 | {:method => :get, :path => '/projects/1/wiki/CookBook_documentation/annotate/2'}, |
|
|||
210 | :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2' |
|
|||
211 | ) |
|
|||
212 | end |
|
|||
213 |
|
||||
214 | def test_annotate |
|
160 | def test_annotate | |
215 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 |
|
161 | get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2 | |
216 | assert_response :success |
|
162 | assert_response :success | |
217 | assert_template 'annotate' |
|
163 | assert_template 'annotate' | |
218 | # Line 1 |
|
164 | # Line 1 | |
219 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, |
|
165 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' }, | |
220 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, |
|
166 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ }, | |
221 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } |
|
167 | :child => { :tag => 'td', :content => /h1\. CookBook documentation/ } | |
222 | # Line 2 |
|
168 | # Line 2 | |
223 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, |
|
169 | assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' }, | |
224 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, |
|
170 | :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ }, | |
225 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } |
|
171 | :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ } | |
226 | end |
|
172 | end | |
227 |
|
173 | |||
228 | def test_rename_routing |
|
|||
229 | assert_routing( |
|
|||
230 | {:method => :get, :path => '/projects/22/wiki/ladida/rename'}, |
|
|||
231 | :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida' |
|
|||
232 | ) |
|
|||
233 | assert_recognizes( |
|
|||
234 | #TODO: should be moved into a update action and use a PUT to the page URI |
|
|||
235 | {:controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'}, |
|
|||
236 | {:method => :post, :path => '/projects/22/wiki/ladida/rename'} |
|
|||
237 | ) |
|
|||
238 | end |
|
|||
239 |
|
||||
240 | def test_rename_with_redirect |
|
174 | def test_rename_with_redirect | |
241 | @request.session[:user_id] = 2 |
|
175 | @request.session[:user_id] = 2 | |
242 | post :rename, :id => 1, :page => 'Another_page', |
|
176 | post :rename, :id => 1, :page => 'Another_page', | |
243 | :wiki_page => { :title => 'Another renamed page', |
|
177 | :wiki_page => { :title => 'Another renamed page', | |
244 | :redirect_existing_links => 1 } |
|
178 | :redirect_existing_links => 1 } | |
245 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' |
|
179 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' | |
246 | wiki = Project.find(1).wiki |
|
180 | wiki = Project.find(1).wiki | |
247 | # Check redirects |
|
181 | # Check redirects | |
248 | assert_not_nil wiki.find_page('Another page') |
|
182 | assert_not_nil wiki.find_page('Another page') | |
249 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
183 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
250 | end |
|
184 | end | |
251 |
|
185 | |||
252 | def test_rename_without_redirect |
|
186 | def test_rename_without_redirect | |
253 | @request.session[:user_id] = 2 |
|
187 | @request.session[:user_id] = 2 | |
254 | post :rename, :id => 1, :page => 'Another_page', |
|
188 | post :rename, :id => 1, :page => 'Another_page', | |
255 | :wiki_page => { :title => 'Another renamed page', |
|
189 | :wiki_page => { :title => 'Another renamed page', | |
256 | :redirect_existing_links => "0" } |
|
190 | :redirect_existing_links => "0" } | |
257 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' |
|
191 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_renamed_page' | |
258 | wiki = Project.find(1).wiki |
|
192 | wiki = Project.find(1).wiki | |
259 | # Check that there's no redirects |
|
193 | # Check that there's no redirects | |
260 | assert_nil wiki.find_page('Another page') |
|
194 | assert_nil wiki.find_page('Another page') | |
261 | end |
|
195 | end | |
262 |
|
196 | |||
263 | def test_destroy_routing |
|
|||
264 | assert_recognizes( |
|
|||
265 | #TODO: should use DELETE on page URI |
|
|||
266 | {:controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida'}, |
|
|||
267 | {:method => :post, :path => 'projects/22/wiki/ladida/destroy'} |
|
|||
268 | ) |
|
|||
269 | end |
|
|||
270 |
|
||||
271 | def test_destroy_child |
|
197 | def test_destroy_child | |
272 | @request.session[:user_id] = 2 |
|
198 | @request.session[:user_id] = 2 | |
273 | post :destroy, :id => 1, :page => 'Child_1' |
|
199 | post :destroy, :id => 1, :page => 'Child_1' | |
274 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' |
|
200 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
275 | end |
|
201 | end | |
276 |
|
202 | |||
277 | def test_destroy_parent |
|
203 | def test_destroy_parent | |
278 | @request.session[:user_id] = 2 |
|
204 | @request.session[:user_id] = 2 | |
279 | assert_no_difference('WikiPage.count') do |
|
205 | assert_no_difference('WikiPage.count') do | |
280 | post :destroy, :id => 1, :page => 'Another_page' |
|
206 | post :destroy, :id => 1, :page => 'Another_page' | |
281 | end |
|
207 | end | |
282 | assert_response :success |
|
208 | assert_response :success | |
283 | assert_template 'destroy' |
|
209 | assert_template 'destroy' | |
284 | end |
|
210 | end | |
285 |
|
211 | |||
286 | def test_destroy_parent_with_nullify |
|
212 | def test_destroy_parent_with_nullify | |
287 | @request.session[:user_id] = 2 |
|
213 | @request.session[:user_id] = 2 | |
288 | assert_difference('WikiPage.count', -1) do |
|
214 | assert_difference('WikiPage.count', -1) do | |
289 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify' |
|
215 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify' | |
290 | end |
|
216 | end | |
291 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' |
|
217 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
292 | assert_nil WikiPage.find_by_id(2) |
|
218 | assert_nil WikiPage.find_by_id(2) | |
293 | end |
|
219 | end | |
294 |
|
220 | |||
295 | def test_destroy_parent_with_cascade |
|
221 | def test_destroy_parent_with_cascade | |
296 | @request.session[:user_id] = 2 |
|
222 | @request.session[:user_id] = 2 | |
297 | assert_difference('WikiPage.count', -3) do |
|
223 | assert_difference('WikiPage.count', -3) do | |
298 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy' |
|
224 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy' | |
299 | end |
|
225 | end | |
300 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' |
|
226 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
301 | assert_nil WikiPage.find_by_id(2) |
|
227 | assert_nil WikiPage.find_by_id(2) | |
302 | assert_nil WikiPage.find_by_id(5) |
|
228 | assert_nil WikiPage.find_by_id(5) | |
303 | end |
|
229 | end | |
304 |
|
230 | |||
305 | def test_destroy_parent_with_reassign |
|
231 | def test_destroy_parent_with_reassign | |
306 | @request.session[:user_id] = 2 |
|
232 | @request.session[:user_id] = 2 | |
307 | assert_difference('WikiPage.count', -1) do |
|
233 | assert_difference('WikiPage.count', -1) do | |
308 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
|
234 | post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 | |
309 | end |
|
235 | end | |
310 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' |
|
236 | assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' | |
311 | assert_nil WikiPage.find_by_id(2) |
|
237 | assert_nil WikiPage.find_by_id(2) | |
312 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
238 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | |
313 | end |
|
239 | end | |
314 |
|
240 | |||
315 | def test_special_routing |
|
|||
316 | assert_routing( |
|
|||
317 | {:method => :get, :path => '/projects/567/wiki/page_index'}, |
|
|||
318 | :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index' |
|
|||
319 | ) |
|
|||
320 | assert_routing( |
|
|||
321 | {:method => :get, :path => '/projects/567/wiki/Page_Index'}, |
|
|||
322 | :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index' |
|
|||
323 | ) |
|
|||
324 | assert_routing( |
|
|||
325 | {:method => :get, :path => '/projects/567/wiki/date_index'}, |
|
|||
326 | :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index' |
|
|||
327 | ) |
|
|||
328 | assert_routing( |
|
|||
329 | {:method => :get, :path => '/projects/567/wiki/export'}, |
|
|||
330 | :controller => 'wiki', :action => 'special', :id => '567', :page => 'export' |
|
|||
331 | ) |
|
|||
332 | end |
|
|||
333 |
|
||||
334 | def test_page_index |
|
241 | def test_page_index | |
335 | get :special, :id => 'ecookbook', :page => 'Page_index' |
|
242 | get :special, :id => 'ecookbook', :page => 'Page_index' | |
336 | assert_response :success |
|
243 | assert_response :success | |
337 | assert_template 'special_page_index' |
|
244 | assert_template 'special_page_index' | |
338 | pages = assigns(:pages) |
|
245 | pages = assigns(:pages) | |
339 | assert_not_nil pages |
|
246 | assert_not_nil pages | |
340 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
247 | assert_equal Project.find(1).wiki.pages.size, pages.size | |
341 |
|
248 | |||
342 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
249 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | |
343 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
|
250 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, | |
344 | :content => 'CookBook documentation' }, |
|
251 | :content => 'CookBook documentation' }, | |
345 | :child => { :tag => 'ul', |
|
252 | :child => { :tag => 'ul', | |
346 | :child => { :tag => 'li', |
|
253 | :child => { :tag => 'li', | |
347 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
|
254 | :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | |
348 | :content => 'Page with an inline image' } } } }, |
|
255 | :content => 'Page with an inline image' } } } }, | |
349 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, |
|
256 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, | |
350 | :content => 'Another page' } } |
|
257 | :content => 'Another page' } } | |
351 | end |
|
258 | end | |
352 |
|
259 | |||
353 | def test_not_found |
|
260 | def test_not_found | |
354 | get :index, :id => 999 |
|
261 | get :index, :id => 999 | |
355 | assert_response 404 |
|
262 | assert_response 404 | |
356 | end |
|
263 | end | |
357 |
|
264 | |||
358 | def test_protect_routing |
|
|||
359 | assert_routing( |
|
|||
360 | {:method => :post, :path => 'projects/22/wiki/ladida/protect'}, |
|
|||
361 | {:controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida'} |
|
|||
362 | ) |
|
|||
363 | end |
|
|||
364 |
|
||||
365 | def test_protect_page |
|
265 | def test_protect_page | |
366 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
266 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | |
367 | assert !page.protected? |
|
267 | assert !page.protected? | |
368 | @request.session[:user_id] = 2 |
|
268 | @request.session[:user_id] = 2 | |
369 | post :protect, :id => 1, :page => page.title, :protected => '1' |
|
269 | post :protect, :id => 1, :page => page.title, :protected => '1' | |
370 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_page' |
|
270 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'Another_page' | |
371 | assert page.reload.protected? |
|
271 | assert page.reload.protected? | |
372 | end |
|
272 | end | |
373 |
|
273 | |||
374 | def test_unprotect_page |
|
274 | def test_unprotect_page | |
375 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
275 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | |
376 | assert page.protected? |
|
276 | assert page.protected? | |
377 | @request.session[:user_id] = 2 |
|
277 | @request.session[:user_id] = 2 | |
378 | post :protect, :id => 1, :page => page.title, :protected => '0' |
|
278 | post :protect, :id => 1, :page => page.title, :protected => '0' | |
379 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'CookBook_documentation' |
|
279 | assert_redirected_to :action => 'index', :id => 'ecookbook', :page => 'CookBook_documentation' | |
380 | assert !page.reload.protected? |
|
280 | assert !page.reload.protected? | |
381 | end |
|
281 | end | |
382 |
|
282 | |||
383 | def test_show_page_with_edit_link |
|
283 | def test_show_page_with_edit_link | |
384 | @request.session[:user_id] = 2 |
|
284 | @request.session[:user_id] = 2 | |
385 | get :index, :id => 1 |
|
285 | get :index, :id => 1 | |
386 | assert_response :success |
|
286 | assert_response :success | |
387 | assert_template 'show' |
|
287 | assert_template 'show' | |
388 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
288 | assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
389 | end |
|
289 | end | |
390 |
|
290 | |||
391 | def test_show_page_without_edit_link |
|
291 | def test_show_page_without_edit_link | |
392 | @request.session[:user_id] = 4 |
|
292 | @request.session[:user_id] = 4 | |
393 | get :index, :id => 1 |
|
293 | get :index, :id => 1 | |
394 | assert_response :success |
|
294 | assert_response :success | |
395 | assert_template 'show' |
|
295 | assert_template 'show' | |
396 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
|
296 | assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | |
397 | end |
|
297 | end | |
398 |
|
298 | |||
399 | def test_edit_unprotected_page |
|
299 | def test_edit_unprotected_page | |
400 | # Non members can edit unprotected wiki pages |
|
300 | # Non members can edit unprotected wiki pages | |
401 | @request.session[:user_id] = 4 |
|
301 | @request.session[:user_id] = 4 | |
402 | get :edit, :id => 1, :page => 'Another_page' |
|
302 | get :edit, :id => 1, :page => 'Another_page' | |
403 | assert_response :success |
|
303 | assert_response :success | |
404 | assert_template 'edit' |
|
304 | assert_template 'edit' | |
405 | end |
|
305 | end | |
406 |
|
306 | |||
407 | def test_edit_protected_page_by_nonmember |
|
307 | def test_edit_protected_page_by_nonmember | |
408 | # Non members can't edit protected wiki pages |
|
308 | # Non members can't edit protected wiki pages | |
409 | @request.session[:user_id] = 4 |
|
309 | @request.session[:user_id] = 4 | |
410 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
310 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
411 | assert_response 403 |
|
311 | assert_response 403 | |
412 | end |
|
312 | end | |
413 |
|
313 | |||
414 | def test_edit_protected_page_by_member |
|
314 | def test_edit_protected_page_by_member | |
415 | @request.session[:user_id] = 2 |
|
315 | @request.session[:user_id] = 2 | |
416 | get :edit, :id => 1, :page => 'CookBook_documentation' |
|
316 | get :edit, :id => 1, :page => 'CookBook_documentation' | |
417 | assert_response :success |
|
317 | assert_response :success | |
418 | assert_template 'edit' |
|
318 | assert_template 'edit' | |
419 | end |
|
319 | end | |
420 |
|
320 | |||
421 | def test_history_of_non_existing_page_should_return_404 |
|
321 | def test_history_of_non_existing_page_should_return_404 | |
422 | get :history, :id => 1, :page => 'Unknown_page' |
|
322 | get :history, :id => 1, :page => 'Unknown_page' | |
423 | assert_response 404 |
|
323 | assert_response 404 | |
424 | end |
|
324 | end | |
425 | end |
|
325 | end |
@@ -1,68 +1,114 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2010 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2010 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require "#{File.dirname(__FILE__)}/../test_helper" |
|
18 | require "#{File.dirname(__FILE__)}/../test_helper" | |
19 |
|
19 | |||
20 | class RoutingTest < ActionController::IntegrationTest |
|
20 | class RoutingTest < ActionController::IntegrationTest | |
21 | context "issues" do |
|
21 | context "issues" do | |
22 | # REST actions |
|
22 | # REST actions | |
23 | should_route :get, "/issues", :controller => 'issues', :action => 'index' |
|
23 | should_route :get, "/issues", :controller => 'issues', :action => 'index' | |
24 | should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf' |
|
24 | should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf' | |
25 | should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom' |
|
25 | should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom' | |
26 | should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml' |
|
26 | should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml' | |
27 | should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23' |
|
27 | should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23' | |
28 | should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf' |
|
28 | should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf' | |
29 | should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom' |
|
29 | should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom' | |
30 | should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml' |
|
30 | should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml' | |
31 | should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64' |
|
31 | should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64' | |
32 | should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf' |
|
32 | should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf' | |
33 | should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom' |
|
33 | should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom' | |
34 | should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml' |
|
34 | should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml' | |
35 |
|
35 | |||
36 | should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23' |
|
36 | should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23' | |
37 |
|
37 | |||
38 | should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' |
|
38 | should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' | |
39 | # TODO: Should use PUT |
|
39 | # TODO: Should use PUT | |
40 | should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' |
|
40 | should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' | |
41 |
|
41 | |||
42 | # TODO: Should use DELETE |
|
42 | # TODO: Should use DELETE | |
43 | should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64' |
|
43 | should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64' | |
44 |
|
44 | |||
45 | # Extra actions |
|
45 | # Extra actions | |
46 | should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64' |
|
46 | should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64' | |
47 |
|
47 | |||
48 | should_route :get, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1' |
|
48 | should_route :get, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1' | |
49 | should_route :post, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1' |
|
49 | should_route :post, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1' | |
50 |
|
50 | |||
51 | should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1' |
|
51 | should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1' | |
52 |
|
52 | |||
53 | should_route :get, "/issues/calendar", :controller => 'issues', :action => 'calendar' |
|
53 | should_route :get, "/issues/calendar", :controller => 'issues', :action => 'calendar' | |
54 | should_route :post, "/issues/calendar", :controller => 'issues', :action => 'calendar' |
|
54 | should_route :post, "/issues/calendar", :controller => 'issues', :action => 'calendar' | |
55 | should_route :get, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name' |
|
55 | should_route :get, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name' | |
56 | should_route :post, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name' |
|
56 | should_route :post, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name' | |
57 |
|
57 | |||
58 | should_route :get, "/issues/gantt", :controller => 'issues', :action => 'gantt' |
|
58 | should_route :get, "/issues/gantt", :controller => 'issues', :action => 'gantt' | |
59 | should_route :post, "/issues/gantt", :controller => 'issues', :action => 'gantt' |
|
59 | should_route :post, "/issues/gantt", :controller => 'issues', :action => 'gantt' | |
60 | should_route :get, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name' |
|
60 | should_route :get, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name' | |
61 | should_route :post, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name' |
|
61 | should_route :post, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name' | |
|
62 | ||||
|
63 | should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete' | |||
62 | end |
|
64 | end | |
63 |
|
65 | |||
64 | context "issue reports" do |
|
66 | context "issue reports" do | |
65 | should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567' |
|
67 | should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567' | |
66 | should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to' |
|
68 | should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to' | |
67 | end |
|
69 | end | |
|
70 | ||||
|
71 | context "users" do | |||
|
72 | should_route :get, "/users", :controller => 'users', :action => 'index' | |||
|
73 | should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44' | |||
|
74 | should_route :get, "/users/new", :controller => 'users', :action => 'add' | |||
|
75 | should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444' | |||
|
76 | should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' | |||
|
77 | ||||
|
78 | should_route :post, "/users/new", :controller => 'users', :action => 'add' | |||
|
79 | should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444' | |||
|
80 | should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123' | |||
|
81 | should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' | |||
|
82 | should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' | |||
|
83 | end | |||
|
84 | ||||
|
85 | context "versions" do | |||
|
86 | should_route :get, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo' | |||
|
87 | ||||
|
88 | should_route :post, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo' | |||
|
89 | end | |||
|
90 | ||||
|
91 | context "wikis" do | |||
|
92 | should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :id => '567' | |||
|
93 | should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala' | |||
|
94 | should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page' | |||
|
95 | should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation' | |||
|
96 | should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1' | |||
|
97 | should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2' | |||
|
98 | should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida' | |||
|
99 | should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index' | |||
|
100 | should_route :get, "/projects/567/wiki/Page_Index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index' | |||
|
101 | should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index' | |||
|
102 | should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'special', :id => '567', :page => 'export' | |||
|
103 | ||||
|
104 | should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page' | |||
|
105 | should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation' | |||
|
106 | should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida' | |||
|
107 | should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida' | |||
|
108 | should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida' | |||
|
109 | end | |||
|
110 | ||||
|
111 | context "administration panel" do | |||
|
112 | should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects' | |||
|
113 | end | |||
68 | end |
|
114 | end |
General Comments 0
You need to be logged in to leave comments.
Login now