Chris@0
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2009 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@0
|
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@0
|
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 require 'groups_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class GroupsController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class GroupsControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :members, :member_roles, :groups_users
|
Chris@0
|
26
|
Chris@0
|
27 def setup
|
Chris@0
|
28 @controller = GroupsController.new
|
Chris@0
|
29 @request = ActionController::TestRequest.new
|
Chris@0
|
30 @response = ActionController::TestResponse.new
|
Chris@0
|
31 User.current = nil
|
Chris@0
|
32 @request.session[:user_id] = 1
|
Chris@0
|
33 end
|
Chris@0
|
34
|
Chris@0
|
35 def test_index
|
Chris@0
|
36 get :index
|
Chris@0
|
37 assert_response :success
|
Chris@0
|
38 assert_template 'index'
|
Chris@0
|
39 end
|
Chris@0
|
40
|
Chris@0
|
41 def test_show
|
Chris@0
|
42 get :show, :id => 10
|
Chris@0
|
43 assert_response :success
|
Chris@0
|
44 assert_template 'show'
|
Chris@0
|
45 end
|
Chris@0
|
46
|
Chris@0
|
47 def test_new
|
Chris@0
|
48 get :new
|
Chris@0
|
49 assert_response :success
|
Chris@0
|
50 assert_template 'new'
|
Chris@0
|
51 end
|
Chris@0
|
52
|
Chris@0
|
53 def test_create
|
Chris@0
|
54 assert_difference 'Group.count' do
|
Chris@0
|
55 post :create, :group => {:lastname => 'New group'}
|
Chris@0
|
56 end
|
chris@37
|
57 assert_redirected_to '/groups'
|
Chris@0
|
58 end
|
Chris@0
|
59
|
Chris@0
|
60 def test_edit
|
Chris@0
|
61 get :edit, :id => 10
|
Chris@0
|
62 assert_response :success
|
Chris@0
|
63 assert_template 'edit'
|
Chris@0
|
64 end
|
Chris@0
|
65
|
Chris@0
|
66 def test_update
|
Chris@0
|
67 post :update, :id => 10
|
chris@37
|
68 assert_redirected_to '/groups'
|
Chris@0
|
69 end
|
Chris@0
|
70
|
Chris@0
|
71 def test_destroy
|
Chris@0
|
72 assert_difference 'Group.count', -1 do
|
Chris@0
|
73 post :destroy, :id => 10
|
Chris@0
|
74 end
|
chris@37
|
75 assert_redirected_to '/groups'
|
Chris@0
|
76 end
|
Chris@0
|
77
|
Chris@0
|
78 def test_add_users
|
Chris@0
|
79 assert_difference 'Group.find(10).users.count', 2 do
|
Chris@0
|
80 post :add_users, :id => 10, :user_ids => ['2', '3']
|
Chris@0
|
81 end
|
Chris@0
|
82 end
|
Chris@0
|
83
|
Chris@0
|
84 def test_remove_user
|
Chris@0
|
85 assert_difference 'Group.find(10).users.count', -1 do
|
Chris@0
|
86 post :remove_user, :id => 10, :user_id => '8'
|
Chris@0
|
87 end
|
Chris@0
|
88 end
|
Chris@0
|
89
|
Chris@0
|
90 def test_new_membership
|
Chris@0
|
91 assert_difference 'Group.find(10).members.count' do
|
Chris@0
|
92 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
|
Chris@0
|
93 end
|
Chris@0
|
94 end
|
Chris@0
|
95
|
Chris@0
|
96 def test_edit_membership
|
Chris@0
|
97 assert_no_difference 'Group.find(10).members.count' do
|
Chris@0
|
98 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
|
Chris@0
|
99 end
|
Chris@0
|
100 end
|
Chris@0
|
101
|
Chris@0
|
102 def test_destroy_membership
|
Chris@0
|
103 assert_difference 'Group.find(10).members.count', -1 do
|
Chris@0
|
104 post :destroy_membership, :id => 10, :membership_id => 6
|
Chris@0
|
105 end
|
Chris@0
|
106 end
|
Chris@441
|
107
|
Chris@441
|
108 def test_autocomplete_for_user
|
Chris@441
|
109 get :autocomplete_for_user, :id => 10, :q => 'mis'
|
Chris@441
|
110 assert_response :success
|
Chris@441
|
111 users = assigns(:users)
|
Chris@441
|
112 assert_not_nil users
|
Chris@441
|
113 assert users.any?
|
Chris@441
|
114 assert !users.include?(Group.find(10).users.first)
|
Chris@441
|
115 end
|
Chris@0
|
116 end
|