feat(payment-gated-subs): Delegate downgrade logic to its own service#5502
Open
osmarluz wants to merge 3 commits into
Open
feat(payment-gated-subs): Delegate downgrade logic to its own service#5502osmarluz wants to merge 3 commits into
osmarluz wants to merge 3 commits into
Conversation
ancorcruz
approved these changes
May 14, 2026
Contributor
ancorcruz
left a comment
There was a problem hiding this comment.
Could we add a case covering the rescue ActiveRecord::RecordInvalid branch? in spec/services/subscriptions/plan_downgrade_service_spec.rb. Something like:
context "when creating the next subscription fails validation" do
before do
allow_any_instance_of(Subscription)
.to receive(:save!)
.and_raise(ActiveRecord::RecordInvalid.new(Subscription.new))
end
it "returns a record validation failure" do
expect(result).not_to be_success
expect(result.error).to be_a(BaseService::ValidationFailure)
end
end
Right now the rescue branch is uncovered for a freshly-extracted service — would rather pin it down.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Subscriptions::PlanUpgradeServicealready owns the upgrade flow, but downgrades stayed inline inSubscriptions::CreateService. This PR brings the two paths into symmetry ahead of the payment-gating work for plan changes (Milestone 3). Pure refactor — no behavior change.Description
Subscriptions::PlanDowngradeService(new) owns the downgrade flow, mirroringSubscriptions::PlanUpgradeService. Returnsresult.subscription = current_subscription— the load-bearing difference from upgrades, which return the new subscription.Subscriptions::CreateService#downgrade_subscriptioncollapses to a one-line delegation to the new service.