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.

issue_categories_test.rb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 File.expand_path('../../../test_helper', __FILE__)
  19. class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
  20. fixtures :projects, :users, :issue_categories, :issues,
  21. :roles,
  22. :member_roles,
  23. :members,
  24. :enabled_modules
  25. test "GET /projects/:project_id/issue_categories.xml should return the issue categories" do
  26. get '/projects/1/issue_categories.xml', :headers => credentials('jsmith')
  27. assert_response :success
  28. assert_equal 'application/xml', @response.media_type
  29. assert_select 'issue_categories issue_category id', :text => '2'
  30. end
  31. test "GET /issue_categories/:id.xml should return the issue category" do
  32. get '/issue_categories/2.xml', :headers => credentials('jsmith')
  33. assert_response :success
  34. assert_equal 'application/xml', @response.media_type
  35. assert_select 'issue_category id', :text => '2'
  36. end
  37. test "POST /projects/:project_id/issue_categories.xml should return create issue category" do
  38. assert_difference 'IssueCategory.count' do
  39. post(
  40. '/projects/1/issue_categories.xml',
  41. :params => {:issue_category => {:name => 'API'}},
  42. :headers => credentials('jsmith'))
  43. end
  44. assert_response :created
  45. assert_equal 'application/xml', @response.media_type
  46. category = IssueCategory.order('id DESC').first
  47. assert_equal 'API', category.name
  48. assert_equal 1, category.project_id
  49. end
  50. test "POST /projects/:project_id/issue_categories.xml with invalid parameters should return errors" do
  51. assert_no_difference 'IssueCategory.count' do
  52. post(
  53. '/projects/1/issue_categories.xml',
  54. :params => {:issue_category => {:name => ''}},
  55. :headers => credentials('jsmith'))
  56. end
  57. assert_response :unprocessable_entity
  58. assert_equal 'application/xml', @response.media_type
  59. assert_select 'errors error', :text => "Name cannot be blank"
  60. end
  61. test "PUT /issue_categories/:id.xml with valid parameters should update the issue category" do
  62. assert_no_difference 'IssueCategory.count' do
  63. put(
  64. '/issue_categories/2.xml',
  65. :params => {:issue_category => {:name => 'API Update'}},
  66. :headers => credentials('jsmith'))
  67. end
  68. assert_response :no_content
  69. assert_equal '', @response.body
  70. assert_equal 'API Update', IssueCategory.find(2).name
  71. end
  72. test "PUT /issue_categories/:id.xml with invalid parameters should return errors" do
  73. assert_no_difference 'IssueCategory.count' do
  74. put(
  75. '/issue_categories/2.xml',
  76. :params => {:issue_category => {:name => ''}},
  77. :headers => credentials('jsmith'))
  78. end
  79. assert_response :unprocessable_entity
  80. assert_equal 'application/xml', @response.media_type
  81. assert_select 'errors error', :text => "Name cannot be blank"
  82. end
  83. test "DELETE /issue_categories/:id.xml should destroy the issue category" do
  84. assert_difference 'IssueCategory.count', -1 do
  85. delete '/issue_categories/1.xml', :headers => credentials('jsmith')
  86. end
  87. assert_response :no_content
  88. assert_equal '', @response.body
  89. assert_nil IssueCategory.find_by_id(1)
  90. end
  91. test "DELETE /issue_categories/:id.xml should reassign issues with :reassign_to_id param" do
  92. issue_count = Issue.where(:category_id => 1).count
  93. assert issue_count > 0
  94. assert_difference 'IssueCategory.count', -1 do
  95. assert_difference 'Issue.where(:category_id => 2).count', 3 do
  96. delete(
  97. '/issue_categories/1.xml',
  98. :params => {:reassign_to_id => 2},
  99. :headers => credentials('jsmith'))
  100. end
  101. end
  102. assert_response :no_content
  103. assert_equal '', @response.body
  104. assert_nil IssueCategory.find_by_id(1)
  105. end
  106. end