選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

issue_relations_test.rb 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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::IssueRelationsTest < Redmine::ApiTest::Base
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :issue_relations
  28. test "GET /issues/:issue_id/relations.xml should return issue relations" do
  29. get '/issues/9/relations.xml', :headers => credentials('jsmith')
  30. assert_response :success
  31. assert_equal 'application/xml', @response.media_type
  32. assert_select 'relations[type=array] relation id', :text => '1'
  33. end
  34. test "POST /issues/:issue_id/relations.xml should create the relation" do
  35. assert_difference('IssueRelation.count') do
  36. post '/issues/2/relations.xml',
  37. :params => {:relation => {:issue_to_id => 7, :relation_type => 'relates'}},
  38. :headers => credentials('jsmith')
  39. end
  40. relation = IssueRelation.order('id DESC').first
  41. assert_equal 2, relation.issue_from_id
  42. assert_equal 7, relation.issue_to_id
  43. assert_equal 'relates', relation.relation_type
  44. assert_response :created
  45. assert_equal 'application/xml', @response.media_type
  46. assert_select 'relation id', :text => relation.id.to_s
  47. end
  48. test "POST /issues/:issue_id/relations.xml with failure should return errors" do
  49. assert_no_difference('IssueRelation.count') do
  50. post '/issues/2/relations.xml',
  51. :params => {:relation => {:issue_to_id => 7, :relation_type => 'foo'}},
  52. :headers => credentials('jsmith')
  53. end
  54. assert_response :unprocessable_entity
  55. assert_select 'errors error', :text => /Relation type is not included in the list/
  56. end
  57. test "GET /relations/:id.xml should return the relation" do
  58. get '/relations/2.xml', :headers => credentials('jsmith')
  59. assert_response :success
  60. assert_equal 'application/xml', @response.media_type
  61. assert_select 'relation id', :text => '2'
  62. end
  63. test "DELETE /relations/:id.xml should delete the relation" do
  64. assert_difference('IssueRelation.count', -1) do
  65. delete '/relations/2.xml', :headers => credentials('jsmith')
  66. end
  67. assert_response :no_content
  68. assert_equal '', @response.body
  69. assert_nil IssueRelation.find_by_id(2)
  70. end
  71. end