Show the card's daily periodic rate instead of APR/12
Fixes jaysbeekay/sure#1009
Upstream issue: none yet for this change (parent we-promise/sure#5444, answered by jaysbeekay/sure#1006); a draft is ready.
Upstream PR: https://github.com/we-promise/sure/pull/5987 (we-promise/sure#5987, draft, position 2 of the native stack https://github.com/we-promise/sure/stack/5995); same branch, same commits.
Stacked on jaysbeekay/sure#1006 (up/card-daily-interest): this PR's base is that branch, so the diff below is this change alone. It needs #1006's DAY_COUNT_BASES and per-card interest basis. jaysbeekay/sure#1006's latest head (0a05b499a, residual interest) is merged in at 30c3e6778; its monthly_rate summary member goes, since this PR replaces it with daily_rate.
Summary
The card Overview's APR card showed "Monthly rate" as APR / 12 beside an "Estimated interest" figure that #1006 works out at APR / 365 (or / 360). It now shows "Daily rate": the APR over the card's basis days, to five decimal places, which is the rate the interest line uses and the rate a card statement quotes. At 18% that is 0.04932% on actual/365 and 0.05000% on actual/360, where it used to say 1.500%.
What changed
CreditCard#daily_rate(public):apr / DAY_COUNT_BASES.fetch(day_count_convention), nil without an APR. It replaces the privatemonthly_rate, and theStatementSummarymembermonthly_ratebecomesdaily_rate.credit_cards/tabs/_overview.html.erb: the row readsdaily_rate_labeland formats the rate withnumber_to_percentage(..., precision: 5).credit_cards.tabs.overview.monthly_rate_label→daily_rate_labelin en and the 8 locales that translated it: de, es, fr, id, nb, nl, pt-BR, zh-CN.nb.ymlkeeps its CRLF line endings.CreditCard#cycle_interest_moneychargesbalance_days * daily_rate / 100instead of recomputing APR / basis days inline, so the rate shown and the rate charged cannot drift apart. The interest figures do not change.
Tests (red on the base branch, green here)
test/models/credit_card_test.rb
- new "the daily rate divides the APR by the card's interest basis days": 18.99% →
0.05203%(actual/365) and0.05275%(actual/360), formatted as the Overview formats them. 18.99 is fractional, so rounding the APR (19 / 365 = 0.05205%) fails it. Before:NoMethodError: undefined method 'daily_rate'. - "the statement summary shows the interest the open cycle has accrued so far":
assert_equal 1, summary.monthly_rate→assert_equal BigDecimal(12) / 365, summary.daily_rate. Before:NoMethodErroronStatementSummary#daily_rate. - "the statement summary has no interest estimate without an APR": also asserts
summary.daily_rateis nil.
test/controllers/accounts_controller_test.rb
- "credit card overview shows what the cycle costs...": the
monthly_rate_labeland"1.000%"assertions are replaced by "Daily rate" and0.03288%(12% / 365), and the page must no longer contain "Monthly rate" or1.000%. Before:Translation missing: en.credit_cards.tabs.overview.daily_rate_label. - new "credit card overview shows the daily rate on the card's interest basis": an actual/360 card at 12% shows
0.03333%and not0.03288%. Before:Expected /0\.03333%/ to match. - unchanged: "credit card overview hides the APR card when APR is blank".
test/i18n_test.rb#test_card_interest_lines_exist_beside_the_interest_label: daily_rate_label joins the keys every locale that translates estimated_interest_label must carry. Before: en: ... daily_rate_label is missing, de: ... daily_rate_label is missing.
Red run on the base branch's code with the new tests: 261 runs, 3 failures, 3 errors, all of them the six above.
Added after the Gatekeeper review (code-review follow-ups):
test/models/credit_card_test.rbnew "cycle interest charges the daily rate the Overview shows": stubsdaily_rateat 0.1% and expects the interest to follow it. Before:Expected: 0.3e2 Actual: 0.1479e2(the inline APR / 365 ignored the shown rate).- The Overview test now also checks that no available locale still carries
monthly_rate_label(refute I18n.exists?(..., locale)for each). Shown red by putting the key back inde.yml:de still has the monthly rate label.
Mutations (each applied alone; credit_card, accounts_controller and i18n tests re-run)
| # | Mutation | Caught by |
|---|---|---|
| M1 | divisor fixed at 365 (apr / 365) | daily rate model test (actual/360), Overview actual/360 test |
| M2 | APR rounded before dividing (apr.round / ...) | daily rate model test, summary test, both Overview tests |
| M3 | daily_rate_label dropped from de.yml | i18n interest lines test |
| M4 | Overview formats with precision: 3 | both Overview tests |
| M5 | nil-APR guard removed | summary without APR, "hides the APR card when APR is blank" (2 errors) |
| M6 | daily_rate divided by a further 1000 | the new cycle-interest test and 9 other CreditCardTest interest tests |
| M7 | cycle_interest_money back to the inline APR / basis | "cycle interest charges the daily rate the Overview shows" |
Verification
- Full unit suite (beastpc) on 30c3e6778 (this change plus jaysbeekay/sure#1006's latest head merged in):
19501 runs, 0 failures, 8 errors; the 8 errors areReleaseNotesWorkflowTest(nonodein the container), environment noise. On d2e64acc6, before that merge:19490 runs, 0 failures, 8 errors. - Targeted: credit_card, accounts_controller, i18n, credit_cards_controller and credit_cards_helper tests:
312 runs, 0 failures, 0 errors. bin/rubocop(changed Ruby files): no offenses.erb_lint(_overview.html.erb): no errors.bin/brakeman: 0 warnings. No JS, no migration.- Checked against upstream
AGENTS.md: text throught(), functional tokens only (the row's existing classes are unchanged), no new comments carrying history.
Screenshots
Before = #1006's head 71d3ff766, after = this branch at 68a2b238e (the later fixes change no markup); same data (18% APR, actual/365, $600 carried, due date passed). Only the row under the APR changes: "Monthly rate 1.500%" becomes "Daily rate 0.04932%".
| View | Before | After |
|---|---|---|
| Overview, APR card, light, desktop | ![]() | ![]() |
| Overview, APR card, light, phone | ![]() | ![]() |
| Overview, APR card, dark, desktop | ![]() | ![]() |
| Overview, APR card, dark, phone | ![]() | ![]() |
Blast radius
StatementSummary#monthly_rate→daily_rate: read only bycredit_cards/tabs/_overview.html.erb(grep -rn monthly_rate app test, loan methods aside). No other view, API or job reads it.Loan::AmortizationMath.monthly_rateandLoan::Insurance#monthly_rateare separate methods and untouched.CreditCard#daily_rateis read bystatement_summary(the Overview's Daily rate row) and bycycle_interest_money, whose only caller isstatement_summary. The interest figure is unchanged; it now comes from the same method as the row.DAY_COUNT_BASESis still read bydaily_rate, the validation and the form helper.
Overlap with we-promise/sure#5271 (annual fees, open)
git merge-tree of this branch with #5271's head (49db1a05) conflicts only in db/schema.rb and Family::DataImporter::CREDIT_CARD_DETAIL_ATTRIBUTES, the same two conflicts #1006 already has; this change adds none. #5271 leaves monthly_rate and its row as they are, so credit_card.rb, _overview.html.erb and en.yml auto-merge.







