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_controller_test.rb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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. require 'issue_relations_controller'
  19. # Re-raise errors caught by the controller.
  20. class IssueRelationsController; def rescue_action(e) raise e end; end
  21. class IssueRelationsControllerTest < ActionController::TestCase
  22. fixtures :projects,
  23. :users,
  24. :roles,
  25. :members,
  26. :member_roles,
  27. :issues,
  28. :issue_statuses,
  29. :issue_relations,
  30. :enabled_modules,
  31. :enumerations,
  32. :trackers
  33. def setup
  34. @controller = IssueRelationsController.new
  35. @request = ActionController::TestRequest.new
  36. @response = ActionController::TestResponse.new
  37. User.current = nil
  38. end
  39. def test_create
  40. assert_difference 'IssueRelation.count' do
  41. @request.session[:user_id] = 3
  42. post :create, :issue_id => 1,
  43. :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
  44. end
  45. relation = IssueRelation.first(:order => 'id DESC')
  46. assert_equal 1, relation.issue_from_id
  47. assert_equal 2, relation.issue_to_id
  48. assert_equal 'relates', relation.relation_type
  49. end
  50. def test_create_xhr
  51. assert_difference 'IssueRelation.count' do
  52. @request.session[:user_id] = 3
  53. xhr :post, :create,
  54. :issue_id => 3,
  55. :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
  56. assert_select_rjs 'relations' do
  57. assert_select 'table', 1
  58. assert_select 'tr', 2 # relations
  59. end
  60. end
  61. relation = IssueRelation.first(:order => 'id DESC')
  62. assert_equal 3, relation.issue_from_id
  63. assert_equal 1, relation.issue_to_id
  64. end
  65. def test_create_should_accept_id_with_hash
  66. assert_difference 'IssueRelation.count' do
  67. @request.session[:user_id] = 3
  68. post :create, :issue_id => 1,
  69. :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
  70. end
  71. relation = IssueRelation.first(:order => 'id DESC')
  72. assert_equal 2, relation.issue_to_id
  73. end
  74. def test_create_should_strip_id
  75. assert_difference 'IssueRelation.count' do
  76. @request.session[:user_id] = 3
  77. post :create, :issue_id => 1,
  78. :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
  79. end
  80. relation = IssueRelation.first(:order => 'id DESC')
  81. assert_equal 2, relation.issue_to_id
  82. end
  83. def test_create_should_not_break_with_non_numerical_id
  84. assert_no_difference 'IssueRelation.count' do
  85. assert_nothing_raised do
  86. @request.session[:user_id] = 3
  87. post :create, :issue_id => 1,
  88. :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
  89. end
  90. end
  91. end
  92. def test_should_create_relations_with_visible_issues_only
  93. Setting.cross_project_issue_relations = '1'
  94. assert_nil Issue.visible(User.find(3)).find_by_id(4)
  95. assert_no_difference 'IssueRelation.count' do
  96. @request.session[:user_id] = 3
  97. post :create, :issue_id => 1,
  98. :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
  99. end
  100. end
  101. should "prevent relation creation when there's a circular dependency"
  102. def test_destroy
  103. assert_difference 'IssueRelation.count', -1 do
  104. @request.session[:user_id] = 3
  105. delete :destroy, :id => '2'
  106. end
  107. end
  108. def test_destroy_xhr
  109. IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
  110. r.issue_from_id = 3
  111. r.issue_to_id = 1
  112. end
  113. assert_difference 'IssueRelation.count', -1 do
  114. @request.session[:user_id] = 3
  115. xhr :delete, :destroy, :id => '2'
  116. assert_select_rjs :remove, 'relation-2'
  117. end
  118. end
  119. end