diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 716e0b9885..f8711145d5 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -174,39 +174,6 @@ module Spree deleted_at end - def set_option_value(opt_name, opt_value) - # no option values on master - return if is_master - - option_type = Spree::OptionType.where(name: opt_name).first_or_initialize do |o| - o.presentation = opt_name - o.save! - end - - current_value = option_values.detect { |o| o.option_type.name == opt_name } - - if current_value.nil? - # then we have to check to make sure that the product has the option type - unless product.option_types.include? option_type - product.option_types << option_type - product.save - end - else - return if current_value.name == opt_value - - option_values.delete(current_value) - end - - option_value = Spree::OptionValue.where(option_type_id: option_type.id, - name: opt_value).first_or_initialize do |o| - o.presentation = opt_value - o.save! - end - - option_values << option_value - save - end - def option_value(opt_name) option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation) end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 422369f0e5..ccb1bcf3db 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -20,72 +20,6 @@ module Spree end end - context "product has other variants" do - describe "option value accessors" do - before { - @multi_variant = create(:variant, product: variant.product) - variant.product.reload - } - - let(:multi_variant) { @multi_variant } - - it "should set option value" do - expect(multi_variant.option_value('media_type')).to be_nil - - multi_variant.set_option_value('media_type', 'DVD') - expect(multi_variant.option_value('media_type')).to eq 'DVD' - - multi_variant.set_option_value('media_type', 'CD') - expect(multi_variant.option_value('media_type')).to eq 'CD' - end - - it "should not duplicate associated option values when set multiple times" do - multi_variant.set_option_value('media_type', 'CD') - - expect { - multi_variant.set_option_value('media_type', 'DVD') - }.to_not change(multi_variant.option_values, :count) - - expect { - multi_variant.set_option_value('coolness_type', 'awesome') - }.to change(multi_variant.option_values, :count).by(1) - end - end - - context "product has other variants" do - describe "option value accessors" do - before { - @multi_variant = create(:variant, product: variant.product) - variant.product.reload - } - - let(:multi_variant) { @multi_variant } - - it "should set option value" do - expect(multi_variant.option_value('media_type')).to be_nil - - multi_variant.set_option_value('media_type', 'DVD') - expect(multi_variant.option_value('media_type')).to eq 'DVD' - - multi_variant.set_option_value('media_type', 'CD') - expect(multi_variant.option_value('media_type')).to eq 'CD' - end - - it "should not duplicate associated option values when set multiple times" do - multi_variant.set_option_value('media_type', 'CD') - - expect { - multi_variant.set_option_value('media_type', 'DVD') - }.to_not change(multi_variant.option_values, :count) - - expect { - multi_variant.set_option_value('coolness_type', 'awesome') - }.to change(multi_variant.option_values, :count).by(1) - end - end - end - end - context "price parsing" do before(:each) do I18n.locale = I18n.default_locale