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:
@@ -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?
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user