diff --git a/app/controllers/spree/api/variants_controller_decorator.rb b/app/controllers/spree/api/variants_controller_decorator.rb index a225c4c401..3bc8b1c511 100644 --- a/app/controllers/spree/api/variants_controller_decorator.rb +++ b/app/controllers/spree/api/variants_controller_decorator.rb @@ -3,11 +3,7 @@ Spree::Api::VariantsController.class_eval do @variant = scope.find(params[:variant_id]) authorize! :delete, @variant - @variant.deleted_at = Time.now() - if @variant.save - respond_with(@variant, :status => 204) - else - invalid_resource!(@variant) - end + @variant.delete + respond_with @variant, status: 204 end end diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 25d09ae097..c7aed600ea 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -51,6 +51,11 @@ Spree::Variant.class_eval do end end + def delete + self.update_column(:deleted_at, Time.now) + end + + private def update_weight_from_unit_value diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index f5a3dd146d..1c87397aec 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -276,6 +276,15 @@ module Spree end end + describe "deletion" do + it "marks the variant as deleted" do + v = create(:variant) + v.deleted_at.should be_nil + v.delete + v.deleted_at.should_not be_nil + end + end + describe "destruction" do it "destroys exchange variants" do v = create(:variant)