Commit 6639c037dd077df006edfac211a195605c1ff251

Authored by Rafael Reggiani Manzo
Committed by Joenio Costa
1 parent ba4a9c7a

Refactor ContextContentBlock#foorter

It now relies on the BoxesHelper rendering structures which improve MVC
compliance by decoupling HTML generation from the model.
plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb
... ... @@ -7,9 +7,11 @@ class ContextContentPluginProfileController < ProfileController
7 7 contents = block.contents(profile.articles.find(params[:article_id]), p)
8 8  
9 9 if contents
  10 + @page = Article.find(params[:article_id])
  11 +
10 12 render :update do |page|
11   - page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents}
12   - page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] }
  13 + page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block}
  14 + page.replace_html "context_content_more_#{block.id}", :file => 'blocks/footers/context_content', :locals => {:block => block}
13 15 end
14 16 else
15 17 render :text => "invalid page", :status => 500
... ...
plugins/context_content/test/unit/context_content_block_test.rb
... ... @@ -123,26 +123,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase
123 123 assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types
124 124 end
125 125  
126   - should 'do not display pagination links if page is nil' do
127   - @page = nil
128   - assert_equal '', instance_eval(&@block.footer)
129   - end
130   -
131   - should 'do not display pagination links if it has until one page' do
132   - assert_equal '', instance_eval(&@block.footer)
133   - end
134   -
135   - should 'display pagination links if it has more than one page' do
136   - @block.limit = 2
137   - @page = fast_create(Folder)
138   - article1 = fast_create(TinyMceArticle, :parent_id => @page.id)
139   - article2 = fast_create(TinyMceArticle, :parent_id => @page.id)
140   - article3 = fast_create(TinyMceArticle, :parent_id => @page.id)
141   - expects(:content_tag).once
142   - expects(:render).with(has_entry(:partial => 'blocks/more'))
143   - instance_eval(&@block.footer)
144   - end
145   -
146 126 should 'return box owner on profile method call' do
147 127 profile = fast_create(Community)
148 128 box = Box.create!(:owner => profile)
... ... @@ -180,7 +160,34 @@ class ContextContentBlockViewTest < ActionView::TestCase
180 160 article.expects(:view_url).returns('http://test.noosfero.plugins')
181 161 @block.expects(:contents).with(@page).returns(contents)
182 162 @block.expects(:parent_title).with(contents).returns(@page.name)
183   - ActionView::Base.any_instance.expects(:block_title).returns(@page.name, @block.subtitle)
  163 + ActionView::Base.any_instance.expects(:block_title).with(@page.name, @block.subtitle).returns("")
  164 +
  165 + render_block_content(@block)
  166 + end
  167 +
  168 + should 'do not display pagination links if page is nil' do
  169 + @page = nil
  170 +
  171 + assert_equal "\n", render_block_content(@block)
  172 + end
  173 +
  174 + should 'do not display pagination links if it has until one page' do
  175 + assert_equal "\n", render_block_content(@block)
  176 + end
  177 +
  178 + should 'display pagination links if it has more than one page' do
  179 + @block.limit = 2
  180 + @page = fast_create(Folder)
  181 + article1 = fast_create(TinyMceArticle, :parent_id => @page.id)
  182 + article2 = fast_create(TinyMceArticle, :parent_id => @page.id)
  183 + article3 = fast_create(TinyMceArticle, :parent_id => @page.id)
  184 + contents = [article1, article2, article3]
  185 + contents.each do |article|
  186 + article.expects(:view_url).returns('http://test.noosfero.plugins')
  187 + end
  188 +
  189 + ActionView::Base.any_instance.expects(:block_title).returns("")
  190 + @block.expects(:contents).with(@page).returns(contents)
184 191  
185 192 render_block_content(@block)
186 193 end
... ...
plugins/context_content/views/blocks/_more.html.erb
... ... @@ -1,4 +0,0 @@
1   -<% if contents.total_pages > 1 %>
2   - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%>
3   - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%>
4   -<% end %>
plugins/context_content/views/blocks/footers/context_content.html.erb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<% contents = block.contents(@page)
  2 + unless contents.blank? %>
  3 + <div id="context_content_more_<%= block.id %>" class="more_button">
  4 + <% if contents.total_pages > 1 %>
  5 + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => @page.id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%>
  6 + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => @page.id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%>
  7 + <% end %>
  8 + </div>
  9 +<% end %>
... ...