diff options
-rw-r--r-- | lib/solidus_subscriptions/subscription_generator.rb | 11 | ||||
-rw-r--r-- | spec/lib/solidus_subscriptions/subscription_generator_spec.rb | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/solidus_subscriptions/subscription_generator.rb b/lib/solidus_subscriptions/subscription_generator.rb index 8153912..7acedfa 100644 --- a/lib/solidus_subscriptions/subscription_generator.rb +++ b/lib/solidus_subscriptions/subscription_generator.rb @@ -34,6 +34,8 @@ module SolidusSubscriptions Subscription.create!(subscription_attributes) do |sub| sub.actionable_date = sub.next_actionable_date + end.tap do |_subscription| + cleanup_subscription_line_items(subscription_line_items) end end @@ -54,6 +56,15 @@ module SolidusSubscriptions private + def cleanup_subscription_line_items(subscription_line_items) + ids = subscription_line_items.pluck :id + SolidusSubscriptions::LineItem.where(id: ids).update_all( + interval_length: nil, + interval_units: nil, + end_date: nil + ) + end + def subscription_configuration(subscription_line_item) SubscriptionConfiguration.new( subscription_line_item.interval_length, diff --git a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb index b7d73b8..073281c 100644 --- a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb +++ b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb @@ -44,6 +44,15 @@ RSpec.describe SolidusSubscriptions::SubscriptionGenerator do payment_source: payment_source, ) end + + it 'cleanups the subscription line items fields duplicated on the subscription' do + subscription_line_item = create(:subscription_line_item) + + described_class.activate([subscription_line_item]) + + attrs = %i[interval_length interval_units end_date] + expect(subscription_line_item.reload.slice(attrs).values).to eq [nil, nil, nil] + end end describe '.group' do |