diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 1523893..3735409 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -72,7 +72,7 @@ class ManageProductsController < ApplicationController def edit_category @product = @profile.products.find(params[:id]) - @category = @product.product_category + @category = @product.product_category || ProductCategory.first @categories = ProductCategory.top_level_for(environment) @edit = true @level = @category.level diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 5e48e1c..e2a0550 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -123,6 +123,13 @@ class ManageProductsControllerTest < Test::Unit::TestCase assert_template 'shared/_dialog_error_messages' end + should "not crash if product has no category" do + product = fast_create(Product, :enterprise_id => @enterprise.id) + assert_nothing_raised do + post 'edit_category', :profile => @enterprise.identifier, :id => product.id + end + end + should "destroy product" do product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) assert_difference Product, :count, -1 do -- libgit2 0.21.2