@@ -1,175 +1,180 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class GroupsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :groups_users |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @request.session[:user_id] = 1 |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_index |
|
28 | 28 | get :index |
|
29 | 29 | assert_response :success |
|
30 | 30 | assert_template 'index' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_show |
|
34 | 34 | get :show, :id => 10 |
|
35 | 35 | assert_response :success |
|
36 | 36 | assert_template 'show' |
|
37 | 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 | 44 | def test_new |
|
40 | 45 | get :new |
|
41 | 46 | assert_response :success |
|
42 | 47 | assert_template 'new' |
|
43 | 48 | assert_select 'input[name=?]', 'group[name]' |
|
44 | 49 | end |
|
45 | 50 | |
|
46 | 51 | def test_create |
|
47 | 52 | assert_difference 'Group.count' do |
|
48 | 53 | post :create, :group => {:name => 'New group'} |
|
49 | 54 | end |
|
50 | 55 | assert_redirected_to '/groups' |
|
51 | 56 | group = Group.first(:order => 'id DESC') |
|
52 | 57 | assert_equal 'New group', group.name |
|
53 | 58 | assert_equal [], group.users |
|
54 | 59 | end |
|
55 | 60 | |
|
56 | 61 | def test_create_and_continue |
|
57 | 62 | assert_difference 'Group.count' do |
|
58 | 63 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' |
|
59 | 64 | end |
|
60 | 65 | assert_redirected_to '/groups/new' |
|
61 | 66 | group = Group.first(:order => 'id DESC') |
|
62 | 67 | assert_equal 'New group', group.name |
|
63 | 68 | end |
|
64 | 69 | |
|
65 | 70 | def test_create_with_failure |
|
66 | 71 | assert_no_difference 'Group.count' do |
|
67 | 72 | post :create, :group => {:name => ''} |
|
68 | 73 | end |
|
69 | 74 | assert_response :success |
|
70 | 75 | assert_template 'new' |
|
71 | 76 | end |
|
72 | 77 | |
|
73 | 78 | def test_edit |
|
74 | 79 | get :edit, :id => 10 |
|
75 | 80 | assert_response :success |
|
76 | 81 | assert_template 'edit' |
|
77 | 82 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} |
|
78 | 83 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} |
|
79 | 84 | end |
|
80 | 85 | |
|
81 | 86 | def test_update |
|
82 | 87 | new_name = 'New name' |
|
83 | 88 | put :update, :id => 10, :group => {:name => new_name} |
|
84 | 89 | assert_redirected_to '/groups' |
|
85 | 90 | group = Group.find(10) |
|
86 | 91 | assert_equal new_name, group.name |
|
87 | 92 | end |
|
88 | 93 | |
|
89 | 94 | def test_update_with_failure |
|
90 | 95 | put :update, :id => 10, :group => {:name => ''} |
|
91 | 96 | assert_response :success |
|
92 | 97 | assert_template 'edit' |
|
93 | 98 | end |
|
94 | 99 | |
|
95 | 100 | def test_destroy |
|
96 | 101 | assert_difference 'Group.count', -1 do |
|
97 | 102 | post :destroy, :id => 10 |
|
98 | 103 | end |
|
99 | 104 | assert_redirected_to '/groups' |
|
100 | 105 | end |
|
101 | 106 | |
|
102 | 107 | def test_add_users |
|
103 | 108 | assert_difference 'Group.find(10).users.count', 2 do |
|
104 | 109 | post :add_users, :id => 10, :user_ids => ['2', '3'] |
|
105 | 110 | end |
|
106 | 111 | end |
|
107 | 112 | |
|
108 | 113 | def test_xhr_add_users |
|
109 | 114 | assert_difference 'Group.find(10).users.count', 2 do |
|
110 | 115 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] |
|
111 | 116 | end |
|
112 | 117 | assert_select_rjs :replace_html, 'tab-content-users' |
|
113 | 118 | end |
|
114 | 119 | |
|
115 | 120 | def test_remove_user |
|
116 | 121 | assert_difference 'Group.find(10).users.count', -1 do |
|
117 | 122 | delete :remove_user, :id => 10, :user_id => '8' |
|
118 | 123 | end |
|
119 | 124 | end |
|
120 | 125 | |
|
121 | 126 | def test_xhr_remove_user |
|
122 | 127 | assert_difference 'Group.find(10).users.count', -1 do |
|
123 | 128 | xhr :delete, :remove_user, :id => 10, :user_id => '8' |
|
124 | 129 | end |
|
125 | 130 | assert_select_rjs :replace_html, 'tab-content-users' |
|
126 | 131 | end |
|
127 | 132 | |
|
128 | 133 | def test_new_membership |
|
129 | 134 | assert_difference 'Group.find(10).members.count' do |
|
130 | 135 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
131 | 136 | end |
|
132 | 137 | end |
|
133 | 138 | |
|
134 | 139 | def test_xhr_new_membership |
|
135 | 140 | assert_difference 'Group.find(10).members.count' do |
|
136 | 141 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
137 | 142 | end |
|
138 | 143 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
139 | 144 | end |
|
140 | 145 | |
|
141 | 146 | def test_xhr_new_membership_with_failure |
|
142 | 147 | assert_no_difference 'Group.find(10).members.count' do |
|
143 | 148 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} |
|
144 | 149 | end |
|
145 | 150 | assert @response.body.match(/alert/i), "Alert message not sent" |
|
146 | 151 | end |
|
147 | 152 | |
|
148 | 153 | def test_edit_membership |
|
149 | 154 | assert_no_difference 'Group.find(10).members.count' do |
|
150 | 155 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} |
|
151 | 156 | end |
|
152 | 157 | end |
|
153 | 158 | |
|
154 | 159 | def test_destroy_membership |
|
155 | 160 | assert_difference 'Group.find(10).members.count', -1 do |
|
156 | 161 | post :destroy_membership, :id => 10, :membership_id => 6 |
|
157 | 162 | end |
|
158 | 163 | end |
|
159 | 164 | |
|
160 | 165 | def test_xhr_destroy_membership |
|
161 | 166 | assert_difference 'Group.find(10).members.count', -1 do |
|
162 | 167 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 |
|
163 | 168 | end |
|
164 | 169 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
165 | 170 | end |
|
166 | 171 | |
|
167 | 172 | def test_autocomplete_for_user |
|
168 | 173 | get :autocomplete_for_user, :id => 10, :q => 'mis' |
|
169 | 174 | assert_response :success |
|
170 | 175 | users = assigns(:users) |
|
171 | 176 | assert_not_nil users |
|
172 | 177 | assert users.any? |
|
173 | 178 | assert !users.include?(Group.find(10).users.first) |
|
174 | 179 | end |
|
175 | 180 | end |
General Comments 0
You need to be logged in to leave comments.
Login now