summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/solidus_subscriptions/subscription_generator.rb11
-rw-r--r--spec/lib/solidus_subscriptions/subscription_generator_spec.rb13
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/solidus_subscriptions/subscription_generator.rb b/lib/solidus_subscriptions/subscription_generator.rb
index 4f675a7..4910c7c 100644
--- a/lib/solidus_subscriptions/subscription_generator.rb
+++ b/lib/solidus_subscriptions/subscription_generator.rb
@@ -35,6 +35,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
@@ -55,6 +57,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 bbf4e74..72cbfe6 100644
--- a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb
+++ b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb
@@ -45,6 +45,19 @@ RSpec.describe SolidusSubscriptions::SubscriptionGenerator do
payment_source: payment_source,
)
end
+
+ it 'cleanups the subscription line items fields duplicated on the subscription' do
+ attrs = { interval_length: 2, interval_units: :week, end_date: Time.zone.tomorrow }
+ subscription_line_item = create(:subscription_line_item, attrs)
+
+ described_class.activate([subscription_line_item])
+
+ expect(subscription_line_item.reload).to have_attributes(
+ interval_length: nil,
+ interval_units: nil,
+ end_date: nil
+ )
+ end
end
describe '.group' do