@@ -1,175 +1,180 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 GroupsControllerTest < ActionController::TestCase |
|
20 | class GroupsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :groups_users |
|
21 | fixtures :projects, :users, :members, :member_roles, :groups_users | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @request.session[:user_id] = 1 |
|
24 | @request.session[:user_id] = 1 | |
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_show |
|
33 | def test_show | |
34 | get :show, :id => 10 |
|
34 | get :show, :id => 10 | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'show' |
|
36 | assert_template 'show' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
|
39 | def test_show_invalid_should_return_404 | |||
|
40 | get :show, :id => 99 | |||
|
41 | assert_response 404 | |||
|
42 | end | |||
|
43 | ||||
39 | def test_new |
|
44 | def test_new | |
40 | get :new |
|
45 | get :new | |
41 | assert_response :success |
|
46 | assert_response :success | |
42 | assert_template 'new' |
|
47 | assert_template 'new' | |
43 | assert_select 'input[name=?]', 'group[name]' |
|
48 | assert_select 'input[name=?]', 'group[name]' | |
44 | end |
|
49 | end | |
45 |
|
50 | |||
46 | def test_create |
|
51 | def test_create | |
47 | assert_difference 'Group.count' do |
|
52 | assert_difference 'Group.count' do | |
48 | post :create, :group => {:name => 'New group'} |
|
53 | post :create, :group => {:name => 'New group'} | |
49 | end |
|
54 | end | |
50 | assert_redirected_to '/groups' |
|
55 | assert_redirected_to '/groups' | |
51 | group = Group.first(:order => 'id DESC') |
|
56 | group = Group.first(:order => 'id DESC') | |
52 | assert_equal 'New group', group.name |
|
57 | assert_equal 'New group', group.name | |
53 | assert_equal [], group.users |
|
58 | assert_equal [], group.users | |
54 | end |
|
59 | end | |
55 |
|
60 | |||
56 | def test_create_and_continue |
|
61 | def test_create_and_continue | |
57 | assert_difference 'Group.count' do |
|
62 | assert_difference 'Group.count' do | |
58 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' |
|
63 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' | |
59 | end |
|
64 | end | |
60 | assert_redirected_to '/groups/new' |
|
65 | assert_redirected_to '/groups/new' | |
61 | group = Group.first(:order => 'id DESC') |
|
66 | group = Group.first(:order => 'id DESC') | |
62 | assert_equal 'New group', group.name |
|
67 | assert_equal 'New group', group.name | |
63 | end |
|
68 | end | |
64 |
|
69 | |||
65 | def test_create_with_failure |
|
70 | def test_create_with_failure | |
66 | assert_no_difference 'Group.count' do |
|
71 | assert_no_difference 'Group.count' do | |
67 | post :create, :group => {:name => ''} |
|
72 | post :create, :group => {:name => ''} | |
68 | end |
|
73 | end | |
69 | assert_response :success |
|
74 | assert_response :success | |
70 | assert_template 'new' |
|
75 | assert_template 'new' | |
71 | end |
|
76 | end | |
72 |
|
77 | |||
73 | def test_edit |
|
78 | def test_edit | |
74 | get :edit, :id => 10 |
|
79 | get :edit, :id => 10 | |
75 | assert_response :success |
|
80 | assert_response :success | |
76 | assert_template 'edit' |
|
81 | assert_template 'edit' | |
77 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} |
|
82 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} | |
78 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} |
|
83 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} | |
79 | end |
|
84 | end | |
80 |
|
85 | |||
81 | def test_update |
|
86 | def test_update | |
82 | new_name = 'New name' |
|
87 | new_name = 'New name' | |
83 | put :update, :id => 10, :group => {:name => new_name} |
|
88 | put :update, :id => 10, :group => {:name => new_name} | |
84 | assert_redirected_to '/groups' |
|
89 | assert_redirected_to '/groups' | |
85 | group = Group.find(10) |
|
90 | group = Group.find(10) | |
86 | assert_equal new_name, group.name |
|
91 | assert_equal new_name, group.name | |
87 | end |
|
92 | end | |
88 |
|
93 | |||
89 | def test_update_with_failure |
|
94 | def test_update_with_failure | |
90 | put :update, :id => 10, :group => {:name => ''} |
|
95 | put :update, :id => 10, :group => {:name => ''} | |
91 | assert_response :success |
|
96 | assert_response :success | |
92 | assert_template 'edit' |
|
97 | assert_template 'edit' | |
93 | end |
|
98 | end | |
94 |
|
99 | |||
95 | def test_destroy |
|
100 | def test_destroy | |
96 | assert_difference 'Group.count', -1 do |
|
101 | assert_difference 'Group.count', -1 do | |
97 | post :destroy, :id => 10 |
|
102 | post :destroy, :id => 10 | |
98 | end |
|
103 | end | |
99 | assert_redirected_to '/groups' |
|
104 | assert_redirected_to '/groups' | |
100 | end |
|
105 | end | |
101 |
|
106 | |||
102 | def test_add_users |
|
107 | def test_add_users | |
103 | assert_difference 'Group.find(10).users.count', 2 do |
|
108 | assert_difference 'Group.find(10).users.count', 2 do | |
104 | post :add_users, :id => 10, :user_ids => ['2', '3'] |
|
109 | post :add_users, :id => 10, :user_ids => ['2', '3'] | |
105 | end |
|
110 | end | |
106 | end |
|
111 | end | |
107 |
|
112 | |||
108 | def test_xhr_add_users |
|
113 | def test_xhr_add_users | |
109 | assert_difference 'Group.find(10).users.count', 2 do |
|
114 | assert_difference 'Group.find(10).users.count', 2 do | |
110 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] |
|
115 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] | |
111 | end |
|
116 | end | |
112 | assert_select_rjs :replace_html, 'tab-content-users' |
|
117 | assert_select_rjs :replace_html, 'tab-content-users' | |
113 | end |
|
118 | end | |
114 |
|
119 | |||
115 | def test_remove_user |
|
120 | def test_remove_user | |
116 | assert_difference 'Group.find(10).users.count', -1 do |
|
121 | assert_difference 'Group.find(10).users.count', -1 do | |
117 | delete :remove_user, :id => 10, :user_id => '8' |
|
122 | delete :remove_user, :id => 10, :user_id => '8' | |
118 | end |
|
123 | end | |
119 | end |
|
124 | end | |
120 |
|
125 | |||
121 | def test_xhr_remove_user |
|
126 | def test_xhr_remove_user | |
122 | assert_difference 'Group.find(10).users.count', -1 do |
|
127 | assert_difference 'Group.find(10).users.count', -1 do | |
123 | xhr :delete, :remove_user, :id => 10, :user_id => '8' |
|
128 | xhr :delete, :remove_user, :id => 10, :user_id => '8' | |
124 | end |
|
129 | end | |
125 | assert_select_rjs :replace_html, 'tab-content-users' |
|
130 | assert_select_rjs :replace_html, 'tab-content-users' | |
126 | end |
|
131 | end | |
127 |
|
132 | |||
128 | def test_new_membership |
|
133 | def test_new_membership | |
129 | assert_difference 'Group.find(10).members.count' do |
|
134 | assert_difference 'Group.find(10).members.count' do | |
130 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
135 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | |
131 | end |
|
136 | end | |
132 | end |
|
137 | end | |
133 |
|
138 | |||
134 | def test_xhr_new_membership |
|
139 | def test_xhr_new_membership | |
135 | assert_difference 'Group.find(10).members.count' do |
|
140 | assert_difference 'Group.find(10).members.count' do | |
136 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
141 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | |
137 | end |
|
142 | end | |
138 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
143 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
139 | end |
|
144 | end | |
140 |
|
145 | |||
141 | def test_xhr_new_membership_with_failure |
|
146 | def test_xhr_new_membership_with_failure | |
142 | assert_no_difference 'Group.find(10).members.count' do |
|
147 | assert_no_difference 'Group.find(10).members.count' do | |
143 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} |
|
148 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} | |
144 | end |
|
149 | end | |
145 | assert @response.body.match(/alert/i), "Alert message not sent" |
|
150 | assert @response.body.match(/alert/i), "Alert message not sent" | |
146 | end |
|
151 | end | |
147 |
|
152 | |||
148 | def test_edit_membership |
|
153 | def test_edit_membership | |
149 | assert_no_difference 'Group.find(10).members.count' do |
|
154 | assert_no_difference 'Group.find(10).members.count' do | |
150 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} |
|
155 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} | |
151 | end |
|
156 | end | |
152 | end |
|
157 | end | |
153 |
|
158 | |||
154 | def test_destroy_membership |
|
159 | def test_destroy_membership | |
155 | assert_difference 'Group.find(10).members.count', -1 do |
|
160 | assert_difference 'Group.find(10).members.count', -1 do | |
156 | post :destroy_membership, :id => 10, :membership_id => 6 |
|
161 | post :destroy_membership, :id => 10, :membership_id => 6 | |
157 | end |
|
162 | end | |
158 | end |
|
163 | end | |
159 |
|
164 | |||
160 | def test_xhr_destroy_membership |
|
165 | def test_xhr_destroy_membership | |
161 | assert_difference 'Group.find(10).members.count', -1 do |
|
166 | assert_difference 'Group.find(10).members.count', -1 do | |
162 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 |
|
167 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 | |
163 | end |
|
168 | end | |
164 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
169 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
165 | end |
|
170 | end | |
166 |
|
171 | |||
167 | def test_autocomplete_for_user |
|
172 | def test_autocomplete_for_user | |
168 | get :autocomplete_for_user, :id => 10, :q => 'mis' |
|
173 | get :autocomplete_for_user, :id => 10, :q => 'mis' | |
169 | assert_response :success |
|
174 | assert_response :success | |
170 | users = assigns(:users) |
|
175 | users = assigns(:users) | |
171 | assert_not_nil users |
|
176 | assert_not_nil users | |
172 | assert users.any? |
|
177 | assert users.any? | |
173 | assert !users.include?(Group.find(10).users.first) |
|
178 | assert !users.include?(Group.find(10).users.first) | |
174 | end |
|
179 | end | |
175 | end |
|
180 | end |
General Comments 0
You need to be logged in to leave comments.
Login now