To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / ae / ae7604689327a3d413e43c105b3415b7c3844f37.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (5.09 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 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 |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
|
| 20 |
class GroupsControllerTest < ActionController::TestCase |
| 21 |
fixtures :projects, :users, :members, :member_roles, :groups_users |
| 22 |
|
| 23 |
def setup |
| 24 |
@request.session[:user_id] = 1 |
| 25 |
end |
| 26 |
|
| 27 |
def test_index |
| 28 |
get :index |
| 29 |
assert_response :success |
| 30 |
assert_template 'index' |
| 31 |
end |
| 32 |
|
| 33 |
def test_show |
| 34 |
get :show, :id => 10 |
| 35 |
assert_response :success |
| 36 |
assert_template 'show' |
| 37 |
end |
| 38 |
|
| 39 |
def test_new |
| 40 |
get :new |
| 41 |
assert_response :success |
| 42 |
assert_template 'new' |
| 43 |
end |
| 44 |
|
| 45 |
def test_create |
| 46 |
assert_difference 'Group.count' do |
| 47 |
post :create, :group => {:lastname => 'New group'}
|
| 48 |
end |
| 49 |
assert_redirected_to '/groups' |
| 50 |
group = Group.first(:order => 'id DESC') |
| 51 |
assert_equal 'New group', group.name |
| 52 |
assert_equal [], group.users |
| 53 |
end |
| 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 |
|
| 72 |
def test_edit |
| 73 |
get :edit, :id => 10 |
| 74 |
assert_response :success |
| 75 |
assert_template 'edit' |
| 76 |
assert_tag 'div', :attributes => {:id => 'tab-content-users'}
|
| 77 |
assert_tag 'div', :attributes => {:id => 'tab-content-memberships'}
|
| 78 |
end |
| 79 |
|
| 80 |
def test_update |
| 81 |
new_name = 'New name' |
| 82 |
put :update, :id => 10, :group => {:lastname => new_name}
|
| 83 |
assert_redirected_to '/groups' |
| 84 |
group = Group.find(10) |
| 85 |
assert_equal new_name, group.name |
| 86 |
end |
| 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 |
|
| 94 |
def test_destroy |
| 95 |
assert_difference 'Group.count', -1 do |
| 96 |
post :destroy, :id => 10 |
| 97 |
end |
| 98 |
assert_redirected_to '/groups' |
| 99 |
end |
| 100 |
|
| 101 |
def test_add_users |
| 102 |
assert_difference 'Group.find(10).users.count', 2 do |
| 103 |
post :add_users, :id => 10, :user_ids => ['2', '3'] |
| 104 |
end |
| 105 |
end |
| 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 |
|
| 114 |
def test_remove_user |
| 115 |
assert_difference 'Group.find(10).users.count', -1 do |
| 116 |
delete :remove_user, :id => 10, :user_id => '8' |
| 117 |
end |
| 118 |
end |
| 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 |
|
| 127 |
def test_new_membership |
| 128 |
assert_difference 'Group.find(10).members.count' do |
| 129 |
post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
|
| 130 |
end |
| 131 |
end |
| 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 |
|
| 147 |
def test_edit_membership |
| 148 |
assert_no_difference 'Group.find(10).members.count' do |
| 149 |
post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
|
| 150 |
end |
| 151 |
end |
| 152 |
|
| 153 |
def test_destroy_membership |
| 154 |
assert_difference 'Group.find(10).members.count', -1 do |
| 155 |
post :destroy_membership, :id => 10, :membership_id => 6 |
| 156 |
end |
| 157 |
end |
| 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 |
|
| 166 |
def test_autocomplete_for_user |
| 167 |
get :autocomplete_for_user, :id => 10, :q => 'mis' |
| 168 |
assert_response :success |
| 169 |
users = assigns(:users) |
| 170 |
assert_not_nil users |
| 171 |
assert users.any? |
| 172 |
assert !users.include?(Group.find(10).users.first) |
| 173 |
end |
| 174 |
end |