diff --git a/saas/app/models/account/billing.rb b/saas/app/models/account/billing.rb index 5b52dd836..7d51b11a9 100644 --- a/saas/app/models/account/billing.rb +++ b/saas/app/models/account/billing.rb @@ -10,14 +10,6 @@ module Account::Billing active_subscription&.plan || Plan.free end - def active_subscription - if comped? - comped_subscription - else - subscription if subscription&.active? - end - end - def subscribed? subscription.present? end @@ -36,6 +28,14 @@ module Account::Billing end private + def active_subscription + if comped? + comped_subscription + else + subscription if subscription&.active? + end + end + def comped_subscription @comped_subscription ||= billing_waiver&.subscription end diff --git a/saas/test/models/account/billing_test.rb b/saas/test/models/account/billing_test.rb index cdb7c3fa9..7283f47da 100644 --- a/saas/test/models/account/billing_test.rb +++ b/saas/test/models/account/billing_test.rb @@ -1,19 +1,19 @@ require "test_helper" class Account::BillingTest < ActiveSupport::TestCase - test "active subscription" do + test "plan reflects active subscription" do account = accounts(:initech) # No subscription - assert_nil account.active_subscription + assert_equal Plan.free, account.plan # Subscription but it is not active account.create_subscription!(plan_key: "monthly_v1", status: "canceled", stripe_customer_id: "cus_test") - assert_nil account.active_subscription + assert_equal Plan.free, account.plan # Active subscription exists account.subscription.update!(status: "active") - assert_equal account.subscription, account.active_subscription + assert_equal Plan.paid, account.plan end test "comped account" do