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.

members_controller_test.rb 8.5KB

Converted routing and urls to follow the Rails REST convention. Patch supplied by commits from Gerrit Kaiser on Github. Existing routes will still work (backwards compatible) but any new urls will be generated using the new routing rules. Changes listed below: * made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id * prettier URL for project roadmap * more nice project URLs * use GET for filtering form * prettified URLs used on issues tab * custom route for activity atom feeds * prettier repository urls * fixed broken route definition * fixed failing tests for issuecontroller that were hardcoding the url string * more RESTful routes for boards and messages * RESTful routes for wiki pages * RESTful routes for documents * moved old routes that are retained for compatibility to the bottom and grouped them together * added RESTful URIs for issues * RESTfulness for the news section * fixed route order * changed hardcoded URLs in tests * fixed badly written tests * fixed forgotten parameter in routes * changed hardcoded URLS to new scheme * changed project add url to the standard POST to collection * create new issue by POSTing to collection * changed hardcoded URLs in integrations tests * made project add form work again * restful routes for project deletion * prettier routes for project (un)archival * made routes table more readable * fixed note quoting * user routing * fixed bug * always sort by GET * Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled. * prettified URLs used on issues tab * urls for time log * fixed reply routing * eliminate revision query paremeter for diff and entry actions * fixed test failures with hard-coded urls * ensure ajax links always use get * refactored ajax link generation into separate method #1901 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
15 years ago
Converted routing and urls to follow the Rails REST convention. Patch supplied by commits from Gerrit Kaiser on Github. Existing routes will still work (backwards compatible) but any new urls will be generated using the new routing rules. Changes listed below: * made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id * prettier URL for project roadmap * more nice project URLs * use GET for filtering form * prettified URLs used on issues tab * custom route for activity atom feeds * prettier repository urls * fixed broken route definition * fixed failing tests for issuecontroller that were hardcoding the url string * more RESTful routes for boards and messages * RESTful routes for wiki pages * RESTful routes for documents * moved old routes that are retained for compatibility to the bottom and grouped them together * added RESTful URIs for issues * RESTfulness for the news section * fixed route order * changed hardcoded URLs in tests * fixed badly written tests * fixed forgotten parameter in routes * changed hardcoded URLS to new scheme * changed project add url to the standard POST to collection * create new issue by POSTing to collection * changed hardcoded URLs in integrations tests * made project add form work again * restful routes for project deletion * prettier routes for project (un)archival * made routes table more readable * fixed note quoting * user routing * fixed bug * always sort by GET * Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled. * prettified URLs used on issues tab * urls for time log * fixed reply routing * eliminate revision query paremeter for diff and entry actions * fixed test failures with hard-coded urls * ensure ajax links always use get * refactored ajax link generation into separate method #1901 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
15 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 MembersControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :members, :member_roles, :roles, :users
  20. def setup
  21. User.current = nil
  22. @request.session[:user_id] = 2
  23. end
  24. def test_new
  25. get :new, :params => {
  26. :project_id => 1
  27. }
  28. assert_response :success
  29. end
  30. def test_new_should_propose_managed_roles_only
  31. role = Role.find(1)
  32. role.update! :all_roles_managed => false
  33. role.managed_roles = Role.where(:id => [2, 3]).to_a
  34. get :new, :params => {
  35. :project_id => 1
  36. }
  37. assert_response :success
  38. assert_select 'div.roles-selection' do
  39. assert_select 'label', :text => 'Manager', :count => 0
  40. assert_select 'label', :text => 'Developer'
  41. assert_select 'label', :text => 'Reporter'
  42. end
  43. end
  44. def test_xhr_new
  45. get :new, :params => {
  46. :project_id => 1
  47. },
  48. :xhr => true
  49. assert_response :success
  50. assert_equal 'text/javascript', response.content_type
  51. end
  52. def test_create
  53. assert_difference 'Member.count' do
  54. post :create, :params => {
  55. :project_id => 1,
  56. :membership => {
  57. :role_ids => [1],
  58. :user_id => 7
  59. }
  60. }
  61. end
  62. assert_redirected_to '/projects/ecookbook/settings/members'
  63. assert User.find(7).member_of?(Project.find(1))
  64. end
  65. def test_create_multiple
  66. assert_difference 'Member.count', 3 do
  67. post :create, :params => {
  68. :project_id => 1,
  69. :membership => {
  70. :role_ids => [1],
  71. :user_ids => [7, 8, 9]
  72. }
  73. }
  74. end
  75. assert_redirected_to '/projects/ecookbook/settings/members'
  76. assert User.find(7).member_of?(Project.find(1))
  77. end
  78. def test_create_should_ignore_unmanaged_roles
  79. role = Role.find(1)
  80. role.update! :all_roles_managed => false
  81. role.managed_roles = Role.where(:id => [2, 3]).to_a
  82. assert_difference 'Member.count' do
  83. post :create, :params => {
  84. :project_id => 1,
  85. :membership => {
  86. :role_ids => [1, 2],
  87. :user_id => 7
  88. }
  89. }
  90. end
  91. member = Member.order(:id => :desc).first
  92. assert_equal [2], member.role_ids
  93. end
  94. def test_create_should_be_allowed_for_admin_without_role
  95. User.find(1).members.delete_all
  96. @request.session[:user_id] = 1
  97. assert_difference 'Member.count' do
  98. post :create, :params => {
  99. :project_id => 1,
  100. :membership => {
  101. :role_ids => [1, 2],
  102. :user_id => 7
  103. }
  104. }
  105. end
  106. member = Member.order(:id => :desc).first
  107. assert_equal [1, 2], member.role_ids
  108. end
  109. def test_xhr_create
  110. assert_difference 'Member.count', 3 do
  111. post :create, :params => {
  112. :project_id => 1,
  113. :membership => {
  114. :role_ids => [1],
  115. :user_ids => [7, 8, 9]
  116. }
  117. },
  118. :xhr => true
  119. assert_response :success
  120. assert_equal 'text/javascript', response.content_type
  121. end
  122. assert User.find(7).member_of?(Project.find(1))
  123. assert User.find(8).member_of?(Project.find(1))
  124. assert User.find(9).member_of?(Project.find(1))
  125. assert_include 'tab-content-members', response.body
  126. end
  127. def test_xhr_create_with_failure
  128. assert_no_difference 'Member.count' do
  129. post :create, :params => {
  130. :project_id => 1,
  131. :membership => {
  132. :role_ids => [],
  133. :user_ids => [7, 8, 9]
  134. }
  135. },
  136. :xhr => true
  137. assert_response :success
  138. assert_equal 'text/javascript', response.content_type
  139. end
  140. assert_match /alert/, response.body, "Alert message not sent"
  141. end
  142. def test_edit
  143. get :edit, :params => {
  144. :id => 2
  145. }
  146. assert_response :success
  147. assert_select 'input[name=?][value=?][checked=checked]', 'membership[role_ids][]', '2'
  148. end
  149. def test_xhr_edit
  150. get :edit, :params => {
  151. :id => 2
  152. },
  153. :xhr => true
  154. assert_response :success
  155. end
  156. def test_update
  157. assert_no_difference 'Member.count' do
  158. put :update, :params => {
  159. :id => 2,
  160. :membership => {
  161. :role_ids => [1],
  162. :user_id => 3
  163. }
  164. }
  165. end
  166. assert_redirected_to '/projects/ecookbook/settings/members'
  167. end
  168. def test_update_locked_member_should_be_allowed
  169. User.find(3).lock!
  170. put :update, :params => {
  171. :id => 2,
  172. :membership => {
  173. :role_ids => [1]
  174. }
  175. }
  176. assert_response 302
  177. member = Member.find(2)
  178. assert member.user.locked?
  179. assert_equal [1], member.role_ids
  180. end
  181. def test_update_should_not_add_unmanaged_roles
  182. role = Role.find(1)
  183. role.update! :all_roles_managed => false
  184. role.managed_roles = Role.where(:id => [2, 3]).to_a
  185. member = Member.create!(:user => User.find(9), :role_ids => [3], :project_id => 1)
  186. put :update, :params => {
  187. :id => member.id,
  188. :membership => {
  189. :role_ids => [1, 2, 3]
  190. }
  191. }
  192. assert_equal [2, 3], member.reload.role_ids.sort
  193. end
  194. def test_update_should_not_remove_unmanaged_roles
  195. role = Role.find(1)
  196. role.update! :all_roles_managed => false
  197. role.managed_roles = Role.where(:id => [2, 3]).to_a
  198. member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1)
  199. put :update, :params => {
  200. :id => member.id,
  201. :membership => {
  202. :role_ids => [2]
  203. }
  204. }
  205. assert_equal [1, 2], member.reload.role_ids.sort
  206. end
  207. def test_xhr_update
  208. assert_no_difference 'Member.count' do
  209. put :update, :params => {
  210. :id => 2,
  211. :membership => {
  212. :role_ids => [1],
  213. :user_id => 3
  214. }
  215. },
  216. :xhr => true
  217. assert_response :success
  218. assert_equal 'text/javascript', response.content_type
  219. end
  220. member = Member.find(2)
  221. assert_equal [1], member.role_ids
  222. assert_equal 3, member.user_id
  223. assert_include 'tab-content-members', response.body
  224. end
  225. def test_destroy
  226. assert_difference 'Member.count', -1 do
  227. delete :destroy, :params => {
  228. :id => 2
  229. }
  230. end
  231. assert_redirected_to '/projects/ecookbook/settings/members'
  232. assert !User.find(3).member_of?(Project.find(1))
  233. end
  234. def test_destroy_locked_member_should_be_allowed
  235. assert User.find(3).lock!
  236. assert_difference 'Member.count', -1 do
  237. delete :destroy, :params => {
  238. :id => 2
  239. }
  240. end
  241. end
  242. def test_destroy_should_fail_with_unmanaged_roles
  243. role = Role.find(1)
  244. role.update! :all_roles_managed => false
  245. role.managed_roles = Role.where(:id => [2, 3]).to_a
  246. member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1)
  247. assert_no_difference 'Member.count' do
  248. delete :destroy, :params => {
  249. :id => member.id
  250. }
  251. end
  252. end
  253. def test_destroy_should_succeed_with_managed_roles_only
  254. role = Role.find(1)
  255. role.update! :all_roles_managed => false
  256. role.managed_roles = Role.where(:id => [2, 3]).to_a
  257. member = Member.create!(:user => User.find(9), :role_ids => [3], :project_id => 1)
  258. assert_difference 'Member.count', -1 do
  259. delete :destroy, :params => {
  260. :id => member.id
  261. }
  262. end
  263. end
  264. def test_xhr_destroy
  265. assert_difference 'Member.count', -1 do
  266. delete :destroy, :params => {
  267. :id => 2
  268. },
  269. :xhr => true
  270. assert_response :success
  271. assert_equal 'text/javascript', response.content_type
  272. end
  273. assert_nil Member.find_by_id(2)
  274. assert_include 'tab-content-members', response.body
  275. end
  276. def test_autocomplete
  277. get :autocomplete, :params => {
  278. :project_id => 1,
  279. :q => 'mis',
  280. :format => 'js'
  281. },
  282. :xhr => true
  283. assert_response :success
  284. assert_include 'User Misc', response.body
  285. end
  286. end