Commit 2c1b5026184466b60b3ffe361adcde2ea0fe7ff5
1 parent
5e5b5f3a
Exists in
master
and in
22 other branches
Product edit category doesn't crash if product has no category
(ActionItem2007)
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/manage_products_controller.rb
... | ... | @@ -72,7 +72,7 @@ class ManageProductsController < ApplicationController |
72 | 72 | |
73 | 73 | def edit_category |
74 | 74 | @product = @profile.products.find(params[:id]) |
75 | - @category = @product.product_category | |
75 | + @category = @product.product_category || ProductCategory.first | |
76 | 76 | @categories = ProductCategory.top_level_for(environment) |
77 | 77 | @edit = true |
78 | 78 | @level = @category.level | ... | ... |
test/functional/manage_products_controller_test.rb
... | ... | @@ -123,6 +123,13 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
123 | 123 | assert_template 'shared/_dialog_error_messages' |
124 | 124 | end |
125 | 125 | |
126 | + should "not crash if product has no category" do | |
127 | + product = fast_create(Product, :enterprise_id => @enterprise.id) | |
128 | + assert_nothing_raised do | |
129 | + post 'edit_category', :profile => @enterprise.identifier, :id => product.id | |
130 | + end | |
131 | + end | |
132 | + | |
126 | 133 | should "destroy product" do |
127 | 134 | product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) |
128 | 135 | assert_difference Product, :count, -1 do | ... | ... |