From 9cd1167f8569b15a3b8339bdf441a287ef6e9eb2 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Tue, 3 Mar 2026 03:28:38 -0600 Subject: [PATCH] Change exceeding and nearing limits to account for the 1000th card (#2345) * Change exceeding and nearing limits to account for the 1000th card (instead of 1001) * Add boundary condition tests for card limit checks Tests now verify behavior at exactly the limit (1000 cards) and at the nearing threshold (remaining = 100), covering the off-by-one fix. --------- Co-authored-by: Jorge Manrubia --- saas/app/models/account/limited.rb | 4 ++-- saas/test/models/account/limited_test.rb | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/saas/app/models/account/limited.rb b/saas/app/models/account/limited.rb index 8e846a117..2918e90a3 100644 --- a/saas/app/models/account/limited.rb +++ b/saas/app/models/account/limited.rb @@ -21,11 +21,11 @@ module Account::Limited end def nearing_plan_cards_limit? - plan.limit_cards? && remaining_cards_count < NEAR_CARD_LIMIT_THRESHOLD + plan.limit_cards? && remaining_cards_count <= NEAR_CARD_LIMIT_THRESHOLD end def exceeding_card_limit? - plan.limit_cards? && billed_cards_count > plan.card_limit + plan.limit_cards? && billed_cards_count >= plan.card_limit end def nearing_plan_storage_limit? diff --git a/saas/test/models/account/limited_test.rb b/saas/test/models/account/limited_test.rb index 828386023..fff154451 100644 --- a/saas/test/models/account/limited_test.rb +++ b/saas/test/models/account/limited_test.rb @@ -10,10 +10,11 @@ class Account::LimitedTest < ActiveSupport::TestCase accounts(:initech).update_column(:cards_count, 899) assert_not accounts(:initech).nearing_plan_cards_limit? - # Free plan near limit + # Free plan at exactly the threshold (remaining = 100) accounts(:initech).update_column(:cards_count, 900) - assert_not accounts(:initech).nearing_plan_cards_limit? + assert accounts(:initech).nearing_plan_cards_limit? + # Free plan over the threshold accounts(:initech).update_column(:cards_count, 901) assert accounts(:initech).nearing_plan_cards_limit? end @@ -27,6 +28,10 @@ class Account::LimitedTest < ActiveSupport::TestCase accounts(:initech).update_column(:cards_count, 999) assert_not accounts(:initech).exceeding_card_limit? + # Free plan at exactly the limit + accounts(:initech).update_column(:cards_count, 1000) + assert accounts(:initech).exceeding_card_limit? + # Free plan over limit accounts(:initech).update_column(:cards_count, 1001) assert accounts(:initech).exceeding_card_limit?