Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the duplicated fields on subscription creation #202

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/solidus_subscriptions/subscription_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def activate(subscription_line_items)

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

Expand All @@ -54,6 +56,15 @@ def group(subscription_line_items)

private

def cleanup_subscription_line_items(subscription_line_items)
ids = subscription_line_items.pluck :id
SolidusSubscriptions::LineItem.where(id: ids).update_all(
blocknotes marked this conversation as resolved.
Show resolved Hide resolved
interval_length: nil,
interval_units: nil,
end_date: nil
)
end

def subscription_configuration(subscription_line_item)
SubscriptionConfiguration.new(
subscription_line_item.interval_length,
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/solidus_subscriptions/subscription_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
payment_source: payment_source,
)
end

it 'cleanups the subscription line items fields duplicated on the subscription' do
subscription_line_item = create(:subscription_line_item)
igorbp marked this conversation as resolved.
Show resolved Hide resolved

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]
igorbp marked this conversation as resolved.
Show resolved Hide resolved
end
end

describe '.group' do
Expand Down