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.

journals_controller_test.rb 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 JournalsControllerTest < ActionController::TestCase
  19. fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
  20. :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
  21. def setup
  22. User.current = nil
  23. end
  24. def test_index
  25. get :index, :project_id => 1
  26. assert_response :success
  27. assert_not_nil assigns(:journals)
  28. assert_equal 'application/atom+xml', @response.content_type
  29. end
  30. def test_index_should_return_privates_notes_with_permission_only
  31. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
  32. @request.session[:user_id] = 2
  33. get :index, :project_id => 1
  34. assert_response :success
  35. assert_include journal, assigns(:journals)
  36. Role.find(1).remove_permission! :view_private_notes
  37. get :index, :project_id => 1
  38. assert_response :success
  39. assert_not_include journal, assigns(:journals)
  40. end
  41. def test_diff
  42. get :diff, :id => 3, :detail_id => 4
  43. assert_response :success
  44. assert_template 'diff'
  45. assert_tag 'span',
  46. :attributes => {:class => 'diff_out'},
  47. :content => /removed/
  48. assert_tag 'span',
  49. :attributes => {:class => 'diff_in'},
  50. :content => /added/
  51. end
  52. def test_reply_to_issue
  53. @request.session[:user_id] = 2
  54. xhr :get, :new, :id => 6
  55. assert_response :success
  56. assert_template 'new'
  57. assert_equal 'text/javascript', response.content_type
  58. assert_include '> This is an issue', response.body
  59. end
  60. def test_reply_to_issue_without_permission
  61. @request.session[:user_id] = 7
  62. xhr :get, :new, :id => 6
  63. assert_response 403
  64. end
  65. def test_reply_to_note
  66. @request.session[:user_id] = 2
  67. xhr :get, :new, :id => 6, :journal_id => 4
  68. assert_response :success
  69. assert_template 'new'
  70. assert_equal 'text/javascript', response.content_type
  71. assert_include '> A comment with a private version', response.body
  72. end
  73. def test_reply_to_private_note_should_fail_without_permission
  74. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
  75. @request.session[:user_id] = 2
  76. xhr :get, :new, :id => 2, :journal_id => journal.id
  77. assert_response :success
  78. assert_template 'new'
  79. assert_equal 'text/javascript', response.content_type
  80. assert_include '> Privates notes', response.body
  81. Role.find(1).remove_permission! :view_private_notes
  82. xhr :get, :new, :id => 2, :journal_id => journal.id
  83. assert_response 404
  84. end
  85. def test_edit_xhr
  86. @request.session[:user_id] = 1
  87. xhr :get, :edit, :id => 2
  88. assert_response :success
  89. assert_template 'edit'
  90. assert_equal 'text/javascript', response.content_type
  91. assert_include 'textarea', response.body
  92. end
  93. def test_edit_private_note_should_fail_without_permission
  94. journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
  95. @request.session[:user_id] = 2
  96. Role.find(1).add_permission! :edit_issue_notes
  97. xhr :get, :edit, :id => journal.id
  98. assert_response :success
  99. assert_template 'edit'
  100. assert_equal 'text/javascript', response.content_type
  101. assert_include 'textarea', response.body
  102. Role.find(1).remove_permission! :view_private_notes
  103. xhr :get, :edit, :id => journal.id
  104. assert_response 404
  105. end
  106. def test_update_xhr
  107. @request.session[:user_id] = 1
  108. xhr :post, :edit, :id => 2, :notes => 'Updated notes'
  109. assert_response :success
  110. assert_template 'update'
  111. assert_equal 'text/javascript', response.content_type
  112. assert_equal 'Updated notes', Journal.find(2).notes
  113. assert_include 'journal-2-notes', response.body
  114. end
  115. def test_update_xhr_with_empty_notes_should_delete_the_journal
  116. @request.session[:user_id] = 1
  117. assert_difference 'Journal.count', -1 do
  118. xhr :post, :edit, :id => 2, :notes => ''
  119. assert_response :success
  120. assert_template 'update'
  121. assert_equal 'text/javascript', response.content_type
  122. end
  123. assert_nil Journal.find_by_id(2)
  124. assert_include 'change-2', response.body
  125. end
  126. end