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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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. test "GET /issues/:issue_id/relations.xml should return issue relations" do
  28. get '/issues/9/relations.xml', {}, credentials('jsmith')
  29. assert_response :success
  30. assert_equal 'application/xml', @response.content_type
  31. assert_select 'relations[type=array] relation id', :text => '1'
  32. end
  33. test "POST /issues/:issue_id/relations.xml should create the relation" do
  34. assert_difference('IssueRelation.count') do
  35. post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
  36. end
  37. relation = IssueRelation.order('id DESC').first
  38. assert_equal 2, relation.issue_from_id
  39. assert_equal 7, relation.issue_to_id
  40. assert_equal 'relates', relation.relation_type
  41. assert_response :created
  42. assert_equal 'application/xml', @response.content_type
  43. assert_select 'relation id', :text => relation.id.to_s
  44. end
  45. test "POST /issues/:issue_id/relations.xml with failure should return errors" do
  46. assert_no_difference('IssueRelation.count') do
  47. post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
  48. end
  49. assert_response :unprocessable_entity
  50. assert_select 'errors error', :text => /Relation type is not included in the list/
  51. end
  52. test "GET /relations/:id.xml should return the relation" do
  53. get '/relations/2.xml', {}, credentials('jsmith')
  54. assert_response :success
  55. assert_equal 'application/xml', @response.content_type
  56. assert_select 'relation id', :text => '2'
  57. end
  58. test "DELETE /relations/:id.xml should delete the relation" do
  59. assert_difference('IssueRelation.count', -1) do
  60. delete '/relations/2.xml', {}, credentials('jsmith')
  61. end
  62. assert_response :ok
  63. assert_equal '', @response.body
  64. assert_nil IssueRelation.find_by_id(2)
  65. end
  66. end