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.

comments_controller_test.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 CommentsControllerTest < ActionController::TestCase
  19. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :news, :comments
  20. def setup
  21. User.current = nil
  22. end
  23. def test_add_comment
  24. @request.session[:user_id] = 2
  25. post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
  26. assert_redirected_to '/news/1'
  27. comment = News.find(1).comments.last
  28. assert_not_nil comment
  29. assert_equal 'This is a test comment', comment.comments
  30. assert_equal User.find(2), comment.author
  31. end
  32. def test_empty_comment_should_not_be_added
  33. @request.session[:user_id] = 2
  34. assert_no_difference 'Comment.count' do
  35. post :create, :id => 1, :comment => { :comments => '' }
  36. assert_response :redirect
  37. assert_redirected_to '/news/1'
  38. end
  39. end
  40. def test_create_should_be_denied_if_news_is_not_commentable
  41. News.any_instance.stubs(:commentable?).returns(false)
  42. @request.session[:user_id] = 2
  43. assert_no_difference 'Comment.count' do
  44. post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
  45. assert_response 403
  46. end
  47. end
  48. def test_destroy_comment
  49. comments_count = News.find(1).comments.size
  50. @request.session[:user_id] = 2
  51. delete :destroy, :id => 1, :comment_id => 2
  52. assert_redirected_to '/news/1'
  53. assert_nil Comment.find_by_id(2)
  54. assert_equal comments_count - 1, News.find(1).comments.size
  55. end
  56. end