[Git][noosfero/noosfero][master] 3 commits: Refactor RecentContentBlock plugin
Joenio Costa
gitlab at mg.gitlab.com
Wed Apr 27 17:56:26 BRT 2016
Joenio Costa pushed to branch master at Noosfero / noosfero
Commits:
7bc3b2b3 by Rafael Reggiani Manzo at 2016-04-16T11:14:49-03:00
Refactor RecentContentBlock plugin
The view rendering has been removed from the model and now relies on the
structure at BoxesHelper.
This improves MVC compliance.
- - - - -
086869c7 by Rafael Reggiani Manzo at 2016-04-16T12:00:18-03:00
Add tests for RecentContentBlock rendering
Those were not covered and were necessary in order to give confidence
about the previous refactor correctness.
- - - - -
d2149070 by Joenio Costa at 2016-04-27T20:56:13+00:00
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
- - - - -
3 changed files:
- plugins/recent_content/lib/recent_content_block.rb
- plugins/recent_content/test/unit/recent_content_block_test.rb
- plugins/recent_content/views/blocks/recent_content_block.html.erb → plugins/recent_content/views/blocks/recent_content.html.erb
Changes:
=====================================
plugins/recent_content/lib/recent_content_block.rb
=====================================
--- a/plugins/recent_content/lib/recent_content_block.rb
+++ b/plugins/recent_content/lib/recent_content_block.rb
@@ -44,13 +44,6 @@ class RecentContentBlock < Block
include DatesHelper
- def content(args={})
- block = self
- proc do
- render :file => 'blocks/recent_content_block', :locals => {:root => block.root, :block => block}
- end
- end
-
def mode?(attr)
attr == self.presentation_mode
end
=====================================
plugins/recent_content/test/unit/recent_content_block_test.rb
=====================================
--- a/plugins/recent_content/test/unit/recent_content_block_test.rb
+++ b/plugins/recent_content/test/unit/recent_content_block_test.rb
@@ -73,3 +73,73 @@ class RecentContentBlockTest < ActiveSupport::TestCase
end
end
+
+require 'boxes_helper'
+
+class RecentContentBlockViewTest < ActionView::TestCase
+ include BoxesHelper
+
+ should 'show the alert when the block has no root' do
+ block = RecentContentBlock.new
+
+ block.expects(:root).returns(nil)
+
+ content = render_block_content(block)
+
+ assert_match /#{_('This is the recent content block. Please edit it to show the content you want.')}/, content
+ end
+
+ should 'show the title and the child titles when the block has a root and is set to title only mode' do
+ profile = create_user('testuser').person
+
+ root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
+
+ block = RecentContentBlock.new
+ block.stubs(:holder).returns(profile)
+ block.selected_folder = root.id
+ block.presentation_mode = 'title_only'
+
+ ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
+ ActionView::Base.any_instance.expects(:profile).returns(profile)
+
+ content = render_block_content(block)
+
+ assert_match /Block Title/, content
+ end
+
+ 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
+ profile = create_user('testuser').person
+
+ root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
+
+ block = RecentContentBlock.new
+ block.stubs(:holder).returns(profile)
+ block.selected_folder = root.id
+ block.presentation_mode = 'title_and_abstract'
+
+ ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
+ ActionView::Base.any_instance.expects(:profile).returns(profile)
+
+ content = render_block_content(block)
+
+ assert_match /Block Title/, content
+ end
+
+ should 'show the title and the child full content when the block has a root and has no mode set' do
+ profile = create_user('testuser').person
+
+ root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
+
+ block = RecentContentBlock.new
+ block.stubs(:holder).returns(profile)
+ block.selected_folder = root.id
+ block.presentation_mode = ''
+
+ ActionView::Base.any_instance.expects(:block_title).returns("Block Title")
+ ActionView::Base.any_instance.expects(:profile).returns(profile)
+
+ content = render_block_content(block)
+
+ assert_match /Block Title/, content
+ end
+end
=====================================
plugins/recent_content/views/blocks/recent_content_block.html.erb → plugins/recent_content/views/blocks/recent_content.html.erb
=====================================
--- a/plugins/recent_content/views/blocks/recent_content_block.html.erb
+++ b/plugins/recent_content/views/blocks/recent_content.html.erb
@@ -1,11 +1,11 @@
-<% unless root.nil? %>
+<% unless block.root.nil? %>
<div id="recent-content-block">
- <% children = block.articles_of_folder(root, block.total_items)%>
+ <% children = block.articles_of_folder(block.root, block.total_items)%>
<div class="recent-content">
<%= block_title(block.title.blank? ? c_("Recent content") : block.title, block.subtitle ) %>
- <% if block.show_blog_picture and !root.image.nil? %>
+ <% if block.show_blog_picture and !block.root.image.nil? %>
<div class="recent-content-cover">
- <%= image_tag(root.image.public_filename(:big)) %>
+ <%= image_tag(block.root.image.public_filename(:big)) %>
</div>
<% end %>
</div>
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c10cc29cdb86ec78dbdf8804c0a8d2e64a8d0e54...d214907008bb1c0a509cd4104597e34ffd00219a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160427/51b3c5d4/attachment-0001.html>
More information about the Noosfero-dev
mailing list