##// END OF EJS Templates
Adds functional tests....
Jean-Philippe Lang -
r8827:e6a64aa00bea
parent child
Show More
@@ -1,110 +1,120
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class EnumerationsControllerTest < ActionController::TestCase
20 class EnumerationsControllerTest < ActionController::TestCase
21 fixtures :enumerations, :issues, :users
21 fixtures :enumerations, :issues, :users
22
22
23 def setup
23 def setup
24 @request.session[:user_id] = 1 # admin
24 @request.session[:user_id] = 1 # admin
25 end
25 end
26
26
27 def test_index
27 def test_index
28 get :index
28 get :index
29 assert_response :success
29 assert_response :success
30 assert_template 'index'
30 assert_template 'index'
31 end
31 end
32
32
33 def test_new
33 def test_new
34 get :new, :type => 'IssuePriority'
34 get :new, :type => 'IssuePriority'
35 assert_response :success
35 assert_response :success
36 assert_template 'new'
36 assert_template 'new'
37 assert_kind_of IssuePriority, assigns(:enumeration)
37 assert_kind_of IssuePriority, assigns(:enumeration)
38 assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
38 assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
39 assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
39 assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
40 end
40 end
41
41
42 def test_new_with_invalid_type_should_respond_with_404
43 get :new, :type => 'UnknownType'
44 assert_response 404
45 end
46
42 def test_create
47 def test_create
43 assert_difference 'IssuePriority.count' do
48 assert_difference 'IssuePriority.count' do
44 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
49 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
45 end
50 end
46 assert_redirected_to '/enumerations?type=IssuePriority'
51 assert_redirected_to '/enumerations?type=IssuePriority'
47 e = IssuePriority.first(:order => 'id DESC')
52 e = IssuePriority.first(:order => 'id DESC')
48 assert_equal 'Lowest', e.name
53 assert_equal 'Lowest', e.name
49 end
54 end
50
55
51 def test_create_with_failure
56 def test_create_with_failure
52 assert_no_difference 'IssuePriority.count' do
57 assert_no_difference 'IssuePriority.count' do
53 post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
58 post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
54 end
59 end
55 assert_response :success
60 assert_response :success
56 assert_template 'new'
61 assert_template 'new'
57 end
62 end
58
63
59 def test_edit
64 def test_edit
60 get :edit, :id => 6
65 get :edit, :id => 6
61 assert_response :success
66 assert_response :success
62 assert_template 'edit'
67 assert_template 'edit'
63 assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
68 assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
64 end
69 end
65
70
71 def test_edit_invalid_should_respond_with_404
72 get :edit, :id => 999
73 assert_response 404
74 end
75
66 def test_update
76 def test_update
67 assert_no_difference 'IssuePriority.count' do
77 assert_no_difference 'IssuePriority.count' do
68 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
78 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
69 end
79 end
70 assert_redirected_to '/enumerations?type=IssuePriority'
80 assert_redirected_to '/enumerations?type=IssuePriority'
71 e = IssuePriority.find(6)
81 e = IssuePriority.find(6)
72 assert_equal 'New name', e.name
82 assert_equal 'New name', e.name
73 end
83 end
74
84
75 def test_update_with_failure
85 def test_update_with_failure
76 assert_no_difference 'IssuePriority.count' do
86 assert_no_difference 'IssuePriority.count' do
77 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
87 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
78 end
88 end
79 assert_response :success
89 assert_response :success
80 assert_template 'edit'
90 assert_template 'edit'
81 end
91 end
82
92
83 def test_destroy_enumeration_not_in_use
93 def test_destroy_enumeration_not_in_use
84 assert_difference 'IssuePriority.count', -1 do
94 assert_difference 'IssuePriority.count', -1 do
85 delete :destroy, :id => 7
95 delete :destroy, :id => 7
86 end
96 end
87 assert_redirected_to :controller => 'enumerations', :action => 'index'
97 assert_redirected_to :controller => 'enumerations', :action => 'index'
88 assert_nil Enumeration.find_by_id(7)
98 assert_nil Enumeration.find_by_id(7)
89 end
99 end
90
100
91 def test_destroy_enumeration_in_use
101 def test_destroy_enumeration_in_use
92 assert_no_difference 'IssuePriority.count' do
102 assert_no_difference 'IssuePriority.count' do
93 delete :destroy, :id => 4
103 delete :destroy, :id => 4
94 end
104 end
95 assert_response :success
105 assert_response :success
96 assert_template 'destroy'
106 assert_template 'destroy'
97 assert_not_nil Enumeration.find_by_id(4)
107 assert_not_nil Enumeration.find_by_id(4)
98 end
108 end
99
109
100 def test_destroy_enumeration_in_use_with_reassignment
110 def test_destroy_enumeration_in_use_with_reassignment
101 issue = Issue.find(:first, :conditions => {:priority_id => 4})
111 issue = Issue.find(:first, :conditions => {:priority_id => 4})
102 assert_difference 'IssuePriority.count', -1 do
112 assert_difference 'IssuePriority.count', -1 do
103 delete :destroy, :id => 4, :reassign_to_id => 6
113 delete :destroy, :id => 4, :reassign_to_id => 6
104 end
114 end
105 assert_redirected_to :controller => 'enumerations', :action => 'index'
115 assert_redirected_to :controller => 'enumerations', :action => 'index'
106 assert_nil Enumeration.find_by_id(4)
116 assert_nil Enumeration.find_by_id(4)
107 # check that the issue was reassign
117 # check that the issue was reassign
108 assert_equal 6, issue.reload.priority_id
118 assert_equal 6, issue.reload.priority_id
109 end
119 end
110 end
120 end
@@ -1,178 +1,183
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RolesControllerTest < ActionController::TestCase
20 class RolesControllerTest < ActionController::TestCase
21 fixtures :roles, :users, :members, :member_roles, :workflows, :trackers
21 fixtures :roles, :users, :members, :member_roles, :workflows, :trackers
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 @request.session[:user_id] = 1 # admin
25 @request.session[:user_id] = 1 # admin
26 end
26 end
27
27
28 def test_index
28 def test_index
29 get :index
29 get :index
30 assert_response :success
30 assert_response :success
31 assert_template 'index'
31 assert_template 'index'
32
32
33 assert_not_nil assigns(:roles)
33 assert_not_nil assigns(:roles)
34 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
34 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
35
35
36 assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' },
36 assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' },
37 :content => 'Manager'
37 :content => 'Manager'
38 end
38 end
39
39
40 def test_new
40 def test_new
41 get :new
41 get :new
42 assert_response :success
42 assert_response :success
43 assert_template 'new'
43 assert_template 'new'
44 end
44 end
45
45
46 def test_create_with_validaton_failure
46 def test_create_with_validaton_failure
47 post :create, :role => {:name => '',
47 post :create, :role => {:name => '',
48 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
48 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
49 :assignable => '0'}
49 :assignable => '0'}
50
50
51 assert_response :success
51 assert_response :success
52 assert_template 'new'
52 assert_template 'new'
53 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
53 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
54 end
54 end
55
55
56 def test_create_without_workflow_copy
56 def test_create_without_workflow_copy
57 post :create, :role => {:name => 'RoleWithoutWorkflowCopy',
57 post :create, :role => {:name => 'RoleWithoutWorkflowCopy',
58 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
58 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
59 :assignable => '0'}
59 :assignable => '0'}
60
60
61 assert_redirected_to '/roles'
61 assert_redirected_to '/roles'
62 role = Role.find_by_name('RoleWithoutWorkflowCopy')
62 role = Role.find_by_name('RoleWithoutWorkflowCopy')
63 assert_not_nil role
63 assert_not_nil role
64 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
64 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
65 assert !role.assignable?
65 assert !role.assignable?
66 end
66 end
67
67
68 def test_create_with_workflow_copy
68 def test_create_with_workflow_copy
69 post :create, :role => {:name => 'RoleWithWorkflowCopy',
69 post :create, :role => {:name => 'RoleWithWorkflowCopy',
70 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
70 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
71 :assignable => '0'},
71 :assignable => '0'},
72 :copy_workflow_from => '1'
72 :copy_workflow_from => '1'
73
73
74 assert_redirected_to '/roles'
74 assert_redirected_to '/roles'
75 role = Role.find_by_name('RoleWithWorkflowCopy')
75 role = Role.find_by_name('RoleWithWorkflowCopy')
76 assert_not_nil role
76 assert_not_nil role
77 assert_equal Role.find(1).workflows.size, role.workflows.size
77 assert_equal Role.find(1).workflows.size, role.workflows.size
78 end
78 end
79
79
80 def test_edit
80 def test_edit
81 get :edit, :id => 1
81 get :edit, :id => 1
82 assert_response :success
82 assert_response :success
83 assert_template 'edit'
83 assert_template 'edit'
84 assert_equal Role.find(1), assigns(:role)
84 assert_equal Role.find(1), assigns(:role)
85 end
85 end
86
86
87 def test_edit_invalid_should_respond_with_404
88 get :edit, :id => 999
89 assert_response 404
90 end
91
87 def test_update
92 def test_update
88 put :update, :id => 1,
93 put :update, :id => 1,
89 :role => {:name => 'Manager',
94 :role => {:name => 'Manager',
90 :permissions => ['edit_project', ''],
95 :permissions => ['edit_project', ''],
91 :assignable => '0'}
96 :assignable => '0'}
92
97
93 assert_redirected_to '/roles'
98 assert_redirected_to '/roles'
94 role = Role.find(1)
99 role = Role.find(1)
95 assert_equal [:edit_project], role.permissions
100 assert_equal [:edit_project], role.permissions
96 end
101 end
97
102
98 def test_update_with_failure
103 def test_update_with_failure
99 put :update, :id => 1, :role => {:name => ''}
104 put :update, :id => 1, :role => {:name => ''}
100 assert_response :success
105 assert_response :success
101 assert_template 'edit'
106 assert_template 'edit'
102 end
107 end
103
108
104 def test_destroy
109 def test_destroy
105 r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
110 r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
106
111
107 delete :destroy, :id => r
112 delete :destroy, :id => r
108 assert_redirected_to '/roles'
113 assert_redirected_to '/roles'
109 assert_nil Role.find_by_id(r.id)
114 assert_nil Role.find_by_id(r.id)
110 end
115 end
111
116
112 def test_destroy_role_in_use
117 def test_destroy_role_in_use
113 delete :destroy, :id => 1
118 delete :destroy, :id => 1
114 assert_redirected_to '/roles'
119 assert_redirected_to '/roles'
115 assert_equal 'This role is in use and cannot be deleted.', flash[:error]
120 assert_equal 'This role is in use and cannot be deleted.', flash[:error]
116 assert_not_nil Role.find_by_id(1)
121 assert_not_nil Role.find_by_id(1)
117 end
122 end
118
123
119 def test_get_permissions
124 def test_get_permissions
120 get :permissions
125 get :permissions
121 assert_response :success
126 assert_response :success
122 assert_template 'permissions'
127 assert_template 'permissions'
123
128
124 assert_not_nil assigns(:roles)
129 assert_not_nil assigns(:roles)
125 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
130 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
126
131
127 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
132 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
128 :name => 'permissions[3][]',
133 :name => 'permissions[3][]',
129 :value => 'add_issues',
134 :value => 'add_issues',
130 :checked => 'checked' }
135 :checked => 'checked' }
131
136
132 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
137 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
133 :name => 'permissions[3][]',
138 :name => 'permissions[3][]',
134 :value => 'delete_issues',
139 :value => 'delete_issues',
135 :checked => nil }
140 :checked => nil }
136 end
141 end
137
142
138 def test_post_permissions
143 def test_post_permissions
139 post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
144 post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
140 assert_redirected_to '/roles'
145 assert_redirected_to '/roles'
141
146
142 assert_equal [:edit_issues], Role.find(1).permissions
147 assert_equal [:edit_issues], Role.find(1).permissions
143 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
148 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
144 assert Role.find(2).permissions.empty?
149 assert Role.find(2).permissions.empty?
145 end
150 end
146
151
147 def test_clear_all_permissions
152 def test_clear_all_permissions
148 post :permissions, :permissions => { '0' => '' }
153 post :permissions, :permissions => { '0' => '' }
149 assert_redirected_to '/roles'
154 assert_redirected_to '/roles'
150 assert Role.find(1).permissions.empty?
155 assert Role.find(1).permissions.empty?
151 end
156 end
152
157
153 def test_move_highest
158 def test_move_highest
154 put :update, :id => 3, :role => {:move_to => 'highest'}
159 put :update, :id => 3, :role => {:move_to => 'highest'}
155 assert_redirected_to '/roles'
160 assert_redirected_to '/roles'
156 assert_equal 1, Role.find(3).position
161 assert_equal 1, Role.find(3).position
157 end
162 end
158
163
159 def test_move_higher
164 def test_move_higher
160 position = Role.find(3).position
165 position = Role.find(3).position
161 put :update, :id => 3, :role => {:move_to => 'higher'}
166 put :update, :id => 3, :role => {:move_to => 'higher'}
162 assert_redirected_to '/roles'
167 assert_redirected_to '/roles'
163 assert_equal position - 1, Role.find(3).position
168 assert_equal position - 1, Role.find(3).position
164 end
169 end
165
170
166 def test_move_lower
171 def test_move_lower
167 position = Role.find(2).position
172 position = Role.find(2).position
168 put :update, :id => 2, :role => {:move_to => 'lower'}
173 put :update, :id => 2, :role => {:move_to => 'lower'}
169 assert_redirected_to '/roles'
174 assert_redirected_to '/roles'
170 assert_equal position + 1, Role.find(2).position
175 assert_equal position + 1, Role.find(2).position
171 end
176 end
172
177
173 def test_move_lowest
178 def test_move_lowest
174 put :update, :id => 2, :role => {:move_to => 'lowest'}
179 put :update, :id => 2, :role => {:move_to => 'lowest'}
175 assert_redirected_to '/roles'
180 assert_redirected_to '/roles'
176 assert_equal Role.count, Role.find(2).position
181 assert_equal Role.count, Role.find(2).position
177 end
182 end
178 end
183 end
General Comments 0
You need to be logged in to leave comments. Login now