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_relations_test.rb 3.2KB

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