Do not error when creating variant for product without non-unit option type

This commit is contained in:
Rohan Mitchell
2014-02-27 11:28:07 +11:00
parent adf4c0e387
commit 353d2a4d9c
2 changed files with 31 additions and 0 deletions

View File

@@ -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

View File

@@ -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")