File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff 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
1519end
Original file line number Diff line number Diff line change 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 %>
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments