Commit 4594576f6607ec7fc21022e05f6d11985af4da4f
1 parent
2d904cef
Exists in
master
and in
29 other branches
ActionItem918: fixing catalog for disabled enteprises
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
app/helpers/catalog_helper.rb
@@ -11,11 +11,21 @@ include DisplayHelper | @@ -11,11 +11,21 @@ include DisplayHelper | ||
11 | content_tag('h3', link_to_product(product)) + | 11 | content_tag('h3', link_to_product(product)) + |
12 | content_tag('ul', | 12 | content_tag('ul', |
13 | (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + | 13 | (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + |
14 | - content_tag('li', profile.enabled? ? link_to_category(product.product_category) : product.product_category.full_name(' → ') , :class => 'product_category') | 14 | + content_tag('li', product_category_name(profile, product.product_category), :class => 'product_category') |
15 | ) + | 15 | ) + |
16 | (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')), | 16 | (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')), |
17 | :class => 'product') | 17 | :class => 'product') |
18 | } | 18 | } |
19 | content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') | 19 | content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') |
20 | end | 20 | end |
21 | + | ||
22 | +private | ||
23 | + | ||
24 | + def product_category_name(profile, product_category) | ||
25 | + if profile.enabled? | ||
26 | + link_to_category(product_category) | ||
27 | + else | ||
28 | + product_category ? product_category.full_name(' → ') : _('Uncategorized product') | ||
29 | + end | ||
30 | + end | ||
21 | end | 31 | end |
test/functional/catalog_controller_test.rb
@@ -105,4 +105,12 @@ class CatalogControllerTest < Test::Unit::TestCase | @@ -105,4 +105,12 @@ class CatalogControllerTest < Test::Unit::TestCase | ||
105 | assert_tag :tag => 'p', :attributes => { :class => 'product_price' }, :content => /Price:/ | 105 | assert_tag :tag => 'p', :attributes => { :class => 'product_price' }, :content => /Price:/ |
106 | end | 106 | end |
107 | 107 | ||
108 | + should 'not crash on index when product has no product_category and enterprise not enabled' do | ||
109 | + ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1', :enabled => false) | ||
110 | + prod = ent.products.create!(:name => 'Product test', :price => 50.00, :product_category => nil) | ||
111 | + assert_nothing_raised do | ||
112 | + get :index, :profile => ent.identifier | ||
113 | + end | ||
114 | + end | ||
115 | + | ||
108 | end | 116 | end |