From 353d2a4d9cc732714c126ca1b189ce2c08d1c3cd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 27 Feb 2014 11:28:07 +1100 Subject: [PATCH] Do not error when creating variant for product without non-unit option type --- .../admin/variants_controller_decorator.rb | 10 +++++++++ spec/features/admin/variants_spec.rb | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/controllers/spree/admin/variants_controller_decorator.rb b/app/controllers/spree/admin/variants_controller_decorator.rb index a567f0a8c9..16a37d5286 100644 --- a/app/controllers/spree/admin/variants_controller_decorator.rb +++ b/app/controllers/spree/admin/variants_controller_decorator.rb @@ -1,3 +1,13 @@ Spree::Admin::VariantsController.class_eval do helper 'spree/products' + + + protected + + def create_before + option_values = params[:new_variant] + option_values.andand.each_value {|id| @object.option_values << OptionValue.find(id)} + @object.save + end + end diff --git a/spec/features/admin/variants_spec.rb b/spec/features/admin/variants_spec.rb index 7e178ab443..d05aa75ef8 100644 --- a/spec/features/admin/variants_spec.rb +++ b/spec/features/admin/variants_spec.rb @@ -7,6 +7,27 @@ feature %q{ include AuthenticationWorkflow include WebHelper + scenario "creating a new variant" do + # Given a product with a unit-related option type + p = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1") + + # When I create a variant on the product + login_to_admin_section + click_link 'Products' + within('#sub_nav') { click_link 'Products' } + click_link p.name + click_link 'Variants' + click_link 'New Variant' + + fill_in 'variant_unit_value', with: '1' + fill_in 'variant_unit_description', with: 'foo' + click_button 'Create' + + # Then the variant should have been created + page.should have_content "Variant \"#{p.name}\" has been successfully created!" + end + + scenario "editing unit value and description for a variant" do # Given a product with unit-related option types, with a variant p = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")