Skip to content

Commit f449f3b

Browse files
gumclawclaude
andcommitted
Fix LinkInvalid on disable for memberships with invalid tier structure
Skip tier version structure validation when a product is being unpublished, so users can disable products even if variant categories were deleted or became inconsistent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3d4fc2a commit f449f3b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

app/models/link.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ def alive_category_variants_presence
13281328

13291329
def valid_tier_version_structure
13301330
return if archived?
1331+
return if purchase_disabled_at.present? && purchase_disabled_at_changed?
13311332

13321333
if variant_categories.alive.size != 1
13331334
errors.add(:base, "Memberships should only have one Tier version category.")

spec/models/link_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,6 +4463,24 @@
44634463
expect(product.is_unpublished_by_admin).to eq true
44644464
end
44654465
end
4466+
4467+
context "when a tiered membership has an invalid tier structure" do
4468+
let(:membership) { create(:product, is_tiered_membership: true) }
4469+
4470+
before do
4471+
# Put the membership in an invalid state by deleting all variant categories
4472+
membership.variant_categories.alive.each { |vc| vc.update!(deleted_at: Time.current) }
4473+
end
4474+
4475+
it "allows unpublishing despite invalid tier structure" do
4476+
expect { membership.unpublish! }.not_to raise_error
4477+
expect(membership.reload.purchase_disabled_at).to be_present
4478+
end
4479+
4480+
it "still validates tier structure on other updates" do
4481+
expect { membership.update!(name: "New Name") }.to raise_error(Link::LinkInvalid, "Memberships should only have one Tier version category.")
4482+
end
4483+
end
44664484
end
44674485

44684486
describe "#alive?" do

0 commit comments

Comments
 (0)