Commit ea44d410bb2b226538ecdd5878806003642ccb14

Authored by Moises Machado
Committed by Antonio Terceiro
1 parent fd9ed84e

ActionItem1195: changed the links for products categories

created a new helper link_to_product_category and used in:
  * catalog page
  * product show page
  * manage product show page
  * manage product index on consumption list
  * extracted from the search controller on listing products
app/helpers/catalog_helper.rb
... ... @@ -23,7 +23,7 @@ private
23 23  
24 24 def product_category_name(profile, product_category)
25 25 if profile.enabled?
26   - link_to_category(product_category)
  26 + link_to_product_category(product_category)
27 27 else
28 28 product_category ? product_category.full_name(' → ') : _('Uncategorized product')
29 29 end
... ...
app/helpers/display_helper.rb
... ... @@ -14,6 +14,14 @@ module DisplayHelper
14 14 link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname })
15 15 end
16 16  
  17 + def link_to_product_category(category)
  18 + if category
  19 + link_to(category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id, :host => category.environment.default_hostname)
  20 + else
  21 + _('Uncategorized product')
  22 + end
  23 + end
  24 +
17 25 def txt2html(txt)
18 26 txt.
19 27 gsub( /\n\s*\n/, ' <p/> ' ).
... ...
app/views/catalog/show.rhtml
... ... @@ -15,7 +15,7 @@
15 15 <% end %>
16 16  
17 17 <p class="product_category">
18   -<%= _('Category: %s ') % link_to_category(@product.product_category) %>
  18 +<%= _('Category: %s ') % link_to_product_category(@product.product_category) %>
19 19 </p>
20 20  
21 21 <% button_bar do %>
... ...
app/views/manage_products/index.rhtml
... ... @@ -45,7 +45,7 @@
45 45 <% @consumptions.each do |consumption| %>
46 46 <tr>
47 47 <td>
48   - <strong><%= link_to_category(consumption.product_category) %></strong>
  48 + <strong><%= link_to_product_category(consumption.product_category) %></strong>
49 49 <br/>
50 50 <em><%= consumption.aditional_specifications %></em>
51 51 </td>
... ...
app/views/manage_products/show.rhtml
... ... @@ -3,7 +3,7 @@
3 3 <p> <%= image_tag @product.image.public_filename if @product.image %> </p>
4 4 <p> <strong><%= _('Price:') %></strong> <%= @product.price %> </p>
5 5 <p> <strong><%= _('Description:') %></strong> <%= txt2html @product.description if @product.description %> </p>
6   -<p> <strong><%= _('Category:') %></strong> <%= link_to_category(@product.product_category) %> </p>
  6 +<p> <strong><%= _('Category:') %></strong> <%= link_to_product_category(@product.product_category) %> </p>
7 7  
8 8 <%= button :back, _('back'), :action => 'index' %>
9 9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
... ...
app/views/search/_product.rhtml
... ... @@ -16,6 +16,6 @@ product_item_pos += 1
16 16 <% if product.enterprise %>
17 17 <li> <%= _('Suplier: %s') % link_to_homepage(product.enterprise.name, product.enterprise.identifier) %> </li>
18 18 <% end %>
19   - <li> <%= _('Category:') + ' ' + (product.product_category ? link_to(product.product_category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => product.product_category.id) : _('Uncategorized product')) %> </li>
  19 + <li> <%=_('Category:') + ' ' + link_to_product_category(product.product_category) %>
20 20 </ul>
21 21 </li>
... ...
test/functional/catalog_controller_test.rb
... ... @@ -12,6 +12,7 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
12 12  
13 13 @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent')
14 14 end
  15 + attr_accessor :enterprise
15 16  
16 17 def test_local_files_reference
17 18 ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
... ... @@ -113,4 +114,20 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
113 114 end
114 115 end
115 116  
  117 + should 'link to assets products wiht product category in the link to product category on index' do
  118 + pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment)
  119 + prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc)
  120 +
  121 + get :index, :profile => enterprise.identifier
  122 + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
  123 + end
  124 +
  125 + should 'link to assets products wiht product category in the link to product category on show' do
  126 + pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment)
  127 + prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc)
  128 +
  129 + get :show, :id => prod.id, :profile => enterprise.identifier
  130 + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
  131 + end
  132 +
116 133 end
... ...
test/functional/manage_products_controller_test.rb
... ... @@ -274,5 +274,23 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
274 274  
275 275 assert_equivalent [pc1, pc2], assigns(:categories)
276 276 end
  277 +
  278 + should 'links to products asset for consumption link' do
  279 + pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment)
  280 + @enterprise.consumptions.create!(:product_category => pc)
  281 +
  282 + get :index, :profile => @enterprise.identifier
  283 +
  284 + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
  285 + end
  286 +
  287 + should 'links to products asset for product category link when showing' do
  288 + pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment)
  289 + p = @enterprise.products.create!(:name => 'test product', :product_category => pc)
  290 +
  291 + get :show, :profile => @enterprise.identifier, :id => p.id
  292 +
  293 + assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
  294 + end
277 295  
278 296 end
... ...