Commit d214907008bb1c0a509cd4104597e34ffd00219a

Authored by Joenio Costa
2 parents c10cc29c 086869c7

Merge branch 'refactor_recent_content_plugin' into 'master'

Refactor recent content plugin

This complies with the new block rendering strategy based on BoxesHelper.

New tests were added in order to ensure the behaviour has been preserved.

Travis build: https://travis-ci.org/rafamanzo/noosfero/builds/123566945

See merge request !856
plugins/recent_content/lib/recent_content_block.rb
... ... @@ -44,13 +44,6 @@ class RecentContentBlock < Block
44 44  
45 45 include DatesHelper
46 46  
47   - def content(args={})
48   - block = self
49   - proc do
50   - render :file => 'blocks/recent_content_block', :locals => {:root => block.root, :block => block}
51   - end
52   - end
53   -
54 47 def mode?(attr)
55 48 attr == self.presentation_mode
56 49 end
... ...
plugins/recent_content/test/unit/recent_content_block_test.rb
... ... @@ -73,3 +73,73 @@ class RecentContentBlockTest < ActiveSupport::TestCase
73 73 end
74 74  
75 75 end
  76 +
  77 +require 'boxes_helper'
  78 +
  79 +class RecentContentBlockViewTest < ActionView::TestCase
  80 + include BoxesHelper
  81 +
  82 + should 'show the alert when the block has no root' do
  83 + block = RecentContentBlock.new
  84 +
  85 + block.expects(:root).returns(nil)
  86 +
  87 + content = render_block_content(block)
  88 +
  89 + assert_match /#{_('This is the recent content block. Please edit it to show the content you want.')}/, content
  90 + end
  91 +
  92 + should 'show the title and the child titles when the block has a root and is set to title only mode' do
  93 + profile = create_user('testuser').person
  94 +
  95 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  96 +
  97 + block = RecentContentBlock.new
  98 + block.stubs(:holder).returns(profile)
  99 + block.selected_folder = root.id
  100 + block.presentation_mode = 'title_only'
  101 +
  102 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  103 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  104 +
  105 + content = render_block_content(block)
  106 +
  107 + assert_match /Block Title/, content
  108 + end
  109 +
  110 + should 'show the title and the child titles and abstracts when the block has a root and is set to title and abstract mode' do
  111 + profile = create_user('testuser').person
  112 +
  113 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  114 +
  115 + block = RecentContentBlock.new
  116 + block.stubs(:holder).returns(profile)
  117 + block.selected_folder = root.id
  118 + block.presentation_mode = 'title_and_abstract'
  119 +
  120 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  121 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  122 +
  123 + content = render_block_content(block)
  124 +
  125 + assert_match /Block Title/, content
  126 + end
  127 +
  128 + should 'show the title and the child full content when the block has a root and has no mode set' do
  129 + profile = create_user('testuser').person
  130 +
  131 + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
  132 +
  133 + block = RecentContentBlock.new
  134 + block.stubs(:holder).returns(profile)
  135 + block.selected_folder = root.id
  136 + block.presentation_mode = ''
  137 +
  138 + ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
  139 + ActionView::Base.any_instance.expects(:profile).returns(profile)
  140 +
  141 + content = render_block_content(block)
  142 +
  143 + assert_match /Block Title/, content
  144 + end
  145 +end
... ...
plugins/recent_content/views/blocks/recent_content.html.erb 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +<% unless block.root.nil? %>
  2 + <div id="recent-content-block">
  3 + <% children = block.articles_of_folder(block.root, block.total_items)%>
  4 + <div class="recent-content">
  5 + <%= block_title(block.title.blank? ? c_("Recent content") : block.title, block.subtitle ) %>
  6 + <% if block.show_blog_picture and !block.root.image.nil? %>
  7 + <div class="recent-content-cover">
  8 + <%= image_tag(block.root.image.public_filename(:big)) %>
  9 + </div>
  10 + <% end %>
  11 + </div>
  12 + <% if block.mode?('title_only') %>
  13 + <div class="recent-content-title">
  14 + <ul>
  15 + <% children.each do |item| %>
  16 + <li> <%= link_to(h(item.title), item.url)%></li>
  17 + <% end %>
  18 + </ul>
  19 + </div>
  20 + <% elsif block.mode?('title_and_abstract') %>
  21 + <div class="recent-content-abstract">
  22 + <% children.each do |item| %>
  23 + <h2><%= link_to(item.title,item.url, :class => 'post-title')%></h2>
  24 + <span class="post-date"><%= show_date(item.published_at, true)%></span>
  25 + <div class="headline"><%=item.lead%></div>
  26 + <p class="highlighted-news-read-more"><%= link_to(_('Read more'), item.url) %></p>
  27 + <% end %>
  28 + </div>
  29 + <% else %>
  30 + <div class="recent-content-full">
  31 + <% children.each do |item| %>
  32 + <h2><%= link_to(item.title,item.url, :class => 'post-title')%></h2>
  33 + <span class="post-date"><%= show_date(item.published_at, true)%></span>
  34 + <div class="headline"><%=item.body%></div>
  35 + <p class="highlighted-news-read-more"><%= link_to(_('Read more'), item.url) %></p>
  36 + <% end %>
  37 + </div>
  38 + <% end %>
  39 + <%= link_to _('View All'), :profile => profile.identifier, :controller => 'content_viewer', :action => 'view_page', :page => block.root.path %>
  40 + </div>
  41 +<% else %>
  42 + <span class="alert-block">
  43 + <%= _('This is the recent content block. Please edit it to show the content you want.') %>
  44 + </span>
  45 +<% end %>
... ...
plugins/recent_content/views/blocks/recent_content_block.html.erb
... ... @@ -1,45 +0,0 @@
1   -<% unless root.nil? %>
2   - <div id="recent-content-block">
3   - <% children = block.articles_of_folder(root, block.total_items)%>
4   - <div class="recent-content">
5   - <%= block_title(block.title.blank? ? c_("Recent content") : block.title, block.subtitle ) %>
6   - <% if block.show_blog_picture and !root.image.nil? %>
7   - <div class="recent-content-cover">
8   - <%= image_tag(root.image.public_filename(:big)) %>
9   - </div>
10   - <% end %>
11   - </div>
12   - <% if block.mode?('title_only') %>
13   - <div class="recent-content-title">
14   - <ul>
15   - <% children.each do |item| %>
16   - <li> <%= link_to(h(item.title), item.url)%></li>
17   - <% end %>
18   - </ul>
19   - </div>
20   - <% elsif block.mode?('title_and_abstract') %>
21   - <div class="recent-content-abstract">
22   - <% children.each do |item| %>
23   - <h2><%= link_to(item.title,item.url, :class => 'post-title')%></h2>
24   - <span class="post-date"><%= show_date(item.published_at, true)%></span>
25   - <div class="headline"><%=item.lead%></div>
26   - <p class="highlighted-news-read-more"><%= link_to(_('Read more'), item.url) %></p>
27   - <% end %>
28   - </div>
29   - <% else %>
30   - <div class="recent-content-full">
31   - <% children.each do |item| %>
32   - <h2><%= link_to(item.title,item.url, :class => 'post-title')%></h2>
33   - <span class="post-date"><%= show_date(item.published_at, true)%></span>
34   - <div class="headline"><%=item.body%></div>
35   - <p class="highlighted-news-read-more"><%= link_to(_('Read more'), item.url) %></p>
36   - <% end %>
37   - </div>
38   - <% end %>
39   - <%= link_to _('View All'), :profile => profile.identifier, :controller => 'content_viewer', :action => 'view_page', :page => block.root.path %>
40   - </div>
41   -<% else %>
42   - <span class="alert-block">
43   - <%= _('This is the recent content block. Please edit it to show the content you want.') %>
44   - </span>
45   -<% end %>