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.

comment_test.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class CommentTest < ActiveSupport::TestCase
  20. fixtures :users, :email_addresses, :news, :comments, :projects, :enabled_modules,
  21. :user_preferences, :roles, :members, :member_roles
  22. def setup
  23. User.current = nil
  24. @jsmith = User.find(2)
  25. @news = News.find(1)
  26. end
  27. def test_create
  28. comment = Comment.new(:commented => @news, :author => @jsmith, :comments => "my comment")
  29. assert comment.save
  30. @news.reload
  31. assert_equal 2, @news.comments_count
  32. end
  33. def test_create_should_send_notification
  34. Watcher.create!(:watchable => @news, :user => @jsmith)
  35. with_settings :notified_events => %w(news_comment_added) do
  36. assert_difference 'ActionMailer::Base.deliveries.size', 2 do
  37. Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
  38. end
  39. end
  40. end
  41. def test_validate
  42. comment = Comment.new(:commented => @news)
  43. assert !comment.save
  44. assert_equal 2, comment.errors.count
  45. end
  46. def test_destroy
  47. comment = Comment.find(1)
  48. assert comment.destroy
  49. @news.reload
  50. assert_equal 0, @news.comments_count
  51. end
  52. end