You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_relations_controller_test.rb 5.2 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 IssueRelationsControllerTest < ActionController::TestCase
  19. fixtures :projects,
  20. :users,
  21. :roles,
  22. :members,
  23. :member_roles,
  24. :issues,
  25. :issue_statuses,
  26. :issue_relations,
  27. :enabled_modules,
  28. :enumerations,
  29. :trackers,
  30. :projects_trackers
  31. def setup
  32. User.current = nil
  33. @request.session[:user_id] = 3
  34. end
  35. def test_create
  36. assert_difference 'IssueRelation.count' do
  37. post :create, :issue_id => 1,
  38. :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
  39. end
  40. relation = IssueRelation.first(:order => 'id DESC')
  41. assert_equal 1, relation.issue_from_id
  42. assert_equal 2, relation.issue_to_id
  43. assert_equal 'relates', relation.relation_type
  44. end
  45. def test_create_xhr
  46. assert_difference 'IssueRelation.count' do
  47. xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
  48. assert_response :success
  49. assert_template 'create'
  50. assert_equal 'text/javascript', response.content_type
  51. end
  52. relation = IssueRelation.first(:order => 'id DESC')
  53. assert_equal 3, relation.issue_from_id
  54. assert_equal 1, relation.issue_to_id
  55. assert_match /Bug #1/, response.body
  56. end
  57. def test_create_should_accept_id_with_hash
  58. assert_difference 'IssueRelation.count' do
  59. post :create, :issue_id => 1,
  60. :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
  61. end
  62. relation = IssueRelation.first(:order => 'id DESC')
  63. assert_equal 2, relation.issue_to_id
  64. end
  65. def test_create_should_strip_id
  66. assert_difference 'IssueRelation.count' do
  67. post :create, :issue_id => 1,
  68. :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
  69. end
  70. relation = IssueRelation.first(:order => 'id DESC')
  71. assert_equal 2, relation.issue_to_id
  72. end
  73. def test_create_should_not_break_with_non_numerical_id
  74. assert_no_difference 'IssueRelation.count' do
  75. assert_nothing_raised do
  76. post :create, :issue_id => 1,
  77. :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
  78. end
  79. end
  80. end
  81. def test_create_follows_relation_should_update_relations_list
  82. issue1 = Issue.generate!(:subject => 'Followed issue', :start_date => Date.yesterday, :due_date => Date.today)
  83. issue2 = Issue.generate!
  84. assert_difference 'IssueRelation.count' do
  85. xhr :post, :create, :issue_id => issue2.id,
  86. :relation => {:issue_to_id => issue1.id, :relation_type => 'follows', :delay => ''}
  87. end
  88. assert_match /Followed issue/, response.body
  89. end
  90. def test_should_create_relations_with_visible_issues_only
  91. Setting.cross_project_issue_relations = '1'
  92. assert_nil Issue.visible(User.find(3)).find_by_id(4)
  93. assert_no_difference 'IssueRelation.count' do
  94. post :create, :issue_id => 1,
  95. :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
  96. end
  97. end
  98. should "prevent relation creation when there's a circular dependency"
  99. def test_create_xhr_with_failure
  100. assert_no_difference 'IssueRelation.count' do
  101. xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
  102. assert_response :success
  103. assert_template 'create'
  104. assert_equal 'text/javascript', response.content_type
  105. end
  106. assert_match /errorExplanation/, response.body
  107. end
  108. def test_destroy
  109. assert_difference 'IssueRelation.count', -1 do
  110. delete :destroy, :id => '2'
  111. end
  112. end
  113. def test_destroy_xhr
  114. IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
  115. r.issue_from_id = 3
  116. r.issue_to_id = 1
  117. end
  118. assert_difference 'IssueRelation.count', -1 do
  119. xhr :delete, :destroy, :id => '2'
  120. assert_response :success
  121. assert_template 'destroy'
  122. assert_equal 'text/javascript', response.content_type
  123. assert_match /relation-2/, response.body
  124. end
  125. end
  126. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...