Mercurial > hg > soundsoftware-site
comparison test/functional/groups_controller_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2009 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 require 'groups_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class GroupsController; def rescue_action(e) raise e end; end | |
23 | 19 |
24 class GroupsControllerTest < ActionController::TestCase | 20 class GroupsControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :members, :member_roles, :groups_users | 21 fixtures :projects, :users, :members, :member_roles, :groups_users |
26 | 22 |
27 def setup | 23 def setup |
28 @controller = GroupsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | |
32 @request.session[:user_id] = 1 | 24 @request.session[:user_id] = 1 |
33 end | 25 end |
34 | 26 |
35 def test_index | 27 def test_index |
36 get :index | 28 get :index |
37 assert_response :success | 29 assert_response :success |
38 assert_template 'index' | 30 assert_template 'index' |
39 end | 31 end |
40 | 32 |
41 def test_show | 33 def test_show |
42 get :show, :id => 10 | 34 get :show, :id => 10 |
43 assert_response :success | 35 assert_response :success |
44 assert_template 'show' | 36 assert_template 'show' |
45 end | 37 end |
46 | 38 |
47 def test_new | 39 def test_new |
48 get :new | 40 get :new |
49 assert_response :success | 41 assert_response :success |
50 assert_template 'new' | 42 assert_template 'new' |
51 end | 43 end |
52 | 44 |
53 def test_create | 45 def test_create |
54 assert_difference 'Group.count' do | 46 assert_difference 'Group.count' do |
55 post :create, :group => {:lastname => 'New group'} | 47 post :create, :group => {:lastname => 'New group'} |
56 end | 48 end |
57 assert_redirected_to '/groups' | 49 assert_redirected_to '/groups' |
50 group = Group.first(:order => 'id DESC') | |
51 assert_equal 'New group', group.name | |
52 assert_equal [], group.users | |
58 end | 53 end |
59 | 54 |
55 def test_create_and_continue | |
56 assert_difference 'Group.count' do | |
57 post :create, :group => {:lastname => 'New group'}, :continue => 'Create and continue' | |
58 end | |
59 assert_redirected_to '/groups/new' | |
60 group = Group.first(:order => 'id DESC') | |
61 assert_equal 'New group', group.name | |
62 end | |
63 | |
64 def test_create_with_failure | |
65 assert_no_difference 'Group.count' do | |
66 post :create, :group => {:lastname => ''} | |
67 end | |
68 assert_response :success | |
69 assert_template 'new' | |
70 end | |
71 | |
60 def test_edit | 72 def test_edit |
61 get :edit, :id => 10 | 73 get :edit, :id => 10 |
62 assert_response :success | 74 assert_response :success |
63 assert_template 'edit' | 75 assert_template 'edit' |
76 assert_tag 'div', :attributes => {:id => 'tab-content-users'} | |
77 assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} | |
64 end | 78 end |
65 | 79 |
66 def test_update | 80 def test_update |
67 post :update, :id => 10 | 81 new_name = 'New name' |
82 put :update, :id => 10, :group => {:lastname => new_name} | |
68 assert_redirected_to '/groups' | 83 assert_redirected_to '/groups' |
84 group = Group.find(10) | |
85 assert_equal new_name, group.name | |
69 end | 86 end |
70 | 87 |
88 def test_update_with_failure | |
89 put :update, :id => 10, :group => {:lastname => ''} | |
90 assert_response :success | |
91 assert_template 'edit' | |
92 end | |
93 | |
71 def test_destroy | 94 def test_destroy |
72 assert_difference 'Group.count', -1 do | 95 assert_difference 'Group.count', -1 do |
73 post :destroy, :id => 10 | 96 post :destroy, :id => 10 |
74 end | 97 end |
75 assert_redirected_to '/groups' | 98 assert_redirected_to '/groups' |
76 end | 99 end |
77 | 100 |
78 def test_add_users | 101 def test_add_users |
79 assert_difference 'Group.find(10).users.count', 2 do | 102 assert_difference 'Group.find(10).users.count', 2 do |
80 post :add_users, :id => 10, :user_ids => ['2', '3'] | 103 post :add_users, :id => 10, :user_ids => ['2', '3'] |
81 end | 104 end |
82 end | 105 end |
83 | 106 |
107 def test_xhr_add_users | |
108 assert_difference 'Group.find(10).users.count', 2 do | |
109 xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] | |
110 end | |
111 assert_select_rjs :replace_html, 'tab-content-users' | |
112 end | |
113 | |
84 def test_remove_user | 114 def test_remove_user |
85 assert_difference 'Group.find(10).users.count', -1 do | 115 assert_difference 'Group.find(10).users.count', -1 do |
86 post :remove_user, :id => 10, :user_id => '8' | 116 delete :remove_user, :id => 10, :user_id => '8' |
87 end | 117 end |
88 end | 118 end |
89 | 119 |
120 def test_xhr_remove_user | |
121 assert_difference 'Group.find(10).users.count', -1 do | |
122 xhr :delete, :remove_user, :id => 10, :user_id => '8' | |
123 end | |
124 assert_select_rjs :replace_html, 'tab-content-users' | |
125 end | |
126 | |
90 def test_new_membership | 127 def test_new_membership |
91 assert_difference 'Group.find(10).members.count' do | 128 assert_difference 'Group.find(10).members.count' do |
92 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | 129 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
93 end | 130 end |
94 end | 131 end |
95 | 132 |
133 def test_xhr_new_membership | |
134 assert_difference 'Group.find(10).members.count' do | |
135 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} | |
136 end | |
137 assert_select_rjs :replace_html, 'tab-content-memberships' | |
138 end | |
139 | |
140 def test_xhr_new_membership_with_failure | |
141 assert_no_difference 'Group.find(10).members.count' do | |
142 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} | |
143 end | |
144 assert @response.body.match(/alert/i), "Alert message not sent" | |
145 end | |
146 | |
96 def test_edit_membership | 147 def test_edit_membership |
97 assert_no_difference 'Group.find(10).members.count' do | 148 assert_no_difference 'Group.find(10).members.count' do |
98 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} | 149 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} |
99 end | 150 end |
100 end | 151 end |
101 | 152 |
102 def test_destroy_membership | 153 def test_destroy_membership |
103 assert_difference 'Group.find(10).members.count', -1 do | 154 assert_difference 'Group.find(10).members.count', -1 do |
104 post :destroy_membership, :id => 10, :membership_id => 6 | 155 post :destroy_membership, :id => 10, :membership_id => 6 |
105 end | 156 end |
106 end | 157 end |
107 | 158 |
159 def test_xhr_destroy_membership | |
160 assert_difference 'Group.find(10).members.count', -1 do | |
161 xhr :post, :destroy_membership, :id => 10, :membership_id => 6 | |
162 end | |
163 assert_select_rjs :replace_html, 'tab-content-memberships' | |
164 end | |
165 | |
108 def test_autocomplete_for_user | 166 def test_autocomplete_for_user |
109 get :autocomplete_for_user, :id => 10, :q => 'mis' | 167 get :autocomplete_for_user, :id => 10, :q => 'mis' |
110 assert_response :success | 168 assert_response :success |
111 users = assigns(:users) | 169 users = assigns(:users) |
112 assert_not_nil users | 170 assert_not_nil users |