Commit 9d4eed1bcf05c2f7b6c5884e92eead3fb526e857

Authored by AntonioTerceiro
1 parent fe5818e0

ActionItem514: caching the correct content

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2256 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/views/layouts/application.rhtml
@@ -94,9 +94,10 @@ @@ -94,9 +94,10 @@
94 { :controller=>"home" }, 94 { :controller=>"home" },
95 :id=>"menu_link_to_envhome", 95 :id=>"menu_link_to_envhome",
96 :title=>@environment.name %> 96 :title=>@environment.name %>
97 - <% cache(:controller => 'public', :action => 'categories_menu', :asset => params[:asset]) do %> 97 + <% cache(:controller => 'public', :action => 'categories_menu') do %>
98 <%= render :file => 'shared/categories_menu' %> 98 <%= render :file => 'shared/categories_menu' %>
99 <% end %> 99 <% end %>
  100 + <%= render :file => 'shared/assets_menu' %>
100 </div><!-- id='navigation_bar' --> 101 </div><!-- id='navigation_bar' -->
101 <script type="text/javascript"> 102 <script type="text/javascript">
102 prepareMenu('navigation_bar', { timeout: 1000 }); 103 prepareMenu('navigation_bar', { timeout: 1000 });
app/views/shared/categories_menu.rhtml
@@ -4,29 +4,9 @@ @@ -4,29 +4,9 @@
4 <%= item.name %> 4 <%= item.name %>
5 <ul> 5 <ul>
6 <% item.children_for_menu.each do |child| %> 6 <% item.children_for_menu.each do |child| %>
7 - <% if (@controller.controller_name == 'search') && (@controller.action_name == 'assets') %>  
8 - <li><%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'assets', :asset => params[:asset], :category_path => child.explode_path) %></li>  
9 - <% else %>  
10 - <li><%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'category_index', :category_path => child.explode_path) %></li>  
11 - <% end %> 7 + <li><%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'category_index', :category_path => child.explode_path) %></li>
12 <% end %> 8 <% end %>
13 </ul> 9 </ul>
14 </li> 10 </li>
15 <% end %> 11 <% end %>
16 </ul><!-- fim id="cat_menu" --> 12 </ul><!-- fim id="cat_menu" -->
17 -  
18 -<div id="assets_menu">  
19 - <%= theme_opt_menu_search %>  
20 - <div id="assets_menu_list" class="top_extra_menu">  
21 - <ul id="assets_menu_ul">  
22 - <%= generate_assets_menu %>  
23 - </ul>  
24 - </div><!-- fim id="assets_menu_list" -->  
25 - <div id="assets_menu_layout_iten"></div>  
26 -</div><!-- fim id="assets_menu" -->  
27 -  
28 -<script type="text/javascript">  
29 - if ( assetsMenu.autoOpen ) {  
30 - setAutoOpenMenu( $("assets_menu") );  
31 - }  
32 -</script>  
test/integration/categories_menu_test.rb
@@ -13,19 +13,30 @@ class CategoriesMenuTest &lt; ActionController::IntegrationTest @@ -13,19 +13,30 @@ class CategoriesMenuTest &lt; ActionController::IntegrationTest
13 13
14 should 'display link to categories' do 14 should 'display link to categories' do
15 get '/' 15 get '/'
16 - assert_tag :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } 16 + assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
17 end 17 end
18 18
19 should 'display link to sub-categories' do 19 should 'display link to sub-categories' do
20 get '/cat/food' 20 get '/cat/food'
21 # there must be a link to the subcategory 21 # there must be a link to the subcategory
22 - assert_tag :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } 22 + assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
23 end 23 end
24 24
25 should 'link to other assets in the same category when viewing an asset' do 25 should 'link to other assets in the same category when viewing an asset' do
26 get '/assets/articles/food/vegetables' 26 get '/assets/articles/food/vegetables'
27 - assert_no_tag :tag => 'a', :attributes => { :href => '/cat/food/vegetables' }  
28 - assert_tag :tag => 'a', :attributes => { :href => '/assets/enterprises/food/vegetables' } 27 + assert_no_tag :attributes => { :id => 'assets_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
  28 + assert_tag :attributes => { :id => 'assets_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/assets/enterprises/food/vegetables' } }
  29 + end
  30 +
  31 + should "always link to category's initial page in category menu" do
  32 + get '/assets/products/food/vegetables'
  33 + assert_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/cat/food/vegetables' } }
  34 + assert_no_tag :attributes => { :id => 'cat_menu' }, :descendant => { :tag => 'a', :attributes => { :href => '/assets/products/food/vegetables' } }
  35 + end
  36 +
  37 + should 'cache the categories menu' do
  38 + ActionView::Base.any_instance.expects(:cache).with(:controller => 'public', :action => 'categories_menu')
  39 + get '/'
29 end 40 end
30 41
31 end 42 end