Commit ea44d410bb2b226538ecdd5878806003642ccb14
Committed by
Antonio Terceiro
1 parent
fd9ed84e
Exists in
staging
and in
42 other branches
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
Showing
8 changed files
with
48 additions
and
5 deletions
Show diff stats
app/helpers/catalog_helper.rb
| @@ -23,7 +23,7 @@ private | @@ -23,7 +23,7 @@ private | ||
| 23 | 23 | ||
| 24 | def product_category_name(profile, product_category) | 24 | def product_category_name(profile, product_category) |
| 25 | if profile.enabled? | 25 | if profile.enabled? |
| 26 | - link_to_category(product_category) | 26 | + link_to_product_category(product_category) |
| 27 | else | 27 | else |
| 28 | product_category ? product_category.full_name(' → ') : _('Uncategorized product') | 28 | product_category ? product_category.full_name(' → ') : _('Uncategorized product') |
| 29 | end | 29 | end |
app/helpers/display_helper.rb
| @@ -14,6 +14,14 @@ module DisplayHelper | @@ -14,6 +14,14 @@ module DisplayHelper | ||
| 14 | link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }) | 14 | link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }) |
| 15 | end | 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 | def txt2html(txt) | 25 | def txt2html(txt) |
| 18 | txt. | 26 | txt. |
| 19 | gsub( /\n\s*\n/, ' <p/> ' ). | 27 | gsub( /\n\s*\n/, ' <p/> ' ). |
app/views/catalog/show.rhtml
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | <% end %> | 15 | <% end %> |
| 16 | 16 | ||
| 17 | <p class="product_category"> | 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 | </p> | 19 | </p> |
| 20 | 20 | ||
| 21 | <% button_bar do %> | 21 | <% button_bar do %> |
app/views/manage_products/index.rhtml
| @@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
| 45 | <% @consumptions.each do |consumption| %> | 45 | <% @consumptions.each do |consumption| %> |
| 46 | <tr> | 46 | <tr> |
| 47 | <td> | 47 | <td> |
| 48 | - <strong><%= link_to_category(consumption.product_category) %></strong> | 48 | + <strong><%= link_to_product_category(consumption.product_category) %></strong> |
| 49 | <br/> | 49 | <br/> |
| 50 | <em><%= consumption.aditional_specifications %></em> | 50 | <em><%= consumption.aditional_specifications %></em> |
| 51 | </td> | 51 | </td> |
app/views/manage_products/show.rhtml
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | <p> <%= image_tag @product.image.public_filename if @product.image %> </p> | 3 | <p> <%= image_tag @product.image.public_filename if @product.image %> </p> |
| 4 | <p> <strong><%= _('Price:') %></strong> <%= @product.price %> </p> | 4 | <p> <strong><%= _('Price:') %></strong> <%= @product.price %> </p> |
| 5 | <p> <strong><%= _('Description:') %></strong> <%= txt2html @product.description if @product.description %> </p> | 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 | <%= button :back, _('back'), :action => 'index' %> | 8 | <%= button :back, _('back'), :action => 'index' %> |
| 9 | | 9 | |
app/views/search/_product.rhtml
| @@ -16,6 +16,6 @@ product_item_pos += 1 | @@ -16,6 +16,6 @@ product_item_pos += 1 | ||
| 16 | <% if product.enterprise %> | 16 | <% if product.enterprise %> |
| 17 | <li> <%= _('Suplier: %s') % link_to_homepage(product.enterprise.name, product.enterprise.identifier) %> </li> | 17 | <li> <%= _('Suplier: %s') % link_to_homepage(product.enterprise.name, product.enterprise.identifier) %> </li> |
| 18 | <% end %> | 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 | </ul> | 20 | </ul> |
| 21 | </li> | 21 | </li> |
test/functional/catalog_controller_test.rb
| @@ -12,6 +12,7 @@ class CatalogControllerTest < Test::Unit::TestCase | @@ -12,6 +12,7 @@ class CatalogControllerTest < Test::Unit::TestCase | ||
| 12 | 12 | ||
| 13 | @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent') | 13 | @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent') |
| 14 | end | 14 | end |
| 15 | + attr_accessor :enterprise | ||
| 15 | 16 | ||
| 16 | def test_local_files_reference | 17 | def test_local_files_reference |
| 17 | ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') | 18 | ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1') |
| @@ -113,4 +114,20 @@ class CatalogControllerTest < Test::Unit::TestCase | @@ -113,4 +114,20 @@ class CatalogControllerTest < Test::Unit::TestCase | ||
| 113 | end | 114 | end |
| 114 | end | 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 | end | 133 | end |
test/functional/manage_products_controller_test.rb
| @@ -274,5 +274,23 @@ class ManageProductsControllerTest < Test::Unit::TestCase | @@ -274,5 +274,23 @@ class ManageProductsControllerTest < Test::Unit::TestCase | ||
| 274 | 274 | ||
| 275 | assert_equivalent [pc1, pc2], assigns(:categories) | 275 | assert_equivalent [pc1, pc2], assigns(:categories) |
| 276 | end | 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 | end | 296 | end |