Skip to content

Commit 1203a05

Browse files
committed
Add method to detect card limit exceeded to accounts
1 parent 6024642 commit 1203a05

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

app/models/account/billing.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ def plan
1212
def subscribed?
1313
subscription&.stripe_customer_id.present?
1414
end
15+
16+
def card_limit_exceeded?
17+
cards_count > plan.card_limit
18+
end
1519
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
signals_monthly:
2+
id: <%= ActiveRecord::FixtureSet.identify("signals_monthly", :uuid) %>
3+
account_id: <%= ActiveRecord::FixtureSet.identify("37s", :uuid) %>
4+
plan_key: monthly_v1
5+
status: active
6+
stripe_customer_id: cus_test_37signals
7+
created_at: <%= Time.current %>
8+
updated_at: <%= Time.current %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "test_helper"
2+
3+
class Account::BillingTest < ActiveSupport::TestCase
4+
test "detect card limit exceeded" do
5+
# Paid plans are never limited
6+
accounts(:"37s").update_column(:cards_count, 1_000_000)
7+
assert_not accounts(:"37s").card_limit_exceeded?
8+
9+
# Free plan under limit
10+
accounts(:initech).update_column(:cards_count, 999)
11+
assert_not accounts(:initech).card_limit_exceeded?
12+
13+
# Free plan over limit
14+
accounts(:initech).update_column(:cards_count, 1001)
15+
assert accounts(:initech).card_limit_exceeded?
16+
end
17+
end

0 commit comments

Comments
 (0)