diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb
index ba24d17..c1195e7 100644
--- a/app/helpers/catalog_helper.rb
+++ b/app/helpers/catalog_helper.rb
@@ -23,7 +23,7 @@ private
def product_category_name(profile, product_category)
if profile.enabled?
- link_to_category(product_category)
+ link_to_product_category(product_category)
else
product_category ? product_category.full_name(' → ') : _('Uncategorized product')
end
diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb
index 3478c68..f14e08b 100644
--- a/app/helpers/display_helper.rb
+++ b/app/helpers/display_helper.rb
@@ -14,6 +14,14 @@ module DisplayHelper
link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname })
end
+ def link_to_product_category(category)
+ if category
+ link_to(category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id, :host => category.environment.default_hostname)
+ else
+ _('Uncategorized product')
+ end
+ end
+
def txt2html(txt)
txt.
gsub( /\n\s*\n/, '
' ).
diff --git a/app/views/catalog/show.rhtml b/app/views/catalog/show.rhtml
index 40c9fa4..22330c5 100644
--- a/app/views/catalog/show.rhtml
+++ b/app/views/catalog/show.rhtml
@@ -15,7 +15,7 @@
<% end %>
-<%= _('Category: %s ') % link_to_category(@product.product_category) %>
+<%= _('Category: %s ') % link_to_product_category(@product.product_category) %>
<% button_bar do %>
diff --git a/app/views/manage_products/index.rhtml b/app/views/manage_products/index.rhtml
index 99dade0..20db4f6 100644
--- a/app/views/manage_products/index.rhtml
+++ b/app/views/manage_products/index.rhtml
@@ -45,7 +45,7 @@
<% @consumptions.each do |consumption| %>
- <%= link_to_category(consumption.product_category) %>
+ <%= link_to_product_category(consumption.product_category) %>
<%= consumption.aditional_specifications %>
|
diff --git a/app/views/manage_products/show.rhtml b/app/views/manage_products/show.rhtml
index 12e8be2..09ed89a 100644
--- a/app/views/manage_products/show.rhtml
+++ b/app/views/manage_products/show.rhtml
@@ -3,7 +3,7 @@
<%= image_tag @product.image.public_filename if @product.image %>
<%= _('Price:') %> <%= @product.price %>
<%= _('Description:') %> <%= txt2html @product.description if @product.description %>
- <%= _('Category:') %> <%= link_to_category(@product.product_category) %>
+ <%= _('Category:') %> <%= link_to_product_category(@product.product_category) %>
<%= button :back, _('back'), :action => 'index' %>
diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml
index 1f3e1c8..09ba5cf 100644
--- a/app/views/search/_product.rhtml
+++ b/app/views/search/_product.rhtml
@@ -16,6 +16,6 @@ product_item_pos += 1
<% if product.enterprise %>
<%= _('Suplier: %s') % link_to_homepage(product.enterprise.name, product.enterprise.identifier) %>
<% end %>
- <%= _('Category:') + ' ' + (product.product_category ? link_to(product.product_category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => product.product_category.id) : _('Uncategorized product')) %>
+ <%=_('Category:') + ' ' + link_to_product_category(product.product_category) %>
diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb
index 91eb6ed..79aee27 100644
--- a/test/functional/catalog_controller_test.rb
+++ b/test/functional/catalog_controller_test.rb
@@ -12,6 +12,7 @@ class CatalogControllerTest < Test::Unit::TestCase
@enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent')
end
+ attr_accessor :enterprise
def test_local_files_reference
ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
@@ -113,4 +114,20 @@ class CatalogControllerTest < Test::Unit::TestCase
end
end
+ should 'link to assets products wiht product category in the link to product category on index' do
+ pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment)
+ prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc)
+
+ get :index, :profile => enterprise.identifier
+ assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
+ end
+
+ should 'link to assets products wiht product category in the link to product category on show' do
+ pc = ProductCategory.create!(:name => 'some product', :environment => enterprise.environment)
+ prod = enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => pc)
+
+ get :show, :id => prod.id, :profile => enterprise.identifier
+ assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
+ end
+
end
diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb
index 7229055..b09c21b 100644
--- a/test/functional/manage_products_controller_test.rb
+++ b/test/functional/manage_products_controller_test.rb
@@ -274,5 +274,23 @@ class ManageProductsControllerTest < Test::Unit::TestCase
assert_equivalent [pc1, pc2], assigns(:categories)
end
+
+ should 'links to products asset for consumption link' do
+ pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment)
+ @enterprise.consumptions.create!(:product_category => pc)
+
+ get :index, :profile => @enterprise.identifier
+
+ assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
+ end
+
+ should 'links to products asset for product category link when showing' do
+ pc = ProductCategory.create!(:name => 'test_category', :environment =>@enterprise.environment)
+ p = @enterprise.products.create!(:name => 'test product', :product_category => pc)
+
+ get :show, :profile => @enterprise.identifier, :id => p.id
+
+ assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
+ end
end
--
libgit2 0.21.2