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