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.6KB

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 vuotta sitten
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 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class MembersControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :members, :member_roles, :roles, :users
  21. def setup
  22. User.current = nil
  23. @request.session[:user_id] = 2
  24. end
  25. def test_new
  26. get(:new, :params => {:project_id => 1})
  27. assert_response :success
  28. end
  29. def test_new_should_propose_managed_roles_only
  30. role = Role.find(1)
  31. role.update! :all_roles_managed => false
  32. role.managed_roles = Role.where(:id => [2, 3]).to_a
  33. get(:new, :params => {:project_id => 1})
  34. assert_response :success
  35. assert_select 'div.roles-selection' do
  36. assert_select 'label', :text => 'Manager', :count => 0
  37. assert_select 'label', :text => 'Developer'
  38. assert_select 'label', :text => 'Reporter'
  39. end
  40. end
  41. def test_xhr_new
  42. get(:new, :params => {:project_id => 1}, :xhr => true)
  43. assert_response :success
  44. assert_equal 'text/javascript', response.media_type
  45. end
  46. def test_create
  47. assert_difference 'Member.count' do
  48. post(
  49. :create,
  50. :params => {
  51. :project_id => 1,
  52. :membership => {
  53. :role_ids => [1],
  54. :user_id => 7
  55. }
  56. }
  57. )
  58. end
  59. assert_redirected_to '/projects/ecookbook/settings/members'
  60. assert User.find(7).member_of?(Project.find(1))
  61. end
  62. def test_create_multiple
  63. assert_difference 'Member.count', 3 do
  64. post(
  65. :create,
  66. :params => {
  67. :project_id => 1,
  68. :membership => {
  69. :role_ids => [1],
  70. :user_ids => [7, 8, 9]
  71. }
  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(
  84. :create,
  85. :params => {
  86. :project_id => 1,
  87. :membership => {
  88. :role_ids => [1, 2],
  89. :user_id => 7
  90. }
  91. }
  92. )
  93. end
  94. member = Member.order(:id => :desc).first
  95. assert_equal [2], member.role_ids
  96. end
  97. def test_create_should_be_allowed_for_admin_without_role
  98. User.find(1).members.delete_all
  99. @request.session[:user_id] = 1
  100. assert_difference 'Member.count' do
  101. post(
  102. :create,
  103. :params => {
  104. :project_id => 1,
  105. :membership => {
  106. :role_ids => [1, 2],
  107. :user_id => 7
  108. }
  109. }
  110. )
  111. end
  112. member = Member.order(:id => :desc).first
  113. assert_equal [1, 2], member.role_ids
  114. end
  115. def test_xhr_create
  116. assert_difference 'Member.count', 3 do
  117. post(
  118. :create,
  119. :params => {
  120. :project_id => 1,
  121. :membership => {
  122. :role_ids => [1],
  123. :user_ids => [7, 8, 9]
  124. }
  125. },
  126. :xhr => true
  127. )
  128. assert_response :success
  129. assert_equal 'text/javascript', response.media_type
  130. end
  131. assert User.find(7).member_of?(Project.find(1))
  132. assert User.find(8).member_of?(Project.find(1))
  133. assert User.find(9).member_of?(Project.find(1))
  134. assert_include 'tab-content-members', response.body
  135. end
  136. def test_xhr_create_with_failure
  137. assert_no_difference 'Member.count' do
  138. post(
  139. :create,
  140. :params => {
  141. :project_id => 1,
  142. :membership => {
  143. :role_ids => [],
  144. :user_ids => [7, 8, 9]
  145. }
  146. },
  147. :xhr => true
  148. )
  149. assert_response :success
  150. assert_equal 'text/javascript', response.media_type
  151. end
  152. assert_match /alert/, response.body, "Alert message not sent"
  153. end
  154. def test_edit
  155. get(:edit, :params => {:id => 2})
  156. assert_response :success
  157. assert_select 'input[name=?][value=?][checked=checked]', 'membership[role_ids][]', '2'
  158. end
  159. def test_xhr_edit
  160. get(:edit, :params => {:id => 2}, :xhr => true)
  161. assert_response :success
  162. end
  163. def test_update
  164. assert_no_difference 'Member.count' do
  165. put(
  166. :update,
  167. :params => {
  168. :id => 2,
  169. :membership => {
  170. :role_ids => [1],
  171. :user_id => 3
  172. }
  173. }
  174. )
  175. end
  176. assert_redirected_to '/projects/ecookbook/settings/members'
  177. end
  178. def test_update_locked_member_should_be_allowed
  179. User.find(3).lock!
  180. put(
  181. :update,
  182. :params => {
  183. :id => 2,
  184. :membership => {
  185. :role_ids => [1]
  186. }
  187. }
  188. )
  189. assert_response :found
  190. member = Member.find(2)
  191. assert member.user.locked?
  192. assert_equal [1], member.role_ids
  193. end
  194. def test_update_should_not_add_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 => [3], :project_id => 1)
  199. put(
  200. :update,
  201. :params => {
  202. :id => member.id,
  203. :membership => {
  204. :role_ids => [1, 2, 3]
  205. }
  206. }
  207. )
  208. assert_equal [2, 3], member.reload.role_ids.sort
  209. end
  210. def test_update_should_not_remove_unmanaged_roles
  211. role = Role.find(1)
  212. role.update! :all_roles_managed => false
  213. role.managed_roles = Role.where(:id => [2, 3]).to_a
  214. member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1)
  215. put(
  216. :update,
  217. :params => {
  218. :id => member.id,
  219. :membership => {
  220. :role_ids => [2]
  221. }
  222. }
  223. )
  224. assert_equal [1, 2], member.reload.role_ids.sort
  225. end
  226. def test_xhr_update
  227. assert_no_difference 'Member.count' do
  228. put(
  229. :update,
  230. :params => {
  231. :id => 2,
  232. :membership => {
  233. :role_ids => [1],
  234. :user_id => 3
  235. }
  236. },
  237. :xhr => true
  238. )
  239. assert_response :success
  240. assert_equal 'text/javascript', response.media_type
  241. end
  242. member = Member.find(2)
  243. assert_equal [1], member.role_ids
  244. assert_equal 3, member.user_id
  245. assert_include 'tab-content-members', response.body
  246. end
  247. def test_destroy
  248. assert_difference 'Member.count', -1 do
  249. delete(:destroy, :params => {:id => 2})
  250. end
  251. assert_redirected_to '/projects/ecookbook/settings/members'
  252. assert !User.find(3).member_of?(Project.find(1))
  253. end
  254. def test_destroy_locked_member_should_be_allowed
  255. assert User.find(3).lock!
  256. assert_difference 'Member.count', -1 do
  257. delete(:destroy, :params => {:id => 2})
  258. end
  259. end
  260. def test_destroy_should_fail_with_unmanaged_roles
  261. role = Role.find(1)
  262. role.update! :all_roles_managed => false
  263. role.managed_roles = Role.where(:id => [2, 3]).to_a
  264. member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1)
  265. assert_no_difference 'Member.count' do
  266. delete(:destroy, :params => {:id => member.id})
  267. end
  268. end
  269. def test_destroy_should_succeed_with_managed_roles_only
  270. role = Role.find(1)
  271. role.update! :all_roles_managed => false
  272. role.managed_roles = Role.where(:id => [2, 3]).to_a
  273. member = Member.create!(:user => User.find(9), :role_ids => [3], :project_id => 1)
  274. assert_difference 'Member.count', -1 do
  275. delete(:destroy, :params => {:id => member.id})
  276. end
  277. end
  278. def test_xhr_destroy
  279. assert_difference 'Member.count', -1 do
  280. delete(:destroy, :params => {:id => 2}, :xhr => true)
  281. assert_response :success
  282. assert_equal 'text/javascript', response.media_type
  283. end
  284. assert_nil Member.find_by_id(2)
  285. assert_include 'tab-content-members', response.body
  286. end
  287. def test_autocomplete
  288. get(
  289. :autocomplete,
  290. :params => {
  291. :project_id => 1,
  292. :q => 'mis',
  293. :format => 'js'
  294. },
  295. :xhr => true
  296. )
  297. assert_response :success
  298. assert_include 'User Misc', response.body
  299. end
  300. end