mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Make subscription line items handle soft deleted variants
This ensures subscription list page works. The variant can be removed from the subscription by the user in the edit subscription page
This commit is contained in:
@@ -10,6 +10,11 @@ class SubscriptionLineItem < ActiveRecord::Base
|
||||
(price_estimate || 0) * (quantity || 0)
|
||||
end
|
||||
|
||||
# Ensure SubscriptionLineItem always has access to soft-deleted Variant attribute
|
||||
def variant
|
||||
Spree::Variant.unscoped { super }
|
||||
end
|
||||
|
||||
# Used to calculators to estimate fees
|
||||
alias_method :amount, :total_estimate
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
describe SubscriptionLineItemSerializer do
|
||||
let(:subscription_line_item) { create(:subscription_line_item) }
|
||||
|
||||
it "serializes a subscription line item with the product name" do
|
||||
serializer = described_class.new(subscription_line_item)
|
||||
|
||||
expect(serializer.to_json).to match subscription_line_item.variant.product.name
|
||||
end
|
||||
|
||||
context "when the variant of the subscription line item is soft deleted" do
|
||||
it "serializers the subscription line item with the product name" do
|
||||
subscription_line_item.variant.update_attribute :deleted_at, Time.zone.now
|
||||
|
||||
serializer = described_class.new(subscription_line_item.reload)
|
||||
|
||||
expect(serializer.to_json).to match subscription_line_item.variant.product.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user