You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

groups_controller_test.rb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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. require File.expand_path('../../test_helper', __FILE__)
  18. class GroupsControllerTest < ActionController::TestCase
  19. fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
  20. def setup
  21. @request.session[:user_id] = 1
  22. end
  23. def test_index
  24. get :index
  25. assert_response :success
  26. assert_template 'index'
  27. end
  28. def test_index_should_show_user_count
  29. get :index
  30. assert_response :success
  31. assert_select 'tr#group-11 td.user_count', :text => '1'
  32. end
  33. def test_show
  34. get :show, :id => 10
  35. assert_response :success
  36. assert_template 'show'
  37. end
  38. def test_show_invalid_should_return_404
  39. get :show, :id => 99
  40. assert_response 404
  41. end
  42. def test_new
  43. get :new
  44. assert_response :success
  45. assert_template 'new'
  46. assert_select 'input[name=?]', 'group[name]'
  47. end
  48. def test_create
  49. assert_difference 'Group.count' do
  50. post :create, :group => {:name => 'New group'}
  51. end
  52. assert_redirected_to '/groups'
  53. group = Group.order('id DESC').first
  54. assert_equal 'New group', group.name
  55. assert_equal [], group.users
  56. end
  57. def test_create_and_continue
  58. assert_difference 'Group.count' do
  59. post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
  60. end
  61. assert_redirected_to '/groups/new'
  62. group = Group.order('id DESC').first
  63. assert_equal 'New group', group.name
  64. end
  65. def test_create_with_failure
  66. assert_no_difference 'Group.count' do
  67. post :create, :group => {:name => ''}
  68. end
  69. assert_response :success
  70. assert_template 'new'
  71. end
  72. def test_edit
  73. get :edit, :id => 10
  74. assert_response :success
  75. assert_template 'edit'
  76. assert_select 'div#tab-content-users'
  77. assert_select 'div#tab-content-memberships' do
  78. assert_select 'a', :text => 'Private child of eCookbook'
  79. end
  80. end
  81. def test_update
  82. new_name = 'New name'
  83. put :update, :id => 10, :group => {:name => new_name}
  84. assert_redirected_to '/groups'
  85. group = Group.find(10)
  86. assert_equal new_name, group.name
  87. end
  88. def test_update_with_failure
  89. put :update, :id => 10, :group => {:name => ''}
  90. assert_response :success
  91. assert_template 'edit'
  92. end
  93. def test_destroy
  94. assert_difference 'Group.count', -1 do
  95. post :destroy, :id => 10
  96. end
  97. assert_redirected_to '/groups'
  98. end
  99. def test_new_users
  100. get :new_users, :id => 10
  101. assert_response :success
  102. assert_template 'new_users'
  103. end
  104. def test_xhr_new_users
  105. xhr :get, :new_users, :id => 10
  106. assert_response :success
  107. assert_equal 'text/javascript', response.content_type
  108. end
  109. def test_add_users
  110. assert_difference 'Group.find(10).users.count', 2 do
  111. post :add_users, :id => 10, :user_ids => ['2', '3']
  112. end
  113. end
  114. def test_xhr_add_users
  115. assert_difference 'Group.find(10).users.count', 2 do
  116. xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
  117. assert_response :success
  118. assert_template 'add_users'
  119. assert_equal 'text/javascript', response.content_type
  120. end
  121. assert_match /John Smith/, response.body
  122. end
  123. def test_remove_user
  124. assert_difference 'Group.find(10).users.count', -1 do
  125. delete :remove_user, :id => 10, :user_id => '8'
  126. end
  127. end
  128. def test_xhr_remove_user
  129. assert_difference 'Group.find(10).users.count', -1 do
  130. xhr :delete, :remove_user, :id => 10, :user_id => '8'
  131. assert_response :success
  132. assert_template 'remove_user'
  133. assert_equal 'text/javascript', response.content_type
  134. end
  135. end
  136. def test_autocomplete_for_user
  137. xhr :get, :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
  138. assert_response :success
  139. assert_include 'John Smith', response.body
  140. end
  141. end