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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 'journals_controller'
  19. # Re-raise errors caught by the controller.
  20. class JournalsController; def rescue_action(e) raise e end; end
  21. class JournalsControllerTest < ActionController::TestCase
  22. fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
  23. :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
  24. def setup
  25. @controller = JournalsController.new
  26. @request = ActionController::TestRequest.new
  27. @response = ActionController::TestResponse.new
  28. User.current = nil
  29. end
  30. def test_index
  31. get :index, :project_id => 1
  32. assert_response :success
  33. assert_not_nil assigns(:journals)
  34. assert_equal 'application/atom+xml', @response.content_type
  35. end
  36. def test_diff
  37. get :diff, :id => 3, :detail_id => 4
  38. assert_response :success
  39. assert_template 'diff'
  40. assert_tag 'span',
  41. :attributes => {:class => 'diff_out'},
  42. :content => /removed/
  43. assert_tag 'span',
  44. :attributes => {:class => 'diff_in'},
  45. :content => /added/
  46. end
  47. def test_reply_to_issue
  48. @request.session[:user_id] = 2
  49. get :new, :id => 6
  50. assert_response :success
  51. assert_select_rjs :show, "update"
  52. end
  53. def test_reply_to_issue_without_permission
  54. @request.session[:user_id] = 7
  55. get :new, :id => 6
  56. assert_response 403
  57. end
  58. def test_reply_to_note
  59. @request.session[:user_id] = 2
  60. get :new, :id => 6, :journal_id => 4
  61. assert_response :success
  62. assert_select_rjs :show, "update"
  63. end
  64. def test_get_edit
  65. @request.session[:user_id] = 1
  66. xhr :get, :edit, :id => 2
  67. assert_response :success
  68. assert_select_rjs :insert, :after, 'journal-2-notes' do
  69. assert_select 'form[id=journal-2-form]'
  70. assert_select 'textarea'
  71. end
  72. end
  73. def test_post_edit
  74. @request.session[:user_id] = 1
  75. xhr :post, :edit, :id => 2, :notes => 'Updated notes'
  76. assert_response :success
  77. assert_select_rjs :replace, 'journal-2-notes'
  78. assert_equal 'Updated notes', Journal.find(2).notes
  79. end
  80. def test_post_edit_with_empty_notes
  81. @request.session[:user_id] = 1
  82. xhr :post, :edit, :id => 2, :notes => ''
  83. assert_response :success
  84. assert_select_rjs :remove, 'change-2'
  85. assert_nil Journal.find_by_id(2)
  86. end
  87. end