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.

news_test.rb 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 NewsTest < ActiveSupport::TestCase
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules, :news
  21. def valid_news
  22. {:title => 'Test news', :description => 'Lorem ipsum etc', :author => User.first}
  23. end
  24. def setup
  25. User.current = nil
  26. end
  27. def test_create_should_send_email_notification
  28. ActionMailer::Base.deliveries.clear
  29. news = Project.find(1).news.new(valid_news)
  30. with_settings :notified_events => %w(news_added) do
  31. assert news.save
  32. end
  33. assert_equal 2, ActionMailer::Base.deliveries.size
  34. end
  35. def test_should_include_news_for_projects_with_news_enabled
  36. project = projects(:projects_001)
  37. assert project.enabled_modules.any?{|em| em.name == 'news'}
  38. # News.latest should return news from projects_001
  39. assert News.latest.any? {|news| news.project == project}
  40. end
  41. def test_should_not_include_news_for_projects_with_news_disabled
  42. EnabledModule.where(["project_id = ? AND name = ?", 2, 'news']).delete_all
  43. project = Project.find(2)
  44. # Add a piece of news to the project
  45. news = project.news.create(valid_news)
  46. # News.latest should not return that new piece of news
  47. assert News.latest.include?(news) == false
  48. end
  49. def test_should_only_include_news_from_projects_visibly_to_the_user
  50. assert News.latest(User.anonymous).all? {|news| news.project.is_public?}
  51. end
  52. def test_should_limit_the_amount_of_returned_news
  53. # Make sure we have a bunch of news stories
  54. 10.times {projects(:projects_001).news.create(valid_news)}
  55. assert_equal 2, News.latest(users(:users_002), 2).size
  56. assert_equal 6, News.latest(users(:users_002), 6).size
  57. end
  58. def test_should_return_5_news_stories_by_default
  59. # Make sure we have a bunch of news stories
  60. 10.times {projects(:projects_001).news.create(valid_news)}
  61. assert_equal 5, News.latest(users(:users_004)).size
  62. end
  63. def test_attachments_should_be_visible
  64. assert News.find(1).attachments_visible?(User.anonymous)
  65. end
  66. def test_attachments_should_be_deletable_with_manage_news_permission
  67. manager = User.find(2)
  68. assert News.find(1).attachments_deletable?(manager)
  69. end
  70. def test_attachments_should_not_be_deletable_without_manage_news_permission
  71. manager = User.find(2)
  72. Role.find_by_name('Manager').remove_permission!(:manage_news)
  73. assert !News.find(1).attachments_deletable?(manager)
  74. end
  75. end