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.

queries_controller_test.rb 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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 QueriesControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :enabled_modules,
  20. :users, :email_addresses,
  21. :members, :member_roles, :roles,
  22. :trackers, :issue_statuses, :issue_categories, :enumerations, :versions,
  23. :issues, :custom_fields, :custom_values,
  24. :queries
  25. def setup
  26. User.current = nil
  27. end
  28. def test_index
  29. get :index
  30. # HTML response not implemented
  31. assert_response 406
  32. end
  33. def test_new_project_query
  34. @request.session[:user_id] = 2
  35. get :new, :params => {
  36. :project_id => 1
  37. }
  38. assert_response :success
  39. assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]'
  40. assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])'
  41. assert_select 'select[name=?]', 'c[]' do
  42. assert_select 'option[value=tracker]'
  43. assert_select 'option[value=subject]'
  44. end
  45. end
  46. def test_new_global_query
  47. @request.session[:user_id] = 2
  48. get :new
  49. assert_response :success
  50. assert_select 'input[name=?]', 'query[visibility]', 0
  51. assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])'
  52. end
  53. def test_new_on_invalid_project
  54. @request.session[:user_id] = 2
  55. get :new, :params => {
  56. :project_id => 'invalid'
  57. }
  58. assert_response 404
  59. end
  60. def test_new_time_entry_query
  61. @request.session[:user_id] = 2
  62. get :new, :params => {
  63. :project_id => 1,
  64. :type => 'TimeEntryQuery'
  65. }
  66. assert_response :success
  67. assert_select 'input[name=type][value=?]', 'TimeEntryQuery'
  68. end
  69. def test_new_time_entry_query_should_select_spent_time_from_main_menu
  70. @request.session[:user_id] = 2
  71. get :new, :params => {
  72. :project_id => 1,
  73. :type => 'TimeEntryQuery'
  74. }
  75. assert_response :success
  76. assert_select '#main-menu a.time-entries.selected'
  77. end
  78. def test_new_time_entry_query_with_issue_tracking_module_disabled_should_be_allowed
  79. Project.find(1).disable_module! :issue_tracking
  80. @request.session[:user_id] = 2
  81. get :new, :params => {
  82. :project_id => 1,
  83. :type => 'TimeEntryQuery'
  84. }
  85. assert_response :success
  86. end
  87. def test_create_project_public_query
  88. @request.session[:user_id] = 2
  89. post :create, :params => {
  90. :project_id => 'ecookbook',
  91. :default_columns => '1',
  92. :f => ["status_id", "assigned_to_id"],
  93. :op => {
  94. "assigned_to_id" => "=", "status_id" => "o"
  95. },
  96. :v => {
  97. "assigned_to_id" => ["1"], "status_id" => ["1"]
  98. },
  99. :query => {
  100. "name" => "test_new_project_public_query", "visibility" => "2"
  101. }
  102. }
  103. q = Query.find_by_name('test_new_project_public_query')
  104. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
  105. assert q.is_public?
  106. assert q.has_default_columns?
  107. assert q.valid?
  108. end
  109. def test_create_project_private_query
  110. @request.session[:user_id] = 3
  111. post :create, :params => {
  112. :project_id => 'ecookbook',
  113. :default_columns => '1',
  114. :fields => ["status_id", "assigned_to_id"],
  115. :operators => {
  116. "assigned_to_id" => "=", "status_id" => "o"
  117. },
  118. :values => {
  119. "assigned_to_id" => ["1"], "status_id" => ["1"]
  120. },
  121. :query => {
  122. "name" => "test_new_project_private_query", "visibility" => "0"
  123. }
  124. }
  125. q = Query.find_by_name('test_new_project_private_query')
  126. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
  127. assert !q.is_public?
  128. assert q.has_default_columns?
  129. assert q.valid?
  130. end
  131. def test_create_project_roles_query
  132. @request.session[:user_id] = 2
  133. post :create, :params => {
  134. :project_id => 'ecookbook',
  135. :default_columns => '1',
  136. :fields => ["status_id", "assigned_to_id"],
  137. :operators => {
  138. "assigned_to_id" => "=", "status_id" => "o"
  139. },
  140. :values => {
  141. "assigned_to_id" => ["1"], "status_id" => ["1"]
  142. },
  143. :query => {
  144. "name" => "test_create_project_roles_query", "visibility" => "1", "role_ids" => ["1", "2", ""]
  145. }
  146. }
  147. q = Query.find_by_name('test_create_project_roles_query')
  148. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
  149. assert_equal Query::VISIBILITY_ROLES, q.visibility
  150. assert_equal [1, 2], q.roles.ids.sort
  151. end
  152. def test_create_global_private_query_with_custom_columns
  153. @request.session[:user_id] = 3
  154. post :create, :params => {
  155. :fields => ["status_id", "assigned_to_id"],
  156. :operators => {
  157. "assigned_to_id" => "=", "status_id" => "o"
  158. },
  159. :values => {
  160. "assigned_to_id" => ["me"], "status_id" => ["1"]
  161. },
  162. :query => {
  163. "name" => "test_new_global_private_query", "visibility" => "0"
  164. },
  165. :c => ["", "tracker", "subject", "priority", "category"]
  166. }
  167. q = Query.find_by_name('test_new_global_private_query')
  168. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
  169. assert !q.is_public?
  170. assert !q.has_default_columns?
  171. assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
  172. assert q.valid?
  173. end
  174. def test_create_global_query_with_custom_filters
  175. @request.session[:user_id] = 3
  176. post :create, :params => {
  177. :fields => ["assigned_to_id"],
  178. :operators => {
  179. "assigned_to_id" => "="
  180. },
  181. :values => {
  182. "assigned_to_id" => ["me"]
  183. },
  184. :query => {
  185. "name" => "test_new_global_query"
  186. }
  187. }
  188. q = Query.find_by_name('test_new_global_query')
  189. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
  190. assert !q.is_public?
  191. assert !q.has_filter?(:status_id)
  192. assert_equal ['assigned_to_id'], q.filters.keys
  193. assert q.valid?
  194. end
  195. def test_create_with_sort
  196. @request.session[:user_id] = 1
  197. post :create, :params => {
  198. :default_columns => '1',
  199. :operators => {
  200. "status_id" => "o"
  201. },
  202. :values => {
  203. "status_id" => ["1"]
  204. },
  205. :query => {
  206. :name => "test_new_with_sort",
  207. :visibility => "2",
  208. :sort_criteria => {
  209. "0" => ["due_date", "desc"], "1" => ["tracker", ""]}
  210. }
  211. }
  212. query = Query.find_by_name("test_new_with_sort")
  213. assert_not_nil query
  214. assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
  215. end
  216. def test_create_with_failure
  217. @request.session[:user_id] = 2
  218. assert_no_difference '::Query.count' do
  219. post :create, :params => {
  220. :project_id => 'ecookbook',
  221. :query => {
  222. :name => ''
  223. }
  224. }
  225. end
  226. assert_response :success
  227. assert_select 'input[name=?]', 'query[name]'
  228. end
  229. def test_create_query_without_permission_should_fail
  230. Role.all.each {|r| r.remove_permission! :save_queries, :manage_public_queries}
  231. @request.session[:user_id] = 2
  232. assert_no_difference '::Query.count' do
  233. post :create, :params => {
  234. :project_id => 'ecookbook',
  235. :query => {:name => 'Foo'}
  236. }
  237. end
  238. assert_response 403
  239. end
  240. def test_create_global_query_without_permission_should_fail
  241. Role.all.each {|r| r.remove_permission! :save_queries, :manage_public_queries}
  242. @request.session[:user_id] = 2
  243. assert_no_difference '::Query.count' do
  244. post :create, :params => {
  245. :query => {:name => 'Foo'}
  246. }
  247. end
  248. assert_response 403
  249. end
  250. def test_create_global_query_from_gantt
  251. @request.session[:user_id] = 1
  252. assert_difference 'IssueQuery.count' do
  253. post :create, :params => {
  254. :gantt => 1,
  255. :operators => {
  256. "status_id" => "o"
  257. },
  258. :values => {
  259. "status_id" => ["1"]
  260. },
  261. :query => {
  262. :name => "test_create_from_gantt",
  263. :draw_relations => '1',
  264. :draw_progress_line => '1'
  265. }
  266. }
  267. assert_response 302
  268. end
  269. query = IssueQuery.order('id DESC').first
  270. assert_redirected_to "/issues/gantt?query_id=#{query.id}"
  271. assert_equal true, query.draw_relations
  272. assert_equal true, query.draw_progress_line
  273. end
  274. def test_create_project_query_from_gantt
  275. @request.session[:user_id] = 1
  276. assert_difference 'IssueQuery.count' do
  277. post :create, :params => {
  278. :project_id => 'ecookbook',
  279. :gantt => 1,
  280. :operators => {
  281. "status_id" => "o"
  282. },
  283. :values => {
  284. "status_id" => ["1"]
  285. },
  286. :query => {
  287. :name => "test_create_from_gantt",
  288. :draw_relations => '0',
  289. :draw_progress_line => '0'
  290. }
  291. }
  292. assert_response 302
  293. end
  294. query = IssueQuery.order('id DESC').first
  295. assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}"
  296. assert_equal false, query.draw_relations
  297. assert_equal false, query.draw_progress_line
  298. end
  299. def test_create_project_public_query_should_force_private_without_manage_public_queries_permission
  300. @request.session[:user_id] = 3
  301. query = new_record(Query) do
  302. post :create, :params => {
  303. :project_id => 'ecookbook',
  304. :query => {
  305. "name" => "name", "visibility" => "2"
  306. }
  307. }
  308. assert_response 302
  309. end
  310. assert_not_nil query.project
  311. assert_equal Query::VISIBILITY_PRIVATE, query.visibility
  312. end
  313. def test_create_global_public_query_should_force_private_without_manage_public_queries_permission
  314. @request.session[:user_id] = 3
  315. query = new_record(Query) do
  316. post :create, :params => {
  317. :project_id => 'ecookbook',
  318. :query_is_for_all => '1',
  319. :query => {
  320. "name" => "name", "visibility" => "2"
  321. }
  322. }
  323. assert_response 302
  324. end
  325. assert_nil query.project
  326. assert_equal Query::VISIBILITY_PRIVATE, query.visibility
  327. end
  328. def test_create_project_public_query_with_manage_public_queries_permission
  329. @request.session[:user_id] = 2
  330. query = new_record(Query) do
  331. post :create, :params => {
  332. :project_id => 'ecookbook',
  333. :query => {
  334. "name" => "name", "visibility" => "2"
  335. }
  336. }
  337. assert_response 302
  338. end
  339. assert_not_nil query.project
  340. assert_equal Query::VISIBILITY_PUBLIC, query.visibility
  341. end
  342. def test_create_global_public_query_should_force_private_with_manage_public_queries_permission
  343. @request.session[:user_id] = 2
  344. query = new_record(Query) do
  345. post :create, :params => {
  346. :project_id => 'ecookbook',
  347. :query_is_for_all => '1',
  348. :query => {
  349. "name" => "name", "visibility" => "2"
  350. }
  351. }
  352. assert_response 302
  353. end
  354. assert_nil query.project
  355. assert_equal Query::VISIBILITY_PRIVATE, query.visibility
  356. end
  357. def test_create_global_public_query_by_admin
  358. @request.session[:user_id] = 1
  359. query = new_record(Query) do
  360. post :create, :params => {
  361. :project_id => 'ecookbook',
  362. :query_is_for_all => '1',
  363. :query => {
  364. "name" => "name", "visibility" => "2"
  365. }
  366. }
  367. assert_response 302
  368. end
  369. assert_nil query.project
  370. assert_equal Query::VISIBILITY_PUBLIC, query.visibility
  371. end
  372. def test_create_project_public_time_entry_query
  373. @request.session[:user_id] = 2
  374. q = new_record(TimeEntryQuery) do
  375. post :create, :params => {
  376. :project_id => 'ecookbook',
  377. :type => 'TimeEntryQuery',
  378. :default_columns => '1',
  379. :f => ["spent_on"],
  380. :op => {
  381. "spent_on" => "="
  382. },
  383. :v => {
  384. "spent_on" => ["2016-07-14"]
  385. },
  386. :query => {
  387. "name" => "test_new_project_public_query", "visibility" => "2"
  388. }
  389. }
  390. end
  391. assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :query_id => q.id
  392. assert q.is_public?
  393. assert q.has_default_columns?
  394. assert q.valid?
  395. end
  396. def test_edit_global_public_query
  397. @request.session[:user_id] = 1
  398. get :edit, :params => {
  399. :id => 4
  400. }
  401. assert_response :success
  402. assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]'
  403. assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]'
  404. end
  405. def test_edit_global_private_query
  406. @request.session[:user_id] = 3
  407. get :edit, :params => {
  408. :id => 3
  409. }
  410. assert_response :success
  411. assert_select 'input[name=?]', 'query[visibility]', 0
  412. assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]'
  413. end
  414. def test_edit_project_private_query
  415. @request.session[:user_id] = 3
  416. get :edit, :params => {
  417. :id => 2
  418. }
  419. assert_response :success
  420. assert_select 'input[name=?]', 'query[visibility]', 0
  421. assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])'
  422. end
  423. def test_edit_project_public_query
  424. @request.session[:user_id] = 2
  425. get :edit, :params => {
  426. :id => 1
  427. }
  428. assert_response :success
  429. assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]'
  430. assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])'
  431. end
  432. def test_edit_sort_criteria
  433. @request.session[:user_id] = 1
  434. get :edit, :params => {
  435. :id => 5
  436. }
  437. assert_response :success
  438. assert_select 'select[name=?]', 'query[sort_criteria][0][]' do
  439. assert_select 'option[value=priority][selected=selected]'
  440. assert_select 'option[value=desc][selected=selected]'
  441. end
  442. end
  443. def test_edit_invalid_query
  444. @request.session[:user_id] = 2
  445. get :edit, :params => {
  446. :id => 99
  447. }
  448. assert_response 404
  449. end
  450. def test_update_global_private_query
  451. @request.session[:user_id] = 3
  452. put :update, :params => {
  453. :id => 3,
  454. :default_columns => '1',
  455. :fields => ["status_id", "assigned_to_id"],
  456. :operators => {
  457. "assigned_to_id" => "=", "status_id" => "o"
  458. },
  459. :values => {
  460. "assigned_to_id" => ["me"], "status_id" => ["1"]
  461. },
  462. :query => {
  463. "name" => "test_edit_global_private_query", "visibility" => "2"
  464. }
  465. }
  466. assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
  467. q = Query.find_by_name('test_edit_global_private_query')
  468. assert !q.is_public?
  469. assert q.has_default_columns?
  470. assert q.valid?
  471. end
  472. def test_update_global_public_query
  473. @request.session[:user_id] = 1
  474. put :update, :params => {
  475. :id => 4,
  476. :default_columns => '1',
  477. :fields => ["status_id", "assigned_to_id"],
  478. :operators => {
  479. "assigned_to_id" => "=", "status_id" => "o"
  480. },
  481. :values => {
  482. "assigned_to_id" => ["1"], "status_id" => ["1"]
  483. },
  484. :query => {
  485. "name" => "test_edit_global_public_query", "visibility" => "2"
  486. }
  487. }
  488. assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
  489. q = Query.find_by_name('test_edit_global_public_query')
  490. assert q.is_public?
  491. assert q.has_default_columns?
  492. assert q.valid?
  493. end
  494. def test_update_with_failure
  495. @request.session[:user_id] = 1
  496. put :update, :params => {
  497. :id => 4,
  498. :query => {
  499. :name => ''
  500. }
  501. }
  502. assert_response :success
  503. assert_select_error /Name cannot be blank/
  504. end
  505. def test_destroy
  506. @request.session[:user_id] = 2
  507. delete :destroy, :params => {
  508. :id => 1
  509. }
  510. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
  511. assert_nil Query.find_by_id(1)
  512. end
  513. def test_backslash_should_be_escaped_in_filters
  514. @request.session[:user_id] = 2
  515. get :new, :params => {
  516. :subject => 'foo/bar'
  517. }
  518. assert_response :success
  519. assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body
  520. end
  521. def test_filter_with_project_id_should_return_filter_values
  522. @request.session[:user_id] = 2
  523. get :filter, :params => {
  524. :project_id => 1,
  525. :name => 'fixed_version_id'
  526. }
  527. assert_response :success
  528. assert_equal 'application/json', response.content_type
  529. json = ActiveSupport::JSON.decode(response.body)
  530. assert_include ["eCookbook - 2.0", "3", "open"], json
  531. end
  532. def test_version_filter_time_entries_with_project_id_should_return_filter_values
  533. @request.session[:user_id] = 2
  534. get :filter, :params => {
  535. :project_id => 1,
  536. :type => 'TimeEntryQuery',
  537. :name => 'issue.fixed_version_id'
  538. }
  539. assert_response :success
  540. assert_equal 'application/json', response.content_type
  541. json = ActiveSupport::JSON.decode(response.body)
  542. assert_include ["eCookbook - 2.0", "3", "open"], json
  543. end
  544. def test_version_filter_without_project_id_should_return_all_visible_fixed_versions
  545. # Remove "jsmith" user from "Private child of eCookbook" project
  546. Project.find(5).memberships.find_by(:user_id => 2).destroy
  547. @request.session[:user_id] = 2
  548. get :filter, :params => {
  549. :name => 'fixed_version_id'
  550. }
  551. assert_response :success
  552. assert_equal 'application/json', response.content_type
  553. json = ActiveSupport::JSON.decode(response.body)
  554. # response includes visible version
  555. assert_include ["eCookbook Subproject 1 - 2.0", "4", "open"], json
  556. assert_include ["eCookbook - 0.1", "1", "closed"], json
  557. # response includes systemwide visible version
  558. assert_include ["OnlineStore - Systemwide visible version", "7", "open"], json
  559. # response doesn't include non visible version
  560. assert_not_include ["Private child of eCookbook - Private Version of public subproject", "6", "open"], json
  561. end
  562. def test_subproject_filter_time_entries_with_project_id_should_return_filter_values
  563. @request.session[:user_id] = 2
  564. get :filter, :params => {
  565. :project_id => 1,
  566. :type => 'TimeEntryQuery',
  567. :name => 'subproject_id'
  568. }
  569. assert_response :success
  570. assert_equal 'application/json', response.content_type
  571. json = ActiveSupport::JSON.decode(response.body)
  572. assert_equal 4, json.count
  573. assert_include ["Private child of eCookbook","5"], json
  574. end
  575. def test_assignee_filter_should_return_active_and_locked_users_grouped_by_status
  576. @request.session[:user_id] = 1
  577. get :filter, :params => {
  578. :project_id => 1,
  579. :type => 'IssueQuery',
  580. :name => 'assigned_to_id'
  581. }
  582. assert_response :success
  583. assert_equal 'application/json', response.content_type
  584. json = ActiveSupport::JSON.decode(response.body)
  585. assert_equal 6, json.count
  586. # "me" value should not be grouped
  587. assert_include ["<< me >>", "me"], json
  588. assert_include ["Dave Lopper", "3", "active"], json
  589. assert_include ["Dave2 Lopper2", "5", "locked"], json
  590. end
  591. def test_author_filter_should_return_active_and_locked_users_grouped_by_status
  592. @request.session[:user_id] = 1
  593. get :filter, :params => {
  594. :project_id => 1,
  595. :type => 'IssueQuery',
  596. :name => 'author_id'
  597. }
  598. assert_response :success
  599. assert_equal 'application/json', response.content_type
  600. json = ActiveSupport::JSON.decode(response.body)
  601. assert_equal 6, json.count
  602. # "me" value should not be grouped
  603. assert_include ["<< me >>", "me"], json
  604. assert_include ["Dave Lopper", "3", "active"], json
  605. assert_include ["Dave2 Lopper2", "5", "locked"], json
  606. end
  607. def test_user_filter_should_return_active_and_locked_users_grouped_by_status
  608. @request.session[:user_id] = 1
  609. get :filter, :params => {
  610. :project_id => 1,
  611. :type => 'TimeEntryQuery',
  612. :name => 'user_id'
  613. }
  614. assert_response :success
  615. assert_equal 'application/json', response.content_type
  616. json = ActiveSupport::JSON.decode(response.body)
  617. assert_equal 6, json.count
  618. # "me" value should not be grouped
  619. assert_include ["<< me >>", "me"], json
  620. assert_include ["Dave Lopper", "3", "active"], json
  621. assert_include ["Dave2 Lopper2", "5", "locked"], json
  622. end
  623. def test_watcher_filter_without_permission_should_show_only_me
  624. # This user does not have view_issue_watchers permission
  625. @request.session[:user_id] = 7
  626. get :filter, :params => {
  627. :project_id => 1,
  628. :type => 'IssueQuery',
  629. :name => 'watcher_id'
  630. }
  631. assert_response :success
  632. assert_equal 'application/json', response.content_type
  633. json = ActiveSupport::JSON.decode(response.body)
  634. assert_equal 1, json.count
  635. assert_equal [["<< me >>", "me"]], json
  636. end
  637. def test_watcher_filter_with_permission_should_show_members
  638. # This user has view_issue_watchers permission
  639. @request.session[:user_id] = 1
  640. get :filter, :params => {
  641. :project_id => 1,
  642. :type => 'IssueQuery',
  643. :name => 'watcher_id'
  644. }
  645. assert_response :success
  646. assert_equal 'application/json', response.content_type
  647. json = ActiveSupport::JSON.decode(response.body)
  648. assert_equal 6, json.count
  649. # "me" value should not be grouped
  650. assert_include ["<< me >>", "me"], json
  651. assert_include ["Dave Lopper", "3", "active"], json
  652. assert_include ["Dave2 Lopper2", "5", "locked"], json
  653. end
  654. end