Commit 9c0082e5cff14548ab35824060e5a1fa738f2b81

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 001bf74b

ActionItem937: home page must show news from a news portal community

* made areas appear in the front page
  * folders can provide specific news for front page
  * adding condition to display news (feature and portal community defined)
  * admin can set the portal community
  * added cache to the news page
  * added migration for highlight attribute
  + renumbering migrations
app/controllers/admin/admin_panel_controller.rb
... ... @@ -34,4 +34,33 @@ class AdminPanelController < AdminController
34 34 end
35 35 redirect_to :action => 'manage_templates'
36 36 end
  37 +
  38 + def set_portal_community
  39 + env = environment
  40 + @portal_community = env.portal_community || Community.new
  41 + if request.post?
  42 + portal_community = env.communities.find_by_identifier(params[:portal_community_identifier])
  43 + if portal_community
  44 + env.portal_community = portal_community
  45 + env.save
  46 + redirect_to :action => 'set_portal_folders'
  47 + else
  48 + flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment')
  49 + end
  50 + end
  51 + end
  52 +
  53 + def set_portal_folders
  54 + @portal_folders = environment.portal_community.articles.find_all_by_type('Folder')
  55 + if request.post?
  56 + env = environment
  57 + folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})}
  58 + env.portal_folders = folders
  59 + if env.save
  60 + flash[:notice] = _('Saved the portal folders')
  61 + redirect_to :action => 'index'
  62 + end
  63 + end
  64 + @selected = (environment.portal_folders || []).map(&:id)
  65 + end
37 66 end
... ...
app/controllers/public/home_controller.rb
1 1 class HomeController < PublicController
2 2  
3 3 def index
  4 + @has_news = false
  5 + if environment.enabled?('use_portal_community') && environment.portal_community
  6 + @has_news = true
  7 + @news_cache_key = "home_page_news_#{environment.id.to_s}"
  8 + if !read_fragment(@news_cache_key)
  9 + portal_community = environment.portal_community
  10 + @portal_news = portal_community.news(5)
  11 + @highlighted_news = portal_community.news(2, true)
  12 + @area_news = environment.portal_folders
  13 + end
  14 + end
4 15 end
5 16  
6 17 end
... ...
app/helpers/dates_helper.rb
... ... @@ -22,8 +22,10 @@ module DatesHelper
22 22 end
23 23  
24 24 # formats a date for displaying.
25   - def show_date(date)
26   - if date
  25 + def show_date(date, use_numbers = false)
  26 + if date && use_numbers
  27 + _('%{month}/%{day}/%{year}') % { :day => date.day, :month => date.month, :year => date.year }
  28 + elsif date
27 29 _('%{month} %{day}, %{year}') % { :day => date.day, :month => month_name(date.month), :year => date.year }
28 30 else
29 31 ''
... ...
app/models/article.rb
... ... @@ -98,7 +98,7 @@ class Article &lt; ActiveRecord::Base
98 98 # oldest.
99 99 #
100 100 # Only includes articles where advertise == true
101   - def self.recent(limit)
  101 + def self.recent(limit, extra_conditions = {})
102 102 # FIXME this method is a horrible hack
103 103 options = { :limit => limit,
104 104 :conditions => [
... ... @@ -117,7 +117,13 @@ class Article &lt; ActiveRecord::Base
117 117 scoped_methods.last[:find][:joins].index('profiles') )
118 118 options.delete(:include)
119 119 end
120   - self.find(:all, options)
  120 + if extra_conditions == {}
  121 + self.find(:all, options)
  122 + else
  123 + with_scope :find => {:conditions => extra_conditions} do
  124 + self.find(:all, options)
  125 + end
  126 + end
121 127 end
122 128  
123 129 # retrives the most commented articles, sorted by the comment count (largest
... ... @@ -265,6 +271,11 @@ class Article &lt; ActiveRecord::Base
265 271 (params[:month] ? "-month-#{params[:month]}" : '')
266 272 end
267 273  
  274 + def first_paragraph
  275 + body =~ /(.*<\/p>)/
  276 + $1
  277 + end
  278 +
268 279 private
269 280  
270 281 def sanitize_tag_list
... ...
app/models/community.rb
... ... @@ -41,4 +41,7 @@ class Community &lt; Organization
41 41 environment.community_template
42 42 end
43 43  
  44 + def news(limit = 30, highlight = false)
  45 + recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight])
  46 + end
44 47 end
... ...
app/models/environment.rb
... ... @@ -47,6 +47,7 @@ class Environment &lt; ActiveRecord::Base
47 47 'media_panel' => _('Media panel in WYSIWYG editor'),
48 48 'select_preferred_domain' => _('Select preferred domains per profile'),
49 49 'display_wizard_signup' => _('Display wizard signup'),
  50 + 'use_portal_community' => _('Use the portal as news source for front page'),
50 51 }
51 52 end
52 53  
... ... @@ -539,6 +540,26 @@ class Environment &lt; ActiveRecord::Base
539 540 settings[:replace_enterprise_template_when_enable] = value
540 541 end
541 542  
  543 + def portal_community
  544 + Community[settings[:portal_community_identifier]]
  545 + end
  546 +
  547 + def portal_community=(value)
  548 + settings[:portal_community_identifier] = value.identifier
  549 + end
  550 +
  551 + def is_portal_community?(profile)
  552 + portal_community == profile
  553 + end
  554 +
  555 + def portal_folders
  556 + (settings[:portal_folders] || []).map{|fid| Folder.find(:first, :conditions => {:profile_id => portal_community.id, :id => fid})}
  557 + end
  558 +
  559 + def portal_folders=(folders)
  560 + settings[:portal_folders] = folders.map(&:id)
  561 + end
  562 +
542 563 after_create :create_templates
543 564  
544 565 def create_templates
... ...
app/models/folder.rb
... ... @@ -65,6 +65,10 @@ class Folder &lt; Article
65 65 false
66 66 end
67 67  
  68 + def news(limit = 30, highlight = false)
  69 + profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id])
  70 + end
  71 +
68 72 has_many :images, :class_name => 'Article',
69 73 :foreign_key => 'parent_id',
70 74 :order => 'type, name',
... ...
app/models/profile.rb
... ... @@ -288,8 +288,8 @@ class Profile &lt; ActiveRecord::Base
288 288 #
289 289 # +limit+ is the maximum number of documents to be returned. It defaults to
290 290 # 10.
291   - def recent_documents(limit = 10)
292   - self.articles.recent(limit)
  291 + def recent_documents(limit = 10, options = {})
  292 + self.articles.recent(limit, options)
293 293 end
294 294  
295 295 class << self
... ... @@ -605,4 +605,5 @@ class Profile &lt; ActiveRecord::Base
605 605 def folders
606 606 self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']])
607 607 end
  608 +
608 609 end
... ...
app/models/text_article.rb
... ... @@ -2,5 +2,4 @@
2 2 class TextArticle < Article
3 3  
4 4 xss_terminate :only => [ :name, :abstract, :body ]
5   -
6 5 end
... ...
app/sweepers/article_sweeper.rb
... ... @@ -15,6 +15,10 @@ protected
15 15 article.hierarchy.each {|a| expire_fragment(/#{a.cache_key}/) }
16 16 blocks = article.profile.blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}}
17 17 blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)}
  18 + env = article.profile.environment
  19 + if env.portal_community == article.profile
  20 + expire_fragment("home_page_news_#{env.id}")
  21 + end
18 22 end
19 23  
20 24 def expire_fragment(*args)
... ...
app/views/admin_panel/index.rhtml
... ... @@ -13,4 +13,5 @@
13 13 <li><%= link_to _('Manage Templates'), :action => 'manage_templates' %></li>
14 14 <li><%= link_to _('Edit Templates'), :action => 'edit_templates' %></li>
15 15 <li><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></li>
  16 + <li><%= link_to _('Set Portal'), :action => 'set_portal_community' %></li>
16 17 </ul>
... ...
app/views/admin_panel/set_portal_community.rhtml 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<h1> <%= _('Set Environment Portal') %></h1>
  2 +
  3 +<% form_tag do %>
  4 + <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %>
  5 +
  6 + <% button_bar do %>
  7 + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %>
  8 + <% end %>
  9 +<% end %>
... ...
app/views/admin_panel/set_portal_folders.rhtml 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<h1><%= _('Select folders') %></h1>
  2 +
  3 +<p><%= _('Select what folder will hold the news for witch area of the initial page of the environment') %></p>
  4 +
  5 +<% form_tag do %>
  6 + <% (1..4).each do |i| %>
  7 + <%= labelled_select _('Area %d: ') % i, 'folders[]', :id, :name, @selected[i-1], @portal_folders %> <br>
  8 + <% end %>
  9 +
  10 + <% button_bar do %>
  11 + <%= submit_button 'save', _('Save'), :cancel => {:action => 'index'} %>
  12 + <% end %>
  13 +<% end %>
... ...
app/views/cms/_published_article.rhtml
1 1 <%= f.text_field 'name', :size => '64' %>
2   -
... ...
app/views/cms/edit.rhtml
... ... @@ -11,6 +11,8 @@
11 11  
12 12 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
13 13  
  14 + <%= f.check_box(:highlighted) if environment.is_portal_community?(profile) %>
  15 +
14 16 <% button_bar do %>
15 17 <%= submit_button :save, _('Save') %>
16 18 <% end %>
... ...
app/views/home/index.rhtml
... ... @@ -2,7 +2,38 @@
2 2 <%= lightbox_button(:new, _('Signup'), { :controller => 'account', :action => 'wizard' }, :class => 'wizard') %>
3 3 <% end %>
4 4  
5   -<%= environment.description %>
  5 +<% if @has_news %>
  6 + <h3><%= _('News') %></h3>
  7 + <% cache @news_cache_key do %>
  8 + <div id='highlighted-news'>
  9 + <% @highlighted_news.each do |highlighted| %>
  10 + <p><%= link_to(highlighted.title, highlighted.url) %><br/>
  11 + <span class="post-date"><%= show_date(highlighted.published_at, true) %> </span></p>
  12 + <div class='headline'><%= highlighted.first_paragraph %></div>
  13 + <br style='clear:both' />
  14 + <% end%>
  15 + </div>
  16 +
  17 + <div id='portal-news'>
  18 + <% @portal_news.each do |news| %>
  19 + <p><span class="post-date"><%= show_date(news.published_at, true) %> </span><%= link_to(news.title, news.url) %></p>
  20 + <% end%>
  21 + </div>
  22 +
  23 + <% @area_news.each_with_index do |folder, i| %>
  24 + <% content_tag(:div, :class => ["news-area", ['even', 'odd'][i%2]].join(' ')) do %>
  25 + <h3><%= link_to folder.title, folder.url %></h3>
  26 + <ul>
  27 + <% folder.news(3).each do |news| %>
  28 + <li><span class='news-symbol'>&gt;</span> <%= link_to(news.title, news.url) %></li>
  29 + <% end%>
  30 + </ul>
  31 + <%end %>
  32 + <% end %>
  33 + <% end %>
  34 +<% else %>
  35 + <%= environment.description %>
  36 +<% end %>
6 37  
7 38 <% if environment.enabled?('enterprise_activation') %>
8 39  
... ...
app/views/tasks/_approve_article.rhtml
... ... @@ -22,6 +22,7 @@
22 22 <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %>
23 23  
24 24 <%= labelled_form_field(_('Select the folder where the article must be published'), select_folder('task', 'article_parent_id', task.target.folders)) %>
  25 + <%= labelled_form_field( _('Highlight'), check_box_tag(:highlighted, true)) %>
25 26 <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %>
26 27  
27 28 </div>
... ...
db/migrate/068_add_highlighted_to_articles.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddHighlightedToArticles < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :articles, :highlighted, :boolean, :default => false
  4 + add_column :article_versions, :highlighted, :boolean, :default => false
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :articles, :highlighted
  9 + remove_column :article_versions, :highlighted
  10 + end
  11 +end
... ...
db/schema.rb
... ... @@ -9,7 +9,7 @@
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11  
12   -ActiveRecord::Schema.define(:version => 67) do
  12 +ActiveRecord::Schema.define(:version => 68) do
13 13  
14 14 create_table "article_versions", :force => true do |t|
15 15 t.integer "article_id"
... ... @@ -44,6 +44,7 @@ ActiveRecord::Schema.define(:version =&gt; 67) do
44 44 t.integer "hits", :default => 0
45 45 t.date "published_at"
46 46 t.string "source"
  47 + t.boolean "highlighted", :default => false
47 48 end
48 49  
49 50 create_table "articles", :force => true do |t|
... ... @@ -79,6 +80,7 @@ ActiveRecord::Schema.define(:version =&gt; 67) do
79 80 t.integer "hits", :default => 0
80 81 t.date "published_at"
81 82 t.string "source"
  83 + t.boolean "highlighted", :default => false
82 84 end
83 85  
84 86 create_table "articles_categories", :id => false, :force => true do |t|
... ...
public/stylesheets/common.css
... ... @@ -481,4 +481,66 @@ div.pending-tasks {
481 481  
482 482 #wizard-content h1 {
483 483 font-size: 22px;
  484 +=======
  485 +
  486 +
  487 +#portal-news {
  488 + font-size: 11px;
  489 +}
  490 +
  491 +#portal-news a, #highlighted-news a, .news-area a {
  492 + text-decoration: none;
  493 +}
  494 +
  495 +#portal-news a:hover, #highlighted-news a:hover, .news-area a:hover {
  496 + text-decoration: underline;
  497 +}
  498 +
  499 +.headline img {
  500 + float:left;
  501 + margin: 5px;
  502 + width: 140px;
  503 + height: 100px;
  504 +}
  505 +
  506 +.news-area {
  507 + border: 1px solid black;
  508 + height: 170px;
  509 + width: 49%;
  510 + margin: 3px 0px;
  511 + font-size: 11px;
  512 + overflow: hidden;
  513 +}
  514 +
  515 +#content .news-area h3 {
  516 + margin-top: 0px;
  517 + padding: 2px;
  518 + background-color: #CCC;
  519 + font-size: 15px;
  520 +}
  521 +
  522 +.news-area ul {
  523 + padding: 2px;
  524 +}
  525 +
  526 +.news-area li {
  527 + list-style: none;
  528 + margin: 0px 2px 10px 2px;
  529 +}
  530 +
  531 +.even {
  532 + float: left;
  533 +}
  534 +
  535 +.odd {
  536 + float: right;
  537 +}
  538 +
  539 +.news-symbol {
  540 + background-color: #CCC;
  541 + color: #FFF;
  542 +}
  543 +
  544 +.post-date {
  545 + color: #E68A00;
484 546 }
... ...
test/functional/admin_panel_controller_test.rb
... ... @@ -147,4 +147,73 @@ class AdminPanelControllerTest &lt; Test::Unit::TestCase
147 147 assert_tag :tag => "script", :content => /tinyMCE\.init/
148 148 end
149 149  
  150 + should 'set portal community' do
  151 + e = Environment.default
  152 + @controller.stubs(:environment).returns(e)
  153 + c = Community.create!(:name => 'portal_community')
  154 +
  155 + post :set_portal_community, :portal_community_identifier => c.identifier
  156 +
  157 + assert_equal c, e.portal_community
  158 + end
  159 +
  160 + should 'redirect to set portal folders' do
  161 + e = Environment.default
  162 + @controller.stubs(:environment).returns(e)
  163 + c = Community.create!(:name => 'portal_community')
  164 +
  165 + post :set_portal_community, :portal_community_identifier => c.identifier
  166 +
  167 + assert_response :redirect
  168 + assert_redirected_to :action => 'set_portal_folders'
  169 + end
  170 +
  171 + should 'not have a portal community from other environment' do
  172 + e = Environment.default
  173 + @controller.stubs(:environment).returns(e)
  174 + other_e = Environment.create!(:name => 'other environment')
  175 + c = Community.create!(:name => 'portal community', :environment => other_e)
  176 +
  177 + post :set_portal_community, :portal_community_identifier => c.identifier
  178 + e.reload
  179 +
  180 + assert_not_equal c, e.portal_community
  181 + end
  182 +
  183 + should 'give error when portal community is not given' do
  184 + post :set_portal_community, :portal_community_identifier => 'no_community'
  185 + assert_response :success
  186 + assert_template 'set_portal_community'
  187 + end
  188 +
  189 + should 'give portal_community folders as option for portal folders' do
  190 + env = Environment.default
  191 + c = Community.create!(:name => 'portal')
  192 + env.portal_community = c
  193 + local = Folder.create!(:profile => c, :name => 'local news')
  194 + tech = Folder.create!(:profile => c, :name => 'tech news')
  195 + politics = Folder.create!(:profile => c, :name => 'politics news')
  196 + env.save!
  197 +
  198 + get :set_portal_folders
  199 + assert_tag :tag => 'option', :attributes => {:value => local.id}, :content => local.name
  200 + assert_tag :tag => 'option', :attributes => {:value => tech.id}, :content => tech.name
  201 + assert_tag :tag => 'option', :attributes => {:value => politics.id}, :content => politics.name
  202 + end
  203 +
  204 + should 'save a list of folders as portal folders for the environment' do
  205 + env = Environment.default
  206 + @controller.stubs(:environment).returns(env)
  207 + c = Community.create!(:name => 'portal')
  208 + env.portal_community = c
  209 + local = Folder.create!(:profile => c, :name => 'local news')
  210 + discarded = Folder.create!(:profile => c, :name => 'discarded news')
  211 + tech = Folder.create!(:profile => c, :name => 'tech news')
  212 + politics = Folder.create!(:profile => c, :name => 'politics news')
  213 + env.save!
  214 +
  215 + post :set_portal_folders, :folders => [local, politics, tech].map(&:id)
  216 +
  217 + assert_equal [local, politics, tech].map(&:id), env.portal_folders.map(&:id)
  218 + end
150 219 end
... ...
test/functional/home_controller_test.rb
... ... @@ -40,4 +40,34 @@ all_fixtures
40 40 assert_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}}
41 41 end
42 42  
  43 + should 'not display news from portal if disabled in environment' do
  44 + env = Environment.default
  45 + env.disable('use_portal_community')
  46 + env.save!
  47 +
  48 + get :index
  49 + assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' }
  50 + end
  51 +
  52 + should 'not display news from portal if environment doesnt have portal community' do
  53 + env = Environment.default
  54 + env.enable('use_portal_community')
  55 + env.save!
  56 +
  57 + get :index
  58 + assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' }
  59 + end
  60 +
  61 + should 'display news from portal if enabled and has portal community' do
  62 + env = Environment.default
  63 + env.enable('use_portal_community')
  64 +
  65 + c = Community.create!(:name => 'community test')
  66 + env.portal_community = c
  67 +
  68 + env.save!
  69 +
  70 + get :index
  71 + assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}}
  72 + end
43 73 end
... ...
test/unit/article_test.rb
... ... @@ -228,6 +228,15 @@ class ArticleTest &lt; Test::Unit::TestCase
228 228 assert_equal [ second ], Article.recent(nil)
229 229 end
230 230  
  231 + should 'accept extra conditions to find recent' do
  232 + p = create_user('usr1').person
  233 + Article.destroy_all
  234 + a1 = p.articles.create!(:name => 'first')
  235 + a2 = p.articles.create!(:name => 'second')
  236 +
  237 + assert_equal [ a1 ], Article.recent(nil, :name => 'first')
  238 + end
  239 +
231 240 should 'require that subclasses define description' do
232 241 assert_raise NotImplementedError do
233 242 Article.description
... ... @@ -707,4 +716,9 @@ class ArticleTest &lt; Test::Unit::TestCase
707 716 assert_equal 'article-id-34-year-2009-month-04', a.cache_key(:year => '2009', :month => '04')
708 717 end
709 718  
  719 + should 'not be highlighted by default' do
  720 + a = Article.new
  721 + assert !a.highlighted
  722 + end
  723 +
710 724 end
... ...
test/unit/community_test.rb
... ... @@ -117,4 +117,32 @@ class CommunityTest &lt; Test::Unit::TestCase
117 117 assert ! community.errors.invalid?(:contact_phone)
118 118 end
119 119  
  120 + should 'return newest text articles as news' do
  121 + c = Community.create!(:name => 'test_com')
  122 + f = Folder.create!(:name => 'folder', :profile => c)
  123 + u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
  124 + older_t = TinyMceArticle.create!(:name => 'old news', :profile => c)
  125 + t = TinyMceArticle.create!(:name => 'news', :profile => c)
  126 + t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f)
  127 +
  128 + assert_equal [t_in_f, t], c.news(2)
  129 + end
  130 +
  131 + should 'not return highlighted news when not asked' do
  132 + c = Community.create!(:name => 'test_com')
  133 + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true)
  134 + t = TinyMceArticle.create!(:name => 'news', :profile => c)
  135 +
  136 + assert_equal [t].map(&:slug), c.news(2).map(&:slug)
  137 + end
  138 +
  139 + should 'return highlighted news when asked' do
  140 + c = Community.create!(:name => 'test_com')
  141 + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true)
  142 + t = TinyMceArticle.create!(:name => 'news', :profile => c)
  143 +
  144 + assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug)
  145 + end
  146 +
  147 +
120 148 end
... ...
test/unit/environment_test.rb
... ... @@ -716,4 +716,33 @@ class EnvironmentTest &lt; Test::Unit::TestCase
716 716 assert_not_equal 'default', e.icon_theme
717 717 end
718 718  
  719 + should 'have a portal community' do
  720 + e = Environment.default
  721 + c = Community.create!(:name => 'portal community')
  722 +
  723 + assert_respond_to e, :portal_community
  724 + e.portal_community = c; e.save!
  725 + e.reload
  726 +
  727 + assert_equal c, e.portal_community
  728 + end
  729 +
  730 + should 'have a set of portal folders' do
  731 + e = Environment.default
  732 +
  733 + assert_respond_to e, :portal_folders
  734 + c = e.portal_community = Community.create!(:name => 'portal community')
  735 + news_folder = Folder.create!(:name => 'news folder', :profile => c)
  736 +
  737 + e.portal_folders = [news_folder]
  738 + e.save!; e.reload
  739 +
  740 + assert_equal [news_folder], e.portal_folders
  741 + end
  742 +
  743 + should 'return empty array when no portal folders' do
  744 + e = Environment.default
  745 +
  746 + assert_equal [], e.portal_folders
  747 + end
719 748 end
... ...
test/unit/folder_test.rb
... ... @@ -107,4 +107,33 @@ class FolderTest &lt; ActiveSupport::TestCase
107 107 assert_equal [image], f.images.paginate(:page => 2, :per_page => 1)
108 108 end
109 109  
  110 + should 'return newest text articles as news' do
  111 + c = Community.create!(:name => 'test_com')
  112 + folder = Folder.create!(:name => 'folder', :profile => c)
  113 + f = Folder.create!(:name => 'folder', :profile => c, :parent => folder)
  114 + u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => folder)
  115 + older_t = TinyMceArticle.create!(:name => 'old news', :profile => c, :parent => folder)
  116 + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder)
  117 + t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f)
  118 +
  119 + assert_equal [t], folder.news(1)
  120 + end
  121 +
  122 + should 'not return highlighted news when not asked' do
  123 + c = Community.create!(:name => 'test_com')
  124 + folder = Folder.create!(:name => 'folder', :profile => c)
  125 + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder)
  126 + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder)
  127 +
  128 + assert_equal [t].map(&:slug), folder.news(2).map(&:slug)
  129 + end
  130 +
  131 + should 'return highlighted news when asked' do
  132 + c = Community.create!(:name => 'test_com')
  133 + folder = Folder.create!(:name => 'folder', :profile => c)
  134 + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder)
  135 + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder)
  136 +
  137 + assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug)
  138 + end
110 139 end
... ...