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 <jorge@37signals.com>
This commit is contained in:
Andy Smith
2026-03-03 03:28:38 -06:00
committed by GitHub
parent f6952187c7
commit 9cd1167f85
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -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?
+7 -2
View File
@@ -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?