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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class CommentTest < ActiveSupport::TestCase
  19. fixtures :users, :news, :comments
  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. Setting.notified_events << 'news_comment_added'
  32. Watcher.create!(:watchable => @news, :user => @jsmith)
  33. assert_difference 'ActionMailer::Base.deliveries.size' do
  34. Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
  35. end
  36. end
  37. def test_validate
  38. comment = Comment.new(:commented => @news)
  39. assert !comment.save
  40. assert_equal 2, comment.errors.count
  41. end
  42. def test_destroy
  43. comment = Comment.find(1)
  44. assert comment.destroy
  45. @news.reload
  46. assert_equal 0, @news.comments_count
  47. end
  48. end