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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 CommentTest < ActiveSupport::TestCase
  19. fixtures :users, :email_addresses, :news, :comments, :projects, :enabled_modules
  20. def setup
  21. @jsmith = User.find(2)
  22. @news = News.find(1)
  23. end
  24. def test_create
  25. comment = Comment.new(:commented => @news, :author => @jsmith, :comments => "my comment")
  26. assert comment.save
  27. @news.reload
  28. assert_equal 2, @news.comments_count
  29. end
  30. def test_create_should_send_notification
  31. Watcher.create!(:watchable => @news, :user => @jsmith)
  32. with_settings :notified_events => %w(news_comment_added) do
  33. assert_difference 'ActionMailer::Base.deliveries.size' do
  34. Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
  35. end
  36. end
  37. end
  38. def test_validate
  39. comment = Comment.new(:commented => @news)
  40. assert !comment.save
  41. assert_equal 2, comment.errors.count
  42. end
  43. def test_destroy
  44. comment = Comment.find(1)
  45. assert comment.destroy
  46. @news.reload
  47. assert_equal 0, @news.comments_count
  48. end
  49. end