Commit e6c086315c508ee7629fdaebd97a9107874d7f99

Authored by Braulio Bhavamitra
2 parents e1163b1c c44cbbc4

Merge branch 'refactor_profile_members_headlines' into 'master'

Remove ProfileMembersHeadlinesBlock#content

This method was in violation of MVC principles and its logic is now
handled by the BoxesHelper.

Minor adaptations to the view and a rename were required in order to
meet BoxesHelper expectations.

See merge request !908
plugins/profile_members_headlines/lib/profile_members_headlines_block.rb
... ... @@ -35,12 +35,4 @@ class ProfileMembersHeadlinesBlock < Block
35 35 result.select{ |p| p.has_headline? }.slice(0..limit-1)
36 36 end
37 37  
38   - def content(args={})
39   - block = self
40   - members = authors_list
41   - proc do
42   - render :file => 'blocks/headlines', :locals => { :block => block, :members => members }
43   - end
44   - end
45   -
46 38 end
... ...
plugins/profile_members_headlines/test/unit/profile_members_headlines_block_test.rb
1 1 require 'test_helper'
  2 +require 'boxes_helper'
2 3  
3 4 class ProfileMembersHeadlinesBlockTest < ActiveSupport::TestCase
4 5  
5 6 include Noosfero::Plugin::HotSpot
  7 + include BoxesHelper
6 8  
7 9 def setup
8 10 @environment = fast_create(Environment)
... ... @@ -32,8 +34,8 @@ class ProfileMembersHeadlinesBlockTest &lt; ActiveSupport::TestCase
32 34 block = ProfileMembersHeadlinesBlock.create
33 35 block.stubs(:owner).returns(community)
34 36  
35   - self.expects(:render).with(:file => 'blocks/headlines', :locals => { :block => block, :members => []}).returns('file-without-authors-and-headlines')
36   - assert_equal 'file-without-authors-and-headlines', instance_eval(&block.content)
  37 + self.expects(:render).with(:template => 'blocks/profile_members_headlines', :locals => { :block => block }).returns('file-without-authors-and-headlines')
  38 + assert_equal 'file-without-authors-and-headlines', render_block_content(block)
37 39 end
38 40  
39 41 should 'display headlines file' do
... ... @@ -41,8 +43,8 @@ class ProfileMembersHeadlinesBlockTest &lt; ActiveSupport::TestCase
41 43 block.stubs(:owner).returns(community)
42 44 blog = fast_create(Blog, :profile_id => member1.id)
43 45 post = fast_create(TinyMceArticle, :name => 'headlines', :profile_id => member1.id, :parent_id => blog.id)
44   - self.expects(:render).with(:file => 'blocks/headlines', :locals => { :block => block, :members => []}).returns('file-with-authors-and-headlines')
45   - assert_equal 'file-with-authors-and-headlines', instance_eval(&block.content)
  46 + self.expects(:render).with(:template => 'blocks/profile_members_headlines', :locals => { :block => block }).returns('file-with-authors-and-headlines')
  47 + assert_equal 'file-with-authors-and-headlines', render_block_content(block)
46 48 end
47 49  
48 50 should 'select only authors with articles and selected roles to display' do
... ...
plugins/profile_members_headlines/views/blocks/headlines.html.erb
... ... @@ -1,39 +0,0 @@
1   -<%= block_title(block.title, block.subtitle) %>
2   -
3   -<% unless members.empty? %>
4   - <div class='headlines-container'>
5   - <% members.each do |member| %>
6   - <div>
7   - <% headline = member.headline %>
8   - <%= link_to_profile(profile_image(member, :big) + content_tag(:p, member.short_name), member.identifier, {:class => 'author'}) %>
9   - <div class='post'>
10   - <h4><%= link_to(headline.title, headline.url, :class => 'title') %></h4>
11   - <div class='lead'>
12   - <%= headline.short_lead %>
13   - </div>
14   - <div class='date'>
15   - <%= show_date(headline.published_at) %>
16   - </div>
17   - <div class='tags'>
18   - <%= safe_join(headline.tags.map { |t| link_to(t, :controller => 'profile', :profile => member.identifier, :action => 'tags', :id => t.name ) }, "\n") %>
19   - </div>
20   - </div>
21   - </div>
22   - <% end %>
23   - </div>
24   - <% if block.navigation %>
25   - <div class='headlines-block-pager'>
26   - </div>
27   - <% end %>
28   -
29   - <script>
30   - (function($) {
31   - var options = {fx: 'fade', pause: 1, fastOnEvent: 1, timeout: <%= block.interval * 1000 %>};
32   - options.pager = '#block-<%= block.id %> .headlines-block-pager';
33   - $('#block-<%= block.id %> .headlines-container').cycle(options);
34   - })(jQuery);
35   - </script>
36   -<% else %>
37   - <em><%= _('No headlines to be shown.') %></em>
38   -<% end %>
39   -
plugins/profile_members_headlines/views/blocks/profile_members_headlines.html.erb 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<%= block_title(block.title, block.subtitle) %>
  2 +<% members = block.authors_list %>
  3 +
  4 +<% unless members.empty? %>
  5 + <div class='headlines-container'>
  6 + <% members.each do |member| %>
  7 + <div>
  8 + <% headline = member.headline %>
  9 + <%= link_to_profile(profile_image(member, :big) + content_tag(:p, member.short_name), member.identifier, {:class => 'author'}) %>
  10 + <div class='post'>
  11 + <h4><%= link_to(headline.title, headline.url, :class => 'title') %></h4>
  12 + <div class='lead'>
  13 + <%= headline.short_lead %>
  14 + </div>
  15 + <div class='date'>
  16 + <%= show_date(headline.published_at) %>
  17 + </div>
  18 + <div class='tags'>
  19 + <%= safe_join(headline.tags.map { |t| link_to(t, :controller => 'profile', :profile => member.identifier, :action => 'tags', :id => t.name ) }, "\n") %>
  20 + </div>
  21 + </div>
  22 + </div>
  23 + <% end %>
  24 + </div>
  25 + <% if block.navigation %>
  26 + <div class='headlines-block-pager'>
  27 + </div>
  28 + <% end %>
  29 +
  30 + <script>
  31 + (function($) {
  32 + var options = {fx: 'fade', pause: 1, fastOnEvent: 1, timeout: <%= block.interval * 1000 %>};
  33 + options.pager = '#block-<%= block.id %> .headlines-block-pager';
  34 + $('#block-<%= block.id %> .headlines-container').cycle(options);
  35 + })(jQuery);
  36 + </script>
  37 +<% else %>
  38 + <em><%= _('No headlines to be shown.') %></em>
  39 +<% end %>
  40 +
... ...