Remove line item adjustments if line item deleted

This commit is contained in:
Kristina Lim
2019-07-13 03:57:56 +10:00
parent 8a048cc155
commit 2c279fd02d
3 changed files with 10 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
module LineItemBasedAdjustmentHandling
extend ActiveSupport::Concern
included do
has_many :adjustments_for_which_source, class_name: "Spree::Adjustment", as: :source,
dependent: :destroy
end
end

View File

@@ -3,6 +3,7 @@ require 'open_food_network/variant_and_line_item_naming'
Spree::LineItem.class_eval do
include OpenFoodNetwork::VariantAndLineItemNaming
include LineItemBasedAdjustmentHandling
has_and_belongs_to_many :option_values, join_table: 'spree_option_values_line_items', class_name: 'Spree::OptionValue'
# Redefining here to add the inverse_of option

View File

@@ -398,7 +398,7 @@ describe Spree::Order do
expect(order.line_items(:reload).map(&:variant)).to eq([v2])
end
pending "removes the variant's adjustment" do
it "removes the variant's adjustment" do
line_item = order.line_items.where(variant_id: v1.id).first
adjustment_scope = Spree::Adjustment.where(source_type: "Spree::LineItem",
source_id: line_item.id)