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.

repositories_test.rb 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 Redmine::ApiTest::RepositoriesTest < Redmine::ApiTest::Base
  20. fixtures :users,
  21. :projects, :enabled_modules,
  22. :members, :roles, :member_roles,
  23. :issues,
  24. :repositories, :changesets, :changes
  25. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml should add related issue' do
  26. changeset = Changeset.find(103)
  27. assert_equal [], changeset.issue_ids
  28. assert_difference 'Changeset.find(103).issues.size' do
  29. post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '2'}
  30. end
  31. assert_response :no_content
  32. assert_equal [2], changeset.reload.issue_ids
  33. end
  34. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json should add related issue' do
  35. changeset = Changeset.find(103)
  36. assert_equal [], changeset.issue_ids
  37. assert_difference 'Changeset.find(103).issues.size' do
  38. post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '2'}
  39. end
  40. assert_response :no_content
  41. assert_equal [2], changeset.reload.issue_ids
  42. end
  43. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml should accept issue_id with sharp' do
  44. changeset = Changeset.find(103)
  45. assert_equal [], changeset.issue_ids
  46. assert_difference 'Changeset.find(103).issues.size' do
  47. post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '#2'}
  48. end
  49. assert_response :no_content
  50. assert_equal [2], changeset.reload.issue_ids
  51. end
  52. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json should accept issue_id with sharp' do
  53. changeset = Changeset.find(103)
  54. assert_equal [], changeset.issue_ids
  55. assert_difference 'Changeset.find(103).issues.size' do
  56. post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '#2'}
  57. end
  58. assert_response :no_content
  59. assert_equal [2], changeset.reload.issue_ids
  60. end
  61. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml with invalid issue_id' do
  62. assert_no_difference 'Changeset.find(103).issues.size' do
  63. post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '9999'}
  64. end
  65. assert_response :unprocessable_entity
  66. assert_select 'errors error', :text => 'Issue is invalid'
  67. end
  68. test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json with invalid issue_id' do
  69. assert_no_difference 'Changeset.find(103).issues.size' do
  70. post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '9999'}
  71. end
  72. assert_response :unprocessable_entity
  73. json = ActiveSupport::JSON.decode(response.body)
  74. assert json['errors'].include?('Issue is invalid')
  75. end
  76. test 'DELETE /projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id.xml should remove related issue' do
  77. changeset = Changeset.find(103)
  78. changeset.issues << Issue.find(1)
  79. changeset.issues << Issue.find(2)
  80. assert_difference 'Changeset.find(103).issues.size', -1 do
  81. delete '/projects/1/repository/10/revisions/4/issues/2.xml', :headers => credentials('jsmith')
  82. end
  83. assert_response :no_content
  84. assert_equal [1], changeset.reload.issue_ids
  85. end
  86. test 'DELETE /projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id.json should remove related issue' do
  87. changeset = Changeset.find(103)
  88. changeset.issues << Issue.find(1)
  89. changeset.issues << Issue.find(2)
  90. assert_difference 'Changeset.find(103).issues.size', -1 do
  91. delete '/projects/1/repository/10/revisions/4/issues/2.json', :headers => credentials('jsmith')
  92. end
  93. assert_response :no_content
  94. assert_equal [1], changeset.reload.issue_ids
  95. end
  96. end