@@ -0,0 +1,63 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2008 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 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class NewsTest < Test::Unit::TestCase | |||
|
21 | fixtures :projects, :users, :roles, :members, :enabled_modules, :news | |||
|
22 | ||||
|
23 | def setup | |||
|
24 | end | |||
|
25 | ||||
|
26 | def test_should_include_news_for_projects_with_news_enabled | |||
|
27 | project = projects(:projects_001) | |||
|
28 | assert project.enabled_modules.any?{ |em| em.name == 'news' } | |||
|
29 | ||||
|
30 | # News.latest should return news from projects_001 | |||
|
31 | assert News.latest.any? { |news| news.project == project } | |||
|
32 | end | |||
|
33 | ||||
|
34 | def test_should_not_include_news_for_projects_with_news_disabled | |||
|
35 | # The projects_002 (OnlineStore) doesn't have the news module enabled, use that project for this test | |||
|
36 | project = projects(:projects_002) | |||
|
37 | assert ! project.enabled_modules.any?{ |em| em.name == 'news' } | |||
|
38 | ||||
|
39 | # Add a piece of news to the project | |||
|
40 | news = project.news.create(:title => 'Test news', :description => 'This should not be returned by News.latest') | |||
|
41 | ||||
|
42 | # News.latest should not return that new piece of news | |||
|
43 | assert News.latest.include?(news) == false | |||
|
44 | end | |||
|
45 | ||||
|
46 | def test_should_only_include_news_from_projects_visibly_to_the_user | |||
|
47 | # users_001 has no memberships so can only get news from public project | |||
|
48 | assert News.latest(users(:users_001)).all? { |news| news.project.is_public? } | |||
|
49 | end | |||
|
50 | ||||
|
51 | def test_should_limit_the_amount_of_returned_news | |||
|
52 | # Make sure we have a bunch of news stories | |||
|
53 | 10.times { projects(:projects_001).news.create(:title => 'Test news', :description => 'Lorem ipsum etc') } | |||
|
54 | assert_equal 2, News.latest(users(:users_002), 2).size | |||
|
55 | assert_equal 6, News.latest(users(:users_002), 6).size | |||
|
56 | end | |||
|
57 | ||||
|
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(:title => 'Test news', :description => 'Lorem ipsum etc') } | |||
|
61 | assert_equal 5, News.latest(users(:users_004)).size | |||
|
62 | end | |||
|
63 | end |
@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -29,7 +29,7 class News < ActiveRecord::Base | |||||
29 | acts_as_activity_provider :find_options => {:include => [:project, :author]} |
|
29 | acts_as_activity_provider :find_options => {:include => [:project, :author]} | |
30 |
|
30 | |||
31 | # returns latest news for projects visible by user |
|
31 | # returns latest news for projects visible by user | |
32 |
def self.latest(user= |
|
32 | def self.latest(user = User.current, count = 5) | |
33 |
find(:all, :limit => count, :conditions => Project. |
|
33 | find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
34 | end |
|
34 | end | |
35 | end |
|
35 | end |
General Comments 0
You need to be logged in to leave comments.
Login now