diff --git a/app/models/concerns/line_item_based_adjustment_handling.rb b/app/models/concerns/line_item_based_adjustment_handling.rb new file mode 100644 index 0000000000..70aa9549c7 --- /dev/null +++ b/app/models/concerns/line_item_based_adjustment_handling.rb @@ -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 diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 710fb56426..dbac611079 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -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 diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 09cb55d215..4327d5e782 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -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)