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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. :user_preferences, :roles, :members, :member_roles
  21. def setup
  22. User.current = nil
  23. @jsmith = User.find(2)
  24. @news = News.find(1)
  25. end
  26. def test_create
  27. comment = Comment.new(:commented => @news, :author => @jsmith, :comments => "my comment")
  28. assert comment.save
  29. @news.reload
  30. assert_equal 2, @news.comments_count
  31. end
  32. def test_create_should_send_notification
  33. Watcher.create!(:watchable => @news, :user => @jsmith)
  34. with_settings :notified_events => %w(news_comment_added) do
  35. assert_difference 'ActionMailer::Base.deliveries.size', 2 do
  36. Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
  37. end
  38. end
  39. end
  40. def test_validate
  41. comment = Comment.new(:commented => @news)
  42. assert !comment.save
  43. assert_equal 2, comment.errors.count
  44. end
  45. def test_destroy
  46. comment = Comment.find(1)
  47. assert comment.destroy
  48. @news.reload
  49. assert_equal 0, @news.comments_count
  50. end
  51. end