Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Two cloud plans: without our AI (cloud) and with it (cloud_ai)
Guido Boyke1fe701ab1773
diff --git a/app/controllers/api/public/v1/price_lists_controller.rb b/app/controllers/api/public/v1/price_lists_controller.rbindex b4babe9..85c0a50 100644--- a/app/controllers/api/public/v1/price_lists_controller.rb+++ b/app/controllers/api/public/v1/price_lists_controller.rb@@ -3,15 +3,31 @@module Apimodule Publicmodule V1- # Returns the price list currently published for the public website.+ # Returns the price lists currently published for the public website.+ #+ # `show` (GET /price_list) is the first contract and answers for the plan+ # 'cloud' only; it stays until the website reads `index`. `index`+ # (GET /price_lists, since 2026-10-15) answers for every plan that has a+ # price level in force, so the website gets both prices from one request+ # and one moment (doc/billing_preisliste_rabatt_plan.md §13).class PriceListsController < Api::Public::BaseController# Keep publication changes bounded while still making the endpoint CDN-friendly.CACHE_TTL = 5.minutes+ def index+ by_plan = Subscriptions::PriceLookup.current_by_plan+ price_lists = Subscriptions::Constants::PLAN_KEYS.filter_map { |plan_key| by_plan[plan_key] }+ render_cached Subscriptions::PublicPriceListPayload.collection(price_lists: price_lists)+ end+def showprice_list = Subscriptions::PriceLookup.current- payload = Subscriptions::PublicPriceListPayload.call(price_list: price_list)+ render_cached Subscriptions::PublicPriceListPayload.call(price_list: price_list)+ end++ private+ def render_cached(payload)# Derive the cache identity from the response bytes so a list change cannot reuse an ETag.body = ActiveSupport::JSON.encode(payload)diff --git a/app/models/account.rb b/app/models/account.rbindex 428b05b..a1f1c90 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -5,6 +5,7 @@# Table name: accounts## id :uuid not null, primary key+# acquisition :jsonb# billing_addressee :string# billing_city :string# billing_country :string(2)@@ -24,6 +25,7 @@# guest_max_projects_per_organisation :integer default(1), not null# name :string not null# payment_terms_days :integer default(14), not null+# plan_key :string default("cloud"), not null# vat_id_checked_at :datetime# vat_id_checked_name :string# vat_id_status :string default("unchecked"), not null@@ -130,6 +132,9 @@ class Account < ApplicationRecord# permit them: a customer setting their own billing start date would be# writing their own invoice.validates :billing_interval, inclusion: { in: Subscriptions::Constants::BILLING_INTERVAL_KEYS }+ # The booked plan (§13 of doc/billing_preisliste_rabatt_plan.md), an operator+ # field like the interval. Booked, not enforced: the AI code never reads it.+ validates :plan_key, inclusion: { in: Subscriptions::Constants::PLAN_KEYS }validates :payment_terms_days,presence: true, numericality: { only_integer: true, greater_than: 0 }validate :billing_starts_on_must_be_parsablediff --git a/app/models/concerns/subscriptions/constants.rb b/app/models/concerns/subscriptions/constants.rbindex c881f81..2d6bfc7 100644--- a/app/models/concerns/subscriptions/constants.rb+++ b/app/models/concerns/subscriptions/constants.rb@@ -21,8 +21,16 @@ module Subscriptions# amounts (V4); a hardcoded factor would be the second price source that this# whole plan removes.module Constants+ # Two prices for the same product (doc/billing_preisliste_rabatt_plan.md §13).+ # PLAN_CLOUD is every account without AI on the operator's own credentials:+ # no AI at all, or the organisation's own key. PLAN_CLOUD_AI is the price+ # with the operator's curated AI. The plan is BOOKED, not enforced: nothing+ # in the AI code reads it, an account on PLAN_CLOUD may still pick an AI+ # package, and the invoice settles it. Each plan has its own price levels;+ # PriceList, PriceLookup and PriceListGaps already work per plan.PLAN_CLOUD = 'cloud'- PLAN_KEYS = [PLAN_CLOUD].freeze+ PLAN_CLOUD_AI = 'cloud_ai'+ PLAN_KEYS = [PLAN_CLOUD, PLAN_CLOUD_AI].freeze# What a price level is denominated in unless it says otherwise. Named here# rather than repeated as a literal, so the day a second currency appearsdiff --git a/app/services/subscriptions/account_summaries.rb b/app/services/subscriptions/account_summaries.rbindex 057e05d..397d1c6 100644--- a/app/services/subscriptions/account_summaries.rb+++ b/app/services/subscriptions/account_summaries.rb@@ -5,11 +5,11 @@# account index. Turns a list of accounts into what those pages render, so the# two of them cannot disagree about seats or amount.#-# The price level is resolved ONCE for the whole list and handed to every-# AmountPreview via `price_list:`. Without that each row would resolve the-# ladder again, which is the N+1 that argument exists to prevent. `tier_in`-# then filters the already loaded tiers in memory, so the ladder costs one-# query no matter how many rows there are.+# The price levels of all plans are resolved ONCE for the whole list and each+# row gets the one of its account's plan via `price_list:`. Without that each+# row would resolve the ladder again, which is the N+1 that argument exists to+# prevent. `tier_in` then filters the already loaded tiers in memory, so the+# ladders cost the same few queries no matter how many rows there are.## Seats are the one cost that DOES scale, and it scales with the size of the# account rather than with the number of rows: SeatCounter walks each@@ -76,13 +76,13 @@ module Subscriptionsenddef call- price_list = PriceLookup.current+ price_lists = PriceLookup.current_by_plandisplayable(@accounts).map do |account|Row.new(account: account,organisations: account.organisations.sort_by(&:name),- amount: amount_for(account, price_list)+ amount: amount_for(account, price_lists[account.plan_key]))endenddiff --git a/app/services/subscriptions/amount_preview.rb b/app/services/subscriptions/amount_preview.rbindex 3dcdf1f..263c9b7 100644--- a/app/services/subscriptions/amount_preview.rb+++ b/app/services/subscriptions/amount_preview.rb@@ -67,6 +67,8 @@ module Subscriptions# already resolved the level. Without it every iteration of a loop -- the# public pricing page, an account list -- would resolve it again and turn# into an N+1.+ # plan_key: defaults to the plan the account is booked on. Passing one is for+ # the question "what would this account cost on the other plan".# Distinguishes "no price_list argument" from "price_list: nil". A plain# truthiness check conflated the two, and the difference is exactly the N+1# the argument exists to prevent: a caller that already resolved the level@@ -75,11 +77,11 @@ module Subscriptionsprivate_constant :NO_PRICE_LIST_GIVENdef initialize(account:, billing_interval: Constants::INTERVAL_MONTHLY,- plan_key: Constants::PLAN_CLOUD, on: Date.current,+ plan_key: nil, on: Date.current,seats: nil, price_list: NO_PRICE_LIST_GIVEN)@account = account@billing_interval = billing_interval- @plan_key = plan_key+ @plan_key = plan_key || account.plan_key@on = on@seats = seats@price_list_given = !price_list.equal?(NO_PRICE_LIST_GIVEN)diff --git a/app/services/subscriptions/price_list_gaps.rb b/app/services/subscriptions/price_list_gaps.rbindex b7866cf..2fdaab2 100644--- a/app/services/subscriptions/price_list_gaps.rb+++ b/app/services/subscriptions/price_list_gaps.rb@@ -23,10 +23,25 @@ module Subscriptions# seamless. `to: nil` means the gap never closes -- no open-ended level# follows.def upcoming(plan_key: Constants::PLAN_CLOUD, from: Date.current)+ gaps_in(relevant_lists(plan_key, from), from)+ end++ # The same answer for every plan, as { plan_key => gaps }, from one query.+ # A plan that never had a level has one open gap from `from` on: a plan+ # nobody can be priced on is exactly what the warning is for.+ def upcoming_by_plan(from: Date.current)+ by_plan = relevant_lists(Constants::PLAN_KEYS, from).group_by(&:plan_key)+ Constants::PLAN_KEYS.index_with { |plan_key| gaps_in(by_plan.fetch(plan_key, []), from) }+ end++ private++ # `price_lists` ordered by start, all of one plan.+ def gaps_in(price_lists, from)gaps = []cursor = from- relevant_lists(plan_key, from).each do |price_list|+ price_lists.each do |price_list|gaps << { from: cursor, to: price_list.starts_on - 1.day } if price_list.starts_on > cursor# An open-ended level covers everything after it -- nothing left to check.return gaps if price_list.ends_on.nil?@@ -38,10 +53,9 @@ module Subscriptionsgapsend- private-# Levels that already ended are irrelevant: they cannot cover a future- # date and would only shift the cursor backwards.+ # date and would only shift the cursor backwards. `plan_key` may be one+ # key or several.def relevant_lists(plan_key, from)PriceList.for_plan(plan_key).where(ends_on: from..).or(PriceList.for_plan(plan_key).where(ends_on: nil))diff --git a/app/services/subscriptions/price_lookup.rb b/app/services/subscriptions/price_lookup.rbindex 4023ed7..f2018b0 100644--- a/app/services/subscriptions/price_lookup.rb+++ b/app/services/subscriptions/price_lookup.rb@@ -27,6 +27,20 @@ module Subscriptions.firstend+ # The level in force on `on` for every plan that has one, as+ # { plan_key => PriceList }, in one query. For the callers that need+ # several plans at once (the account list, the public price lists); one+ # `.current` per plan would be an N+1 over the plan registry.+ def current_by_plan(on: Date.current)+ PriceList.where(plan_key: Constants::PLAN_KEYS)+ .effective_on(on)+ .includes(:tiers)+ # Same tie-break as .current: the most recent start wins.+ .order(starts_on: :desc)+ .group_by(&:plan_key)+ .transform_values(&:first)+ end+# The rung for `seats`, or nil when no price level applies or no rung# covers that seat count.def tier_for(seats:, billing_interval: Constants::INTERVAL_MONTHLY,diff --git a/app/services/subscriptions/public_price_list_payload.rb b/app/services/subscriptions/public_price_list_payload.rbindex 6164470..e32e183 100644--- a/app/services/subscriptions/public_price_list_payload.rb+++ b/app/services/subscriptions/public_price_list_payload.rb@@ -3,12 +3,19 @@# Serializes one published price list into the stable public API contract used# by the website. Internal identifiers, audit fields and validity dates stay out.# Contract and field semantics: docs/api/public_v1.md.+#+# `call` wraps one list (GET /price_list), `collection` several, one per plan+# (GET /price_lists). Both serialize a list the same way.module Subscriptionsclass PublicPriceListPayloaddef self.call(**kwargs)new(**kwargs).callend+ def self.collection(price_lists:)+ { data: { price_lists: price_lists.map { |price_list| new(price_list: price_list).serialized_price_list } } }+ end+def initialize(price_list:)@price_list = price_listend@@ -17,8 +24,6 @@ module Subscriptions{ data: { price_list: serialized_price_list } }end- private-def serialized_price_listreturn nil if @price_list.nil?@@ -33,6 +38,8 @@ module Subscriptions}end+ private+def billing_intervals(tiers)published = tiers.map(&:billing_interval).uniqConstants::BILLING_INTERVAL_KEYS.filter_map do |key|diff --git a/app/views/billing_accounts/show.html.erb b/app/views/billing_accounts/show.html.erbindex eb6b6be..b132085 100644--- a/app/views/billing_accounts/show.html.erb+++ b/app/views/billing_accounts/show.html.erb@@ -104,13 +104,18 @@</tbody></table>- <%# The amounts follow the account's own billing interval, so naming it is what keeps- a yearly figure from being read as a monthly one. spec/locales/billing_interval_keys_spec.rb- covers every registry interval in both locales. %>+ <%# The amounts follow the account's own billing interval and plan, so naming both is+ what keeps a yearly figure from being read as a monthly one, and the price with AI+ from being read as the price without. spec/locales/billing_interval_keys_spec.rb+ covers every registry interval and plan in both locales. %><p class="text-sm text-cream-600 mt-3"><%= t('views.billing_accounts.show.interval_note',interval: t("views.billing_accounts.show.billing_interval.#{@account.billing_interval}")) %></p>+ <p class="text-sm text-cream-600 mt-1">+ <%= t('views.billing_accounts.show.plan_note',+ plan: t("views.billing_accounts.show.plan.#{@account.plan_key}")) %>+ </p><% if @active_discount %><p class="text-sm text-cream-700 mt-4">diff --git a/config/locales/billing_accounts.de.yml b/config/locales/billing_accounts.de.ymlindex 4df49c7..aa5984b 100644--- a/config/locales/billing_accounts.de.yml+++ b/config/locales/billing_accounts.de.yml@@ -67,6 +67,10 @@ de:monthly: Monatlichyearly: Jährlichinterval_note: 'Abrechnungszeitraum: %{interval}'+ plan:+ cloud: Ohne KI oder mit eigenem KI-Schlüssel+ cloud_ai: Mit der KI-Auswahl des Betreibers+ plan_note: 'Gebuchte Variante: %{plan}'discount_note: Enthalten ist dein Rabatt von %{percent} %, gültig bis %{until}.discount_open_end: auf Weiterespreview_disclaimer: 'Die Vorschau zeigt, was die heutige Zahl an Personen kostet.diff --git a/config/locales/billing_accounts.en.yml b/config/locales/billing_accounts.en.ymlindex 2ab7bc9..d6a743b 100644--- a/config/locales/billing_accounts.en.yml+++ b/config/locales/billing_accounts.en.yml@@ -55,6 +55,10 @@ en:monthly: Monthlyyearly: Yearlyinterval_note: 'Billing period: %{interval}'+ plan:+ cloud: Without AI or with your own AI key+ cloud_ai: With the operator's AI selection+ plan_note: 'Booked plan: %{plan}'discount_note: This includes your %{percent} % discount, valid until %{until}.discount_open_end: further noticepreview_disclaimer: 'The preview shows what today''s number of people costs. Itdiff --git a/config/routes.rb b/config/routes.rbindex 451ed94..2f12934 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -871,6 +871,7 @@ Rails.application.routes.draw donamespace :public donamespace :v1 doresource :price_list, only: :show, format: false+ resources :price_lists, only: :index, format: falseendenddiff --git a/db/migrate/20261015120000_add_plan_key_to_accounts.rb b/db/migrate/20261015120000_add_plan_key_to_accounts.rbnew file mode 100644index 0000000..5de57a2--- /dev/null+++ b/db/migrate/20261015120000_add_plan_key_to_accounts.rb@@ -0,0 +1,10 @@+# frozen_string_literal: true++# The plan an account is billed on (doc/billing_preisliste_rabatt_plan.md §13).+# Every existing account stays on 'cloud', the price it pays today; a constant+# default adds the column without rewriting the table.+class AddPlanKeyToAccounts < ActiveRecord::Migration[8.1]+ def change+ add_column :accounts, :plan_key, :string, default: 'cloud', null: false+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 910010d..e23fec8 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[8.1].define(version: 2026_10_07_120000) do+ActiveRecord::Schema[8.1].define(version: 2026_10_15_120000) do# These are extensions that must be enabled in order to support this databaseenable_extension "pg_catalog.plpgsql"enable_extension "pgcrypto"@@ -68,6 +68,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_10_07_120000) dot.uuid "business_confirmed_by_id"t.string "business_confirmation_version"t.jsonb "acquisition"+ t.string "plan_key", default: "cloud", null: falset.index ["billing_starts_on"], name: "index_accounts_on_billing_starts_on"t.index ["business_confirmed_by_id"], name: "index_accounts_on_business_confirmed_by_id"t.index ["owner_id"], name: "index_accounts_on_owner_id"diff --git a/spec/factories/accounts.rb b/spec/factories/accounts.rbindex 95f1be4..2af891c 100644--- a/spec/factories/accounts.rb+++ b/spec/factories/accounts.rb@@ -5,6 +5,7 @@# Table name: accounts## id :uuid not null, primary key+# acquisition :jsonb# billing_addressee :string# billing_city :string# billing_country :string(2)@@ -24,6 +25,7 @@# guest_max_projects_per_organisation :integer default(1), not null# name :string not null# payment_terms_days :integer default(14), not null+# plan_key :string default("cloud"), not null# vat_id_checked_at :datetime# vat_id_checked_name :string# vat_id_status :string default("unchecked"), not nulldiff --git a/spec/locales/billing_interval_keys_spec.rb b/spec/locales/billing_interval_keys_spec.rbindex 99b7ac2..14e689e 100644--- a/spec/locales/billing_interval_keys_spec.rb+++ b/spec/locales/billing_interval_keys_spec.rb@@ -3,7 +3,9 @@require 'rails_helper'# Guard: every billing interval in the registry has a label and a billing note,-# in BOTH locales.+# in BOTH locales. Since 2026-10-15 the same for every plan in+# `Subscriptions::Constants::PLAN_KEYS`: the billing-account view names the+# booked plan through a key built the same way.## Why this exists (the drift it prevents):# `Subscriptions::Constants::BILLING_INTERVALS` is a REGISTRY (D10). Two places@@ -36,12 +38,14 @@ require 'rails_helper'# configured, `I18n.exists?(key, :en)` answers true for a key that exists only in# German, which is exactly the drift this guard is meant to catch.RSpec.describe 'Billing interval locale keys' do- # Every I18n scope that builds per-interval keys from the registry, with the- # groups it builds underneath. Adding a consumer means adding a line here, not- # writing a second guard.+ # Every I18n scope that builds keys from a registry, with the group it builds+ # underneath and the registry it reads. Adding a consumer means adding a line+ # here, not writing a second guard.key_sources = [- { scope: %i[views billing_accounts show], groups: %i[billing_interval] },- { scope: %i[admin], groups: %i[billing_interval] }+ { scope: %i[views billing_accounts show], groups: %i[billing_interval],+ registry: Subscriptions::Constants::BILLING_INTERVAL_KEYS },+ { scope: %i[admin], groups: %i[billing_interval], registry: Subscriptions::Constants::BILLING_INTERVAL_KEYS },+ { scope: %i[views billing_accounts show], groups: %i[plan], registry: Subscriptions::Constants::PLAN_KEYS }].freezelocales = %i[de en].freeze@@ -58,24 +62,23 @@ RSpec.describe 'Billing interval locale keys' dolocales.each do |locale|source[:groups].each do |group|- Subscriptions::Constants::BILLING_INTERVAL_KEYS.each do |interval|- it "has #{locale}.#{scope_label}.#{group}.#{interval}" do- value = stored(locale, *scope, group, interval.to_sym)+ source[:registry].each do |entry|+ it "has #{locale}.#{scope_label}.#{group}.#{entry}" do+ value = stored(locale, *scope, group, entry.to_sym)expect(value).to be_present,- "missing #{locale}.#{scope_label}.#{group}.#{interval} — " \- 'this key is built from ' \- 'Subscriptions::Constants::BILLING_INTERVAL_KEYS'+ "missing #{locale}.#{scope_label}.#{group}.#{entry}: this key is built from " \+ 'a registry in Subscriptions::Constants'endend- # The other half of the contract: a stale label for an interval that left+ # The other half of the contract: a stale label for an entry that left# the registry is dead weight, and the next reader cannot tell it from a# live one.it "has no #{locale}.#{scope_label}.#{group} entry outside the registry" dostored_keys = (stored(locale, *scope, group) || {}).keys.map(&:to_s)- expect(stored_keys).to match_array(Subscriptions::Constants::BILLING_INTERVAL_KEYS)+ expect(stored_keys).to match_array(source[:registry])endendenddiff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rbindex bb942bf..3477835 100644--- a/spec/models/account_spec.rb+++ b/spec/models/account_spec.rb@@ -5,6 +5,7 @@# Table name: accounts## id :uuid not null, primary key+# acquisition :jsonb# billing_addressee :string# billing_city :string# billing_country :string(2)@@ -24,6 +25,7 @@# guest_max_projects_per_organisation :integer default(1), not null# name :string not null# payment_terms_days :integer default(14), not null+# plan_key :string default("cloud"), not null# vat_id_checked_at :datetime# vat_id_checked_name :string# vat_id_status :string default("unchecked"), not null@@ -109,6 +111,39 @@ RSpec.describe Account, type: :model doexpect(account).not_to be_validend+ # §13 of doc/billing_preisliste_rabatt_plan.md: new customers start without+ # the AI surcharge, and every existing account stayed there by the default.+ # The DATABASE default, not the factory's: every account that existed before+ # the column, and every one the signup creates, lands here without anyone+ # setting it.+ it 'starts on the plan without AI by the column default' do+ account = described_class.create!(name: 'Konto ohne Angabe')++ expect(account.reload.plan_key).to eq(Subscriptions::Constants::PLAN_CLOUD)+ end++ Subscriptions::Constants::PLAN_KEYS.each do |key|+ it "accepts the plan #{key}" do+ expect(build(:account, plan_key: key)).to be_valid+ end+ end++ ['enterprise', 'Cloud', ' cloud', 'cloud_ai ', ''].each do |bad|+ it "rejects the plan #{bad.inspect}" do+ account = build(:account, plan_key: bad)++ expect(account).not_to be_valid+ expect(account.errors[:plan_key]).to be_present+ end+ end++ # Defense in depth: the validation can be skipped, the column cannot be emptied.+ it 'refuses NULL in the database when the validation is bypassed' do+ account = create(:account)++ expect { account.update_column(:plan_key, nil) }.to raise_error(ActiveRecord::NotNullViolation)+ end+it 'rejects a non-positive payment_terms_days' doexpect(build(:account, payment_terms_days: 0)).not_to be_validenddiff --git a/spec/requests/billing_accounts_list_spec.rb b/spec/requests/billing_accounts_list_spec.rbindex c0991b3..e72d569 100644--- a/spec/requests/billing_accounts_list_spec.rb+++ b/spec/requests/billing_accounts_list_spec.rb@@ -167,6 +167,28 @@ RSpec.describe 'BillingAccounts list', type: :request doendend+ # AccountSummaries resolves one level per plan, not one for the whole list: an+ # account booked on the AI plan must not be listed at the price without AI.+ it 'lists each account at the price of its own plan' do+ owner = create(:user)+ plans = { 'Konto ohne KI' => Subscriptions::Constants::PLAN_CLOUD,+ 'Konto mit KI' => Subscriptions::Constants::PLAN_CLOUD_AI }+ plans.each do |name, plan|+ account = create(:account, owner: owner, name: name, plan_key: plan, billing_starts_on: Date.current)+ make_account_admin(owner, create(:organisation, account: account))+ end+ [[Subscriptions::Constants::PLAN_CLOUD, 1000], [Subscriptions::Constants::PLAN_CLOUD_AI, 1300]].each do |plan, cents|+ list = create(:price_list, plan_key: plan)+ create(:price_tier, price_list: list, min_seats: 1, max_seats: nil,+ base_amount_cents: 0, per_seat_amount_cents: cents)+ end+ sign_in owner++ get billing_accounts_path++ expect(response.body).to include(formatted_price(1000), formatted_price(1300))+ end+describe 'cost shape' doit 'grows by exactly one query per additional organisation in the account' dosiblings = 5diff --git a/spec/requests/billing_accounts_spec.rb b/spec/requests/billing_accounts_spec.rbindex edd7032..12ba327 100644--- a/spec/requests/billing_accounts_spec.rb+++ b/spec/requests/billing_accounts_spec.rb@@ -185,6 +185,27 @@ RSpec.describe 'BillingAccounts', type: :request doexpect(response.body).to include(I18n.t('views.billing_accounts.show.preview_disclaimer'))end+ # §13 of doc/billing_preisliste_rabatt_plan.md: the page prices the plan the account+ # is booked on and names it, so 13 EUR is never read as the price without AI.+ it 'prices and names the booked plan' do+ [[Subscriptions::Constants::PLAN_CLOUD, 1000], [Subscriptions::Constants::PLAN_CLOUD_AI, 1300]].each do |plan, cents|+ list = create(:price_list, plan_key: plan)+ create(:price_tier, price_list: list, min_seats: 1, max_seats: nil,+ base_amount_cents: 0, per_seat_amount_cents: cents)+ end+ account.update!(plan_key: Subscriptions::Constants::PLAN_CLOUD_AI)+ sign_in_owner++ get billing_account_path(account)++ # One billable seat (the owner).+ expect(response.body).to include(formatted_price(1300))+ expect(response.body).not_to include(formatted_price(1000))+ expect(response.body).to include(+ ERB::Util.html_escape(I18n.t('views.billing_accounts.show.plan.cloud_ai'))+ )+ end+# A missing price rung is our gap, not the customer's. Wording it as an error would# produce a support request nobody on the customer side can act on.it 'says the price is still being sorted out when no rung applies' dodiff --git a/spec/services/subscriptions/amount_preview_spec.rb b/spec/services/subscriptions/amount_preview_spec.rbindex 9f5d04c..36163a9 100644--- a/spec/services/subscriptions/amount_preview_spec.rb+++ b/spec/services/subscriptions/amount_preview_spec.rb@@ -309,6 +309,36 @@ RSpec.describe Subscriptions::AmountPreview doendend+ # Two prices for the same product (§13 of doc/billing_preisliste_rabatt_plan.md):+ # the account's booked plan decides which level applies, so a caller that only+ # passes the account cannot price it on the wrong plan.+ describe 'the plan' do+ def publish(plan_key, per_seat_cents)+ list = create(:price_list, plan_key: plan_key, starts_on: today - 1.day, ends_on: nil)+ create(:price_tier, price_list: list, min_seats: 1, max_seats: nil,+ base_amount_cents: 0, per_seat_amount_cents: per_seat_cents)+ end++ before do+ publish(Subscriptions::Constants::PLAN_CLOUD, 1000)+ publish(Subscriptions::Constants::PLAN_CLOUD_AI, 1300)+ end++ it 'prices a new account on the plan without AI' do+ expect(preview.total_cents).to eq(5000)+ end++ it 'prices an account booked on the AI plan on that plan' do+ account.update!(plan_key: Subscriptions::Constants::PLAN_CLOUD_AI)++ expect(preview.total_cents).to eq(6500)+ end++ it 'prices the other plan when a caller asks for it' do+ expect(preview(plan_key: Subscriptions::Constants::PLAN_CLOUD_AI).total_cents).to eq(6500)+ end+ end+describe 'failure propagation' do# SeatCounter raises loudly on a broken organisation (D7 of the billing# plan). Swallowing that here would turn a countable error into a silentlydiff --git a/spec/services/subscriptions/price_list_gaps_spec.rb b/spec/services/subscriptions/price_list_gaps_spec.rbindex 66971d2..2053fef 100644--- a/spec/services/subscriptions/price_list_gaps_spec.rb+++ b/spec/services/subscriptions/price_list_gaps_spec.rb@@ -57,6 +57,18 @@ RSpec.describe Subscriptions::PriceListGaps doendend+ describe '.upcoming_by_plan' do+ it 'answers what .upcoming answers, for every plan, and an open gap for a plan without levels' do+ create(:price_list, plan_key: Subscriptions::Constants::PLAN_CLOUD, starts_on: today - 10, ends_on: today + 4)+ create(:price_list, plan_key: Subscriptions::Constants::PLAN_CLOUD, starts_on: today + 10, ends_on: nil)++ expect(described_class.upcoming_by_plan(from: today)).to eq(+ Subscriptions::Constants::PLAN_CLOUD => [{ from: today + 5, to: today + 9 }],+ Subscriptions::Constants::PLAN_CLOUD_AI => [{ from: today, to: nil }]+ )+ end+ end+describe 'levels that already expired' doit 'ignores them instead of letting them pull the cursor backwards' docreate(:price_list, starts_on: today - 90.days, ends_on: today - 60.days)diff --git a/spec/services/subscriptions/price_lookup_spec.rb b/spec/services/subscriptions/price_lookup_spec.rbindex 89f2bd4..c79dfe8 100644--- a/spec/services/subscriptions/price_lookup_spec.rb+++ b/spec/services/subscriptions/price_lookup_spec.rb@@ -44,6 +44,30 @@ RSpec.describe Subscriptions::PriceLookup doendend+ describe '.current_by_plan' do+ def publish(plan_key, starts_on, ends_on = nil)+ create(:price_list, plan_key: plan_key, starts_on: starts_on, ends_on: ends_on)+ end++ it 'finds the level in force for every plan at once, past and announced ones left out' do+ publish(Subscriptions::Constants::PLAN_CLOUD, today - 30, today - 1)+ cloud = publish(Subscriptions::Constants::PLAN_CLOUD, today)+ cloud_ai = publish(Subscriptions::Constants::PLAN_CLOUD_AI, today - 1, today)+ publish(Subscriptions::Constants::PLAN_CLOUD_AI, today + 1)++ by_plan = described_class.current_by_plan(on: today)++ expect(by_plan).to eq(Subscriptions::Constants::PLAN_CLOUD => cloud,+ Subscriptions::Constants::PLAN_CLOUD_AI => cloud_ai)+ end++ it 'leaves out a plan without a level in force' do+ publish(Subscriptions::Constants::PLAN_CLOUD, today)++ expect(described_class.current_by_plan(on: today).keys).to eq([Subscriptions::Constants::PLAN_CLOUD])+ end+ end+describe '.tier_for -- the V4 ladder at every boundary' dobefore { create(:price_list, :with_v4_monthly_ladder, starts_on: today - 1.day, ends_on: nil) }