diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index 9003b1f..ba24d17 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -11,11 +11,21 @@ include DisplayHelper content_tag('h3', link_to_product(product)) + content_tag('ul', (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + - content_tag('li', profile.enabled? ? link_to_category(product.product_category) : product.product_category.full_name(' → ') , :class => 'product_category') + content_tag('li', product_category_name(profile, product.product_category), :class => 'product_category') ) + (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')), :class => 'product') } content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') end + +private + + def product_category_name(profile, product_category) + if profile.enabled? + link_to_category(product_category) + else + product_category ? product_category.full_name(' → ') : _('Uncategorized product') + end + end end diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index 0cbc308..91eb6ed 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -105,4 +105,12 @@ class CatalogControllerTest < Test::Unit::TestCase assert_tag :tag => 'p', :attributes => { :class => 'product_price' }, :content => /Price:/ end + should 'not crash on index when product has no product_category and enterprise not enabled' do + ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1', :enabled => false) + prod = ent.products.create!(:name => 'Product test', :price => 50.00, :product_category => nil) + assert_nothing_raised do + get :index, :profile => ent.identifier + end + end + end -- libgit2 0.21.2