From 9c0082e5cff14548ab35824060e5a1fa738f2b81 Mon Sep 17 00:00:00 2001 From: Daniela Feitosa Date: Sat, 9 May 2009 06:03:31 -0300 Subject: [PATCH] ActionItem937: home page must show news from a news portal community --- app/controllers/admin/admin_panel_controller.rb | 29 +++++++++++++++++++++++++++++ app/controllers/public/home_controller.rb | 11 +++++++++++ app/helpers/dates_helper.rb | 6 ++++-- app/models/article.rb | 15 +++++++++++++-- app/models/community.rb | 3 +++ app/models/environment.rb | 21 +++++++++++++++++++++ app/models/folder.rb | 4 ++++ app/models/profile.rb | 5 +++-- app/models/text_article.rb | 1 - app/sweepers/article_sweeper.rb | 4 ++++ app/views/admin_panel/index.rhtml | 1 + app/views/admin_panel/set_portal_community.rhtml | 9 +++++++++ app/views/admin_panel/set_portal_folders.rhtml | 13 +++++++++++++ app/views/cms/_published_article.rhtml | 1 - app/views/cms/edit.rhtml | 2 ++ app/views/home/index.rhtml | 33 ++++++++++++++++++++++++++++++++- app/views/tasks/_approve_article.rhtml | 1 + db/migrate/068_add_highlighted_to_articles.rb | 11 +++++++++++ db/schema.rb | 4 +++- public/stylesheets/common.css | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/functional/admin_panel_controller_test.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/functional/home_controller_test.rb | 30 ++++++++++++++++++++++++++++++ test/unit/article_test.rb | 14 ++++++++++++++ test/unit/community_test.rb | 28 ++++++++++++++++++++++++++++ test/unit/environment_test.rb | 29 +++++++++++++++++++++++++++++ test/unit/folder_test.rb | 29 +++++++++++++++++++++++++++++ 26 files changed, 425 insertions(+), 10 deletions(-) create mode 100644 app/views/admin_panel/set_portal_community.rhtml create mode 100644 app/views/admin_panel/set_portal_folders.rhtml create mode 100644 db/migrate/068_add_highlighted_to_articles.rb diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 933e686..2419cee 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -34,4 +34,33 @@ class AdminPanelController < AdminController end redirect_to :action => 'manage_templates' end + + def set_portal_community + env = environment + @portal_community = env.portal_community || Community.new + if request.post? + portal_community = env.communities.find_by_identifier(params[:portal_community_identifier]) + if portal_community + env.portal_community = portal_community + env.save + redirect_to :action => 'set_portal_folders' + else + flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment') + end + end + end + + def set_portal_folders + @portal_folders = environment.portal_community.articles.find_all_by_type('Folder') + if request.post? + env = environment + folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} + env.portal_folders = folders + if env.save + flash[:notice] = _('Saved the portal folders') + redirect_to :action => 'index' + end + end + @selected = (environment.portal_folders || []).map(&:id) + end end diff --git a/app/controllers/public/home_controller.rb b/app/controllers/public/home_controller.rb index 3636638..0acf562 100644 --- a/app/controllers/public/home_controller.rb +++ b/app/controllers/public/home_controller.rb @@ -1,6 +1,17 @@ class HomeController < PublicController def index + @has_news = false + if environment.enabled?('use_portal_community') && environment.portal_community + @has_news = true + @news_cache_key = "home_page_news_#{environment.id.to_s}" + if !read_fragment(@news_cache_key) + portal_community = environment.portal_community + @portal_news = portal_community.news(5) + @highlighted_news = portal_community.news(2, true) + @area_news = environment.portal_folders + end + end end end diff --git a/app/helpers/dates_helper.rb b/app/helpers/dates_helper.rb index 77b97fe..c833455 100644 --- a/app/helpers/dates_helper.rb +++ b/app/helpers/dates_helper.rb @@ -22,8 +22,10 @@ module DatesHelper end # formats a date for displaying. - def show_date(date) - if date + def show_date(date, use_numbers = false) + if date && use_numbers + _('%{month}/%{day}/%{year}') % { :day => date.day, :month => date.month, :year => date.year } + elsif date _('%{month} %{day}, %{year}') % { :day => date.day, :month => month_name(date.month), :year => date.year } else '' diff --git a/app/models/article.rb b/app/models/article.rb index 42f15f0..9fb22e4 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -98,7 +98,7 @@ class Article < ActiveRecord::Base # oldest. # # Only includes articles where advertise == true - def self.recent(limit) + def self.recent(limit, extra_conditions = {}) # FIXME this method is a horrible hack options = { :limit => limit, :conditions => [ @@ -117,7 +117,13 @@ class Article < ActiveRecord::Base scoped_methods.last[:find][:joins].index('profiles') ) options.delete(:include) end - self.find(:all, options) + if extra_conditions == {} + self.find(:all, options) + else + with_scope :find => {:conditions => extra_conditions} do + self.find(:all, options) + end + end end # retrives the most commented articles, sorted by the comment count (largest @@ -265,6 +271,11 @@ class Article < ActiveRecord::Base (params[:month] ? "-month-#{params[:month]}" : '') end + def first_paragraph + body =~ /(.*<\/p>)/ + $1 + end + private def sanitize_tag_list diff --git a/app/models/community.rb b/app/models/community.rb index 77510d9..850590d 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -41,4 +41,7 @@ class Community < Organization environment.community_template end + def news(limit = 30, highlight = false) + recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight]) + end end diff --git a/app/models/environment.rb b/app/models/environment.rb index f8fef0d..4a69f9d 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -47,6 +47,7 @@ class Environment < ActiveRecord::Base 'media_panel' => _('Media panel in WYSIWYG editor'), 'select_preferred_domain' => _('Select preferred domains per profile'), 'display_wizard_signup' => _('Display wizard signup'), + 'use_portal_community' => _('Use the portal as news source for front page'), } end @@ -539,6 +540,26 @@ class Environment < ActiveRecord::Base settings[:replace_enterprise_template_when_enable] = value end + def portal_community + Community[settings[:portal_community_identifier]] + end + + def portal_community=(value) + settings[:portal_community_identifier] = value.identifier + end + + def is_portal_community?(profile) + portal_community == profile + end + + def portal_folders + (settings[:portal_folders] || []).map{|fid| Folder.find(:first, :conditions => {:profile_id => portal_community.id, :id => fid})} + end + + def portal_folders=(folders) + settings[:portal_folders] = folders.map(&:id) + end + after_create :create_templates def create_templates diff --git a/app/models/folder.rb b/app/models/folder.rb index 8198f55..9fbe2b4 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -65,6 +65,10 @@ class Folder < Article false end + def news(limit = 30, highlight = false) + profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) + end + has_many :images, :class_name => 'Article', :foreign_key => 'parent_id', :order => 'type, name', diff --git a/app/models/profile.rb b/app/models/profile.rb index 918a6fd..85dfbd2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -288,8 +288,8 @@ class Profile < ActiveRecord::Base # # +limit+ is the maximum number of documents to be returned. It defaults to # 10. - def recent_documents(limit = 10) - self.articles.recent(limit) + def recent_documents(limit = 10, options = {}) + self.articles.recent(limit, options) end class << self @@ -605,4 +605,5 @@ class Profile < ActiveRecord::Base def folders self.articles.find(:all, :conditions => ['type in (?)', ['Folder', 'Blog']]) end + end diff --git a/app/models/text_article.rb b/app/models/text_article.rb index 0c7305c..c919b5e 100644 --- a/app/models/text_article.rb +++ b/app/models/text_article.rb @@ -2,5 +2,4 @@ class TextArticle < Article xss_terminate :only => [ :name, :abstract, :body ] - end diff --git a/app/sweepers/article_sweeper.rb b/app/sweepers/article_sweeper.rb index dd786e2..77644ca 100644 --- a/app/sweepers/article_sweeper.rb +++ b/app/sweepers/article_sweeper.rb @@ -15,6 +15,10 @@ protected article.hierarchy.each {|a| expire_fragment(/#{a.cache_key}/) } blocks = article.profile.blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} + env = article.profile.environment + if env.portal_community == article.profile + expire_fragment("home_page_news_#{env.id}") + end end def expire_fragment(*args) diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml index 63ee4bf..9a3006e 100644 --- a/app/views/admin_panel/index.rhtml +++ b/app/views/admin_panel/index.rhtml @@ -13,4 +13,5 @@
  • <%= link_to _('Manage Templates'), :action => 'manage_templates' %>
  • <%= link_to _('Edit Templates'), :action => 'edit_templates' %>
  • <%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %>
  • +
  • <%= link_to _('Set Portal'), :action => 'set_portal_community' %>
  • diff --git a/app/views/admin_panel/set_portal_community.rhtml b/app/views/admin_panel/set_portal_community.rhtml new file mode 100644 index 0000000..dbc1693 --- /dev/null +++ b/app/views/admin_panel/set_portal_community.rhtml @@ -0,0 +1,9 @@ +

    <%= _('Set Environment Portal') %>

    + +<% form_tag do %> + <%= labelled_form_field(_('Portal identifier'), text_field_tag('portal_community_identifier', @portal_community.identifier, :size => 40) ) %> + + <% button_bar do %> + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %> + <% end %> +<% end %> diff --git a/app/views/admin_panel/set_portal_folders.rhtml b/app/views/admin_panel/set_portal_folders.rhtml new file mode 100644 index 0000000..ab69986 --- /dev/null +++ b/app/views/admin_panel/set_portal_folders.rhtml @@ -0,0 +1,13 @@ +

    <%= _('Select folders') %>

    + +

    <%= _('Select what folder will hold the news for witch area of the initial page of the environment') %>

    + +<% form_tag do %> + <% (1..4).each do |i| %> + <%= labelled_select _('Area %d: ') % i, 'folders[]', :id, :name, @selected[i-1], @portal_folders %>
    + <% end %> + + <% button_bar do %> + <%= submit_button 'save', _('Save'), :cancel => {:action => 'index'} %> + <% end %> +<% end %> diff --git a/app/views/cms/_published_article.rhtml b/app/views/cms/_published_article.rhtml index 5be82c8..96a00a8 100644 --- a/app/views/cms/_published_article.rhtml +++ b/app/views/cms/_published_article.rhtml @@ -1,2 +1 @@ <%= f.text_field 'name', :size => '64' %> - diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index 1f370a7..2536230 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -11,6 +11,8 @@ <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> + <%= f.check_box(:highlighted) if environment.is_portal_community?(profile) %> + <% button_bar do %> <%= submit_button :save, _('Save') %> <% end %> diff --git a/app/views/home/index.rhtml b/app/views/home/index.rhtml index 7ad5476..55b9c09 100644 --- a/app/views/home/index.rhtml +++ b/app/views/home/index.rhtml @@ -2,7 +2,38 @@ <%= lightbox_button(:new, _('Signup'), { :controller => 'account', :action => 'wizard' }, :class => 'wizard') %> <% end %> -<%= environment.description %> +<% if @has_news %> +

    <%= _('News') %>

    + <% cache @news_cache_key do %> +
    + <% @highlighted_news.each do |highlighted| %> +

    <%= link_to(highlighted.title, highlighted.url) %>
    +

    +
    <%= highlighted.first_paragraph %>
    +
    + <% end%> +
    + +
    + <% @portal_news.each do |news| %> +

    <%= link_to(news.title, news.url) %>

    + <% end%> +
    + + <% @area_news.each_with_index do |folder, i| %> + <% content_tag(:div, :class => ["news-area", ['even', 'odd'][i%2]].join(' ')) do %> +

    <%= link_to folder.title, folder.url %>

    + + <%end %> + <% end %> + <% end %> +<% else %> + <%= environment.description %> +<% end %> <% if environment.enabled?('enterprise_activation') %> diff --git a/app/views/tasks/_approve_article.rhtml b/app/views/tasks/_approve_article.rhtml index 6e5447a..de2cc3c 100644 --- a/app/views/tasks/_approve_article.rhtml +++ b/app/views/tasks/_approve_article.rhtml @@ -22,6 +22,7 @@ <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %> <%= labelled_form_field(_('Select the folder where the article must be published'), select_folder('task', 'article_parent_id', task.target.folders)) %> + <%= labelled_form_field( _('Highlight'), check_box_tag(:highlighted, true)) %> <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %> diff --git a/db/migrate/068_add_highlighted_to_articles.rb b/db/migrate/068_add_highlighted_to_articles.rb new file mode 100644 index 0000000..a7930a5 --- /dev/null +++ b/db/migrate/068_add_highlighted_to_articles.rb @@ -0,0 +1,11 @@ +class AddHighlightedToArticles < ActiveRecord::Migration + def self.up + add_column :articles, :highlighted, :boolean, :default => false + add_column :article_versions, :highlighted, :boolean, :default => false + end + + def self.down + remove_column :articles, :highlighted + remove_column :article_versions, :highlighted + end +end diff --git a/db/schema.rb b/db/schema.rb index 159bdfc..f34944d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 67) do +ActiveRecord::Schema.define(:version => 68) do create_table "article_versions", :force => true do |t| t.integer "article_id" @@ -44,6 +44,7 @@ ActiveRecord::Schema.define(:version => 67) do t.integer "hits", :default => 0 t.date "published_at" t.string "source" + t.boolean "highlighted", :default => false end create_table "articles", :force => true do |t| @@ -79,6 +80,7 @@ ActiveRecord::Schema.define(:version => 67) do t.integer "hits", :default => 0 t.date "published_at" t.string "source" + t.boolean "highlighted", :default => false end create_table "articles_categories", :id => false, :force => true do |t| diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index 064352a..275e2e9 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -481,4 +481,66 @@ div.pending-tasks { #wizard-content h1 { font-size: 22px; +======= + + +#portal-news { + font-size: 11px; +} + +#portal-news a, #highlighted-news a, .news-area a { + text-decoration: none; +} + +#portal-news a:hover, #highlighted-news a:hover, .news-area a:hover { + text-decoration: underline; +} + +.headline img { + float:left; + margin: 5px; + width: 140px; + height: 100px; +} + +.news-area { + border: 1px solid black; + height: 170px; + width: 49%; + margin: 3px 0px; + font-size: 11px; + overflow: hidden; +} + +#content .news-area h3 { + margin-top: 0px; + padding: 2px; + background-color: #CCC; + font-size: 15px; +} + +.news-area ul { + padding: 2px; +} + +.news-area li { + list-style: none; + margin: 0px 2px 10px 2px; +} + +.even { + float: left; +} + +.odd { + float: right; +} + +.news-symbol { + background-color: #CCC; + color: #FFF; +} + +.post-date { + color: #E68A00; } diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index 1186f66..58c3ce5 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -147,4 +147,73 @@ class AdminPanelControllerTest < Test::Unit::TestCase assert_tag :tag => "script", :content => /tinyMCE\.init/ end + should 'set portal community' do + e = Environment.default + @controller.stubs(:environment).returns(e) + c = Community.create!(:name => 'portal_community') + + post :set_portal_community, :portal_community_identifier => c.identifier + + assert_equal c, e.portal_community + end + + should 'redirect to set portal folders' do + e = Environment.default + @controller.stubs(:environment).returns(e) + c = Community.create!(:name => 'portal_community') + + post :set_portal_community, :portal_community_identifier => c.identifier + + assert_response :redirect + assert_redirected_to :action => 'set_portal_folders' + end + + should 'not have a portal community from other environment' do + e = Environment.default + @controller.stubs(:environment).returns(e) + other_e = Environment.create!(:name => 'other environment') + c = Community.create!(:name => 'portal community', :environment => other_e) + + post :set_portal_community, :portal_community_identifier => c.identifier + e.reload + + assert_not_equal c, e.portal_community + end + + should 'give error when portal community is not given' do + post :set_portal_community, :portal_community_identifier => 'no_community' + assert_response :success + assert_template 'set_portal_community' + end + + should 'give portal_community folders as option for portal folders' do + env = Environment.default + c = Community.create!(:name => 'portal') + env.portal_community = c + local = Folder.create!(:profile => c, :name => 'local news') + tech = Folder.create!(:profile => c, :name => 'tech news') + politics = Folder.create!(:profile => c, :name => 'politics news') + env.save! + + get :set_portal_folders + assert_tag :tag => 'option', :attributes => {:value => local.id}, :content => local.name + assert_tag :tag => 'option', :attributes => {:value => tech.id}, :content => tech.name + assert_tag :tag => 'option', :attributes => {:value => politics.id}, :content => politics.name + end + + should 'save a list of folders as portal folders for the environment' do + env = Environment.default + @controller.stubs(:environment).returns(env) + c = Community.create!(:name => 'portal') + env.portal_community = c + local = Folder.create!(:profile => c, :name => 'local news') + discarded = Folder.create!(:profile => c, :name => 'discarded news') + tech = Folder.create!(:profile => c, :name => 'tech news') + politics = Folder.create!(:profile => c, :name => 'politics news') + env.save! + + post :set_portal_folders, :folders => [local, politics, tech].map(&:id) + + assert_equal [local, politics, tech].map(&:id), env.portal_folders.map(&:id) + end end diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index c922a00..41d22c1 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -40,4 +40,34 @@ all_fixtures assert_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} end + should 'not display news from portal if disabled in environment' do + env = Environment.default + env.disable('use_portal_community') + env.save! + + get :index + assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' } + end + + should 'not display news from portal if environment doesnt have portal community' do + env = Environment.default + env.enable('use_portal_community') + env.save! + + get :index + assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' } + end + + should 'display news from portal if enabled and has portal community' do + env = Environment.default + env.enable('use_portal_community') + + c = Community.create!(:name => 'community test') + env.portal_community = c + + env.save! + + get :index + assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} + end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 7196539..84340b4 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -228,6 +228,15 @@ class ArticleTest < Test::Unit::TestCase assert_equal [ second ], Article.recent(nil) end + should 'accept extra conditions to find recent' do + p = create_user('usr1').person + Article.destroy_all + a1 = p.articles.create!(:name => 'first') + a2 = p.articles.create!(:name => 'second') + + assert_equal [ a1 ], Article.recent(nil, :name => 'first') + end + should 'require that subclasses define description' do assert_raise NotImplementedError do Article.description @@ -707,4 +716,9 @@ class ArticleTest < Test::Unit::TestCase assert_equal 'article-id-34-year-2009-month-04', a.cache_key(:year => '2009', :month => '04') end + should 'not be highlighted by default' do + a = Article.new + assert !a.highlighted + end + end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 34f876c..6d4fd22 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -117,4 +117,32 @@ class CommunityTest < Test::Unit::TestCase assert ! community.errors.invalid?(:contact_phone) end + should 'return newest text articles as news' do + c = Community.create!(:name => 'test_com') + f = Folder.create!(:name => 'folder', :profile => c) + u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + older_t = TinyMceArticle.create!(:name => 'old news', :profile => c) + t = TinyMceArticle.create!(:name => 'news', :profile => c) + t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) + + assert_equal [t_in_f, t], c.news(2) + end + + should 'not return highlighted news when not asked' do + c = Community.create!(:name => 'test_com') + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) + t = TinyMceArticle.create!(:name => 'news', :profile => c) + + assert_equal [t].map(&:slug), c.news(2).map(&:slug) + end + + should 'return highlighted news when asked' do + c = Community.create!(:name => 'test_com') + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) + t = TinyMceArticle.create!(:name => 'news', :profile => c) + + assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug) + end + + end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 954cab9..10e9022 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -716,4 +716,33 @@ class EnvironmentTest < Test::Unit::TestCase assert_not_equal 'default', e.icon_theme end + should 'have a portal community' do + e = Environment.default + c = Community.create!(:name => 'portal community') + + assert_respond_to e, :portal_community + e.portal_community = c; e.save! + e.reload + + assert_equal c, e.portal_community + end + + should 'have a set of portal folders' do + e = Environment.default + + assert_respond_to e, :portal_folders + c = e.portal_community = Community.create!(:name => 'portal community') + news_folder = Folder.create!(:name => 'news folder', :profile => c) + + e.portal_folders = [news_folder] + e.save!; e.reload + + assert_equal [news_folder], e.portal_folders + end + + should 'return empty array when no portal folders' do + e = Environment.default + + assert_equal [], e.portal_folders + end end diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb index 147fb29..053e438 100644 --- a/test/unit/folder_test.rb +++ b/test/unit/folder_test.rb @@ -107,4 +107,33 @@ class FolderTest < ActiveSupport::TestCase assert_equal [image], f.images.paginate(:page => 2, :per_page => 1) end + should 'return newest text articles as news' do + c = Community.create!(:name => 'test_com') + folder = Folder.create!(:name => 'folder', :profile => c) + f = Folder.create!(:name => 'folder', :profile => c, :parent => folder) + u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => folder) + older_t = TinyMceArticle.create!(:name => 'old news', :profile => c, :parent => folder) + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) + t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) + + assert_equal [t], folder.news(1) + end + + should 'not return highlighted news when not asked' do + c = Community.create!(:name => 'test_com') + folder = Folder.create!(:name => 'folder', :profile => c) + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) + + assert_equal [t].map(&:slug), folder.news(2).map(&:slug) + end + + should 'return highlighted news when asked' do + c = Community.create!(:name => 'test_com') + folder = Folder.create!(:name => 'folder', :profile => c) + highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) + t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) + + assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug) + end end -- libgit2 0.21.2